diff options
author | sobomax <sobomax@FreeBSD.org> | 2001-03-23 18:45:24 +0000 |
---|---|---|
committer | sobomax <sobomax@FreeBSD.org> | 2001-03-23 18:45:24 +0000 |
commit | af0ef4a0618c8bc04852f5517a94e7bb9cf23a79 (patch) | |
tree | 7199089cfce7e2607cf0b53bfce882718f758082 /usr.sbin/pkg_install/lib/exec.c | |
parent | e22250630ad78bc0b2b6b8f7b7eef84c54dcc10a (diff) | |
download | FreeBSD-src-af0ef4a0618c8bc04852f5517a94e7bb9cf23a79.zip FreeBSD-src-af0ef4a0618c8bc04852f5517a94e7bb9cf23a79.tar.gz |
- Add which(1)-like functionality into pkg_info;
- fix a harmless bug in match_installed() function introduced in my last
commit;
- uniformely reorder includes across files.
Submitted by: Garrett Rooney <rooneg@electricjellyfish.net>
Not objected by: jkh, -ports
Diffstat (limited to 'usr.sbin/pkg_install/lib/exec.c')
-rw-r--r-- | usr.sbin/pkg_install/lib/exec.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c index 4ed452e..dbb4625 100644 --- a/usr.sbin/pkg_install/lib/exec.c +++ b/usr.sbin/pkg_install/lib/exec.c @@ -23,8 +23,8 @@ static const char rcsid[] = * */ -#include <err.h> #include "lib.h" +#include <err.h> /* * Unusual system() substitute. Accepts format string and args, @@ -60,3 +60,50 @@ printf("Executing %s\n", cmd); return ret; } +char * +vpipe(const char *fmt, ...) +{ + FILE *fp; + char *cmd, *rp; + int maxargs; + va_list args; + + rp = malloc(MAXPATHLEN); + if (!rp) { + warnx("vpipe can't alloc buffer space"); + return NULL; + } + maxargs = sysconf(_SC_ARG_MAX); + maxargs -= 32; /* some slop for the sh -c */ + cmd = alloca(maxargs); + if (!cmd) { + warnx("vpipe can't alloc arg space"); + return NULL; + } + + va_start(args, fmt); + if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) { + warnx("vsystem args are too long"); + return NULL; + } +#ifdef DEBUG + fprintf(stderr, "Executing %s\n", cmd); +#endif + fflush(NULL); + fp = popen(cmd, "r"); + if (fp == NULL) { + warnx("popen() failed"); + return NULL; + } + get_string(rp, MAXPATHLEN, fp); +#ifdef DEBUG + fprintf(stderr, "Returned %s\n", rp); +#endif + va_end(args); + if (pclose(fp) || (strlen(rp) == 0)) { + free(rp); + return NULL; + } + return rp; +} + |