2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
17 * Miscellaneous system routines.
19 * $FreeBSD: src/usr.sbin/pkg_install/lib/exec.c,v 1.10 2002/04/01 09:39:07 obrien Exp $
20 * $DragonFly: src/usr.sbin/pkg_install/lib/Attic/exec.c,v 1.3 2004/07/30 04:46:13 dillon Exp $
27 * Unusual system() substitute. Accepts format string and args,
28 * builds and executes command. Returns exit code.
32 vsystem(const char *fmt, ...)
38 maxargs = sysconf(_SC_ARG_MAX);
39 maxargs -= 32; /* some slop for the sh -c */
40 cmd = malloc(maxargs);
42 warnx("vsystem can't alloc arg space");
47 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
48 warnx("vsystem args are too long");
52 printf("Executing %s\n", cmd);
61 vpipe(const char *fmt, ...)
68 rp = malloc(MAXPATHLEN);
70 warnx("vpipe can't alloc buffer space");
73 maxargs = sysconf(_SC_ARG_MAX);
74 maxargs -= 32; /* some slop for the sh -c */
75 cmd = alloca(maxargs);
77 warnx("vpipe can't alloc arg space");
82 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
83 warnx("vsystem args are too long");
87 fprintf(stderr, "Executing %s\n", cmd);
92 warnx("popen() failed");
95 get_string(rp, MAXPATHLEN, fp);
97 fprintf(stderr, "Returned %s\n", rp);
100 if (pclose(fp) || (strlen(rp) == 0)) {