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