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, ...)
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");
54 printf("Executing %s\n", cmd);
63 vpipe(const char *fmt, ...)
70 rp = malloc(MAXPATHLEN);
72 warnx("vpipe can't alloc buffer space");
75 maxargs = sysconf(_SC_ARG_MAX);
76 maxargs -= 32; /* some slop for the sh -c */
77 cmd = alloca(maxargs);
79 warnx("vpipe can't alloc arg space");
84 if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
85 warnx("vsystem args are too long");
89 fprintf(stderr, "Executing %s\n", cmd);
94 warnx("popen() failed");
97 get_string(rp, MAXPATHLEN, fp);
99 fprintf(stderr, "Returned %s\n", rp);
102 if (pclose(fp) || (strlen(rp) == 0)) {