2004-08-27 [paul] 0.9.12cvs83
[claws.git] / src / common / utils.c
index 6bbc316674bb7f613a8dcef0e4221f453eae5ee3..c0b6cf744e5fa48a965809d5d7c0c4a11e6416e9 100644 (file)
@@ -3020,6 +3020,7 @@ gchar *file_read_stream_to_str(FILE *fp)
 gint execute_async(gchar *const argv[])
 {
        pid_t pid;
+       gint status;
 
        if ((pid = fork()) < 0) {
                perror("fork");
@@ -3044,14 +3045,18 @@ gint execute_async(gchar *const argv[])
                _exit(0);
        }
 
-       waitpid(pid, NULL, 0);
+       waitpid(pid, &status, 0);
 
-       return 0;
+       if (WIFEXITED(status))
+               return WEXITSTATUS(status);
+       else
+               return -1;
 }
 
 gint execute_sync(gchar *const argv[])
 {
        pid_t pid;
+       gint status;
 
        if ((pid = fork()) < 0) {
                perror("fork");
@@ -3065,9 +3070,12 @@ gint execute_sync(gchar *const argv[])
                _exit(1);
        }
 
-       waitpid(pid, NULL, 0);
+       waitpid(pid, &status, 0);
 
-       return 0;
+       if (WIFEXITED(status))
+               return WEXITSTATUS(status);
+       else
+               return -1;
 }
 
 gint execute_command_line(const gchar *cmdline, gboolean async)
@@ -3075,12 +3083,15 @@ gint execute_command_line(const gchar *cmdline, gboolean async)
        gchar **argv;
        gint ret;
 
+       debug_print("executing: %s\n", cmdline);
+
        argv = strsplit_with_quote(cmdline, " ", 0);
 
        if (async)
                ret = execute_async(argv);
        else
                ret = execute_sync(argv);
+
        g_strfreev(argv);
 
        return ret;
@@ -3167,11 +3178,12 @@ gint open_uri(const gchar *uri, const gchar *cmdline)
                g_snprintf(buf, sizeof(buf), cmdline, encoded_uri);
        else {
                if (cmdline)
-                       g_warning("Open URI command line is invalid: `%s'",
+                       g_warning("Open URI command line is invalid "
+                                 "(there must be only one '%%s'): %s",
                                  cmdline);
                g_snprintf(buf, sizeof(buf), DEFAULT_BROWSER_CMD, encoded_uri);
        }
-       
+
        execute_command_line(buf, TRUE);
 
        return 0;