2 #include <stdio.h> /* vsprintf() */
4 #include <sys/types.h> /* open() */
7 #include <unistd.h> /* write() */
8 #include <string.h> /* strcmp(), strerror() */
9 #include <errno.h> /* errno */
10 #include <time.h> /* time() and friends */
16 /* Logging file descriptor, -1 if logging is disabled */
17 static int logfd
= -1;
22 if (settings
.logfname
== NULL
) {
27 if (strcmp(settings
.logfname
, "-") == 0) {
32 logfd
= open(settings
.logfname
, O_WRONLY
| O_APPEND
| O_CREAT
, 0660);
41 /* Just call log_init(), it will do just fine as we don't need any
42 * special considerations for reopens */
46 void wlog(const char *fmt
, ...)
50 char str
[MAX_LOG_STR
];
51 char timestr
[MAX_LOG_STR
];
60 tr
= strftime(timestr
, MAX_LOG_STR
, "%F %H:%M:%S ", tmp
);
63 r
= vsnprintf(str
, MAX_LOG_STR
, fmt
, ap
);
66 write(logfd
, timestr
, tr
);
70 void errlog(const char *s
)
72 wlog("%s: %s\n", s
, strerror(errno
));
79 if (settings
.pidfile
== NULL
)
82 f
= fopen(settings
.pidfile
, "w");
84 errlog("Can't open pidfile for writing");
88 fprintf(f
, "%d\n", getpid());