]> git.saurik.com Git - apple/syslog.git/blob - syslogd.tproj/daemon.h
f4fce9eaf3700f33c2b2ef09e1df9f7cfb3c1504
[apple/syslog.git] / syslogd.tproj / daemon.h
1 /*
2 * Copyright (c) 2004-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef __DAEMON_H__
25 #define __DAEMON_H__
26
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/queue.h>
30 #include <time.h>
31 #include <asl.h>
32 #include <asl_private.h>
33 #include <asl_store.h>
34 #include <asl_memory.h>
35 #include <asl_mini_memory.h>
36 #include <notify.h>
37 #include <launch.h>
38 #include <libkern/OSAtomic.h>
39
40 #define ADDFD_FLAGS_LOCAL 0x00000001
41
42 #define ASL_DB_NOTIFICATION "com.apple.system.logger.message"
43 #define SELF_DB_NOTIFICATION "self.logger.message"
44
45 #define ASL_KEY_READ_UID "ReadUID"
46 #define ASL_KEY_READ_GID "ReadGID"
47 #define ASL_KEY_EXPIRE_TIME "ASLExpireTime"
48 #define ASL_KEY_TIME_NSEC "TimeNanoSec"
49 #define ASL_KEY_REF_PID "RefPID"
50 #define ASL_KEY_REF_PROC "RefProc"
51 #define ASL_KEY_SESSION "Session"
52 #define ASL_KEY_OPTION "ASLOption"
53
54 #define ASL_OPT_IGNORE "ignore"
55 #define ASL_OPT_STORE "store"
56
57 #define _PATH_PIDFILE "/var/run/syslog.pid"
58 #define _PATH_ASL_IN "/var/run/asl_input"
59 #define _PATH_SYSLOG_CONF "/etc/syslog.conf"
60 #define _PATH_SYSLOG_IN "/var/run/syslog"
61 #define _PATH_KLOG "/dev/klog"
62 #define _PATH_MODULE_LIB "/usr/lib/asl"
63
64 #define DB_TYPE_FILE 0x00000001
65 #define DB_TYPE_MEMORY 0x00000002
66 #define DB_TYPE_MINI 0x00000004
67
68 #define KERN_DISASTER_LEVEL 3
69
70 #define SOURCE_UNKNOWN 0
71 #define SOURCE_INTERNAL 1
72 #define SOURCE_ASL_SOCKET 2
73 #define SOURCE_BSD_SOCKET 3
74 #define SOURCE_UDP_SOCKET 4
75 #define SOURCE_KERN 5
76 #define SOURCE_ASL_MESSAGE 6
77 #define SOURCE_LAUNCHD 7
78
79 #define SOURCE_SESSION 100 /* does not generate messages */
80
81 #define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001
82
83 #define RESET_NONE 0
84 #define RESET_CONFIG 1
85 #define RESET_NETWORK 2
86
87 struct global_s
88 {
89 OSSpinLock lock;
90 int client_count;
91 int disaster_occurred;
92 mach_port_t listen_set;
93 mach_port_t server_port;
94 mach_port_t self_port;
95 mach_port_t dead_session_port;
96 launch_data_t launch_dict;
97 uint32_t store_flags;
98 time_t start_time;
99 int kfd;
100 int reset;
101 uint64_t bsd_flush_time;
102 pthread_mutex_t *db_lock;
103 pthread_mutex_t *work_queue_lock;
104 pthread_cond_t work_queue_cond;
105 asl_search_result_t *work_queue;
106 asl_store_t *file_db;
107 asl_memory_t *memory_db;
108 asl_mini_memory_t *mini_db;
109 asl_mini_memory_t *disaster_db;
110
111 /* parameters below are configurable as command-line args or in /etc/asl.conf */
112 int asl_log_filter;
113 int debug;
114 char *debug_file;
115 int dbtype;
116 uint32_t db_file_max;
117 uint32_t db_memory_max;
118 uint32_t db_mini_max;
119 uint32_t mps_limit;
120 uint64_t bsd_max_dup_time;
121 uint64_t asl_store_ping_time;
122 uint64_t mark_time;
123 time_t utmp_ttl;
124 time_t fs_ttl;
125 };
126
127 extern struct global_s global;
128
129 typedef asl_msg_t *(*aslreadfn)(int);
130 typedef char *(*aslwritefn)(const char *, int);
131 typedef char *(*aslexceptfn)(int);
132 typedef int (*aslsendmsgfn)(asl_msg_t *msg, const char *outid);
133
134 struct aslevent
135 {
136 int source;
137 int fd;
138 unsigned char read:1;
139 unsigned char write:1;
140 unsigned char except:1;
141 aslreadfn readfn;
142 aslwritefn writefn;
143 aslexceptfn exceptfn;
144 char *sender;
145 uid_t uid;
146 gid_t gid;
147 TAILQ_ENTRY(aslevent) entries;
148 };
149
150 struct module_list
151 {
152 char *name;
153 void *module;
154 int (*init)(void);
155 int (*reset)(void);
156 int (*close)(void);
157 TAILQ_ENTRY(module_list) entries;
158 };
159
160 void config_debug(int enable, const char *path);
161 void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t mini_max);
162 void config_timers(uint64_t bsd_max_dup, uint64_t asl_store_ping, uint64_t utmp, uint64_t fs);
163
164 char **explode(const char *s, const char *delim);
165 void freeList(char **l);
166
167 int aslevent_init(void);
168 int aslevent_fdsets(fd_set *, fd_set *, fd_set *);
169 void aslevent_handleevent(fd_set *, fd_set *, fd_set *);
170 void asl_mark(void);
171 void asl_archive(void);
172
173 void asl_client_count_increment();
174 void asl_client_count_decrement();
175
176 char *get_line_from_file(FILE *f);
177
178 int asldebug(const char *, ...);
179 int asl_log_string(const char *str);
180
181 char *asl_msg_to_string(asl_msg_t *msg, uint32_t *len);
182 asl_msg_t *asl_msg_from_string(const char *buf);
183 int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b);
184 time_t asl_parse_time(const char *str);
185
186 int aslevent_addfd(int source, int fd, uint32_t flags, aslreadfn readfn, aslwritefn writefn, aslexceptfn exceptfn);
187 int aslevent_removefd(int fd);
188 int aslevent_addmatch(asl_msg_t *query, char *outid);
189
190 int asl_check_option(asl_msg_t *msg, const char *opt);
191
192 int aslevent_addoutput(aslsendmsgfn, const char *outid);
193
194 void asl_enqueue_message(uint32_t source, struct aslevent *e, asl_msg_t *msg);
195 asl_msg_t **asl_work_dequeue(uint32_t *count);
196 void asl_message_match_and_log(asl_msg_t *msg);
197
198 int asl_syslog_faciliy_name_to_num(const char *fac);
199 const char *asl_syslog_faciliy_num_to_name(int num);
200 asl_msg_t *asl_input_parse(const char *in, int len, char *rhost, int flag);
201
202 void db_ping_store(void);
203
204 /* message refcount utilities */
205 uint32_t asl_msg_type(asl_msg_t *m);
206 asl_msg_t *asl_msg_retain(asl_msg_t *m);
207 void asl_msg_release(asl_msg_t *m);
208
209 /* notify SPI */
210 uint32_t notify_register_plain(const char *name, int *out_token);
211
212 #endif /* __DAEMON_H__ */