static void logit(int priority, char *buf)
{
if (logfname) {
- if (!logfile) {
- extern int orig_umask;
- int old_umask = umask(022 | orig_umask);
- logfile = fopen(logfname, "a");
- umask(old_umask);
- }
+ if (!logfile)
+ log_open();
fprintf(logfile,"%s [%d] %s",
timestring(time(NULL)), (int)getpid(), buf);
fflush(logfile);
/* optionally use a log file instead of syslog */
logfname = lp_log_file();
if (logfname) {
- if (*logfname)
+ if (*logfname) {
+ log_open();
return;
+ }
logfname = NULL;
}
#endif
}
-/* for long runs when using a log file, close it before potential long waits
- so it can be trimmed by another process instead of growing forever */
-void log_release()
+void log_open()
+{
+ if (logfname && !logfile) {
+ extern int orig_umask;
+ int old_umask = umask(022 | orig_umask);
+ logfile = fopen(logfname, "a");
+ umask(old_umask);
+ }
+}
+
+void log_close()
{
if (logfile) {
fclose(logfile);
struct sockaddr addr;
int in_addrlen = sizeof(addr);
- log_release();
+ /* close log file before the potentially very long select so
+ file can be trimmed by another process instead of growing
+ forever */
+ log_close();
FD_ZERO(&fds);
FD_SET(s, &fds);
if (fork()==0) {
close(s);
+ /* open log file in child before possibly giving
+ up privileges */
+ log_open();
+
_exit(fn(fd));
}