File bnc#858660_detect_gzip_failures.patch of Package star

Index: star-1.5/star/buffer.c
===================================================================
--- star-1.5.orig/star/buffer.c
+++ star-1.5/star/buffer.c
@@ -37,6 +37,8 @@ static	char sccsid[] =
 #endif
 
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <schily/stdlib.h>
 #include <schily/unistd.h>
 #include <schily/libport.h>	/* getpagesize() */
@@ -1731,6 +1733,10 @@ checkerrs()
 			errmsgno(EX_BAD, "Problems with restore database.\n");
 		return (TRUE);
 	}
+	if (xstats.s_comprerrs > 0) {
+		errmsgno(EX_BAD, "Compress program returned error[%d].\n", xstats.s_comprerrs);
+		return (TRUE);
+	}
 	return (FALSE);
 }
 
@@ -1806,6 +1812,16 @@ die(err)
 	excomerrno(err, "Cannot recover from error - exiting.\n");
 }
 
+void sigchld_handler(int sig)
+{
+	int status;
+	pid_t pid;
+	while ((pid = wait4(compresspid, &status, 0, NULL)) > 0) {
+		if (pid == compresspid)
+			xstats.s_comprerrs = WEXITSTATUS(status);
+	}
+
+}
 /*
  * Quick hack to implement a -z flag. May be changed soon.
  */
@@ -1821,6 +1837,8 @@ compressopen()
 	int	mypid;
 	char	*zip_prog = "gzip";
 
+	compresspid = 0;
+
 	if (compress_prg)
 		zip_prog = compress_prg;
 	else if (bzflag)
@@ -1880,6 +1898,7 @@ compressopen()
 #else
 	if (fpipe(pp) == 0)
 		comerr("Compress pipe failed\n");
+	signal(SIGCHLD, sigchld_handler);
 	mypid = fork();
 	if (mypid < 0)
 		comerr("Compress fork failed\n");
@@ -1909,7 +1928,10 @@ compressopen()
 			fexecl(zip_prog, tarf, pp[1], null, zip_prog, "-d", (char *)NULL);
 		errmsg("Compress: exec of '%s' failed\n", zip_prog);
 		_exit(-1);
+	} else {
+		compresspid = mypid;
 	}
+
 	fclose(tarf);
 	if (cflag) {
 		tarf = pp[1];
Index: star-1.5/star/star.c
===================================================================
--- star-1.5.orig/star/star.c
+++ star-1.5/star/star.c
@@ -112,6 +112,7 @@ char	strvers[] = "1.5";		/* The pure ver
 char	*vers;				/* the full version string	*/
 
 struct star_stats	xstats;		/* for printing statistics	*/
+pid_t compresspid = 0;
 
 extern	BOOL		havepat;	/* Pattern matching in use	*/
 
Index: star-1.5/star/star.h
===================================================================
--- star-1.5.orig/star/star.h
+++ star-1.5/star/star.h
@@ -823,9 +823,11 @@ struct star_stats {
 	int	s_setxattr;	/* set xattr for file failed		  */
 #endif
 	int	s_restore;	/* other incremental restore specific	  */
+	int     s_comprerrs;    /* errors of compress-subprogram */
 };
 
 extern	struct	star_stats	xstats;
+extern  pid_t compresspid;      /* pid of compress-subprogram child */
 
 
 #include <schily/param.h>
openSUSE Build Service is sponsored by