mirror of https://github.com/GnoConsortium/gno.git
This is a re-implementation of the syslog(3) and related functions.
This commit is contained in:
parent
4e1bec2062
commit
b7010abc60
|
@ -1,18 +1,18 @@
|
|||
#
|
||||
# Makefile for libc/gen.
|
||||
#
|
||||
# $Id: Makefile,v 1.10 1998/03/24 16:10:35 gdr-ftp Exp $
|
||||
# $Id: Makefile,v 1.11 1998/06/24 04:19:57 gdr-ftp Exp $
|
||||
#
|
||||
|
||||
LIB = c
|
||||
LIBPFX = $(OBJ_DIR)../
|
||||
NO_REZ = true
|
||||
SRC_ASM = setjmp.asm syslog.asm
|
||||
SRC_ASM = setjmp.asm
|
||||
SRC_C = basename.c bmem.c compat.c dirent.c err.c fnmatch.c fts.c \
|
||||
getcwd.c getgrent.c getlogin.c getpass.c getpwent.c \
|
||||
getttyent.c hostname.c \
|
||||
oldlog.c popen.c psignal.c pwcache.c scandir.c siglist.c sleep.c \
|
||||
tty.c uname.c utime.c
|
||||
syslog.c tty.c uname.c utime.c
|
||||
|
||||
SRCS = $(SRC_ASM) $(SRC_C)
|
||||
|
||||
|
|
|
@ -1,501 +0,0 @@
|
|||
* These syslog() related routines use syslogd. They replace the old
|
||||
* syslog() routines in the lbsd library.
|
||||
*
|
||||
* If syslogd is not found, syslog() calls old_syslog with the handle it
|
||||
* would have passed to syslogd. If you are sure your program will have
|
||||
* syslogd available when it is run, you can replace old_syslog() with
|
||||
* a dummy routine that does nothing and returns. This will make your
|
||||
* program smaller.
|
||||
*
|
||||
* syslogd is built into init and is automatically started by it. I
|
||||
* recommend that you use init with GNO/ME 2.0
|
||||
*
|
||||
* Phillip Vandry, August 1993
|
||||
*
|
||||
* $Id: syslog.asm,v 1.1 1997/02/28 05:12:45 gdr Exp $
|
||||
*
|
||||
* This file is formatted for tab stops at positions 10, 16, 41, 40, 57,
|
||||
* 65, and 73 (standard Orca/M systabs setting).
|
||||
*
|
||||
keep syslog
|
||||
mcopy syslog.mac
|
||||
case on
|
||||
|
||||
dummy start ; ends up in .root
|
||||
end
|
||||
|
||||
syslog start libc_gen__
|
||||
tsc
|
||||
sec
|
||||
sbc #$8
|
||||
tcs
|
||||
phd
|
||||
tcd
|
||||
* Direct: 1=va_list, 9=RTL, 12=prio, 14=char *, 18=args
|
||||
|
||||
lda #0
|
||||
sta 3
|
||||
sta 7
|
||||
tdc
|
||||
clc
|
||||
adc #18
|
||||
sta 1
|
||||
sta 5
|
||||
|
||||
pea 0
|
||||
tdc
|
||||
inc a
|
||||
pha
|
||||
pei 16
|
||||
pei 14
|
||||
pei 12
|
||||
jsl vsyslog
|
||||
|
||||
lda 1
|
||||
clc
|
||||
sec
|
||||
sbc 5
|
||||
tax ; num extra parms
|
||||
|
||||
* Direct: 1=va_list, 9=RTL, 12=prio, 14=char *, 18=args
|
||||
lda 10
|
||||
sta 16,x
|
||||
lda 9
|
||||
sta 15,x
|
||||
pld
|
||||
tsc
|
||||
clc
|
||||
adc #14
|
||||
phx
|
||||
adc 1,s
|
||||
tcs
|
||||
rtl
|
||||
end
|
||||
|
||||
vsyslog start libc_gen__
|
||||
using syslog_dat
|
||||
|
||||
space equ 26
|
||||
argstart equ space+4
|
||||
|
||||
tsc
|
||||
sec
|
||||
sbc #space
|
||||
tcs
|
||||
phd
|
||||
tcd
|
||||
phb
|
||||
|
||||
prio equ argstart
|
||||
format equ argstart+2
|
||||
valist equ argstart+6
|
||||
|
||||
sendhand equ 1
|
||||
sendptr equ 5
|
||||
lerrno equ 9
|
||||
errlen equ 9
|
||||
chand equ 11
|
||||
cptr equ 15
|
||||
cumlen equ 19
|
||||
error equ 23
|
||||
|
||||
lda >~USER_ID ; uck! bad name!
|
||||
sta >memid
|
||||
|
||||
* Log only if bit clear in LogMask
|
||||
lda >errno
|
||||
sta lerrno
|
||||
lda prio
|
||||
and #7
|
||||
tax
|
||||
lda >LogMask
|
||||
lsrloop lsr a
|
||||
dex
|
||||
bpl lsrloop
|
||||
* carry = apropriate bit
|
||||
bcc dolog
|
||||
|
||||
* get rif of parameters by running through sprintf
|
||||
jsr mksendhand
|
||||
pei valist+2
|
||||
pei valist
|
||||
pei format+2
|
||||
pei format
|
||||
pei sendptr+2
|
||||
pei sendptr
|
||||
jsl vsprintf
|
||||
~DisposeHandle <sendhand
|
||||
brl return
|
||||
|
||||
dolog anop
|
||||
lda prio
|
||||
and #$3f8
|
||||
bne gotone
|
||||
lda prio
|
||||
ora >LogFacility
|
||||
sta prio
|
||||
gotone anop
|
||||
jsr mksendhand
|
||||
jsr cpsendhand
|
||||
|
||||
lda >LogTag
|
||||
sta cptr
|
||||
lda >LogTag+2
|
||||
sta cptr+2
|
||||
ora cptr
|
||||
beq notag
|
||||
|
||||
lda >TagLen
|
||||
bne already
|
||||
ldy #0
|
||||
short m
|
||||
lppp lda [cptr],y
|
||||
beq foundlen
|
||||
iny
|
||||
bra lppp
|
||||
foundlen long m
|
||||
tya
|
||||
sta >TagLen
|
||||
|
||||
already sta [cumlen]
|
||||
tay
|
||||
short m
|
||||
fincp2 dey
|
||||
bmi fincp
|
||||
lda [cptr],y
|
||||
sta [sendptr],y
|
||||
bra fincp2
|
||||
fincp long m
|
||||
lda [cumlen]
|
||||
clc
|
||||
adc sendptr
|
||||
sta sendptr
|
||||
lda sendptr+2
|
||||
adc #0
|
||||
sta sendptr+2
|
||||
|
||||
notag anop
|
||||
lda >LogFlag
|
||||
lsr a
|
||||
bcc nopid
|
||||
|
||||
pha
|
||||
ldx #$0903
|
||||
jsl $e10008 ; getpid
|
||||
pea fmt|-16
|
||||
pea fmt
|
||||
pei sendptr+2
|
||||
pei sendptr
|
||||
jsl sprintf
|
||||
pha
|
||||
clc
|
||||
adc [cumlen]
|
||||
sta [cumlen]
|
||||
pla
|
||||
clc
|
||||
adc sendptr
|
||||
sta sendptr
|
||||
lda sendptr+2
|
||||
adc #0
|
||||
sta sendptr+2
|
||||
|
||||
nopid anop
|
||||
lda >LogTag
|
||||
ora >LogTag+2
|
||||
beq notagsecond
|
||||
lda [cumlen]
|
||||
inc a
|
||||
inc a
|
||||
sta [cumlen]
|
||||
lda #$203a
|
||||
sta [sendptr]
|
||||
lda sendptr
|
||||
clc
|
||||
adc #2
|
||||
sta sendptr
|
||||
lda sendptr+2
|
||||
adc #0
|
||||
sta sendptr+2
|
||||
|
||||
notagsecond anop
|
||||
lda lerrno
|
||||
bne isone
|
||||
lda #ptrtozero
|
||||
sta error
|
||||
lda #^ptrtozero
|
||||
sta error+2
|
||||
bra none
|
||||
isone pha
|
||||
jsl strerror
|
||||
sta error
|
||||
stx error+2
|
||||
phx
|
||||
pha
|
||||
jsl strlen
|
||||
sta errlen
|
||||
|
||||
none ldx #2 ; = bytes needed in copy (one null+slop)
|
||||
ldy #0
|
||||
runthrough lda [format],y
|
||||
cmp #$6d25 ; '%m'
|
||||
beq account
|
||||
and #$ff
|
||||
beq endstring
|
||||
iny
|
||||
inx
|
||||
bra runthrough
|
||||
account iny
|
||||
iny
|
||||
txa
|
||||
clc
|
||||
adc errlen
|
||||
tax
|
||||
bra runthrough
|
||||
endstring pha
|
||||
pha
|
||||
pea 0
|
||||
phx ; length
|
||||
stz chand
|
||||
stz chand+2
|
||||
lda format
|
||||
sta cptr
|
||||
lda format+2
|
||||
sta cptr+2
|
||||
lda >memid
|
||||
pha
|
||||
pea $4000
|
||||
pha
|
||||
pha
|
||||
~NewHandle *,*,*,*
|
||||
pla
|
||||
plx
|
||||
bcs impossible
|
||||
sta chand
|
||||
stx chand+2
|
||||
ldy #2
|
||||
lda [chand],y
|
||||
sta cptr+2
|
||||
lda [chand]
|
||||
sta cptr
|
||||
|
||||
pea 0 ; offset in source
|
||||
ldy #0 ; offset in dest
|
||||
realtime tyx
|
||||
ply
|
||||
lda [format],y
|
||||
cmp #$6d25 ; '%m'
|
||||
beq coper
|
||||
and #$ff
|
||||
beq excited
|
||||
iny
|
||||
phy
|
||||
txy
|
||||
sta [cptr],y
|
||||
iny
|
||||
bra realtime
|
||||
coper iny
|
||||
iny
|
||||
phy
|
||||
txy ; Y=offset in destination
|
||||
pea 0 ; offset in source
|
||||
anotherreal tyx
|
||||
ply
|
||||
lda [error],y
|
||||
and #$ff
|
||||
beq donerr
|
||||
iny
|
||||
phy
|
||||
txy
|
||||
sta [cptr],y
|
||||
iny
|
||||
bra anotherreal
|
||||
donerr txy
|
||||
bra realtime
|
||||
excited txy
|
||||
sta [cptr],y ; zero
|
||||
|
||||
impossible anop ; jump here if malloc() failed
|
||||
pei valist+2
|
||||
pei valist
|
||||
pei cptr+2
|
||||
pei cptr
|
||||
pei sendptr+2
|
||||
pei sendptr
|
||||
jsl vsprintf
|
||||
clc
|
||||
adc [cumlen]
|
||||
sta [cumlen]
|
||||
lda >LogFlag
|
||||
and #$20 ; PERROR
|
||||
beq noper
|
||||
|
||||
ldx cumlen
|
||||
ldy cumlen+2
|
||||
lda #3
|
||||
jsl WriteGString ; echo on standard error
|
||||
ldx #nlonly
|
||||
ldy #^nlonly
|
||||
lda #3
|
||||
jsl WriteGString
|
||||
|
||||
noper lda chand
|
||||
ora chand+2
|
||||
beq nochand
|
||||
~DisposeHandle <chand
|
||||
|
||||
nochand pei sendhand+2
|
||||
pei sendhand
|
||||
pea portname|-16
|
||||
pea portname
|
||||
jsl pgetport
|
||||
cmp #$ffff
|
||||
beq nosyslogd
|
||||
pha
|
||||
jsl psend
|
||||
ldy #6
|
||||
tryagain lda [sendhand],y
|
||||
cmp >memid
|
||||
bne return
|
||||
cop $7f
|
||||
bra tryagain
|
||||
|
||||
return plb
|
||||
lda argstart-3
|
||||
sta valist+1
|
||||
lda argstart-2
|
||||
sta valist+2
|
||||
pld
|
||||
tsc
|
||||
clc
|
||||
adc #(space+10)
|
||||
tcs
|
||||
rtl
|
||||
nosyslogd jsl old_syslog
|
||||
bra return
|
||||
|
||||
mksendhand pha
|
||||
pha
|
||||
pea 0
|
||||
pea 1024
|
||||
lda >memid
|
||||
pha
|
||||
pea $4000
|
||||
pha
|
||||
pha
|
||||
~NewHandle *,*,*,*
|
||||
plx
|
||||
stx sendhand
|
||||
plx
|
||||
stx sendhand+2
|
||||
bcs giveup
|
||||
ldy #2
|
||||
lda [sendhand],y
|
||||
sta sendptr+2
|
||||
lda [sendhand]
|
||||
sta sendptr
|
||||
rts
|
||||
giveup pea 1
|
||||
jsl sleep
|
||||
bra mksendhand
|
||||
|
||||
cpsendhand ldy #(Xthis-Xsyslog-2) ; is even
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
still lda Xsyslog,y
|
||||
sta [sendptr],y
|
||||
dey
|
||||
dey
|
||||
bpl still
|
||||
plb
|
||||
ldy #2
|
||||
lda prio
|
||||
sta [sendptr],y
|
||||
lda sendptr
|
||||
clc
|
||||
adc #(Xthis-Xsyslog)
|
||||
sta cumlen
|
||||
lda sendptr+2
|
||||
adc #0
|
||||
sta cumlen+2
|
||||
lda #0
|
||||
sta [cumlen]
|
||||
lda cumlen
|
||||
clc
|
||||
adc #2
|
||||
sta sendptr
|
||||
lda cumlen+2
|
||||
adc #0
|
||||
sta sendptr+2
|
||||
rts
|
||||
end
|
||||
|
||||
setlogmask start libc_gen__
|
||||
using syslog_dat
|
||||
* Stack: 1:RTL, 4:mask
|
||||
lda 4,s
|
||||
tax
|
||||
lda >LogMask
|
||||
sta 4,s
|
||||
txa
|
||||
sta >LogMask
|
||||
phb
|
||||
plx
|
||||
ply
|
||||
pla
|
||||
phy
|
||||
phx
|
||||
plb
|
||||
rtl
|
||||
end
|
||||
|
||||
closelog start libc_gen__
|
||||
using syslog_dat
|
||||
rtl
|
||||
end
|
||||
|
||||
openlog start libc_gen__
|
||||
using syslog_dat
|
||||
phb
|
||||
plx
|
||||
ply
|
||||
* Stack: 1:char *, 5:int, 7:int
|
||||
lda 1,s
|
||||
ora 3,s
|
||||
beq notag
|
||||
pla
|
||||
sta >LogTag
|
||||
pla
|
||||
sta >LogTag+2
|
||||
lda #0
|
||||
sta >TagLen
|
||||
dc h'a9'
|
||||
notag pla
|
||||
pla
|
||||
wastag pla
|
||||
sta >LogFlag
|
||||
pla
|
||||
sta >LogFacility
|
||||
phy
|
||||
phx
|
||||
plb
|
||||
rtl
|
||||
end
|
||||
|
||||
syslog_dat privdata libc_gen__
|
||||
LogTag ds 4
|
||||
TagLen ds 2
|
||||
LogFlag ds 2
|
||||
LogMask ds 2
|
||||
LogFacility ds 2
|
||||
memid ds 2
|
||||
|
||||
Xsyslog dc i'0,0,1,0,Xthis-Xsyslog'
|
||||
Xthis anop
|
||||
|
||||
fmt dc c'[%u] ',h'0'
|
||||
portname dc c'syslogd'
|
||||
ptrtozero dc h'0'
|
||||
|
||||
nlonly dc h'01 00 0d'
|
||||
end
|
|
@ -0,0 +1,446 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)syslog.c 8.4 (Berkeley) 3/18/94";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#define USE_PORTS /* use ports mech rather than TCP/IP */
|
||||
#define __SYSLOG_INTERNALS /* needed for the ports interface */
|
||||
|
||||
#ifndef USE_PORTS
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#ifndef USE_PORTS
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __GNO__
|
||||
#include <gno/gno.h> /* __prognameGS() */
|
||||
#endif
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#ifdef __ORCAC__
|
||||
#define STATIC static
|
||||
#else
|
||||
#define STATIC
|
||||
#endif
|
||||
|
||||
static int LogFile = -1; /* fd for log */
|
||||
static int connected; /* have done connect */
|
||||
static int LogStat = 0; /* status bits, set by openlog() */
|
||||
static const char *LogTag = NULL; /* string to tag the entry with */
|
||||
static int LogFacility = LOG_USER; /* default facility code */
|
||||
static int LogMask = 0xff; /* mask of priorities to be logged */
|
||||
#ifndef __GNO__ /* get __prognameGS() from <gno/gno.h>
|
||||
extern char *__progname; /* Program name, from crt0. */
|
||||
#endif
|
||||
|
||||
#ifdef USE_PORTS
|
||||
#include <sys/ports.h>
|
||||
static int openPort(void);
|
||||
static int sendPort(int port, const void *buf, int len);
|
||||
static void closePort(int port);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Format of the magic cookie passed through the stdio hook
|
||||
*/
|
||||
struct bufcookie {
|
||||
char *base; /* start of buffer */
|
||||
int left;
|
||||
};
|
||||
|
||||
/*
|
||||
* stdio write hook for writing to a static string buffer
|
||||
* XXX: Maybe one day, dynamically allocate it so that the line length
|
||||
* is `unlimited'.
|
||||
*/
|
||||
static ssize_t writehook(
|
||||
void *cookie, /* really [struct bufcookie *] */
|
||||
const char *buf, /* characters to copy */
|
||||
size_t len) /* length to copy */
|
||||
{
|
||||
struct bufcookie *h; /* private `handle' */
|
||||
|
||||
h = (struct bufcookie *)cookie;
|
||||
if (len > h->left) {
|
||||
/* clip in case of wraparound */
|
||||
len = h->left;
|
||||
}
|
||||
if (len > 0) {
|
||||
(void)memcpy(h->base, buf, len); /* `write' it. */
|
||||
h->base += len;
|
||||
h->left -= len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __ORCAC__
|
||||
#pragma optimize 78
|
||||
#pragma debug 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* syslog, vsyslog --
|
||||
* print message on log file; output is intended for syslogd(8).
|
||||
*/
|
||||
void
|
||||
#if __STDC__
|
||||
syslog(long pri, const char *fmt, ...)
|
||||
#else
|
||||
syslog(pri, fmt, va_alist)
|
||||
int pri;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
vsyslog(pri, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef __ORCAC__
|
||||
#pragma optimize 0
|
||||
#pragma debug 25
|
||||
#endif
|
||||
|
||||
void
|
||||
vsyslog(long pri, const char *fmt, va_list ap)
|
||||
{
|
||||
register int cnt;
|
||||
register char ch, *p, *t;
|
||||
time_t now;
|
||||
int fd, saved_errno;
|
||||
char *stdp;
|
||||
STATIC char tbuf[2048], fmt_cpy[1024];
|
||||
FILE *fp, *fmt_fp;
|
||||
struct bufcookie tbuf_cookie;
|
||||
struct bufcookie fmt_cookie;
|
||||
|
||||
#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
|
||||
/* Check for invalid bits. */
|
||||
if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
|
||||
syslog(INTERNALLOG,
|
||||
"syslog: unknown facility/priority: %x", pri);
|
||||
pri &= LOG_PRIMASK|LOG_FACMASK;
|
||||
}
|
||||
|
||||
/* Check priority against setlogmask values. */
|
||||
if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
|
||||
return;
|
||||
|
||||
saved_errno = errno;
|
||||
|
||||
/* Set default facility if none specified. */
|
||||
if ((pri & LOG_FACMASK) == 0)
|
||||
pri |= LogFacility;
|
||||
|
||||
/* Create the primary stdio hook */
|
||||
tbuf_cookie.base = tbuf;
|
||||
tbuf_cookie.left = sizeof(tbuf);
|
||||
fp = fwopen(&tbuf_cookie, writehook);
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
/* Build the message. */
|
||||
(void)time(&now);
|
||||
(void)fprintf(fp, "<%ld>", pri);
|
||||
(void)fprintf(fp, "%.15s ", ctime(&now) + 4);
|
||||
if (LogStat & LOG_PERROR) {
|
||||
/* Transfer to string buffer */
|
||||
(void)fflush(fp);
|
||||
stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left);
|
||||
}
|
||||
if (LogTag == NULL)
|
||||
#ifdef __GNO__
|
||||
LogTag = __prognameGS();
|
||||
#else
|
||||
LogTag = __progname;
|
||||
#endif
|
||||
if (LogTag != NULL)
|
||||
(void)fprintf(fp, "%s", LogTag);
|
||||
if (LogStat & LOG_PID)
|
||||
(void)fprintf(fp, "[%d]", getpid());
|
||||
if (LogTag != NULL) {
|
||||
(void)fprintf(fp, ": ");
|
||||
}
|
||||
|
||||
/* Check to see if we can skip expanding the %m */
|
||||
if (strstr(fmt, "%m")) {
|
||||
|
||||
/* Create the second stdio hook */
|
||||
fmt_cookie.base = fmt_cpy;
|
||||
fmt_cookie.left = sizeof(fmt_cpy) - 1;
|
||||
fmt_fp = fwopen(&fmt_cookie, writehook);
|
||||
if (fmt_fp == NULL) {
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Substitute error message for %m. */
|
||||
for ( ; ch = *fmt; ++fmt)
|
||||
if (ch == '%' && fmt[1] == 'm') {
|
||||
++fmt;
|
||||
fputs(strerror(saved_errno), fmt_fp);
|
||||
} else
|
||||
fputc(ch, fmt_fp);
|
||||
|
||||
/* Null terminate if room */
|
||||
fputc(0, fmt_fp);
|
||||
fclose(fmt_fp);
|
||||
|
||||
/* Guarantee null termination */
|
||||
fmt_cpy[sizeof(fmt_cpy) - 1] = '\0';
|
||||
|
||||
fmt = fmt_cpy;
|
||||
}
|
||||
|
||||
(void)vfprintf(fp, fmt, ap);
|
||||
(void)fclose(fp);
|
||||
|
||||
cnt = sizeof(tbuf) - tbuf_cookie.left;
|
||||
|
||||
/* Output to stderr if requested. */
|
||||
if (LogStat & LOG_PERROR) {
|
||||
#ifdef BROKEN_WRITEV
|
||||
write(STDERR_FILENO, stdp, cnt - (stdp - tbuf));
|
||||
write(STDERR_FILENO, "\r", 1);
|
||||
#else
|
||||
struct iovec iov[2];
|
||||
register struct iovec *v = iov;
|
||||
|
||||
v->iov_base = stdp;
|
||||
v->iov_len = cnt - (stdp - tbuf);
|
||||
++v;
|
||||
#ifdef __appleiigs__
|
||||
v->iov_base = "\r";
|
||||
#else
|
||||
v->iov_base = "\n";
|
||||
#endif
|
||||
v->iov_len = 1;
|
||||
(void)writev(STDERR_FILENO, iov, 2);
|
||||
#endif /* BROKEN_WRITEV */
|
||||
}
|
||||
|
||||
/* Get connected, output the message to the local logger. */
|
||||
if (!connected)
|
||||
openlog(LogTag, LogStat | LOG_NDELAY, 0);
|
||||
#ifdef USE_PORTS
|
||||
if (sendPort(LogFile, tbuf, cnt) >= 0)
|
||||
return;
|
||||
#else
|
||||
if (send(LogFile, tbuf, cnt, 0) >= 0)
|
||||
return;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Output the message to the console; don't worry about blocking,
|
||||
* if console blocks everything will. Make sure the error reported
|
||||
* is the one from the syslogd failure.
|
||||
*/
|
||||
|
||||
#ifdef __ORCAC__ /* watch for stack trashing */
|
||||
#define OPEN(path, flags, mode) open(path, flags)
|
||||
#else
|
||||
#define OPEN(path, flags, mode) open(path, flags, mode)
|
||||
#endif
|
||||
if (LogStat & LOG_CONS &&
|
||||
(fd = OPEN(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) {
|
||||
#undef OPEN
|
||||
#ifdef BROKEN_WRITEV
|
||||
p = strchr(tbuf, '>') + 1;
|
||||
write(fd, p, cnt - (p - tbuf));
|
||||
write(fd, "\r", 1);
|
||||
#else
|
||||
struct iovec iov[2];
|
||||
register struct iovec *v = iov;
|
||||
|
||||
p = strchr(tbuf, '>') + 1;
|
||||
v->iov_base = p;
|
||||
v->iov_len = cnt - (p - tbuf);
|
||||
++v;
|
||||
#ifdef __appleiigs__
|
||||
v->iov_base = "\r";
|
||||
v->iov_len = 1;
|
||||
#else
|
||||
v->iov_base = "\r\n";
|
||||
v->iov_len = 2;
|
||||
#endif
|
||||
(void)writev(fd, iov, 2);
|
||||
#endif /* BROKEN_WRITEV */
|
||||
(void)close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
|
||||
|
||||
void
|
||||
openlog(const char *ident, int logstat, long logfac)
|
||||
{
|
||||
if (ident != NULL)
|
||||
LogTag = ident;
|
||||
LogStat = logstat;
|
||||
if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
|
||||
LogFacility = logfac;
|
||||
|
||||
if (LogFile == -1) {
|
||||
#ifdef USE_PORTS
|
||||
if (LogStat & LOG_NDELAY) {
|
||||
if ((LogFile = openPort()) == -1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else /* not USE_PORTS */
|
||||
SyslogAddr.sa_family = AF_UNIX;
|
||||
(void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
|
||||
sizeof(SyslogAddr.sa_data));
|
||||
if (LogStat & LOG_NDELAY) {
|
||||
if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
|
||||
return;
|
||||
(void)fcntl(LogFile, F_SETFD, 1);
|
||||
}
|
||||
#endif /* not USE_PORTS */
|
||||
}
|
||||
if (LogFile != -1 && !connected)
|
||||
#ifdef USE_PORTS
|
||||
connected = 1;
|
||||
#else
|
||||
if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) {
|
||||
(void)close(LogFile);
|
||||
LogFile = -1;
|
||||
} else
|
||||
connected = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
closelog(void)
|
||||
{
|
||||
#ifdef USE_PORTS
|
||||
closePort(LogFile);
|
||||
#else
|
||||
(void)close(LogFile);
|
||||
#endif
|
||||
LogFile = -1;
|
||||
connected = 0;
|
||||
}
|
||||
|
||||
/* setlogmask -- set the log mask level */
|
||||
long
|
||||
setlogmask(long pmask)
|
||||
{
|
||||
int omask;
|
||||
|
||||
omask = LogMask;
|
||||
if (pmask != 0)
|
||||
LogMask = pmask;
|
||||
return (omask);
|
||||
}
|
||||
|
||||
#ifdef USE_PORTS
|
||||
static int
|
||||
openPort(void) {
|
||||
/* may return -1 */
|
||||
return pgetport(__SYSLOG_PORT_NAME);
|
||||
}
|
||||
|
||||
static int
|
||||
sendPort(int port, const void *buf, int len) {
|
||||
static SyslogDataBuffer_t data;
|
||||
static pid_t pid = 0;
|
||||
long answer;
|
||||
|
||||
if (port == -1) {
|
||||
return 0;
|
||||
}
|
||||
if (pid == 0) {
|
||||
data.magic = SYSLOG_MAGIC;
|
||||
data.sender = pid = getpid();
|
||||
}
|
||||
if (len > MSG_BUF_LEN) {
|
||||
len = MSG_BUF_LEN;
|
||||
}
|
||||
memcpy(data.msg_buffer, buf, len);
|
||||
data.len = len;
|
||||
|
||||
/* send the data */
|
||||
psend (port, (long) &data);
|
||||
|
||||
/* wait for a reply */
|
||||
while((answer = procreceive()) != SYSLOG_MAGIC) {
|
||||
/* try to write a message to the console */
|
||||
int fd;
|
||||
char *s;
|
||||
#define BAD_MAGIC ": bad magic from syslogd\r"
|
||||
if ((fd = open(_PATH_CONSOLE, O_WRONLY)) >= 0) {
|
||||
s = __prognameGS();
|
||||
write(fd, s, strlen(s));
|
||||
write(fd, BAD_MAGIC, sizeof(BAD_MAGIC)-1);
|
||||
close(fd);
|
||||
}
|
||||
#undef BAD_MAGIC
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static void
|
||||
closePort(int port) {
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,146 +0,0 @@
|
|||
macro
|
||||
&lab ~DisposeHandle &p1
|
||||
&lab ph4 &p1
|
||||
ldx #$1002
|
||||
jsl $E10000
|
||||
mend
|
||||
macro
|
||||
&lab ~NewHandle &p1,&p2,&p3,&p4
|
||||
&lab ph4 &p1
|
||||
ph2 &p2
|
||||
ph2 &p2
|
||||
ph4 &p4
|
||||
ldx #$0902
|
||||
jsl $E10000
|
||||
mend
|
||||
macro
|
||||
&l long &a,&b
|
||||
lclb &i
|
||||
lclb &m
|
||||
&a amid &a,1,1
|
||||
&m setb ("&a"="M").or.("&a"="m")
|
||||
&i setb ("&a"="I").or.("&a"="i")
|
||||
aif c:&b=0,.a
|
||||
&b amid &b,1,1
|
||||
&m setb ("&b"="M").or.("&b"="m").or.&m
|
||||
&i setb ("&b"="I").or.("&b"="i").or.&i
|
||||
.a
|
||||
&l rep #&m*32+&i*16
|
||||
aif .not.&m,.b
|
||||
longa on
|
||||
.b
|
||||
aif .not.&i,.c
|
||||
longi on
|
||||
.c
|
||||
mend
|
||||
macro
|
||||
&l ph2 &n1
|
||||
aif "&n1"="*",.f
|
||||
lclc &c
|
||||
&l anop
|
||||
&c amid &n1,1,1
|
||||
aif "&c"="#",.d
|
||||
aif s:longa=1,.a
|
||||
rep #%00100000
|
||||
.a
|
||||
aif "&c"<>"{",.b
|
||||
&c amid &n1,l:&n1,1
|
||||
aif "&c"<>"}",.g
|
||||
&n1 amid &n1,2,l:&n1-2
|
||||
lda (&n1)
|
||||
pha
|
||||
ago .e
|
||||
.b
|
||||
aif "&c"="<",.c
|
||||
lda &n1
|
||||
pha
|
||||
ago .e
|
||||
.c
|
||||
&n1 amid &n1,2,l:&n1-1
|
||||
pei &n1
|
||||
ago .e
|
||||
.d
|
||||
&n1 amid &n1,2,l:&n1-1
|
||||
pea &n1
|
||||
ago .f
|
||||
.e
|
||||
aif s:longa=1,.f
|
||||
sep #%00100000
|
||||
.f
|
||||
mexit
|
||||
.g
|
||||
mnote "Missing closing '}'",16
|
||||
mend
|
||||
macro
|
||||
&l ph4 &n1
|
||||
aif "&n1"="*",.f
|
||||
lclc &c
|
||||
&l anop
|
||||
&c amid &n1,1,1
|
||||
aif "&c"="#",.d
|
||||
aif s:longa=1,.a
|
||||
rep #%00100000
|
||||
.a
|
||||
aif "&c"<>"{",.b
|
||||
&c amid &n1,l:&n1,1
|
||||
aif "&c"<>"}",.g
|
||||
&n1 amid &n1,2,l:&n1-2
|
||||
ldy #2
|
||||
lda (&n1),y
|
||||
pha
|
||||
lda (&n1)
|
||||
pha
|
||||
ago .e
|
||||
.b
|
||||
aif "&c"<>"[",.c
|
||||
ldy #2
|
||||
lda &n1,y
|
||||
pha
|
||||
lda &n1
|
||||
pha
|
||||
ago .e
|
||||
.c
|
||||
aif "&c"<>"<",.c1
|
||||
&n1 amid &n1,2,l:&n1-1
|
||||
pei &n1+2
|
||||
pei &n1
|
||||
ago .e
|
||||
.c1
|
||||
lda &n1+2
|
||||
pha
|
||||
lda &n1
|
||||
pha
|
||||
ago .e
|
||||
.d
|
||||
&n1 amid &n1,2,l:&n1-1
|
||||
pea +(&n1)|-16
|
||||
pea &n1
|
||||
ago .f
|
||||
.e
|
||||
aif s:longa=1,.f
|
||||
sep #%00100000
|
||||
.f
|
||||
mexit
|
||||
.g
|
||||
mnote "Missing closing '}'",16
|
||||
mend
|
||||
macro
|
||||
&l short &a,&b
|
||||
lclb &i
|
||||
lclb &m
|
||||
&a amid &a,1,1
|
||||
&m setb ("&a"="M").or.("&a"="m")
|
||||
&i setb ("&a"="I").or.("&a"="i")
|
||||
aif c:&b=0,.a
|
||||
&b amid &b,1,1
|
||||
&m setb ("&b"="M").or.("&b"="m").or.&m
|
||||
&i setb ("&b"="I").or.("&b"="i").or.&i
|
||||
.a
|
||||
&l sep #&m*32+&i*16
|
||||
aif .not.&m,.b
|
||||
longa off
|
||||
.b
|
||||
aif .not.&i,.c
|
||||
longi off
|
||||
.c
|
||||
mend
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
* Phillip Vandry, August 1993
|
||||
*
|
||||
* $Id: syslog2.asm,v 1.1 1997/02/28 05:12:45 gdr Exp $
|
||||
* $Id: syslog2.asm,v 1.2 1998/06/24 04:19:59 gdr-ftp Exp $
|
||||
*
|
||||
* This file is formatted for tab stops at positions 10, 16, 41, 40, 57,
|
||||
* 65, and 73 (standard Orca/M systabs setting).
|
||||
|
|
Loading…
Reference in New Issue