Added working_directory parameter to execute_command_line()
authorAndrej Kacian <ticho@claws-mail.org>
Sat, 23 Jul 2016 20:41:04 +0000 (22:41 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Sat, 23 Jul 2016 20:41:04 +0000 (22:41 +0200)
It gets passed as a first argument to g_spawn_sync/async.
Mostly NULL, since that's what was passed until now, but
bsfilter plugin on Windows needs to change to installation
directory (startup_dir).

14 files changed:
src/common/utils.c
src/common/utils.h
src/inc.c
src/mimeview.c
src/plugins/acpi_notifier/acpi_notifier.c
src/plugins/bogofilter/bogofilter.c
src/plugins/bsfilter/bsfilter.c
src/plugins/bsfilter/claws.def
src/plugins/fancy/claws.def
src/plugins/notification/notification_command.c
src/plugins/pdf_viewer/poppler_viewer.c
src/plugins/spamassassin/spamassassin.c
src/plugins/vcalendar/vcal_folder.c
src/textview.c

index ca75a33ee791f614b9acb7e27349f463467f9b87..182be8e6be97ebfbb3a30ef54972ef8051ee00a6 100644 (file)
@@ -3246,11 +3246,11 @@ char *fgets_crlf(char *buf, int size, FILE *stream)
        return buf;     
 }
 
-static gint execute_async(gchar *const argv[])
+static gint execute_async(gchar *const argv[], const gchar *working_directory)
 {
        cm_return_val_if_fail(argv != NULL && argv[0] != NULL, -1);
 
-       if (g_spawn_async(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
+       if (g_spawn_async(working_directory, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
                          NULL, NULL, NULL, FALSE) == FALSE) {
                g_warning("couldn't execute command: %s", argv[0]);
                return -1;
@@ -3259,14 +3259,14 @@ static gint execute_async(gchar *const argv[])
        return 0;
 }
 
-static gint execute_sync(gchar *const argv[])
+static gint execute_sync(gchar *const argv[], const gchar *working_directory)
 {
        gint status;
 
        cm_return_val_if_fail(argv != NULL && argv[0] != NULL, -1);
 
 #ifdef G_OS_UNIX
-       if (g_spawn_sync(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
+       if (g_spawn_sync(working_directory, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
                         NULL, NULL, NULL, NULL, &status, NULL) == FALSE) {
                g_warning("couldn't execute command: %s", argv[0]);
                return -1;
@@ -3277,8 +3277,10 @@ static gint execute_sync(gchar *const argv[])
        else
                return -1;
 #else
-       if (g_spawn_sync(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH| 
-                        G_SPAWN_CHILD_INHERITS_STDIN|G_SPAWN_LEAVE_DESCRIPTORS_OPEN,
+       if (g_spawn_sync(working_directory, (gchar **)argv, NULL,
+                               G_SPAWN_SEARCH_PATH|
+                               G_SPAWN_CHILD_INHERITS_STDIN|
+                               G_SPAWN_LEAVE_DESCRIPTORS_OPEN,
                         NULL, NULL, NULL, NULL, &status, NULL) == FALSE) {
                g_warning("couldn't execute command: %s", argv[0]);
                return -1;
@@ -3288,7 +3290,8 @@ static gint execute_sync(gchar *const argv[])
 #endif
 }
 
-gint execute_command_line(const gchar *cmdline, gboolean async)
+gint execute_command_line(const gchar *cmdline, gboolean async,
+               const gchar *working_directory)
 {
        gchar **argv;
        gint ret;
@@ -3298,9 +3301,9 @@ gint execute_command_line(const gchar *cmdline, gboolean async)
        argv = strsplit_with_quote(cmdline, " ", 0);
 
        if (async)
-               ret = execute_async(argv);
+               ret = execute_async(argv, working_directory);
        else
-               ret = execute_sync(argv);
+               ret = execute_sync(argv, working_directory);
 
        g_strfreev(argv);
 
@@ -3385,7 +3388,7 @@ gint open_uri(const gchar *uri, const gchar *cmdline)
                g_snprintf(buf, sizeof(buf), DEFAULT_BROWSER_CMD, encoded_uri);
        }
 
-       execute_command_line(buf, TRUE);
+       execute_command_line(buf, TRUE, NULL);
 #else
        ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOW);
 #endif
@@ -3411,7 +3414,7 @@ gint open_txt_editor(const gchar *filepath, const gchar *cmdline)
                g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, filepath);
        }
 
-       execute_command_line(buf, TRUE);
+       execute_command_line(buf, TRUE, NULL);
 
        return 0;
 }
index 5f35f737720d952ff1ec807c7c758d1de98fb3e6..2279b86664701705391259fd1e7815bc51bfc1f3 100644 (file)
@@ -505,7 +505,8 @@ char *fgets_crlf(char *buf, int size, FILE *stream);
 
 /* process execution */
 gint execute_command_line      (const gchar    *cmdline,
-                                gboolean        async);
+                                gboolean        async,
+                                const gchar    *working_directory);
 gchar *get_command_output      (const gchar    *cmdline);
 
 /* open URI with external browser */
index 4dafe9735ac453aac76fc981abd67542d365937f..c8504c9b7620a2bf22c8b48ae3e1dba01a49685b 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -193,7 +193,7 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
 
        if (prefs_common.use_extinc && prefs_common.extinc_cmd) {
                /* external incorporating program */
-               if (execute_command_line(prefs_common.extinc_cmd, FALSE) < 0) {
+               if (execute_command_line(prefs_common.extinc_cmd, FALSE, NULL) < 0) {
                        main_window_unlock(mainwin);
                        inc_autocheck_timer_set();
                        inc_unlock();
@@ -339,7 +339,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
 
        if (prefs_common.use_extinc && prefs_common.extinc_cmd) {
                /* external incorporating program */
-               if (execute_command_line(prefs_common.extinc_cmd, FALSE) < 0) {
+               if (execute_command_line(prefs_common.extinc_cmd, FALSE, NULL) < 0) {
                        log_error(LOG_PROTOCOL, _("%s failed\n"), prefs_common.extinc_cmd);
                        
                        main_window_unlock(mainwin);
@@ -1433,7 +1433,7 @@ static void inc_notify_cmd(gint new_msgs, gboolean notify)
                buf = ret_str;
        }
        debug_print("executing new mail notification command: %s\n", buf);
-       execute_command_line(buf, TRUE);
+       execute_command_line(buf, TRUE, NULL);
 
        g_free(buf);
 }
index 33ccc7e41a7e2b37a209cb740a7880cfc7b1d5b6..3a496638801a28e16c094976ebb2bfbfa047faa4 100644 (file)
@@ -2213,7 +2213,7 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
                        g_warning("MIME viewer command-line is invalid: '%s'", cmd);
                        mimeview_open_part_with(mimeview, partinfo, FALSE);
                }
-               if (execute_command_line(buf, TRUE) != 0) {
+               if (execute_command_line(buf, TRUE, NULL) != 0) {
                        if (!prefs_common.save_parts_readwrite)
                                g_chmod(filename, S_IRUSR|S_IWUSR);
                        mimeview_open_part_with(mimeview, partinfo, FALSE);
index b25b724300039dfae949f93d1f37ebdd59b8df58..8de12ba39b5b6f67e0635c01b4cb3b076dc8ae41 100644 (file)
@@ -680,7 +680,7 @@ static void acpi_set(gboolean on)
                gchar *cmd = g_strdup_printf("%s %s", 
                                acpiprefs.file_path,
                                on ? acpiprefs.on_param:acpiprefs.off_param);
-               execute_command_line(cmd, TRUE);
+               execute_command_line(cmd, TRUE, NULL);
                g_free(cmd);
        }
 }
index 2d97c3d27b7bbb347b4af25f9bcac041d8b08a92..2363848fa2d0836c9ffbbd7891b303ec3bb486c7 100644 (file)
@@ -775,7 +775,7 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                                cmd = g_strdup_printf("%s -n -I '%s'", bogo_exec, file);
                                
                        debug_print("%s\n", cmd);
-                       if ((status = execute_command_line(cmd, FALSE)) != 0)
+                       if ((status = execute_command_line(cmd, FALSE, NULL)) != 0)
                                log_error(LOG_PROTOCOL, _("Learning failed; `%s` returned with status %d."),
                                                cmd, status);
                        g_free(cmd);
@@ -822,7 +822,7 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                                        cmd = g_strdup_printf("%s -n -I '%s'", bogo_exec, file);
                                
                                debug_print("%s\n", cmd);
-                               if ((status = execute_command_line(cmd, FALSE)) != 0)
+                               if ((status = execute_command_line(cmd, FALSE, NULL)) != 0)
                                        log_error(LOG_PROTOCOL, _("Learning failed; `%s` returned with status %d."),
                                                        cmd, status);
 
index d36096f7028e88523c559a70be4818f8e72804af..374c1dd01edd8cf5a3eef35dfcc67e6242d4e65f 100644 (file)
@@ -200,7 +200,8 @@ static void bsfilter_do_filter(BsFilterData *data)
                gchar *classify = g_strconcat((config.bspath && *config.bspath) ? config.bspath:"bsfilterw.exe",
                        " --homedir '",get_rc_dir(),"' '", file, "'", NULL);
 #endif
-               status = execute_command_line(classify, FALSE);
+               status = execute_command_line(classify, FALSE,
+                               claws_get_startup_dir());
        }
 
        if (config.whitelist_ab)
@@ -507,7 +508,8 @@ int bsfilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                                cmd = g_strdup_printf("%s --homedir '%s' -cu '%s'", bs_exec, get_rc_dir(), file);
                                
                        debug_print("%s\n", cmd);
-                       if ((status = execute_command_line(cmd, FALSE)) != 0)
+                       if ((status = execute_command_line(cmd, FALSE,
+                                                       claws_get_startup_dir())) != 0)
                                log_error(LOG_PROTOCOL, _("Learning failed; `%s` returned with status %d."),
                                                cmd, status);
                        g_free(cmd);
index 602907b9e7b14dc4dce33e33e3171a84dc688fdc..b32663297f4142d9186ed5e5855c2f3cb7454b75 100644 (file)
@@ -3,6 +3,7 @@ EXPORTS
 get_locale_dir
 check_plugin_version
 alertpanel
+claws_get_startup_dir
 conv_codeset_strdup
 conv_get_locale_charset_str_no_utf8
 debug_print_real
index bcd9b84f7e691b98e576a80a9fac698a759a3e70..d8ac10cae727e6776f3f1ff153608a77d3b6e2ac 100644 (file)
@@ -16,7 +16,6 @@ conv_get_locale_charset_str_no_utf8
 debug_print_real
 debug_srcname
 end_address_completion
-execute_command_line
 extract_address
 file_exist
 filesel_select_file_open
index 0da54ec9e33ea9e4073fbc6810668069e51c1cda..ac4bfb8157bfbaa6877a265ef8632c7a349ea3a3 100644 (file)
@@ -94,7 +94,7 @@ void notification_command_msg(MsgInfo *msginfo)
       g_free(buf);
       buf = ret_str;
     }
-    execute_command_line(buf, TRUE);
+    execute_command_line(buf, TRUE, NULL);
     g_free(buf);
   }
 
index 235a01a10729629ac6f438cb6e7053211a98480e..572cb2ca89b1f33afc636f8c3606c354474309c6 100644 (file)
@@ -1290,7 +1290,7 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                                        "gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
                                          "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
                                        tmpfile, viewer->filename);
-                               result = execute_command_line(cmdline, FALSE);
+                               result = execute_command_line(cmdline, FALSE, NULL);
                                if (result == 0) {
                                        tmp = g_filename_to_uri(tmpfile, NULL, NULL);
                                        viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
index 4cbcbf918a28aed11c570c5656c62e6edf8e8f21..d75c72a30b3c2521ecffd11b0436348f1d4431ca 100644 (file)
@@ -469,7 +469,7 @@ int spamassassin_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                                        tmpcmd = g_strconcat(shell?shell:"sh", " ", spamc_wrapper, " ",
                                                                                tmpfile, NULL);
                                        debug_print("%s\n", tmpcmd);
-                                       execute_command_line(tmpcmd, FALSE);
+                                       execute_command_line(tmpcmd, FALSE, NULL);
                                        g_free(tmpcmd);
                                }
                                g_free(tmpfile);
@@ -503,7 +503,7 @@ int spamassassin_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
        }
        debug_print("%s\n", cmd);
        /* only run sync calls to sa-learn/spamc to prevent system lockdown */
-       execute_command_line(cmd, FALSE);
+       execute_command_line(cmd, FALSE, NULL);
        g_free(cmd);
        g_free(spamc_wrapper);
 
index af30bbbcd77255666946bbdfcdced4b5dbedefa3..6eb23209d13acefcbb886b2272b35d5d0685a2d2 100644 (file)
@@ -1190,7 +1190,7 @@ void vcal_folder_export(Folder *folder)
                    vcalprefs.export_command &&
                    strlen(vcalprefs.export_command))
                        execute_command_line(
-                               vcalprefs.export_command, TRUE);
+                               vcalprefs.export_command, TRUE, NULL);
        }
        if (export_pass != NULL) {
                memset(export_pass, 0, strlen(export_pass));
@@ -1204,7 +1204,7 @@ void vcal_folder_export(Folder *folder)
                    vcalprefs.export_freebusy_command &&
                    strlen(vcalprefs.export_freebusy_command))
                        execute_command_line(
-                               vcalprefs.export_freebusy_command, TRUE);
+                               vcalprefs.export_freebusy_command, TRUE, NULL);
        }
        if (export_freebusy_pass != NULL) {
                memset(export_freebusy_pass, 0, strlen(export_freebusy_pass));
index 523d060ca72b6fe45d33669d0e26d9eae60d4c70..8f226443d19f069f84cac5d04865b64d2e2cd660 100644 (file)
@@ -3007,7 +3007,7 @@ static void open_image_cb (GtkAction *action, TextView *textview)
                return;
        }
 
-       execute_command_line(buf, TRUE);
+       execute_command_line(buf, TRUE, NULL);
 
        g_free(filepath);
        g_free(filename);