logrotate/logrotate-autoext.dif

70 lines
2.1 KiB
Plaintext

--- config.c
+++ config.c
@@ -343,7 +343,7 @@
logInfo ** logsPtr, int *numLogsPtr)
{
int fd;
- char *buf, *endtag;
+ char *buf, *endtag, *compresscmd_base;
char oldchar, foo;
int length;
int lineNum = 1;
@@ -889,6 +889,18 @@
message(MESS_DEBUG, "compress_prog is now %s\n",
newlog->compress_prog);
+ compresscmd_base=strdup(basename(newlog->compress_prog));
+ i=0; /* have to check whether we may do this! */
+ /* we check whether we changed the compress_cmd. In case we use the apropriate extension
+ as listed in compress_cmd_list */
+ while ((i>=0)&&(strcmp(compress_cmd_list[i][0], "EOLIST"))){
+ if (0==strcmp(compress_cmd_list[i][0], compresscmd_base)){
+ newlog->compress_ext=strdup((char *)compress_cmd_list[i][1]);
+ message(MESS_DEBUG, "compress_ext was changed to %s\n", newlog->compress_ext);
+ i=-10; /* terminate loop! */
+ }
+ i++;
+ }
} else if (!strcmp(start, "uncompresscmd")) {
*endtag = oldchar, start = endtag;
if (!
--- logrotate.c
+++ logrotate.c
@@ -50,6 +50,15 @@
int debug = 0;
char *mailCommand = DEFAULT_MAIL_COMMAND;
+/* This is the declaration. Note the "2" is needed in the definition (logrotate.h), too! */
+const char * compress_cmd_list[][2] = {
+ {"gzip", ".gz"},
+ {"bzip2", ".bz2"},
+ {"compress", ".Z"},
+ {"zip", "zip"},
+ {"EOLIST", "EOLIST"} /* end-marker */
+};
+
time_t nowSecs = 0;
static int globerr(const char *pathname, int theerr)
@@ -263,7 +272,7 @@
char *uncompressCommand, char *address, char *subject)
{
int mailInput;
- pid_t mailChild, uncompressChild;
+ pid_t mailChild, uncompressChild=(pid_t) 0;
int mailStatus, uncompressStatus;
int uncompressPipe[2];
char *mailArgv[] = { mailCommand, "-s", subject, address, NULL };
--- logrotate.h
+++ logrotate.h
@@ -51,6 +51,9 @@
int compress_options_count;
} logInfo;
+/* This is the definition. Note we have to carry the "2" within the declaration (logrotate.c), too! */
+extern const char * compress_cmd_list[][2];
+
int readAllConfigPaths(const char **paths, logInfo ** logsPtr,
int *numLogsPtr);