Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F167889765
D16518.id46171.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D16518.id46171.diff
View Options
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,32 @@
#define MAX_OLDLOGS 65536 /* Default maximum number of old logfiles */
+#define COMPRESS_SUFFIX_MAXLEN 3
+
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 **args; /* Compression program arguments */
int nargs; /* Program argument count */
};
-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 bz2_args gz_args
-#define xz_args gz_args
-static char *zstd_args[] = { NULL, q_arg, rm_arg, NULL, NULL };
+/*
+ * The args arrays need three more entries in addition to the compression
+ * flags themselves: one at the beginning for the command, one at the end
+ * for the filename to compress, and the trailing NULL needed by execv.
+ */
+static const char *gzip_args[] = { NULL, "-f", NULL, NULL };
+#define bzip2_args gzip_args
+#define xz_args gzip_args
+static const char *zstd_args[] = { NULL, "-q", "--rm", NULL, NULL };
static const struct compress_types compress_type[COMPRESS_TYPES] = {
- { "", "", "", NULL, 0},
- { "Z", COMPRESS_SUFFIX_GZ, _PATH_GZIP, gz_args, nitems(gz_args) },
- { "J", COMPRESS_SUFFIX_BZ2, _PATH_BZIP2, bz2_args, nitems(bz2_args) },
- { "X", COMPRESS_SUFFIX_XZ, _PATH_XZ, xz_args, nitems(xz_args) },
- { "Y", COMPRESS_SUFFIX_ZST, _PATH_ZSTD, zstd_args, nitems(zstd_args) }
+ { "", "", "", NULL, 0 },
+ { "Z", ".gz", _PATH_GZIP, gzip_args, nitems(gzip_args) },
+ { "J", ".bz2", _PATH_BZIP2, bzip2_args, nitems(bzip2_args) },
+ { "X", ".xz", _PATH_XZ, xz_args, nitems(xz_args) },
+ { "Y", ".zst", _PATH_ZSTD, zstd_args, nitems(zstd_args) }
};
struct conf_entry {
@@ -2027,31 +2010,26 @@
char zresult[MAXPATHLEN];
char command[BUFSIZ];
char **args;
- int c, i, nargs;
+ int c, nargs;
assert(zwork != NULL);
pgm_path = NULL;
strlcpy(zresult, zwork->zw_fname, sizeof(zresult));
if (zwork->zw_conf != NULL &&
- zwork->zw_conf->compress > COMPRESS_NONE)
- for (c = 1; c < COMPRESS_TYPES; c++) {
- if (zwork->zw_conf->compress == c) {
- nargs = compress_type[c].nargs;
- args = calloc(nargs, sizeof(*args));
- if (args == NULL)
- err(1, "calloc()");
- 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 < nargs; i++) {
- if (compress_type[c].args[i] == NULL)
- break;
- args[i] = compress_type[c].args[i];
- }
- break;
- }
+ zwork->zw_conf->compress > COMPRESS_NONE) {
+ nargs = compress_type[zwork->zw_conf->compress].nargs;
+ args = calloc(nargs, sizeof(*args));
+ if (args == NULL)
+ err(1, "calloc()");
+ 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 < nargs; c++) {
+ args[c] = __DECONST(char *,
+ compress_type[zwork->zw_conf->compress].args[c]);
}
+ }
if (pgm_path == NULL) {
warnx("invalid entry for %s in do_zipwork", zwork->zw_fname);
return;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 26, 6:55 AM (4 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37273870
Default Alt Text
D16518.id46171.diff (4 KB)
Attached To
Mode
D16518: newsyslog: simplify compression code
Attached
Detach File
Event Timeline
Log In to Comment