syslogd: Minor, factor out O_CREATE

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-12-09 13:41:34 +01:00
parent 08b6c6fd0f
commit d6b7cd6134
2 changed files with 7 additions and 6 deletions

View File

@ -61,21 +61,18 @@ static char sccsid[] __attribute__((unused)) =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <signal.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/wait.h>
@ -1319,7 +1316,7 @@ void logrotate(struct filed *f)
(void)rename(f->f_un.f_fname, newFile);
close(f->f_file);
f->f_file = open(f->f_un.f_fname, O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK | O_NOCTTY, 0644);
f->f_file = open(f->f_un.f_fname, O_CREATE | O_NONBLOCK | O_NOCTTY, 0644);
if (f->f_file < 0) {
f->f_type = F_UNUSED;
ERR("Failed re-opening log file %s after rotation", f->f_un.f_fname);
@ -2497,8 +2494,7 @@ static struct filed *cfline(char *line)
f->f_file = open(++p, O_RDWR | O_NONBLOCK | O_NOCTTY);
f->f_type = F_PIPE;
} else {
f->f_file = open(p, O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK | O_NOCTTY,
0644);
f->f_file = open(p, O_CREATE | O_NONBLOCK | O_NOCTTY, 0644);
f->f_type = F_FILE;
}

View File

@ -34,12 +34,15 @@
#include "config.h"
#include <fcntl.h>
#include <netdb.h> /* struct addrinfo */
#ifdef __linux__
#include <sys/klog.h>
#endif
#include <sys/param.h> /* MAXHOSTNAMELEN */
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h> /* struct sockaddr_un */
#include "queue.h"
#include "syslog.h"
@ -117,6 +120,8 @@
#define AI_SECURE 0x8000 /* Tell socket_create() to not bind() */
#define O_CREATE O_WRONLY | O_APPEND | O_CREAT
/* From The Practice of Programming, by Kernighan and Pike */
#ifndef NELEMS
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))