summaryrefslogtreecommitdiff
path: root/syslogd/logfile.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-08-13 22:06:34 +0200
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-08-13 22:06:34 +0200
commit0624f95de639a41e8a47c264cdb7387a386a4dcd (patch)
treee2385f329e659eace10c91af28bad30c31c16627 /syslogd/logfile.c
parente15208097cf3e97c8165536c2005e53961227621 (diff)
usyslogd: cleanup log file filename handling
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'syslogd/logfile.c')
-rw-r--r--syslogd/logfile.c37
1 files changed, 8 insertions, 29 deletions
diff --git a/syslogd/logfile.c b/syslogd/logfile.c
index 56f8d53..adc7e3c 100644
--- a/syslogd/logfile.c
+++ b/syslogd/logfile.c
@@ -28,53 +28,32 @@
#include "logfile.h"
-logfile_t *logfile_create(const char *ident, const char *name, int facility)
+logfile_t *logfile_create(const char *filename, int facility)
{
- int dfd = AT_FDCWD;
- logfile_t *file;
- size_t size;
+ logfile_t *file = calloc(1, sizeof(*file) + strlen(filename) + 1);
- size = sizeof(*file) + 1;
- if (ident != NULL)
- size += strlen(ident);
-
- file = calloc(1, size);
if (file == NULL) {
perror("calloc");
return NULL;
}
- if (ident != NULL) {
- strcpy(file->ident, ident);
- if (mkdir(file->ident, 0750) != 0 && errno != EEXIST) {
- perror(file->ident);
- goto fail;
- }
-
- dfd = open(file->ident, O_DIRECTORY | O_RDONLY);
- if (dfd < 0) {
- perror(file->ident);
- goto fail;
- }
- }
+ strcpy(file->filename, filename);
file->facility = facility;
- file->fd = openat(dfd, name, O_WRONLY | O_CREAT, 0640);
+ file->fd = open(file->filename, O_WRONLY | O_CREAT, 0640);
if (file->fd < 0) {
- perror(name);
+ perror(file->filename);
goto fail;
}
if (lseek(file->fd, 0, SEEK_END))
- goto fail;
+ goto fail_fd;
- if (dfd != AT_FDCWD)
- close(dfd);
return file;
+fail_fd:
+ close(file->fd);
fail:
- if (dfd != AT_FDCWD)
- close(dfd);
free(file);
return NULL;
}