Added working_directory parameter to execute_command_line()
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).
This commit is contained in:
parent
e66778e76d
commit
d0f52e970e
14 changed files with 35 additions and 29 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue