Page MenuHomeFreeBSD

D16518.id46086.diff
No OneTemporary

D16518.id46086.diff

Index: usr.sbin/newsyslog/newsyslog.c
===================================================================
--- usr.sbin/newsyslog/newsyslog.c
+++ usr.sbin/newsyslog/newsyslog.c
@@ -87,27 +87,6 @@
#include "extern.h"
/*
- * Compression suffixes
- */
-#ifndef COMPRESS_SUFFIX_GZ
-#define COMPRESS_SUFFIX_GZ ".gz"
-#endif
-
-#ifndef COMPRESS_SUFFIX_BZ2
-#define COMPRESS_SUFFIX_BZ2 ".bz2"
-#endif
-
-#ifndef COMPRESS_SUFFIX_XZ
-#define COMPRESS_SUFFIX_XZ ".xz"
-#endif
-
-#ifndef COMPRESS_SUFFIX_ZST
-#define COMPRESS_SUFFIX_ZST ".zst"
-#endif
-
-#define COMPRESS_SUFFIX_MAXLEN MAX(MAX(MAX(sizeof(COMPRESS_SUFFIX_GZ),sizeof(COMPRESS_SUFFIX_BZ2)),sizeof(COMPRESS_SUFFIX_XZ)),sizeof(COMPRESS_SUFFIX_ZST))
-
-/*
* Compression types
*/
#define COMPRESS_TYPES 5 /* Number of supported compression types */
@@ -148,28 +127,27 @@
#define MAX_OLDLOGS 65536 /* Default maximum number of old logfiles */
+#define COMPRESS_SUFFIX_MAXLEN 3
+#define COMPRESS_FLAGS_MAX 2
+
struct compress_types {
const char *flag; /* Flag in configuration file */
- const char *suffix; /* Compression suffix */
+ const char suffix[COMPRESS_SUFFIX_MAXLEN+1]; /* Compression suffix */
const char *path; /* Path to compression program */
- char **args; /* Compression program arguments */
+ const char **flags; /* Compression program 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 char *gzip_args[COMPRESS_FLAGS_MAX] = { "-f" };
+#define bzip2_args gzip_args
+#define xz_args gzip_args
+static const char *zstd_args[COMPRESS_FLAGS_MAX] = { "-q", "--rm" };
-#define ARGS_NUM 4
static const struct compress_types compress_type[COMPRESS_TYPES] = {
- { "", "", "", 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 */
+ { "", "", "", NULL }, /* none */
+ { "Z", ".gz", _PATH_GZIP, gzip_args }, /* gzip */
+ { "J", ".bz2", _PATH_BZIP2, bzip2_args }, /* bzip2 */
+ { "X", ".xz", _PATH_XZ, xz_args }, /* xz */
+ { "Y", ".zst", _PATH_ZSTD, zstd_args } /* zstd */
};
struct conf_entry {
@@ -2027,30 +2005,30 @@
char zresult[MAXPATHLEN];
char command[BUFSIZ];
char **args;
- int c, i;
+ int c;
assert(zwork != NULL);
pgm_path = NULL;
strlcpy(zresult, zwork->zw_fname, sizeof(zresult));
- args = calloc(ARGS_NUM, sizeof(*args));
+ /*
+ * The args array needs three more entries in addition to the
+ * compression flags: one at the beginning for the command, one at
+ * the end for the filename to compress, and the trailing NULL.
+ */
+ args = calloc(COMPRESS_FLAGS_MAX + 3, 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++) {
- if (zwork->zw_conf->compress == c) {
- pgm_path = compress_type[c].path;
- (void) strlcat(zresult,
- compress_type[c].suffix, sizeof(zresult));
- /* the first argument is always NULL, skip it */
- for (i = 1; i < ARGS_NUM; i++) {
- if (compress_type[c].args[i] == NULL)
- break;
- args[i] = compress_type[c].args[i];
- }
- break;
- }
+ zwork->zw_conf->compress > COMPRESS_NONE) {
+ pgm_path = compress_type[zwork->zw_conf->compress].path;
+ (void) strlcat(zresult,
+ compress_type[zwork->zw_conf->compress].suffix,
+ sizeof(zresult));
+ for (c = 0; c < COMPRESS_FLAGS_MAX; c++) {
+ args[c+1] = __DECONST(char *,
+ compress_type[zwork->zw_conf->compress].flags[c]);
}
+ }
if (pgm_path == NULL) {
warnx("invalid entry for %s in do_zipwork", zwork->zw_fname);
return;

File Metadata

Mime Type
text/plain
Expires
Tue, Jun 16, 7:08 PM (5 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33999786
Default Alt Text
D16518.id46086.diff (3 KB)

Event Timeline