about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-09-06 12:56:11 +0200
committerGitHub <noreply@github.com>2022-09-06 12:56:11 +0200
commit359e2614ff40467306e519931be27f52ac2fe2b1 (patch)
treeb79cc956bf779f7cb965431efb1f5e528ceb3ef2
parent0864bc68d7037abd41cf75901ffaa0cd8bceb04d (diff)
parente1ed012f72495e2d2bdd10520eb943fbba932ed4 (diff)
downloadprofani-tty-359e2614ff40467306e519931be27f52ac2fe2b1.tar.gz
Merge pull request #1748 from nandesu-utils/fix/issue1742
Fix https://github.com/profanity-im/profanity/issues/1742
-rw-r--r--src/common.c49
-rw-r--r--src/xmpp/avatar.c16
2 files changed, 40 insertions, 25 deletions
diff --git a/src/common.c b/src/common.c
index b2496087..de35ea2d 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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**
diff --git a/src/xmpp/avatar.c b/src/xmpp/avatar.c
index 9345ba3a..fb3b01ea 100644
--- a/src/xmpp/avatar.c
+++ b/src/xmpp/avatar.c
@@ -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);
     }