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.
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, ...)
39 maxargs = sysconf(_SC_ARG_MAX);
40 maxargs -= 32; /* some slop for the sh -c */
41 cmd = malloc(maxargs);
43 warnx("vsystem can't alloc arg space");
48 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
49 warnx("vsystem args are too long");
53 printf("Executing %s\n", cmd);
62 vpipe(const char *fmt, ...)
69 rp = malloc(MAXPATHLEN);
71 warnx("vpipe can't alloc buffer space");
74 maxargs = sysconf(_SC_ARG_MAX);
75 maxargs -= 32; /* some slop for the sh -c */
76 cmd = alloca(maxargs);
78 warnx("vpipe can't alloc arg space");
83 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
84 warnx("vsystem args are too long");
88 fprintf(stderr, "Executing %s\n", cmd);
93 warnx("popen() failed");
96 get_string(rp, MAXPATHLEN, fp);
98 fprintf(stderr, "Returned %s\n", rp);
101 if (pclose(fp) || (strlen(rp) == 0)) {