syslogd: Minor, factor out O_CREATE
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
08b6c6fd0f
commit
d6b7cd6134
@ -61,21 +61,18 @@ static char sccsid[] __attribute__((unused)) =
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utmp.h>
|
#include <utmp.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -1319,7 +1316,7 @@ void logrotate(struct filed *f)
|
|||||||
(void)rename(f->f_un.f_fname, newFile);
|
(void)rename(f->f_un.f_fname, newFile);
|
||||||
close(f->f_file);
|
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) {
|
if (f->f_file < 0) {
|
||||||
f->f_type = F_UNUSED;
|
f->f_type = F_UNUSED;
|
||||||
ERR("Failed re-opening log file %s after rotation", f->f_un.f_fname);
|
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_file = open(++p, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||||
f->f_type = F_PIPE;
|
f->f_type = F_PIPE;
|
||||||
} else {
|
} else {
|
||||||
f->f_file = open(p, O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK | O_NOCTTY,
|
f->f_file = open(p, O_CREATE | O_NONBLOCK | O_NOCTTY, 0644);
|
||||||
0644);
|
|
||||||
f->f_type = F_FILE;
|
f->f_type = F_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +34,15 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <netdb.h> /* struct addrinfo */
|
#include <netdb.h> /* struct addrinfo */
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sys/klog.h>
|
#include <sys/klog.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/un.h> /* struct sockaddr_un */
|
#include <sys/un.h> /* struct sockaddr_un */
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "syslog.h"
|
#include "syslog.h"
|
||||||
@ -117,6 +120,8 @@
|
|||||||
|
|
||||||
#define AI_SECURE 0x8000 /* Tell socket_create() to not bind() */
|
#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 */
|
/* From The Practice of Programming, by Kernighan and Pike */
|
||||||
#ifndef NELEMS
|
#ifndef NELEMS
|
||||||
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user