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

Merge pull request #1748 from nandesu-utils/fix/issue1742

Fix https://github.com/profanity-im/profanity/issues/1742
This commit is contained in:
Michael Vetter 2022-09-06 12:56:11 +02:00 committed by GitHub
commit 359e2614ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 25 deletions

View File

@ -445,9 +445,10 @@ get_mentions(gboolean whole_word, gboolean case_sensitive, const char* const mes
gboolean
call_external(gchar** argv, gchar** std_out, gchar** std_err)
{
GError *spawn_error, *status_error;
gboolean spawn_result;
gint exit_status;
GError* spawn_error = NULL;
GError* exit_error = NULL;
gboolean is_successful;
gint wait_status;
GSpawnFlags flags = G_SPAWN_SEARCH_PATH;
if (std_out == NULL)
@ -455,30 +456,34 @@ call_external(gchar** argv, gchar** std_out, gchar** std_err)
if (std_err == NULL)
flags |= G_SPAWN_STDERR_TO_DEV_NULL;
spawn_result = 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,
&exit_status, &spawn_error);
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);
if (!spawn_result || !g_spawn_check_exit_status(exit_status, &status_error)) {
if (!is_successful) {
gchar* cmd = g_strjoinv(" ", argv);
if (spawn_error && spawn_error->message) {
log_error("Spawning '%s' failed with '%s'.", cmd, spawn_error->message);
g_error_free(spawn_error);
} else if (status_error && status_error->message) {
log_error("Spawning '%s' failed with '%s'.", cmd, status_error->message);
g_error_free(status_error);
spawn_result = FALSE;
} else {
log_error("Spawning '%s' failed with.", cmd);
}
log_error("Spawning '%s' failed with 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 spawn_result;
return is_successful;
}
gchar**

View File

@ -339,10 +339,20 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
// if we shall open it
if (g_hash_table_contains(shall_open, from_attr)) {
gchar* argv[] = { prefs_get_string(PREF_AVATAR_CMD), filename->str, NULL };
if (!call_external(argv, NULL, NULL)) {
cons_show_error("Unable to display avatar: check the logs for more information.");
gchar* cmdtemplate = prefs_get_string(PREF_AVATAR_CMD);
if (cmdtemplate == NULL) {
cons_show_error("No default `avatar open` command found in executables preferences.");
} else {
gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
if (!call_external(argv, NULL, NULL)) {
cons_show_error("Unable to display avatar: check the logs for more information.");
}
g_strfreev(argv);
}
g_hash_table_remove(shall_open, from_attr);
}