Date: Wed, 6 Dec 2017 09:44:35 +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: r326617 - head/usr.sbin/newsyslog Message-ID: <201712060944.vB69iZQe027554@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Wed Dec 6 09:44:35 2017 New Revision: 326617 URL: https://svnweb.freebsd.org/changeset/base/326617 Log: Allow newsyslog to execute compression commands which have a semantic different than the traditional gzip(1) This is done to allow to use zstd(1) as a compression tool without having to patch it to change its default behavior. Modified: head/usr.sbin/newsyslog/newsyslog.c Modified: head/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- head/usr.sbin/newsyslog/newsyslog.c Wed Dec 6 06:49:53 2017 (r326616) +++ head/usr.sbin/newsyslog/newsyslog.c Wed Dec 6 09:44:35 2017 (r326617) @@ -151,14 +151,23 @@ struct compress_types { const char *flag; /* Flag in configuration file */ const char *suffix; /* Compression suffix */ const char *path; /* Path to compression program */ + char **args; /* Comrpession arguments */ }; +static char f_arg[] = "-f"; +static char q_arg[] = "-q"; +static char rm_arg[] = "--rm"; +static char *gz_args[] ={ NULL, f_arg, NULL, NULL }; +#define bzip2_args gz_args +#define xz_args gz_args +static char *zstd_args[] = { NULL, q_arg, rm_arg, NULL, NULL }; + static const struct compress_types compress_type[COMPRESS_TYPES] = { - { "", "", "" }, /* no compression */ - { "Z", COMPRESS_SUFFIX_GZ, _PATH_GZIP }, /* gzip compression */ - { "J", COMPRESS_SUFFIX_BZ2, _PATH_BZIP2 }, /* bzip2 compression */ - { "X", COMPRESS_SUFFIX_XZ, _PATH_XZ }, /* xz compression */ - { "Y", COMPRESS_SUFFIX_ZST, _PATH_ZSTD } /* zst compression */ + { "", "", "", NULL}, /* none */ + { "Z", COMPRESS_SUFFIX_GZ, _PATH_GZIP, gz_args}, /* gzip */ + { "J", COMPRESS_SUFFIX_BZ2, _PATH_BZIP2, bzip2_args}, /* bzip2 */ + { "X", COMPRESS_SUFFIX_XZ, _PATH_XZ, xz_args }, /* xz */ + { "Y", COMPRESS_SUFFIX_ZST, _PATH_ZSTD, zstd_args } /* zst */ }; struct conf_entry { @@ -2001,6 +2010,8 @@ do_zipwork(struct zipwork_entry *zwork) int errsav, fcount, zstatus; pid_t pidzip, wpid; char zresult[MAXPATHLEN]; + char command[BUFSIZ]; + char **args; int c; assert(zwork != NULL); @@ -2013,6 +2024,7 @@ 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; break; } } @@ -2026,6 +2038,13 @@ do_zipwork(struct zipwork_entry *zwork) else pgm_name++; + args[0] = strdup(pgm_name); + if (args[0] == NULL) + err(1, "strdup()"); + for (c = 0; args[c] != NULL; c++) + ; + args[c] = zwork->zw_fname; + if (zwork->zw_swork != NULL && zwork->zw_swork->sw_runcmd == 0 && zwork->zw_swork->sw_pidok <= 0) { warnx( @@ -2035,6 +2054,11 @@ do_zipwork(struct zipwork_entry *zwork) return; } + strlcpy(command, pgm_path, sizeof(command)); + for (c = 1; args[c] != NULL; c++) { + strlcat(command, " ", sizeof(command)); + strlcat(command, args[c], sizeof(command)); + } if (noaction) { printf("\t%s %s\n", pgm_name, zwork->zw_fname); change_attrs(zresult, zwork->zw_conf); @@ -2058,8 +2082,8 @@ do_zipwork(struct zipwork_entry *zwork) } if (!pidzip) { /* The child process executes the compression command */ - execl(pgm_path, pgm_path, "-f", zwork->zw_fname, (char *)0); - err(1, "execl(`%s -f %s')", pgm_path, zwork->zw_fname); + execv(pgm_path, (char *const*) args); + err(1, "execv(`%s')", command); } wpid = waitpid(pidzip, &zstatus, 0); @@ -2069,13 +2093,12 @@ do_zipwork(struct zipwork_entry *zwork) return; } if (!WIFEXITED(zstatus)) { - warnx("`%s -f %s' did not terminate normally", pgm_name, - zwork->zw_fname); + warnx("`%s' did not terminate normally", command); return; } if (WEXITSTATUS(zstatus)) { - warnx("`%s -f %s' terminated with a non-zero status (%d)", - pgm_name, zwork->zw_fname, WEXITSTATUS(zstatus)); + warnx("`%s' terminated with a non-zero status (%d)", command, + WEXITSTATUS(zstatus)); return; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712060944.vB69iZQe027554>