]> git.saurik.com Git - apple/syslog.git/blobdiff - syslogd.tproj/daemon.h
syslog-356.200.4.tar.gz
[apple/syslog.git] / syslogd.tproj / daemon.h
index f4fce9eaf3700f33c2b2ef09e1df9f7cfb3c1504..4646c3d1ce0b6ebec25d2b934f160f7b8f16a673 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2009 Apple Inc. All rights reserved.
+ * Copyright (c) 2004-2012 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
 #include <sys/queue.h>
 #include <time.h>
 #include <asl.h>
+#include <asl_msg.h>
+#include <asl_core.h>
 #include <asl_private.h>
 #include <asl_store.h>
-#include <asl_memory.h>
-#include <asl_mini_memory.h>
+#include "asl_memory.h"
+#include "asl_common.h"
 #include <notify.h>
+#include <notify_keys.h>
 #include <launch.h>
+#include <dispatch/dispatch.h>
 #include <libkern/OSAtomic.h>
 
+#include <TargetConditionals.h>
+
 #define ADDFD_FLAGS_LOCAL 0x00000001
 
-#define ASL_DB_NOTIFICATION "com.apple.system.logger.message"
 #define SELF_DB_NOTIFICATION "self.logger.message"
 
-#define ASL_KEY_READ_UID "ReadUID"
-#define ASL_KEY_READ_GID "ReadGID"
-#define ASL_KEY_EXPIRE_TIME "ASLExpireTime"
-#define ASL_KEY_TIME_NSEC "TimeNanoSec"
-#define ASL_KEY_REF_PID "RefPID"
-#define ASL_KEY_REF_PROC "RefProc"
-#define ASL_KEY_SESSION "Session"
-#define ASL_KEY_OPTION "ASLOption"
-
 #define ASL_OPT_IGNORE "ignore"
 #define ASL_OPT_STORE "store"
-
+#define ASL_OPT_CONTROL "control"
+#define ASL_OPT_DB_FILE "asl_db_file"
+#define ASL_OPT_DB_MEMORY "asl_db_memory"
+
+#if TARGET_IPHONE_SIMULATOR
+/* These paths are appropriately prefixed in the simulator */
+extern const char *_path_pidfile;
+extern const char *_path_syslogd_log;
+
+#define _PATH_PIDFILE _path_pidfile
+#define _PATH_SYSLOGD_LOG _path_syslogd_log
+#else
 #define _PATH_PIDFILE          "/var/run/syslog.pid"
-#define _PATH_ASL_IN           "/var/run/asl_input"
 #define _PATH_SYSLOG_CONF   "/etc/syslog.conf"
 #define _PATH_SYSLOG_IN                "/var/run/syslog"
 #define _PATH_KLOG                     "/dev/klog"
-#define _PATH_MODULE_LIB       "/usr/lib/asl"
+#define _PATH_SYSLOGD_LOG      "/var/log/syslogd.log"
+#endif
+
+#define NOTIFY_PATH_SERVICE "com.apple.system.notify.service.path:0x87:"
 
 #define DB_TYPE_FILE   0x00000001
 #define DB_TYPE_MEMORY 0x00000002
-#define DB_TYPE_MINI   0x00000004
 
 #define KERN_DISASTER_LEVEL 3
 
 #define SOURCE_UNKNOWN      0
 #define SOURCE_INTERNAL     1
-#define SOURCE_ASL_SOCKET   2
-#define SOURCE_BSD_SOCKET   3
-#define SOURCE_UDP_SOCKET   4
-#define SOURCE_KERN         5
-#define SOURCE_ASL_MESSAGE  6
-#define SOURCE_LAUNCHD      7
+#define SOURCE_BSD_SOCKET   2
+#define SOURCE_UDP_SOCKET   3
+#define SOURCE_KERN         4
+#define SOURCE_ASL_MESSAGE  5
+#define SOURCE_LAUNCHD      6
 
 #define SOURCE_SESSION    100 /* does not generate messages */
 
 #define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001
 
-#define RESET_NONE 0
-#define RESET_CONFIG 1
-#define RESET_NETWORK 2
+#define FS_TTL_SEC 31622400
+
+#define SEC_PER_DAY 86400
+
+typedef struct sender_stats_s
+{
+       char *sender;
+       uint64_t count;
+       uint64_t size;
+       struct sender_stats_s *next;
+} sender_stats_t;
+
+typedef struct
+{
+       uint32_t mcount;
+       uint32_t shim_count;
+       uint32_t bucket_count;
+       sender_stats_t **bucket;
+} stats_table_t;
+
+typedef struct
+{
+       const char *name;
+       int enabled;
+       int (*init)(void);
+       int (*reset)(void);
+       int (*close)(void);
+} module_t;
 
 struct global_s
 {
@@ -91,120 +123,83 @@ struct global_s
        int disaster_occurred;
        mach_port_t listen_set;
        mach_port_t server_port;
-       mach_port_t self_port;
        mach_port_t dead_session_port;
        launch_data_t launch_dict;
-       uint32_t store_flags;
-       time_t start_time;
-       int kfd;
+       int *lockdown_session_fds;
+       int lockdown_session_count;
+       int watchers_active;
        int reset;
-       uint64_t bsd_flush_time;
+       pid_t pid;
+       int32_t work_queue_count;
+       /* memory_size must be aligned for OSAtomicAdd64 */
+       __attribute__((aligned(8))) int64_t memory_size;
+       int32_t asl_queue_count;
+       int32_t bsd_queue_count;
        pthread_mutex_t *db_lock;
-       pthread_mutex_t *work_queue_lock;
        pthread_cond_t work_queue_cond;
-       asl_search_result_t *work_queue;
+       dispatch_queue_t work_queue;
+       dispatch_source_t mark_timer;
+       dispatch_source_t sig_hup_src;
        asl_store_t *file_db;
        asl_memory_t *memory_db;
-       asl_mini_memory_t *mini_db;
-       asl_mini_memory_t *disaster_db;
+       asl_memory_t *disaster_db;
+       int module_count;
+       int bsd_out_enabled;
+       int launchd_enabled;
+       module_t **module;
+       asl_out_module_t *asl_out_module;
+       time_t stats_last;
+       stats_table_t *stats;
 
        /* parameters below are configurable as command-line args or in /etc/asl.conf */
-       int asl_log_filter;
        int debug;
        char *debug_file;
+       char *hostname;
        int dbtype;
        uint32_t db_file_max;
        uint32_t db_memory_max;
-       uint32_t db_mini_max;
+       uint32_t db_memory_str_max;
        uint32_t mps_limit;
+       uint32_t remote_delay_time;
        uint64_t bsd_max_dup_time;
-       uint64_t asl_store_ping_time;
        uint64_t mark_time;
        time_t utmp_ttl;
-       time_t fs_ttl;
+       time_t stats_interval;
+       int64_t memory_max;
 };
 
 extern struct global_s global;
 
-typedef asl_msg_t *(*aslreadfn)(int);
-typedef char *(*aslwritefn)(const char *, int);
-typedef char *(*aslexceptfn)(int);
-typedef int (*aslsendmsgfn)(asl_msg_t *msg, const char *outid);
-
-struct aslevent
-{
-       int source;
-       int fd;
-       unsigned char read:1; 
-       unsigned char write:1; 
-       unsigned char except:1;
-       aslreadfn readfn;
-       aslwritefn writefn;
-       aslexceptfn exceptfn;
-       char *sender;
-       uid_t uid;
-       gid_t gid;
-       TAILQ_ENTRY(aslevent) entries;
-};
-
-struct module_list
-{
-       char *name;
-       void *module;
-       int (*init)(void);
-       int (*reset)(void);
-       int (*close)(void);
-       TAILQ_ENTRY(module_list) entries;
-};
+void init_globals(void);
 
 void config_debug(int enable, const char *path);
-void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t mini_max);
-void config_timers(uint64_t bsd_max_dup, uint64_t asl_store_ping, uint64_t utmp, uint64_t fs);
-
-char **explode(const char *s, const char *delim);
-void freeList(char **l);
+void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t str_memory_max);
 
-int aslevent_init(void);
-int aslevent_fdsets(fd_set *, fd_set *, fd_set *);
-void aslevent_handleevent(fd_set *, fd_set *, fd_set *);
 void asl_mark(void);
 void asl_archive(void);
 
 void asl_client_count_increment();
 void asl_client_count_decrement();
 
-char *get_line_from_file(FILE *f);
-
 int asldebug(const char *, ...);
-int asl_log_string(const char *str);
-
-char *asl_msg_to_string(asl_msg_t *msg, uint32_t *len);
-asl_msg_t *asl_msg_from_string(const char *buf);
-int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b);
-time_t asl_parse_time(const char *str);
+int internal_log_message(const char *str);
 
-int aslevent_addfd(int source, int fd, uint32_t flags, aslreadfn readfn, aslwritefn writefn, aslexceptfn exceptfn);
-int aslevent_removefd(int fd);
-int aslevent_addmatch(asl_msg_t *query, char *outid);
+void send_to_direct_watchers(asl_msg_t *msg);
 
-int asl_check_option(asl_msg_t *msg, const char *opt);
-
-int aslevent_addoutput(aslsendmsgfn, const char *outid);
-
-void asl_enqueue_message(uint32_t source, struct aslevent *e, asl_msg_t *msg);
-asl_msg_t **asl_work_dequeue(uint32_t *count);
-void asl_message_match_and_log(asl_msg_t *msg);
+#if !TARGET_IPHONE_SIMULATOR
+void launchd_callback();
+#endif
 
 int asl_syslog_faciliy_name_to_num(const char *fac);
 const char *asl_syslog_faciliy_num_to_name(int num);
-asl_msg_t *asl_input_parse(const char *in, int len, char *rhost, int flag);
-
-void db_ping_store(void);
-
-/* message refcount utilities */
-uint32_t asl_msg_type(asl_msg_t *m);
-asl_msg_t *asl_msg_retain(asl_msg_t *m);
-void asl_msg_release(asl_msg_t *m);
+asl_msg_t *asl_input_parse(const char *in, int len, char *rhost, uint32_t source);
+
+void process_message(asl_msg_t *msg, uint32_t source);
+void asl_out_message(asl_msg_t *msg, int64_t msize);
+void bsd_out_message(asl_msg_t *msg, int64_t msize);
+int control_set_param(const char *s, bool eval);
+int asl_action_control_set_param(const char *s);
+void asl_action_out_module_query(asl_msg_t *q, asl_msg_t *m, bool all);
 
 /* notify SPI */
 uint32_t notify_register_plain(const char *name, int *out_token);