diff options
| author | Maxim Sobolev <sobomax@FreeBSD.org> | 2001-03-23 18:45:24 +0000 |
|---|---|---|
| committer | Maxim Sobolev <sobomax@FreeBSD.org> | 2001-03-23 18:45:24 +0000 |
| commit | c805813625feb77d75b9207eb0fbfac1aeccaf07 (patch) | |
| tree | 8c6eb7b78bcc2a4125accadde044812ed11fc8d1 /usr.sbin/pkg_install/lib | |
| parent | 53046c5fd56902282f5d0beab0d716d41c9c92af (diff) | |
Notes
Diffstat (limited to 'usr.sbin/pkg_install/lib')
| -rw-r--r-- | usr.sbin/pkg_install/lib/deps.c | 1 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/exec.c | 49 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 2 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/match.c | 21 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/msg.c | 2 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 2 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/str.c | 19 |
7 files changed, 83 insertions, 13 deletions
diff --git a/usr.sbin/pkg_install/lib/deps.c b/usr.sbin/pkg_install/lib/deps.c index 4c06da8df1fa..84d5c474fc38 100644 --- a/usr.sbin/pkg_install/lib/deps.c +++ b/usr.sbin/pkg_install/lib/deps.c @@ -25,7 +25,6 @@ static const char rcsid[] = */ #include "lib.h" - #include <err.h> #include <stdio.h> diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c index 4ed452ebfbf5..dbb4625a0c47 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; +} + diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 0ed689984366..3ab1b633ece2 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -112,6 +112,7 @@ typedef struct _pack Package; /* Prototypes */ /* Misc */ int vsystem(const char *, ...); +char *vpipe(const char *, ...); void cleanup(int); char *make_playpen(char *, size_t); char *where_playpen(void); @@ -126,6 +127,7 @@ void nuke_suffix(char *); void str_lowercase(char *); char *basename_of(char *); char *strconcat(char *, char *); +char *get_string(char *, int, FILE *); /* File */ Boolean fexists(char *); diff --git a/usr.sbin/pkg_install/lib/match.c b/usr.sbin/pkg_install/lib/match.c index 2bcae2a34fca..f3dc99901351 100644 --- a/usr.sbin/pkg_install/lib/match.c +++ b/usr.sbin/pkg_install/lib/match.c @@ -24,7 +24,6 @@ static const char rcsid[] = */ #include "lib.h" - #include <err.h> #include <fnmatch.h> #include <fts.h> @@ -97,14 +96,18 @@ matchinstalled(match_t MatchType, char **patterns, int *retval) } /* Count number of patterns */ - for (len = 0; patterns[len]; len++) {} - lmatched = alloca(sizeof(*lmatched) * len); - if (lmatched == NULL) { - warnx("%s(): alloca() failed", __FUNCTION__); - if (retval != NULL) - *retval = 1; - return NULL; - } + if (patterns != NULL) { + for (len = 0; patterns[len]; len++) {} + lmatched = alloca(sizeof(*lmatched) * len); + if (lmatched == NULL) { + warnx("%s(): alloca() failed", __FUNCTION__); + if (retval != NULL) + *retval = 1; + return NULL; + } + } else + len = 0; + for (i = 0; i < len; i++) lmatched[i] = FALSE; diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c index 068d305a2e31..5f954cac1f31 100644 --- a/usr.sbin/pkg_install/lib/msg.c +++ b/usr.sbin/pkg_install/lib/msg.c @@ -24,9 +24,9 @@ static const char rcsid[] = * */ +#include "lib.h" #include <err.h> #include <paths.h> -#include "lib.h" /* Die a relatively simple death */ void diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 687d6bb49db6..62465bf3f902 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -23,8 +23,8 @@ static const char rcsid[] = * */ -#include <err.h> #include "lib.h" +#include <err.h> #include <sys/signal.h> #include <sys/param.h> #include <sys/mount.h> diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c index 67a5e642d533..c5f11a290fc9 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -109,3 +109,22 @@ str_lowercase(char *str) ++str; } } + +char * +get_string(char *str, int max, FILE *fp) +{ + int len; + + if (!str) + return NULL; + str[0] = '\0'; + while (fgets(str, max, fp)) { + len = strlen(str); + while (len && isspace(str[len - 1])) + str[--len] = '\0'; + if (len) + return str; + } + return NULL; +} + |
