/* logger.c - system logging routines */
static char *rcsid
= "$Header: /f/osi/compat/RCS/logger.c,v 7.6 91/02/22 09:15:32 mrose Interim $";
* $Header: /f/osi/compat/RCS/logger.c,v 7.6 91/02/22 09:15:32 mrose Interim $
* Revision 7.6 91/02/22 09:15:32 mrose
* Revision 7.5 90/11/21 11:29:50 mrose
* Revision 7.4 90/10/23 20:40:43 mrose
* Revision 7.3 90/08/14 14:25:18 mrose
* Revision 7.2 90/04/23 00:08:12 mrose
* Revision 7.1 90/02/19 13:07:17 mrose
* Revision 7.0 89/11/23 21:23:17 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
#define CHKINT 15 /* call ll_check 1 in every 15 uses... */
static struct ll_private
*llp
= NULL
;
static IFP _ll_header_routine
= ll_defmhdr
;
&& (llp
= (struct ll_private
*)
calloc ((unsigned int) getdtablesize (),
if (lp
-> ll_file
== NULLCP
|| *lp
-> ll_file
== NULL
) {
lp
-> ll_stat
|= LLOGERR
;
lp
-> ll_stat
&= ~LLOGERR
;
if (lp
-> ll_fd
!= NOTOK
)
if (strcmp (lp
-> ll_file
, "-") == 0) {
lp
-> ll_stat
|= LLOGTTY
;
(void) sprintf (bp
= buffer
, _isodefile (isodelogpath
, lp
-> ll_file
),
mode
= O_WRONLY
| O_APPEND
;
if (stat (bp
, &st
) == NOTOK
&& (lp
-> ll_stat
& LLOGCRT
))
lp
-> ll_fd
= open (bp
, mode
, 0666);
if (ll_check (lp
) == NOTOK
)
if (lp
-> ll_fd
!= NOTOK
)
llp
[lp
-> ll_fd
].ll_checks
= CHKINT
;
return (lp
-> ll_fd
!= NOTOK
? OK
: NOTOK
);
if (lp
-> ll_fd
== NOTOK
)
status
= close (lp
-> ll_fd
);
lp
= va_arg (ap
, LLog
*);
event
= va_arg (ap
, int);
result
= _ll_log (lp
, event
, ap
);
int ll_log (lp
, event
, what
, fmt
)
return ll_log (lp
, event
, what
, fmt
);
int _ll_log (lp
, event
, ap
) /* what, fmt, args ... */
if (!(lp
-> ll_events
& event
))
(*_ll_header_routine
)(bp
, lp
-> ll_hdr
, lp
-> ll_dhdr
);
what
= va_arg (ap
, char *);
_asprintf (bp
, what
, ap
);
if (lp
-> ll_syslog
& event
) {
(void) syslog (priority
, "%s", buffer
+ 13);
if (lp
-> ll_stat
& LLOGCLS
)
if (!(lp
-> ll_stat
& LLOGTTY
)
&& strcmp (lp
-> ll_file
, "-") == 0)
lp
-> ll_stat
|= LLOGTTY
;
if (lp
-> ll_stat
& LLOGTTY
) {
if (lp
-> ll_fd
!= NOTOK
)
(void) fprintf (stderr
, "LOGGING: ");
(void) fputs (bp
, stderr
);
(void) fputc ('\n', stderr
);
if (lp
-> ll_fd
== NOTOK
) {
if ((lp
-> ll_stat
& (LLOGERR
| LLOGTTY
)) == (LLOGERR
| LLOGTTY
))
if (ll_open (lp
) == NOTOK
)
if ((!llp
|| llp
[lp
-> ll_fd
].ll_checks
-- < 0)
&& ll_check (lp
) == NOTOK
)
*bp
++ = '\n', *bp
= NULL
;
if ((status
= write (lp
-> ll_fd
, buffer
, cc
)) != cc
) {
lp
-> ll_stat
|= LLOGERR
;
if ((lp
-> ll_stat
& LLOGCLS
) && ll_close (lp
) == NOTOK
)
void ll_hdinit (lp
, prefix
)
if ((lp
-> ll_stat
& LLOGHDR
) && strlen (lp
-> ll_hdr
) == 25)
(cp
= lp
-> ll_hdr
)[8] = NULL
;
if ((cp
= rindex (prefix
, '/')))
if (cp
== NULL
|| *cp
== NULL
)
if ((up
= getenv ("USER")) == NULLCP
&& (up
= getenv ("LOGNAME")) == NULLCP
) {
(void) sprintf (user
, "#%d", getuid ());
(void) sprintf (buffer
, "%-8.8s %05d (%-8.8s)",
cp
, getpid () % 100000, up
);
if (lp
-> ll_stat
& LLOGHDR
)
lp
-> ll_stat
&= ~LLOGHDR
;
if ((lp
-> ll_hdr
= malloc ((unsigned) (strlen (buffer
) + 1))) == NULLCP
)
(void) strcpy (lp
-> ll_hdr
, buffer
);
lp
-> ll_stat
|= LLOGHDR
;
void ll_dbinit (lp
, prefix
)
if ((cp
= rindex (prefix
, '/')))
if (cp
== NULL
|| *cp
== NULL
)
(void) sprintf (buffer
, "./%s.log", cp
);
if ((lp
-> ll_file
= malloc ((unsigned) (strlen (buffer
) + 1)))
(void) strcpy (lp
-> ll_file
, buffer
);
lp
-> ll_events
|= LLOG_ALL
;
lp
-> ll_stat
|= LLOGTTY
;
lp
= va_arg (ap
, LLog
*);
result
= _ll_printf (lp
, ap
);
return ll_printf (lp
, fmt
);
int _ll_printf (lp
, ap
) /* fmt, args ... */
fmt
= va_arg (fp
, char *);
if (strcmp (fmt
, "%s") != 0) {
_asprintf (bp
, NULLCP
, ap
);
fmt
= va_arg (fp
, char *);
if (!(lp
-> ll_stat
& LLOGTTY
)
&& strcmp (lp
-> ll_file
, "-") == 0)
lp
-> ll_stat
|= LLOGTTY
;
if (lp
-> ll_stat
& LLOGTTY
) {
(void) fputs (bp
, stderr
);
(void) fputs (fmt
, stderr
);
if (lp
-> ll_fd
== NOTOK
) {
if ((lp
-> ll_stat
& (LLOGERR
| LLOGTTY
)) == (LLOGERR
| LLOGTTY
))
if (ll_open (lp
) == NOTOK
)
if ((!llp
|| llp
[lp
-> ll_fd
].ll_checks
-- < 0)
&& ll_check (lp
) == NOTOK
)
if ((status
= write (lp
-> ll_fd
, bp
? buffer
: fmt
, cc
)) != cc
) {
lp
-> ll_stat
|= LLOGERR
;
if (lp
-> ll_stat
& LLOGCLS
)
char *ll_preset (va_alist
)
static char buffer
[BUFSIZ
];
_asprintf (buffer
, NULLCP
, ap
);
if ((size
= lp
-> ll_msize
) <= 0)
if (llp
&& lp
-> ll_fd
!= NOTOK
)
llp
[lp
-> ll_fd
].ll_checks
= CHKINT
;
|| (fstat (lp
-> ll_fd
, &st
) != NOTOK
&& st
.st_size
< (size
<<= 10)))
if (!(lp
-> ll_stat
& LLOGZER
)) {
lp
-> ll_stat
|= LLOGERR
;
(void) ftruncate (lp
-> ll_fd
, (off_t
) 0);
(void) ftruncate (lp
-> ll_fd
, 0);
(void) lseek (lp
-> ll_fd
, 0L, 0);
(void) sprintf (buffer
, _isodefile (isodelogpath
, lp
-> ll_file
),
if ((fd
= open (buffer
, O_WRONLY
| O_APPEND
| O_TRUNC
)) == NOTOK
)
* ll_defmhdr - Default "make header" routine.
int ll_defmhdr(bufferp
, headerp
, dheaderp
)
char *bufferp
; /* Buffer pointer */
char *headerp
; /* Static header string */
char *dheaderp
; /* Dynamic header string */
(void) sprintf (bufferp
, "%2d/%2d %2d:%02d:%02d %s %s ",
tm
-> tm_mon
+ 1, tm
-> tm_mday
,
tm
-> tm_hour
, tm
-> tm_min
, tm
-> tm_sec
,
dheaderp
? dheaderp
: "");
* ll_setmhdr - Set "make header" routine, overriding default.
IFP
ll_setmhdr (make_header_routine
)
IFP result
= _ll_header_routine
;
_ll_header_routine
= make_header_routine
;