about summary refs log tree commit diff stats
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/common.c b/src/common.c
index ab5c6c8b..d2bbc1c6 100644
--- a/src/common.c
+++ b/src/common.c
@@ -46,6 +46,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+// fork / exec
+#include <sys/wait.h>
+#include <readline/readline.h>
+#include "ui/ui.h"
+
+#include "config/preferences.h"
+
 #include <curl/curl.h>
 #include <curl/easy.h>
 #include <glib.h>
@@ -466,7 +473,7 @@ get_mentions(gboolean whole_word, gboolean case_sensitive, const char* const mes
 }
 
 gboolean
-call_external(gchar** argv)
+call_external_async(gchar** argv)
 {
     GError* spawn_error;
     gboolean is_successful;
@@ -489,6 +496,38 @@ call_external(gchar** argv)
     return is_successful;
 }
 
+gboolean
+call_external_fork(gchar** argv)
+{
+    // Fork / exec external executable
+    pid_t pid = fork();
+    if (pid == 0) {
+        int x = execvp(argv[0], argv);
+        if (x == -1) {
+            auto_gchar gchar* cmd = g_strjoinv(" ", argv);
+            log_error("Unable to call external executable '%s'", cmd);
+        }
+        _exit(EXIT_FAILURE);
+    } else {
+        if (pid == -1) {
+            return TRUE;
+        }
+        waitpid(pid, NULL, 0);
+
+        // refresh display
+        ui_resize();
+        rl_forced_update_display();
+    }
+
+    return TRUE;
+}
+
+gboolean
+call_external(gchar** argv)
+{
+    return prefs_get_boolean(PREF_EXECUTABLE_ASYNC) ? call_external_async(argv) : call_external_fork(argv);
+}
+
 gchar**
 format_call_external_argv(const char* template, const char* url, const char* filename)
 {