3 * syslog.c - syslog function stubs for the AmiTCP/IP
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
8 * Copyright © 2005 Pavel Fedin
11 #include <sys/param.h>
12 #include <sys/syslog.h>
14 #include <proto/socket.h>
15 #include <bsdsocket/socketbasetags.h>
17 /****** net.lib/syslog *********************************************
20 * openlog(), closelog(), setlogmask() -- syslog utility functions
25 * openlog(ident, logopt, facility);
27 * void openlog(const char *, int, int);
31 * void closelog(void);
33 * oldmask = setlogmask(maskpri);
35 * int setlogmask(int);
38 * openlog() can be called to initialize the log file, if special
39 * processing is needed. ident is a string that precedes every
40 * message. logopt is a mask of bits, logically OR'ed together,
41 * indicating logging options. The values for logopt are:
43 * LOG_PID Log the process ID with each message;
44 * useful for identifying instantiations
47 * LOG_CONS Force writing messages to the console
48 * if unable to send it to syslogd.
49 * This option is safe to use in daemon
50 * processes that have no controlling
51 * terminal because syslog() forks
52 * before opening the console.
54 * LOG_NDELAY Open the connection to syslogd
55 * immediately. Normally, the open is
56 * delayed until the first message is
57 * logged. This is useful for programs
58 * that need to manage the order in
59 * which file descriptors are allocated.
61 * LOG_NOWAIT Do not wait for children forked to
62 * log messages on the console. Obsolete
63 * in AmiTCP/IP, since AmiTCP/IP does
66 * facility encodes a default facility to be assigned to all
67 * messages written subsequently by syslog() with no explicit
68 * facility encoded. The facility codes are:
70 * LOG_KERN Messages generated by the kernel.
71 * These cannot be generated by any user
74 * LOG_USER Messages generated by random user
75 * processes. This is the default
76 * facility identifier if none is
79 * LOG_MAIL The mail system.
81 * LOG_DAEMON System daemons, such as inetd, ftpd,
84 * LOG_AUTH The authorization system: login, su,
87 * LOG_LPR The line printer spooling system: lp,
90 * LOG_LOCAL0 Reserved for local use. Similarly for
91 * LOG_LOCAL1 through LOG_LOCAL7.
94 * closelog() closes the log file.
96 * setlogmask() sets the log priority mask to maskpri and returns
97 * the previous mask. Calls to syslog() with a priority not set
98 * in maskpri are rejected. The mask for an individual priority
99 * pri is calculated by the macro LOG_MASK(pri); the mask for all
100 * priorities up to and including toppri is given by the macro
101 * LOG_UPTO(toppri). By default, all priorities are logged.
104 * who logs a message regarding some sort of unexpected and
107 * syslog(LOG_ALERT, "who: internal error 23");
109 * ftpd uses openlog() to arrange to log its process ID, to log
110 * to the console if necessary, and to log in the name of the
113 * openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
115 * Arrange to log messages only at levels LOG_ERR and lower:
117 * setlogmask(LOG_UPTO(LOG_ERR));
119 * Typical usage of syslog() to log a connection:
121 * syslog(LOG_INFO, "Connection from host %d", CallingHost);
123 * If the facility has not been set with openlog(), it defaults
126 * Explicitly set the facility for this message:
128 * syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
131 * openlog() does not copy and store the ident string internally;
132 * it stores only the character pointer. Therefore it is the
133 * responsibility of the programmer to make sure that the ident
134 * argument points to the correct string while syslog() is being
138 * Most of the logopt and facility codes are currently being
139 * ignored by AmiTCP/IP, but they should be used for future
142 * The autoinit module of the net.lib tells the program name
143 * to the AmiTCP/IP at program startup, so use of the openlog()
144 * for that purpose only is not necessary.
147 * syslog() was developed by the University of California,
151 * bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
152 *****************************************************************************
156 openlog(const char *ident
, int logstat
, int logfac
)
159 * Note: SocketBaseTags() does value checking for the arguments
161 SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR
), ident
,
162 SBTM_SETVAL(SBTC_LOGSTAT
), logstat
,
163 SBTM_SETVAL(SBTC_LOGFACILITY
), logfac
,
170 SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR
), NULL
,
174 /* setlogmask -- set the log mask level */
176 setlogmask(int pmask
)
180 taglist
[0] = SBTM_GETVAL(SBTC_LOGMASK
);
181 taglist
[2] = SBTM_SETVAL(SBTC_LOGMASK
);
183 taglist
[4] = TAG_END
;
185 SocketBaseTagList((struct TagItem
*)taglist
);
186 return (int)taglist
[1];