diff options
author | Joern Engel <joern@logfs.org> | 2011-12-22 16:32:51 -0800 |
---|---|---|
committer | Joern Engel <joern@logfs.org> | 2011-12-22 16:41:49 -0800 |
commit | 6a8b621bce2e4e0c6d0922749140cc61d13c0168 (patch) | |
tree | c9201346050c8398a25b4bb9c65c71f5657de2f3 | |
parent | 7f0a9d42554e07c3aa03a1e5ba886332ae9595f7 (diff) | |
download | cancd-6a8b621bce2e4e0c6d0922749140cc61d13c0168.tar.gz |
Simplify file format
No more funny business with time/date. We expect a lot of output, not
just the rare kernel panic. Having literally millions of files around
simply doesn't fly.
Also, I believe the old code failed to NUL-terminate the string.
Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r-- | cancd.c | 51 |
1 files changed, 16 insertions, 35 deletions
@@ -64,12 +64,12 @@ static char *log_prefix = "/var/crash"; * to 10.0.0.1/2005-10-01-15:30/log. The files are underneath * the log_prefix. Modified with the '-o' option. */ -static char *log_format = "%Q/%Y-%m-%d-%H:%M/log"; +static char *log_format = "%Q.log"; /* * Port number to listen on. Modified with the '-p' option. */ -static uint16_t log_port = 6667; +static uint16_t log_port = 7075; /* Socket we are using */ static int sock_fd; @@ -106,31 +106,27 @@ static int setup_signals() return rc; } -static char *get_path(const void *src) +static char *get_path(const void *addr) { char ntop[INET6_ADDRSTRLEN + 1]; - char format[PATH_MAX]; + char path[PATH_MAX]; size_t ntop_len; - char *newstr, *ptr, *fptr; + char *src, *dst; int havep; - time_t now; - if (!inet_ntop(PF_INET, src, ntop, sizeof(ntop))) { + if (!inet_ntop(PF_INET, addr, ntop, sizeof(ntop))) { syslog(LOG_ERR, "Unable to resolve address: %s", strerror(errno)); return NULL; } - ntop_len = strlen(ntop); - for (havep = 0, ptr = log_format, fptr = format; *ptr; ptr++) { - switch (*ptr) { + for (havep = 0, src = log_format, dst = path; *src; src++) { + switch (*src) { case '%': if (havep) { /* '%%' should be passed on to strftime(3) */ - *fptr = '%'; - fptr++; - *fptr = '%'; - fptr++; + *dst++ = '%'; + *dst++ = '%'; havep = 0; } else @@ -139,38 +135,23 @@ static char *get_path(const void *src) case 'Q': if (havep) { /* Copy our address in */ - memmove(fptr, ntop, ntop_len); - fptr += ntop_len; + memmove(dst, ntop, ntop_len); + dst += ntop_len; havep = 0; break; } /* Fall Through */ default: if (havep) { - *fptr = '%'; - fptr++; + *dst++ = '%'; havep = 0; } - *fptr = *ptr; - fptr++; + *dst++ = *src; break; } } - - newstr = malloc(sizeof(char) * PATH_MAX); - if (!newstr) { - syslog(LOG_ERR, "Unable to allocate memory while formating log filename"); - return NULL; - } - - now = time(NULL); - if (!strftime(newstr, PATH_MAX, format, localtime(&now))) { - syslog(LOG_ERR, "Unable to format filename: %s", strerror(errno)); - free(newstr); - newstr = NULL; - } - - return newstr; + *dst++ = 0; + return strdup(path); } struct dir_to_make { |