1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge pull request #1760 from techmetx11/fix/1759-async

Replace `call_external`'s implementation with an async one
This commit is contained in:
Michael Vetter 2022-10-12 12:45:07 +02:00 committed by GitHub
commit aa9ba63f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 34 deletions

View File

@ -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);
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.");
} else {
cons_show("URL '%s' has been called with '%s'.", url, cmd_template);

View File

@ -443,44 +443,25 @@ get_mentions(gboolean whole_word, gboolean case_sensitive, const char* const mes
}
gboolean
call_external(gchar** argv, gchar** std_out, gchar** std_err)
call_external(gchar** argv)
{
GError* spawn_error = NULL;
GError* exit_error = NULL;
GError* spawn_error;
gboolean is_successful;
gint wait_status;
GSpawnFlags flags = G_SPAWN_SEARCH_PATH;
if (std_out == NULL)
flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
if (std_err == NULL)
flags |= G_SPAWN_STDERR_TO_DEV_NULL;
GSpawnFlags flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
is_successful = g_spawn_sync(NULL, // Inherit the parent PWD.
is_successful = g_spawn_async(NULL, // Inherit the parent PWD
argv,
NULL, // Inherit the parent environment.
NULL, // Inherit the parent environment
flags,
NULL, NULL, // No func. before exec() in child.
std_out, std_err,
&wait_status, &spawn_error);
NULL, NULL, NULL,
&spawn_error);
if (!is_successful) {
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_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;

View File

@ -103,7 +103,7 @@ void get_file_paths_recursive(const char* directory, GSList** contents);
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* unique_filename_from_url(const char* url, const char* path);

View File

@ -155,7 +155,7 @@ aesgcm_file_get(void* userdata)
aesgcm_dl->filename);
// TODO: Log the error.
if (!call_external(argv, NULL, NULL)) {
if (!call_external(argv)) {
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url,
"Downloading '%s' failed: Unable to call "
"command '%s' with file at '%s' (%s).",

View File

@ -202,7 +202,7 @@ http_file_get(void* userdata)
download->filename);
// TODO: Log the error.
if (!call_external(argv, NULL, NULL)) {
if (!call_external(argv)) {
http_print_transfer_update(download->window, download->url,
"Downloading '%s' failed: Unable to call "
"command '%s' with file at '%s' (%s).",

View File

@ -346,7 +346,7 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
} else {
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.");
}