Skip to content

Commit

Permalink
5596 tar doesn't properly wait for its children
Browse files Browse the repository at this point in the history
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Approved by: Garrett D'Amore <garrett@damore.org>
  • Loading branch information
rmustacc committed Apr 30, 2015
1 parent 999cb8a commit c536b1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
2 changes: 0 additions & 2 deletions usr/src/cmd/tar/Makefile
Expand Up @@ -37,8 +37,6 @@ LINTFLAGS += -u
LDLIBS += -lsec -lcmdutils -lnvpair -ltsol

CFLAGS += $(CCVERBOSE)
CERRWARN += -_gcc=-Wno-unused-variable
CERRWARN += -_gcc=-Wno-parentheses
CERRWARN += -_gcc=-Wno-uninitialized

CPPFLAGS += -DEUC
Expand Down
38 changes: 17 additions & 21 deletions usr/src/cmd/tar/tar.c
Expand Up @@ -565,7 +565,7 @@ static char *myname;
static char *xtract_chdir = NULL;
static int checkflag = 0;
static int Xflag, Fflag, iflag, hflag, Bflag, Iflag;
static int rflag, xflag, vflag, tflag, mt, svmt, cflag, mflag, pflag;
static int rflag, xflag, vflag, tflag, mt, cflag, mflag, pflag;
static int uflag;
static int errflag;
static int oflag;
Expand Down Expand Up @@ -643,6 +643,8 @@ static int charset_type = 0;

static u_longlong_t xhdr_flgs; /* Bits set determine which items */
/* need to be in extended header. */
static pid_t comp_pid = 0;

#define _X_DEVMAJOR 0x1
#define _X_DEVMINOR 0x2
#define _X_GID 0x4
Expand Down Expand Up @@ -725,8 +727,6 @@ main(int argc, char *argv[])
char *cp;
char *tmpdirp;
pid_t thispid;
pid_t pid;
int wstat;

(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
Expand Down Expand Up @@ -1114,10 +1114,8 @@ main(int argc, char *argv[])
if (Aflag && vflag)
(void) printf(
gettext("Suppressing absolute pathnames\n"));
if (cflag && compress_opt != NULL) {
pid = compress_file();
wait_pid(pid);
}
if (cflag && compress_opt != NULL)
comp_pid = compress_file();
dorep(argv);
if (rflag && !cflag && (compress_opt != NULL))
compress_back();
Expand Down Expand Up @@ -1168,10 +1166,8 @@ main(int argc, char *argv[])

if (strcmp(usefile, "-") != 0) {
check_compression();
if (compress_opt != NULL) {
pid = uncompress_file();
wait_pid(pid);
}
if (compress_opt != NULL)
comp_pid = uncompress_file();
}
if (xflag) {
if (xtract_chdir != NULL) {
Expand Down Expand Up @@ -4876,6 +4872,13 @@ done(int n)
exit(2);
}
}
/*
* If we have a compression child, we should have a child process that
* we're waiting for to finish compressing or uncompressing the tar
* stream.
*/
if (comp_pid != 0)
wait_pid(comp_pid);
exit(n);
}

Expand Down Expand Up @@ -6109,7 +6112,6 @@ check_prefix(char **namep, char **dirp, char **compp)
if ((tflag || xflag) && !Pflag) {
if (is_absolute(fullname) || has_dot_dot(fullname)) {
char *stripped_prefix;
size_t prefix_len = 0;

(void) strcpy(savename, fullname);
strcpy(fullname,
Expand Down Expand Up @@ -7891,7 +7893,7 @@ xattrs_put(char *longname, char *shortname, char *parent, char *attrparent)
return;
}

while (dp = readdir(dirp)) {
while ((dp = readdir(dirp)) != NULL) {
if (strcmp(dp->d_name, "..") == 0) {
continue;
} else if (strcmp(dp->d_name, ".") == 0) {
Expand Down Expand Up @@ -9191,9 +9193,6 @@ static void
compress_back()
{
pid_t pid;
int status;
int wret;
struct stat statb;

if (vflag) {
(void) fprintf(vfile,
Expand Down Expand Up @@ -9299,9 +9298,6 @@ void
decompress_file(void)
{
pid_t pid;
int status;
char cmdstr[PATH_MAX];
char fname[PATH_MAX];
char *added_suffix;


Expand Down Expand Up @@ -9344,7 +9340,7 @@ compress_file(void)
if (pipe(fd) < 0) {
vperror(1, gettext("Could not create pipe"));
}
if (pid = fork() > 0) {
if ((pid = fork()) > 0) {
mt = fd[1];
(void) close(fd[0]);
return (pid);
Expand Down Expand Up @@ -9373,7 +9369,7 @@ uncompress_file(void)
if (pipe(fd) < 0) {
vperror(1, gettext("Could not create pipe"));
}
if (pid = fork() > 0) {
if ((pid = fork()) > 0) {
mt = fd[0];
(void) close(fd[1]);
return (pid);
Expand Down
8 changes: 4 additions & 4 deletions usr/src/common/util/getresponse.c
Expand Up @@ -23,9 +23,6 @@
* Use is subject to license terms.
*/

#pragma ident "%Z%%M% %I% %E% SMI"


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -125,11 +122,14 @@ yes_no(int (*func)(char *))
char ans[LINE_MAX + 1];

/* Get user's answer */
for (i = 0; b = getchar(); i++) {
i = 0;
for (;;) {
b = getchar();
if (b == '\n' || b == '\0' || b == EOF)
break;
if (i < LINE_MAX)
ans[i] = b;
i++;
}
if (i >= LINE_MAX)
ans[LINE_MAX] = '\0';
Expand Down

0 comments on commit c536b1f

Please sign in to comment.