dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / syslogd / syslogd.h
blob9ec1f1dbe5e7b0934d3ed1a08864cc4145d5a0d0
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright 1983,1984,1985,1986,1987,1988,1989 AT&T.
28 * All rights reserved.
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
39 #ifndef _SYSLOGD_H
40 #define _SYSLOGD_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 struct utmpx dummy; /* for sizeof ut_user, ut_line */
49 * Various constants & tunable values for syslogd
51 #define DEBUGFILE "/var/adm/syslog.debug"
52 #define MAXLINE 1024 /* maximum line length */
53 #define DEFUPRI (LOG_USER|LOG_INFO)
54 #define DEFSPRI (LOG_KERN|LOG_CRIT)
55 #define MARKCOUNT 3 /* ratio of minor to major marks */
56 #define UNAMESZ (sizeof (dummy.ut_user)) /* length of a login name */
57 #define UDEVSZ (sizeof (dummy.ut_line)) /* length of login dev name */
58 #define MAXUNAMES 20 /* maximum number of user names */
59 #define Q_HIGHWATER_MARK 10000 /* max outstanding msgs per file */
60 #define NOPRI 0x10 /* the "no priority" priority */
61 #define LOG_MARK (LOG_NFACILITIES << 3) /* mark "facility" */
64 * host_list_t structure contains a list of hostnames for a given address
66 typedef struct host_list {
67 int hl_cnt; /* number of hl_hosts entries */
68 char **hl_hosts; /* hostnames */
69 pthread_mutex_t hl_mutex; /* protects this structs members */
70 int hl_refcnt; /* reference count */
71 } host_list_t;
74 * host_info_t structure contains address information for a host
75 * from which we received a message.
77 typedef struct host_info {
78 struct netconfig *ncp;
79 struct netbuf addr;
80 } host_info_t;
83 * statistics structure attached to each filed for debugging
85 typedef struct filed_stats {
86 int flag; /* flag word */
87 int total; /* total messages logged */
88 int dups; /* duplicate messages */
89 int cantfwd; /* can't forward */
90 int errs; /* write errors */
91 } filed_stats_t;
95 * internal representation of a log message. Includes all routing & bookkeeping
96 * information for the message. created in the system & network poll routines,
97 * and passed among the various processing threads as necessary
100 typedef struct log_message {
101 pthread_mutex_t msg_mutex; /* protects this structs members */
102 int refcnt; /* message reference count */
103 int pri; /* message priority */
104 int flags; /* misc flags */
105 time_t ts; /* timestamp */
106 host_list_t *hlp; /* ptr to host list struct */
107 void *ptr; /* for anonymous use */
108 char msg[MAXLINE+1]; /* the message itself */
109 } log_message_t;
112 * format of a saved message. For each active file we are logging
113 * we save the last message and the current message, to make it
114 * possible to suppress duplicates on a per file basis. Earlier
115 * syslogd's used a global buffer for duplicate checking, so
116 * strict per file duplicate suppression was not always possible.
118 typedef struct saved_msg {
119 int pri;
120 int flags;
121 time_t time;
122 char host[SYS_NMLN+1];
123 char msg[MAXLINE+1];
124 } saved_message_t;
128 * Flags to logmsg().
131 #define IGN_CONS 0x001 /* don't print on console */
132 #define IGN_FILE 0x002 /* don't write to log file */
133 #define SYNC_FILE 0x004 /* do fsync on file after printing */
134 #define NOCOPY 0x008 /* don't suppress duplicate messages */
135 #define ADDDATE 0x010 /* add a date to the message */
136 #define MARK 0x020 /* this message is a mark */
137 #define LOGSYNC 0x040 /* nightly log update message */
138 #define NETWORK 0x100 /* message came from the net */
139 #define SHUTDOWN 0x200 /* internal shutdown message */
140 #define FLUSHMSG 0x400 /* internal flush message */
143 * This structure represents the files that will have log
144 * copies printed. There is one instance of this for each
145 * file that is being logged to.
147 struct filed {
148 pthread_mutex_t filed_mutex; /* protects this filed */
149 pthread_t f_thread; /* thread that handles this file */
150 dataq_t f_queue; /* queue of messages for this file */
151 int f_queue_count; /* count of messages on the queue */
152 int f_prev_queue_count; /* prev count of msgs on the queue */
153 short f_type; /* entry type, see below */
154 short f_orig_type; /* save entry type */
155 int f_file; /* file descriptor */
156 int f_msgflag; /* message disposition */
157 filed_stats_t f_stat; /* statistics */
158 saved_message_t f_prevmsg; /* previous message */
159 saved_message_t f_current; /* current message */
160 int f_prevcount; /* message repeat count */
161 uchar_t f_pmask[LOG_NFACILITIES+1]; /* priority mask */
162 union {
163 char f_uname[MAXUNAMES][SYS_NMLN + 1];
164 struct {
165 char f_hname[SYS_NMLN + 1];
166 struct netbuf f_addr;
167 } f_forw; /* forwarding address */
168 char f_fname[MAXPATHLEN + 1];
169 } f_un;
172 /* values for f_type */
173 #define F_UNUSED 0 /* unused entry */
174 #define F_FILE 1 /* regular file */
175 #define F_TTY 2 /* terminal */
176 #define F_CONSOLE 3 /* console terminal */
177 #define F_FORW 4 /* remote machine */
178 #define F_USERS 5 /* list of users */
179 #define F_WALL 6 /* everyone logged on */
182 * values for logit routine
184 #define CURRENT 0 /* print current message */
185 #define SAVED 1 /* print saved message */
187 * values for f_msgflag
189 #define CURRENT_VALID 0x01 /* new message is good */
190 #define OLD_VALID 0x02 /* old message is valid */
193 * code translation struct for use in processing config file
195 struct code {
196 char *c_name;
197 int c_val;
201 * structure describing a message to be sent to the wall thread.
202 * the thread id and attributes are stored in the structure
203 * passed to the thread, and the thread is created detached.
205 typedef struct wall_device {
206 pthread_t thread;
207 pthread_attr_t thread_attr;
208 char dev[PATH_MAX + 1];
209 char msg[MAXLINE+1];
210 char ut_name[sizeof (dummy.ut_name)];
211 } walldev_t;
214 * hostname caching struct to reduce hostname name lookup.
216 struct hostname_cache {
217 struct hostname_cache *next;
218 struct netbuf addr;
219 struct netconfig *ncp;
220 host_list_t *h;
221 time_t expire;
224 #define DEF_HNC_SIZE 2037
225 #define DEF_HNC_TTL 1200 /* 20 minutes */
226 #define MAX_BUCKETS 30
229 * function prototypes
231 int main(int argc, char **argv);
232 static void usage(void);
233 static void untty(void);
234 static void formatnet(struct netbuf *nbp, log_message_t *mp);
235 static void formatsys(struct log_ctl *lp, char *msg, int sync);
236 static void *logmsg(void *ap);
237 static void wallmsg(struct filed *f, char *from, char *msg);
238 static host_list_t *cvthname(struct netbuf *nbp, struct netconfig *ncp, char *);
239 static void set_flush_msg(struct filed *f);
240 static void flushmsg(int flags);
241 void logerror(const char *type, ...);
242 static void init(void);
243 static void conf_init(void);
244 static void cfline(char *line, int lineno, struct filed *f);
245 static int decode(char *name, struct code *codetab);
246 static int ismyaddr(struct netbuf *nbp);
247 static void getnets(void);
248 static int addnet(struct netconfig *ncp, struct netbuf *nbp);
249 static void bindnet(void);
250 static int logforward(struct filed *f, char *ebuf, size_t elen);
251 static int amiloghost(void);
252 static int same_addr(struct netbuf *, struct netbuf *);
253 static void prepare_sys_poll(void);
254 static void *sys_poll(void *ap);
255 static void getkmsg(int);
256 static void *net_poll(void *ap);
257 static log_message_t *new_msg(void);
258 static void free_msg(log_message_t *lm);
259 static int logmymsg(int pri, char *msg, int flags, int);
260 static void *logit(void *ap);
261 static void freehl(host_list_t *h);
262 static int filed_init(struct filed *h);
263 static void copy_msg(struct filed *f);
264 static void dumpstats(int fd);
265 static void filter_string(char *orig, char *new, size_t max);
266 static int openklog(char *name, int mode);
267 static void writemsg(int selection, struct filed *f);
268 static void *writetodev(void *ap);
269 static int shutdown_msg(void);
270 static void server(void *, char *, size_t, door_desc_t *, uint_t);
271 static void *create_door_thr(void *);
272 static void door_server_pool(door_info_t *);
273 static char *alloc_stacks(int);
274 static void dealloc_stacks(int);
275 static int checkm4(void);
276 static void filed_destroy(struct filed *f);
277 static void open_door(void);
278 static void close_door(void);
279 static void delete_doorfiles(void);
280 static void signull(int, siginfo_t *, void *);
281 static int putctrlc(int, char **, size_t *, size_t);
282 static size_t findnl_bkwd(const char *, const size_t);
283 static size_t copynl_frwd(char *, const size_t, const char *, const size_t);
284 static size_t copy_frwd(char *, const size_t, const char *, const size_t);
285 static void logerror_format(const char *, char *, va_list);
286 static int logerror_to_console(int, const char *);
287 static void properties(void);
288 static void shutdown_input(void);
289 static void *hostname_lookup(void *);
290 static void reconfigure(void);
291 static void disable_errorlog(void);
292 static void enable_errorlog(void);
294 static void hnc_init(int);
295 static host_list_t *hnc_lookup(struct netbuf *,
296 struct netconfig *, int *);
297 static void hnc_register(struct netbuf *,
298 struct netconfig *, host_list_t *, int);
299 static void hnc_unreg(struct hostname_cache **);
300 static int addr_hash(struct netbuf *nbp);
303 #ifdef __cplusplus
305 #endif
307 #endif /* _SYSLOGD_H */