summary refs log tree commit diff stats
path: root/src/common/util.c
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-04-25 13:41:38 -0400
committerTingPing <tingping@fedoraproject.org>2014-06-04 10:38:23 -0400
commit5849a0588e7b12003f8b9afcfcdc31f46c6b2329 (patch)
tree0eb7fa462318506be8b4303a9b32cb6a888c47cf /src/common/util.c
parentb8c02f71d9bbaf805534d5327d8c3935a3b87636 (diff)
Use glib to parse and launch commands for util_exec
Fixes #958
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c165
1 files changed, 2 insertions, 163 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 69ddaff4..2dc0034b 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1298,171 +1298,10 @@ country_search (char *pattern, void *ud, void (*print)(void *, char *, ...))
 	}
 }
 
-/* I think gnome1.0.x isn't necessarily linked against popt, ah well! */
-/* !!! For now use this inlined function, or it would break fe-text building */
-/* .... will find a better solution later. */
-/*#ifndef USE_GNOME*/
-
-/* this is taken from gnome-libs 1.2.4 */
-#define POPT_ARGV_ARRAY_GROW_DELTA 5
-
-int my_poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) {
-    char * buf, * bufStart, * dst;
-    const char * src;
-    char quote = '\0';
-    int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
-    char ** argv = malloc(sizeof(*argv) * argvAlloced);
-    const char ** argv2;
-    int argc = 0;
-    int i, buflen;
-
-    buflen = strlen(s) + 1;
-/*    bufStart = buf = alloca(buflen);*/
-	 bufStart = buf = malloc (buflen);
-    memset(buf, '\0', buflen);
-
-    src = s;
-    argv[argc] = buf;
-
-    while (*src) {
-	if (quote == *src) {
-	    quote = '\0';
-	} else if (quote) {
-	    if (*src == '\\') {
-		src++;
-		if (!*src) {
-		    free(argv);
-			 free(bufStart);
-		    return 1;
-		}
-		if (*src != quote) *buf++ = '\\';
-	    }
-	    *buf++ = *src;
-	/*} else if (isspace((unsigned char) *src)) {*/
-	} else if (*src == ' ') {
-	    if (*argv[argc]) {
-		buf++, argc++;
-		if (argc == argvAlloced) {
-		    char **temp;
-		    argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
-		    temp = realloc(argv, sizeof(*argv) * argvAlloced);
-		    if (temp)
-			argv = temp;
-		    else
-		    {
-			free(argv);
-			free(bufStart);
-			return 1;
-		    }
-		}
-		argv[argc] = buf;
-	    }
-	} else switch (*src) {
-	  case '"':
-	  case '\'':
-	    quote = *src;
-	    break;
-	  case '\\':
-	    src++;
-	    if (!*src) {
-		free(argv);
-		free(bufStart);
-		return 1;
-	    }
-	    /* fallthrough */
-	  default:
-	    *buf++ = *src;
-	}
-
-	src++;
-    }
-
-    if (strlen(argv[argc])) {
-	argc++, buf++;
-    }
-
-    dst = malloc((argc + 1) * sizeof(*argv) + (buf - bufStart));
-    argv2 = (void *) dst;
-    dst += (argc + 1) * sizeof(*argv);
-    memcpy((void *)argv2, argv, argc * sizeof(*argv));
-    argv2[argc] = NULL;
-    memcpy(dst, bufStart, buf - bufStart);
-
-    for (i = 0; i < argc; i++) {
-	argv2[i] = dst + (argv[i] - bufStart);
-    }
-
-    free(argv);
-
-    *argvPtr = (char **)argv2;	/* XXX don't change the API */
-    *argcPtr = argc;
-
-	 free (bufStart);
-
-    return 0;
-}
-
-int
+void
 util_exec (const char *cmd)
 {
-	char **argv;
-	int argc;
-#ifndef WIN32
-	int pid;
-	int fd;
-#endif
-
-	if (my_poptParseArgvString (cmd, &argc, &argv) != 0)
-		return -1;
-
-#ifndef WIN32
-	pid = fork ();
-	if (pid == -1)
-	{
-		free (argv);
-		return -1;
-	}
-	if (pid == 0)
-	{
-		/* Now close all open file descriptors except stdin, stdout and stderr */
-		for (fd = 3; fd < 1024; fd++) close(fd);
-		execvp (argv[0], argv);
-		_exit (0);
-	} else
-	{
-		free (argv);
-		return pid;
-	}
-#else
-	spawnvp (_P_DETACH, argv[0], argv);
-	free (argv);
-	return 0;
-#endif
-}
-
-int
-util_execv (char * const argv[])
-{
-#ifndef WIN32
-	int pid, fd;
-
-	pid = fork ();
-	if (pid == -1)
-		return -1;
-	if (pid == 0)
-	{
-		/* Now close all open file descriptors except stdin, stdout and stderr */
-		for (fd = 3; fd < 1024; fd++) close(fd);
-		execv (argv[0], argv);
-		_exit (0);
-	} else
-	{
-		return pid;
-	}
-#else
-	spawnv (_P_DETACH, argv[0], argv);
-	return 0;
-#endif
+	g_spawn_command_line_async (cmd, NULL);
 }
 
 unsigned long