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 ca75a33..182be8e 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 5f35f73..2279b86 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 4dafe97..c8504c9 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 33ccc7e..3a49663 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 b25b724..8de12ba 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 2d97c3d..2363848 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 d36096f..374c1dd 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 602907b..b326632 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 bcd9b84..d8ac10c 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 0da54ec..ac4bfb8 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 235a01a..572cb2c 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 4cbcbf9..d75c72a 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 af30bbb..6eb2320 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 523d060..8f22644 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);