Fix detection of running of recent Claws Mail
authorRicardo Mones <ricardo@mones.org>
Sun, 7 Feb 2021 18:33:04 +0000 (19:33 +0100)
committerRicardo Mones <ricardo@mones.org>
Sun, 7 Feb 2021 18:33:04 +0000 (19:33 +0100)
Starting in version 3.17.8-15-ge56346845 the socket path is built using
g_get_user_runtime_dir¹ insead of g_get_tmp_dir².

This change rendered the  current detection scheme invalid, though it's
still available as fallback to detect older Claws Mail versions.

This fix hopefully emulates that function by reading the same
environment variables.

¹ https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html#g-get-user-runtime-dir
² https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html#g-get-tmp-dir

clawsker

index d8ae30afc7c11dd3b1401b99593865924aefc320..d68c3898a98edb19af59590c6d8e0a45e4a72884 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -461,16 +461,27 @@ sub claws_is_running {
     return FALSE;
 }
 
-sub check_claws_not_running {
-    return TRUE if $READONLY;
-    my $tmpdir = File::Spec->tmpdir ();
-    my $lockdir = catfile ($tmpdir, "claws-mail-$<");
+sub has_claws_socket {
+    my $lockdir = shift;
     -d $lockdir and do {
         $_ = $CONFIGDIR;
         s/\/$//;
         my $socket = catfile ($lockdir, md5_hex ($_));
-        -S $socket and return claws_is_running ();
+        -S $socket and return TRUE;
+    };
+    return FALSE;
+}
+
+sub check_claws_not_running {
+    return TRUE if $READONLY;
+    my $rundir = $ENV{XDG_RUNTIME_DIR} // $ENV{XDG_CACHE_HOME};
+    defined $rundir and do {
+        my $lockdir = catfile ($rundir, "claws-mail");
+        return claws_is_running () if has_claws_socket ($lockdir);
     };
+    my $tmpdir = File::Spec->tmpdir ();
+    my $lockdir = catfile ($tmpdir, "claws-mail-$<");
+    return claws_is_running () if has_claws_socket ($lockdir);
     return TRUE;
 }