static char sccsid
[] = "@(#)logent.c 5.9 (Berkeley) %G%";
#if defined(USG) || defined(BSD4_2)
extern char *sys_errlist
[];
get_logfd(pname
, logfilename
)
savemask
= umask(LOGMASK
);
(void) sprintf(lfile
, "%s/%s/%s", LOGBYSITE
, pname
, Rmtname
);
fp
= fopen(logfilename
, "a");
flags
= fcntl(fileno(fp
), F_GETFL
, 0);
fcntl(fileno(Lp
), F_SETFL
, flags
|O_APPEND
);
} else /* we really want to log this, but it's the logging that failed*/
mlogent(fp
, status
, text
)
extern struct tm
*localtime();
tp
= localtime(&Now
.time
);
fprintf(fp
, "%s %s (%d/%d-%2.2d:%2.2d-%d) ",
fprintf(fp
, "%s %s (%d/%d-%02d:%02d-%d) ",
User
, Rmtname
, 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-%2.2d:%2.2d-%d) ", tp
->tm_mon
+ 1,
tp
->tm_mday
, tp
->tm_hour
, tp
->tm_min
, pid
);
fprintf(stderr
, "(%d/%d-%02d:%02d-%d) ", tp
->tm_mon
+ 1,
tp
->tm_mday
, tp
->tm_hour
, tp
->tm_min
, pid
);
fprintf(stderr
, "%s %s\n", status
, text
);
* Arrange to close fd on exec(II).
* Otherwise unwanted file descriptors are inherited
* by other programs. And that may be a security hole.
#if defined(USG) || defined(BSD4_2)
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
);
Lp
= get_logfd(Progname
, LOGFILE
);
mlogent(Lp
, status
, text
);
Sp
= get_logfd("xferstats", SYSLOG
);
sprintf(tbuf
, "(%ld.%02u)", Now
.time
, Now
.millitm
/10);
* This is for sites that don't have a decent syslog() in their library
* This routine would be a lot simpler if syslog() didn't permit %m
syslog(priority
, format
, p0
, p1
, p2
, p3
, p4
)
char nformat
[BUFSIZ
], sbuf
[BUFSIZ
];
while ((c
= *s
++) != '\0' && c
!= '\n' && d
< &nformat
[BUFSIZ
]) {
if ((unsigned)errno
> sys_nerr
)
sprintf(d
, "error %d", errno
);
strcpy(d
, sys_errlist
[errno
]);
Ep
= get_logfd(NULL
, ERRLOG
);
sprintf(sbuf
, nformat
, p0
, p1
, p2
, p3
, p4
);