2 * FreeBSD install - a package for the installation and maintenance
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.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
28 * Unusual system() substitute. Accepts format string and args,
29 * builds and executes command. Returns exit code.
33 vsystem(const char *fmt, ...)
40 maxargs = sysconf(_SC_ARG_MAX);
41 maxargs -= 32; /* some slop for the sh -c */
42 cmd = malloc(maxargs);
44 warnx("vsystem can't alloc arg space");
49 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
50 warnx("vsystem args are too long");
55 printf("Executing %s\n", cmd);
64 vpipe(const char *fmt, ...)
71 rp = malloc(MAXPATHLEN);
73 warnx("vpipe can't alloc buffer space");
76 maxargs = sysconf(_SC_ARG_MAX);
77 maxargs -= 32; /* some slop for the sh -c */
78 cmd = alloca(maxargs);
80 warnx("vpipe can't alloc arg space");
85 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
86 warnx("vsystem args are too long");
91 fprintf(stderr, "Executing %s\n", cmd);
96 warnx("popen() failed");
100 get_string(rp, MAXPATHLEN, fp);
102 fprintf(stderr, "Returned %s\n", rp);
105 if (pclose(fp) || (strlen(rp) == 0)) {