svn commit: r326617 - head/usr.sbin/newsyslog
Baptiste Daroussin
bapt at FreeBSD.org
Mon Dec 18 09:36:36 UTC 2017
On Fri, Dec 15, 2017 at 05:40:15PM -0800, Cy Schubert wrote:
> In message <201712060944.vB69iZQe027554 at repo.freebsd.org>, Baptiste
> Daroussin w
> rites:
> > 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;
> > }
> >
> >
>
> Ever since this revision I'm seeing the following errors:
>
> bzip2: Can't open input file ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ: No such
> file or directory.
> newsyslog: `/usr/bin/bzip2 -f ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
> /var/log/debug.log.0' terminated with a non-zero status (1)
> bzip2: Bad flag `--rm'
> bzip2, a block-sorting file compressor. Version 1.0.6, 6-Sept-2010.
>
> usage: bzip2 [flags and input files in any order]
>
> -h --help print this message
> -d --decompress force decompression
> -z --compress force compression
> -k --keep keep (don't delete) input files
> -f --force overwrite existing output files
> -t --test test compressed file integrity
> -c --stdout output to standard out
> -q --quiet suppress noncritical error messages
> -v --verbose be verbose (a 2nd -v gives more)
> -L --license display software version & license
> -V --version display software version & license
> -s --small use less memory (at most 2500k)
> -1 .. -9 set block size to 100k .. 900k
> --fast alias for -1
> --best alias for -9
>
> If invoked as `bzip2', default action is to compress.
> as `bunzip2', default action is to decompress.
> as `bzcat', default action is to decompress to stdout.
>
> If no file names are given, bzip2 compresses or decompresses
> from standard input to standard output. You can combine
> short flags, so `-v -4' means the same as -v4 or -4v, &c.
>
> newsyslog: `/usr/bin/bzip2 -f ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
> ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
> ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ /var/log/messages.0 -q --rm'
> terminated with a non-zero status (1)
Should be fixed in r326930.
Sorry about that,
Best regards,
Bapt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20171218/2cb82598/attachment.sig>
More information about the svn-src-head
mailing list