mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Spawn external programs asynchronously
Drawback is that we can't check the exitcode anymore. But we were unsure why/when we need this, see: https://github.com/profanity-im/profanity/pull/1760/files#r980868708 Fixes https://github.com/profanity-im/profanity/issues/1759
This commit is contained in:
parent
7ffe55e980
commit
2d11a35ee1
@ -9424,7 +9424,7 @@ _url_external_method(const char* cmd_template, const char* url, const char* file
|
|||||||
{
|
{
|
||||||
gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
||||||
|
|
||||||
if (!call_external(argv, NULL, NULL)) {
|
if (!call_external(argv)) {
|
||||||
cons_show_error("Unable to call external executable for url: check the logs for more information.");
|
cons_show_error("Unable to call external executable for url: check the logs for more information.");
|
||||||
} else {
|
} else {
|
||||||
cons_show("URL '%s' has been called with '%s'.", url, cmd_template);
|
cons_show("URL '%s' has been called with '%s'.", url, cmd_template);
|
||||||
|
39
src/common.c
39
src/common.c
@ -443,44 +443,25 @@ get_mentions(gboolean whole_word, gboolean case_sensitive, const char* const mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
call_external(gchar** argv, gchar** std_out, gchar** std_err)
|
call_external(gchar** argv)
|
||||||
{
|
{
|
||||||
GError* spawn_error = NULL;
|
GError* spawn_error;
|
||||||
GError* exit_error = NULL;
|
|
||||||
gboolean is_successful;
|
gboolean is_successful;
|
||||||
gint wait_status;
|
|
||||||
|
|
||||||
GSpawnFlags flags = G_SPAWN_SEARCH_PATH;
|
GSpawnFlags flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
|
||||||
if (std_out == NULL)
|
|
||||||
flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
|
|
||||||
if (std_err == NULL)
|
|
||||||
flags |= G_SPAWN_STDERR_TO_DEV_NULL;
|
|
||||||
|
|
||||||
is_successful = g_spawn_sync(NULL, // Inherit the parent PWD.
|
|
||||||
argv,
|
|
||||||
NULL, // Inherit the parent environment.
|
|
||||||
flags,
|
|
||||||
NULL, NULL, // No func. before exec() in child.
|
|
||||||
std_out, std_err,
|
|
||||||
&wait_status, &spawn_error);
|
|
||||||
|
|
||||||
|
is_successful = g_spawn_async(NULL, // Inherit the parent PWD
|
||||||
|
argv,
|
||||||
|
NULL, // Inherit the parent environment
|
||||||
|
flags,
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
&spawn_error);
|
||||||
if (!is_successful) {
|
if (!is_successful) {
|
||||||
gchar* cmd = g_strjoinv(" ", argv);
|
gchar* cmd = g_strjoinv(" ", argv);
|
||||||
log_error("Spawning '%s' failed with with error '%s'", cmd, spawn_error ? spawn_error->message : "Unknown, spawn_error is NULL");
|
log_error("Spawning '%s' failed with error '%s'", cmd, spawn_error ? spawn_error->message : "Unknown, spawn_error is NULL");
|
||||||
;
|
|
||||||
|
|
||||||
g_error_free(spawn_error);
|
g_error_free(spawn_error);
|
||||||
g_free(cmd);
|
g_free(cmd);
|
||||||
} else {
|
|
||||||
is_successful = g_spawn_check_exit_status(wait_status, &exit_error);
|
|
||||||
|
|
||||||
if (!is_successful) {
|
|
||||||
gchar* cmd = g_strjoinv(" ", argv);
|
|
||||||
log_error("'%s' exited with error '%s'", cmd, exit_error->message);
|
|
||||||
|
|
||||||
g_error_free(exit_error);
|
|
||||||
g_free(cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_successful;
|
return is_successful;
|
||||||
|
@ -103,7 +103,7 @@ void get_file_paths_recursive(const char* directory, GSList** contents);
|
|||||||
|
|
||||||
char* get_random_string(int length);
|
char* get_random_string(int length);
|
||||||
|
|
||||||
gboolean call_external(gchar** argv, gchar** std_out, gchar** std_err);
|
gboolean call_external(gchar** argv);
|
||||||
gchar** format_call_external_argv(const char* template, const char* url, const char* filename);
|
gchar** format_call_external_argv(const char* template, const char* url, const char* filename);
|
||||||
|
|
||||||
gchar* unique_filename_from_url(const char* url, const char* path);
|
gchar* unique_filename_from_url(const char* url, const char* path);
|
||||||
|
@ -155,7 +155,7 @@ aesgcm_file_get(void* userdata)
|
|||||||
aesgcm_dl->filename);
|
aesgcm_dl->filename);
|
||||||
|
|
||||||
// TODO: Log the error.
|
// TODO: Log the error.
|
||||||
if (!call_external(argv, NULL, NULL)) {
|
if (!call_external(argv)) {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
|
||||||
"Downloading '%s' failed: Unable to call "
|
"Downloading '%s' failed: Unable to call "
|
||||||
"command '%s' with file at '%s' (%s).",
|
"command '%s' with file at '%s' (%s).",
|
||||||
|
@ -202,7 +202,7 @@ http_file_get(void* userdata)
|
|||||||
download->filename);
|
download->filename);
|
||||||
|
|
||||||
// TODO: Log the error.
|
// TODO: Log the error.
|
||||||
if (!call_external(argv, NULL, NULL)) {
|
if (!call_external(argv)) {
|
||||||
http_print_transfer_update(download->window, download->url,
|
http_print_transfer_update(download->window, download->url,
|
||||||
"Downloading '%s' failed: Unable to call "
|
"Downloading '%s' failed: Unable to call "
|
||||||
"command '%s' with file at '%s' (%s).",
|
"command '%s' with file at '%s' (%s).",
|
||||||
|
@ -346,7 +346,7 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
|
|||||||
} else {
|
} else {
|
||||||
gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
|
gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
|
||||||
|
|
||||||
if (!call_external(argv, NULL, NULL)) {
|
if (!call_external(argv)) {
|
||||||
cons_show_error("Unable to display avatar: check the logs for more information.");
|
cons_show_error("Unable to display avatar: check the logs for more information.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user