static char sccsid
[] = "@(#)logent.c 5.2 (Berkeley) 7/2/83";
/* This logfile stuff was awful -- it did output to an
* This new version just open the single logfile and writes
* the record in the stdio buffer. Once that's done, it
* positions itself at the end of the file (lseek), and
* writes the buffer out. This could mangle things but
* it isn't likely. -- ittvax!swatt
* If the files could be opened with "guaranteed append to end",
* the lseeks could be removed.
* Using fseek would be slightly cleaner,
* but would mangle things slightly more often.
* logent(text, status) make log entry
/* Open the log file if necessary */
savemask
= umask(LOGMASK
);
Lp
= fopen (LOGFILE
, "a");
/* make entry in existing temp log file */
mlogent(Lp
, status
, text
);
* mlogent(fp, status, text) - make a log entry
mlogent(fp
, status
, text
)
extern struct tm
*localtime();
fprintf(fp
, "%s %s ", User
, Rmtname
);
fprintf(fp
, "(%d/%d-%d:%02d-%d) ", tp
->tm_mon
+ 1,
tp
->tm_mday
, tp
->tm_hour
, tp
->tm_min
, pid
);
fprintf(fp
, "%s (%s)\n", status
, text
);
/* Since it's buffered */
lseek (fileno(fp
), (long)0, 2);
fprintf(stderr
, "%s %s ", User
, Rmtname
);
fprintf(stderr
, "(%d/%d-%d:%02d-%d) ", tp
->tm_mon
+ 1,
tp
->tm_mday
, tp
->tm_hour
, tp
->tm_min
, pid
);
fprintf(stderr
, "%s (%s)\n", status
, text
);
* logcls() close log file
* syslog(text) make system log entry
extern struct tm
*localtime();
savemask
= umask(LOGMASK
);
fprintf(Sp
, "%s %s ", User
, Rmtname
);
fprintf(Sp
, "(%d/%d-%d:%02d) ", tp
->tm_mon
+ 1,
tp
->tm_mday
, tp
->tm_hour
, tp
->tm_min
);
fprintf(Sp
, "(%ld) %s\n", clock
, text
);
/* Position at end and flush */
lseek (fileno(Sp
), (long)0, 2);
* Arrange to close fd on exec(II).
* Otherwise unwanted file descriptors are inherited
* by other programs. And that may be a security hole.
ret
= fcntl(fd
, F_SETFD
, 1); /* Steve Bellovin says this does it */
ret
= ioctl(fd
, FIOCLEX
, STBNULL
);
DEBUG(2, "CAN'T FIOCLEX %d\n", fd
);