]> git.saurik.com Git - apple/syslog.git/blob - syslogd.tproj/daemon.h
36f2934701a1c28c8f1b6ed7af6b1d3a3691ce79
[apple/syslog.git] / syslogd.tproj / daemon.h
1 /*
2 * Copyright (c) 2004-2012 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_msg.h>
33 #include <asl_core.h>
34 #include <asl_private.h>
35 #include <asl_store.h>
36 #include "asl_memory.h"
37 #include "asl_mini_memory.h"
38 #include "asl_common.h"
39 #include <notify.h>
40 #include <notify_keys.h>
41 #include <launch.h>
42 #include <dispatch/dispatch.h>
43 #include <libkern/OSAtomic.h>
44
45 #include <TargetConditionals.h>
46
47 #define ADDFD_FLAGS_LOCAL 0x00000001
48
49 #define SELF_DB_NOTIFICATION "self.logger.message"
50
51 #define ASL_OPT_IGNORE "ignore"
52 #define ASL_OPT_STORE "store"
53 #define ASL_OPT_CONTROL "control"
54 #define ASL_OPT_DB_FILE "asl_db_file"
55 #define ASL_OPT_DB_MINI "asl_db_mini_memory"
56 #define ASL_OPT_DB_MEMORY "asl_db_memory"
57
58 #if TARGET_IPHONE_SIMULATOR
59 /* These paths are appropriately prefixed in the simulator */
60 extern const char *_path_pidfile;
61 extern const char *_path_syslogd_log;
62
63 #define _PATH_PIDFILE _path_pidfile
64 #define _PATH_SYSLOGD_LOG _path_syslogd_log
65 #else
66 #define _PATH_PIDFILE "/var/run/syslog.pid"
67 #define _PATH_SYSLOG_CONF "/etc/syslog.conf"
68 #define _PATH_SYSLOG_IN "/var/run/syslog"
69 #define _PATH_KLOG "/dev/klog"
70 #define _PATH_SYSLOGD_LOG "/var/log/syslogd.log"
71 #endif
72
73 #define DB_TYPE_FILE 0x00000001
74 #define DB_TYPE_MEMORY 0x00000002
75 #define DB_TYPE_MINI 0x00000004
76
77 #define KERN_DISASTER_LEVEL 3
78
79 #define SOURCE_UNKNOWN 0
80 #define SOURCE_INTERNAL 1
81 #define SOURCE_ASL_SOCKET 2
82 #define SOURCE_BSD_SOCKET 3
83 #define SOURCE_UDP_SOCKET 4
84 #define SOURCE_KERN 5
85 #define SOURCE_ASL_MESSAGE 6
86 #define SOURCE_LAUNCHD 7
87
88 #define SOURCE_SESSION 100 /* does not generate messages */
89
90 #define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001
91
92 #define FS_TTL_SEC 31622400
93
94 #define SEC_PER_DAY 86400
95
96 typedef struct
97 {
98 const char *name;
99 int enabled;
100 int (*init)(void);
101 int (*reset)(void);
102 int (*close)(void);
103 } module_t;
104
105 struct global_s
106 {
107 OSSpinLock lock;
108 int client_count;
109 int disaster_occurred;
110 mach_port_t listen_set;
111 mach_port_t server_port;
112 mach_port_t dead_session_port;
113 launch_data_t launch_dict;
114 int *lockdown_session_fds;
115 int lockdown_session_count;
116 int watchers_active;
117 int reset;
118 pid_t pid;
119 int32_t work_queue_count;
120 int32_t asl_queue_count;
121 int32_t bsd_queue_count;
122 pthread_mutex_t *db_lock;
123 pthread_cond_t work_queue_cond;
124 dispatch_queue_t work_queue;
125 dispatch_source_t mark_timer;
126 dispatch_source_t sig_hup_src;
127 asl_store_t *file_db;
128 asl_memory_t *memory_db;
129 asl_mini_memory_t *mini_db;
130 asl_mini_memory_t *disaster_db;
131 int module_count;
132 int bsd_out_enabled;
133 int launchd_enabled;
134 module_t **module;
135 asl_out_module_t *asl_out_module;
136
137 /* parameters below are configurable as command-line args or in /etc/asl.conf */
138 int debug;
139 char *debug_file;
140 int dbtype;
141 uint32_t db_file_max;
142 uint32_t db_memory_max;
143 uint32_t db_mini_max;
144 uint32_t mps_limit;
145 uint32_t remote_delay_time;
146 uint64_t bsd_max_dup_time;
147 uint64_t mark_time;
148 time_t utmp_ttl;
149 };
150
151 extern struct global_s global;
152
153 void init_globals(void);
154
155 void config_debug(int enable, const char *path);
156 void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t mini_max);
157
158 void asl_mark(void);
159 void asl_archive(void);
160
161 void asl_client_count_increment();
162 void asl_client_count_decrement();
163
164 int asldebug(const char *, ...);
165 int internal_log_message(const char *str);
166
167 asl_msg_t *asl_msg_from_string(const char *buf);
168 int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b);
169 time_t asl_parse_time(const char *str);
170
171 void send_to_direct_watchers(asl_msg_t *msg);
172
173 #if !TARGET_IPHONE_SIMULATOR
174 void launchd_callback();
175 #endif
176
177 int asl_syslog_faciliy_name_to_num(const char *fac);
178 const char *asl_syslog_faciliy_num_to_name(int num);
179 aslmsg asl_input_parse(const char *in, int len, char *rhost, uint32_t source);
180
181 void process_message(aslmsg m, uint32_t source);
182 void asl_out_message(aslmsg msg);
183 void bsd_out_message(aslmsg msg);
184 int control_set_param(const char *s, bool eval);
185 int asl_action_control_set_param(const char *s);
186
187 /* notify SPI */
188 uint32_t notify_register_plain(const char *name, int *out_token);
189
190 #endif /* __DAEMON_H__ */