]>
Commit | Line | Data |
---|---|---|
b16a592a | 1 | /* |
81582353 | 2 | * Copyright (c) 2004-2012 Apple Inc. All rights reserved. |
b16a592a A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
5dd30d76 A |
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. | |
b16a592a A |
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, | |
5dd30d76 A |
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. | |
b16a592a A |
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> | |
a83ff38a | 32 | #include <asl_msg.h> |
db78b1bd | 33 | #include <asl_core.h> |
b16a592a | 34 | #include <asl_private.h> |
57b0aad2 | 35 | #include <asl_store.h> |
a83ff38a | 36 | #include "asl_memory.h" |
81582353 | 37 | #include "asl_common.h" |
b16a592a | 38 | #include <notify.h> |
db78b1bd | 39 | #include <notify_keys.h> |
5dd30d76 | 40 | #include <launch.h> |
db78b1bd | 41 | #include <dispatch/dispatch.h> |
c4fdb7d1 | 42 | #include <libkern/OSAtomic.h> |
5dd30d76 | 43 | |
81582353 A |
44 | #include <TargetConditionals.h> |
45 | ||
5dd30d76 A |
46 | #define ADDFD_FLAGS_LOCAL 0x00000001 |
47 | ||
57b0aad2 | 48 | #define SELF_DB_NOTIFICATION "self.logger.message" |
5dd30d76 | 49 | |
c4fdb7d1 A |
50 | #define ASL_OPT_IGNORE "ignore" |
51 | #define ASL_OPT_STORE "store" | |
db78b1bd A |
52 | #define ASL_OPT_CONTROL "control" |
53 | #define ASL_OPT_DB_FILE "asl_db_file" | |
db78b1bd | 54 | #define ASL_OPT_DB_MEMORY "asl_db_memory" |
b16a592a | 55 | |
86a8bcf5 | 56 | #if TARGET_OS_SIMULATOR |
81582353 A |
57 | /* These paths are appropriately prefixed in the simulator */ |
58 | extern const char *_path_pidfile; | |
59 | extern const char *_path_syslogd_log; | |
60 | ||
61 | #define _PATH_PIDFILE _path_pidfile | |
62 | #define _PATH_SYSLOGD_LOG _path_syslogd_log | |
63 | #else | |
b16a592a | 64 | #define _PATH_PIDFILE "/var/run/syslog.pid" |
b16a592a A |
65 | #define _PATH_SYSLOG_CONF "/etc/syslog.conf" |
66 | #define _PATH_SYSLOG_IN "/var/run/syslog" | |
67 | #define _PATH_KLOG "/dev/klog" | |
db78b1bd | 68 | #define _PATH_SYSLOGD_LOG "/var/log/syslogd.log" |
81582353 | 69 | #endif |
b16a592a | 70 | |
51023e60 | 71 | |
f3df4c03 A |
72 | #define NOTIFY_PATH_SERVICE "com.apple.system.notify.service.path:0x87:" |
73 | ||
57b0aad2 A |
74 | #define DB_TYPE_FILE 0x00000001 |
75 | #define DB_TYPE_MEMORY 0x00000002 | |
57b0aad2 | 76 | |
5dd30d76 A |
77 | #define KERN_DISASTER_LEVEL 3 |
78 | ||
c4fdb7d1 A |
79 | #define SOURCE_UNKNOWN 0 |
80 | #define SOURCE_INTERNAL 1 | |
f3df4c03 A |
81 | #define SOURCE_BSD_SOCKET 2 |
82 | #define SOURCE_UDP_SOCKET 3 | |
83 | #define SOURCE_KERN 4 | |
84 | #define SOURCE_ASL_MESSAGE 5 | |
85 | #define SOURCE_LAUNCHD 6 | |
c4fdb7d1 A |
86 | |
87 | #define SOURCE_SESSION 100 /* does not generate messages */ | |
88 | ||
89 | #define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001 | |
90 | ||
db78b1bd A |
91 | #define FS_TTL_SEC 31622400 |
92 | ||
81582353 A |
93 | #define SEC_PER_DAY 86400 |
94 | ||
5222c21d A |
95 | typedef struct sender_stats_s |
96 | { | |
97 | char *sender; | |
98 | uint64_t count; | |
99 | uint64_t size; | |
100 | struct sender_stats_s *next; | |
101 | } sender_stats_t; | |
102 | ||
103 | typedef struct | |
104 | { | |
105 | uint32_t mcount; | |
106 | uint32_t shim_count; | |
107 | uint32_t bucket_count; | |
108 | sender_stats_t **bucket; | |
109 | } stats_table_t; | |
f3df4c03 | 110 | |
db78b1bd A |
111 | typedef struct |
112 | { | |
113 | const char *name; | |
114 | int enabled; | |
115 | int (*init)(void); | |
116 | int (*reset)(void); | |
117 | int (*close)(void); | |
118 | } module_t; | |
c4fdb7d1 | 119 | |
57b0aad2 A |
120 | struct global_s |
121 | { | |
c4fdb7d1 A |
122 | OSSpinLock lock; |
123 | int client_count; | |
57b0aad2 | 124 | int disaster_occurred; |
c4fdb7d1 | 125 | mach_port_t listen_set; |
57b0aad2 | 126 | mach_port_t server_port; |
c4fdb7d1 | 127 | mach_port_t dead_session_port; |
57b0aad2 | 128 | launch_data_t launch_dict; |
81582353 A |
129 | int *lockdown_session_fds; |
130 | int lockdown_session_count; | |
a83ff38a | 131 | int watchers_active; |
c4fdb7d1 | 132 | int reset; |
81582353 A |
133 | pid_t pid; |
134 | int32_t work_queue_count; | |
5222c21d A |
135 | /* memory_size must be aligned for OSAtomicAdd64 */ |
136 | __attribute__((aligned(8))) int64_t memory_size; | |
81582353 A |
137 | int32_t asl_queue_count; |
138 | int32_t bsd_queue_count; | |
c4fdb7d1 | 139 | pthread_mutex_t *db_lock; |
c4fdb7d1 | 140 | pthread_cond_t work_queue_cond; |
db78b1bd A |
141 | dispatch_queue_t work_queue; |
142 | dispatch_source_t mark_timer; | |
143 | dispatch_source_t sig_hup_src; | |
57b0aad2 A |
144 | asl_store_t *file_db; |
145 | asl_memory_t *memory_db; | |
f3df4c03 | 146 | asl_memory_t *disaster_db; |
db78b1bd A |
147 | int module_count; |
148 | int bsd_out_enabled; | |
81582353 | 149 | int launchd_enabled; |
db78b1bd | 150 | module_t **module; |
81582353 | 151 | asl_out_module_t *asl_out_module; |
5222c21d A |
152 | time_t stats_last; |
153 | stats_table_t *stats; | |
c4fdb7d1 A |
154 | |
155 | /* parameters below are configurable as command-line args or in /etc/asl.conf */ | |
c4fdb7d1 A |
156 | int debug; |
157 | char *debug_file; | |
5222c21d | 158 | char *hostname; |
c4fdb7d1 A |
159 | int dbtype; |
160 | uint32_t db_file_max; | |
161 | uint32_t db_memory_max; | |
f3df4c03 | 162 | uint32_t db_memory_str_max; |
c4fdb7d1 | 163 | uint32_t mps_limit; |
db78b1bd | 164 | uint32_t remote_delay_time; |
c4fdb7d1 | 165 | uint64_t bsd_max_dup_time; |
c4fdb7d1 A |
166 | uint64_t mark_time; |
167 | time_t utmp_ttl; | |
5222c21d A |
168 | time_t stats_interval; |
169 | int64_t memory_max; | |
57b0aad2 A |
170 | }; |
171 | ||
172 | extern struct global_s global; | |
5dd30d76 | 173 | |
db78b1bd | 174 | void init_globals(void); |
b16a592a | 175 | |
c4fdb7d1 | 176 | void config_debug(int enable, const char *path); |
f3df4c03 | 177 | void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t str_memory_max); |
c4fdb7d1 | 178 | |
5dd30d76 A |
179 | void asl_mark(void); |
180 | void asl_archive(void); | |
b16a592a | 181 | |
c4fdb7d1 A |
182 | void asl_client_count_increment(); |
183 | void asl_client_count_decrement(); | |
184 | ||
b16a592a | 185 | int asldebug(const char *, ...); |
db78b1bd | 186 | int internal_log_message(const char *str); |
b16a592a | 187 | |
a83ff38a | 188 | void send_to_direct_watchers(asl_msg_t *msg); |
c4fdb7d1 | 189 | |
86a8bcf5 | 190 | #if !TARGET_OS_SIMULATOR |
db78b1bd | 191 | void launchd_callback(); |
81582353 | 192 | #endif |
db78b1bd | 193 | |
b16a592a A |
194 | int asl_syslog_faciliy_name_to_num(const char *fac); |
195 | const char *asl_syslog_faciliy_num_to_name(int num); | |
f3df4c03 | 196 | asl_msg_t *asl_input_parse(const char *in, int len, char *rhost, uint32_t source); |
5dd30d76 | 197 | |
f3df4c03 | 198 | void process_message(asl_msg_t *msg, uint32_t source); |
5222c21d A |
199 | void asl_out_message(asl_msg_t *msg, int64_t msize); |
200 | void bsd_out_message(asl_msg_t *msg, int64_t msize); | |
81582353 A |
201 | int control_set_param(const char *s, bool eval); |
202 | int asl_action_control_set_param(const char *s); | |
c8dfc69e | 203 | void asl_action_out_module_query(asl_msg_t *q, asl_msg_t *m, bool all); |
5dd30d76 | 204 | |
b16a592a | 205 | /* notify SPI */ |
b16a592a A |
206 | uint32_t notify_register_plain(const char *name, int *out_token); |
207 | ||
208 | #endif /* __DAEMON_H__ */ |