version 1.9, 2005/11/07 22:57:48 |
version 1.10, 2005/11/22 15:44:59 |
Line 52 __RCSID("$NetBSD$"); |
|
Line 52 __RCSID("$NetBSD$"); |
|
#endif |
#endif |
|
|
static char *Home; |
static char *Home; |
|
void cleanup_callback(void); |
|
|
static void |
static void |
make_dist(const char *home, const char *pkg, const char *suffix, const package_t *plist) |
make_dist(const char *home, const char *pkg, const char *suffix, const package_t *plist) |
Line 61 make_dist(const char *home, const char * |
|
Line 62 make_dist(const char *home, const char * |
|
int ret; |
int ret; |
char *args[50]; /* Much more than enough. */ |
char *args[50]; /* Much more than enough. */ |
int nargs = 1; |
int nargs = 1; |
int pipefds[2]; |
|
FILE *totar; |
FILE *totar; |
pid_t pid; |
pipe_to_system_t *to_pipe; |
|
|
if ((args[0] = strrchr(TAR_CMD, '/')) == NULL) |
if ((args[0] = strrchr(TAR_CMD, '/')) == NULL) |
args[0] = TAR_CMD; |
args[0] = TAR_CMD; |
Line 93 make_dist(const char *home, const char * |
|
Line 93 make_dist(const char *home, const char * |
|
args[nargs++] = "-"; /* Use stdin for the file. */ |
args[nargs++] = "-"; /* Use stdin for the file. */ |
args[nargs] = NULL; |
args[nargs] = NULL; |
|
|
/* Set up a pipe for passing the filenames, and fork off a tar process. */ |
to_pipe = pipe_to_system_begin(TAR_CMD, args, cleanup_callback); |
if (pipe(pipefds) == -1) { |
totar = to_pipe->fp; |
cleanup(0); |
|
errx(2, "cannot create pipe"); |
|
} |
|
if ((pid = fork()) == -1) { |
|
cleanup(0); |
|
errx(2, "cannot fork process for %s", TAR_CMD); |
|
} |
|
if (pid == 0) { /* The child */ |
|
dup2(pipefds[0], 0); |
|
close(pipefds[0]); |
|
close(pipefds[1]); |
|
execvp(TAR_CMD, args); |
|
cleanup(0); |
|
errx(2, "failed to execute %s command", TAR_CMD); |
|
} |
|
|
|
/* Meanwhile, back in the parent process ... */ |
|
close(pipefds[0]); |
|
if ((totar = fdopen(pipefds[1], "w")) == NULL) { |
|
cleanup(0); |
|
errx(2, "fdopen failed"); |
|
} |
|
|
|
fprintf(totar, "%s\n", CONTENTS_FNAME); |
fprintf(totar, "%s\n", CONTENTS_FNAME); |
fprintf(totar, "%s\n", COMMENT_FNAME); |
fprintf(totar, "%s\n", COMMENT_FNAME); |
Line 173 make_dist(const char *home, const char * |
|
Line 151 make_dist(const char *home, const char * |
|
} |
} |
} |
} |
|
|
fclose(totar); |
ret = pipe_to_system_end(to_pipe); |
waitpid(-1, &ret, 0); |
|
/* assume either signal or bad exit is enough for us */ |
/* assume either signal or bad exit is enough for us */ |
if (ret) { |
if (ret) { |
cleanup(0); |
cleanup(0); |
Line 199 sanity_check(void) |
|
Line 176 sanity_check(void) |
|
} |
} |
} |
} |
|
|
|
/* |
|
* Clean up callback for pipe_to_system() |
|
*/ |
|
void |
|
cleanup_callback(void) |
|
{ |
|
cleanup(0); |
|
} |
|
|
/* |
/* |
* Clean up those things that would otherwise hang around |
* Clean up those things that would otherwise hang around |