Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Dec 2017 09:35:04 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r326930 - head/usr.sbin/newsyslog
Message-ID:  <201712180935.vBI9Z4qc012188@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Mon Dec 18 09:35:04 2017
New Revision: 326930
URL: https://svnweb.freebsd.org/changeset/base/326930

Log:
  newsyslog: Fix issues after r326616
  
  When building the command to execute for compression, newsyslog was modifying
  the generic arguments array instead of its own copy.
  Meaning on the second file to compress with the same arguments, the command line
  was not the one expected.
  Fix it by creating one copy of the arguments per execution and modifying that
  copy.
  
  While here, print the command line executed in verbose mode.
  
  Reported by:	many

Modified:
  head/usr.sbin/newsyslog/newsyslog.c

Modified: head/usr.sbin/newsyslog/newsyslog.c
==============================================================================
--- head/usr.sbin/newsyslog/newsyslog.c	Mon Dec 18 09:32:56 2017	(r326929)
+++ head/usr.sbin/newsyslog/newsyslog.c	Mon Dec 18 09:35:04 2017	(r326930)
@@ -162,6 +162,7 @@ static char *gz_args[] ={ NULL, f_arg, NULL, NULL };
 #define xz_args gz_args
 static char *zstd_args[] = { NULL, q_arg, rm_arg, NULL, NULL };
 
+#define ARGS_NUM 4
 static const struct compress_types compress_type[COMPRESS_TYPES] = {
 	{ "", "", "", NULL},					/* none */
 	{ "Z", COMPRESS_SUFFIX_GZ, _PATH_GZIP, gz_args},	/* gzip */
@@ -2017,6 +2018,9 @@ do_zipwork(struct zipwork_entry *zwork)
 	assert(zwork != NULL);
 	pgm_path = NULL;
 	strlcpy(zresult, zwork->zw_fname, sizeof(zresult));
+	args = calloc(ARGS_NUM, sizeof(*args));
+	if (args == NULL)
+		err(1, "calloc()");
 	if (zwork->zw_conf != NULL &&
 	    zwork->zw_conf->compress > COMPRESS_NONE)
 		for (c = 1; c < COMPRESS_TYPES; c++) {
@@ -2024,7 +2028,12 @@ do_zipwork(struct zipwork_entry *zwork)
 				pgm_path = compress_type[c].path;
 				(void) strlcat(zresult,
 				    compress_type[c].suffix, sizeof(zresult));
-				args = compress_type[c].args;
+				/* the first argument is always NULL, skip it */
+				for (c = 1; c < ARGS_NUM; c++) {
+					if (compress_type[c].args[c] == NULL)
+						break;
+					args[c] = compress_type[c].args[c];
+				}
 				break;
 			}
 		}
@@ -2065,6 +2074,9 @@ do_zipwork(struct zipwork_entry *zwork)
 		return;
 	}
 
+	if (verbose) {
+		printf("Executing: %s\n", command);
+	}
 	fcount = 1;
 	pidzip = fork();
 	while (pidzip < 0) {
@@ -2094,14 +2106,20 @@ do_zipwork(struct zipwork_entry *zwork)
 	}
 	if (!WIFEXITED(zstatus)) {
 		warnx("`%s' did not terminate normally", command);
+		free(args[0]);
+		free(args);
 		return;
 	}
 	if (WEXITSTATUS(zstatus)) {
 		warnx("`%s' terminated with a non-zero status (%d)", command,
 		    WEXITSTATUS(zstatus));
+		free(args[0]);
+		free(args);
 		return;
 	}
 
+	free(args[0]);
+	free(args);
 	/* Compression was successful, set file attributes on the result. */
 	change_attrs(zresult, zwork->zw_conf);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712180935.vBI9Z4qc012188>