about summary refs log tree commit diff stats
path: root/src/common.c
diff options
context:
space:
mode:
authorMarouane L <techmetx11@disroot.org>2022-09-26 12:29:14 +0100
committerMichael Vetter <jubalh@iodoru.org>2022-10-12 12:25:00 +0200
commit2d11a35ee1975f015c1c4d7696d71a408178e5be (patch)
treeabd26bacfea04f1d49315a8f191b69924d8b8d9e /src/common.c
parent7ffe55e980a7d33f1129331bb5dc34c6455b55a4 (diff)
downloadprofani-tty-2d11a35ee1975f015c1c4d7696d71a408178e5be.tar.gz
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
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c41
1 files changed, 11 insertions, 30 deletions
diff --git a/src/common.c b/src/common.c
index de35ea2d..14f87da5 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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;
-
-    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);
 
+    GSpawnFlags flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
+
+    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) {
         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;