From owner-svn-src-head@freebsd.org Mon Dec 18 09:35:05 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CAD03E81AFC; Mon, 18 Dec 2017 09:35:05 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A23EF724DB; Mon, 18 Dec 2017 09:35:05 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBI9Z4Eo012189; Mon, 18 Dec 2017 09:35:04 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBI9Z4qc012188; Mon, 18 Dec 2017 09:35:04 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201712180935.vBI9Z4qc012188@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Mon, 18 Dec 2017 09:35:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326930 - head/usr.sbin/newsyslog X-SVN-Group: head X-SVN-Commit-Author: bapt X-SVN-Commit-Paths: head/usr.sbin/newsyslog X-SVN-Commit-Revision: 326930 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Dec 2017 09:35:05 -0000 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); }