X-Git-Url: https://git.saurik.com/apple/syslog.git/blobdiff_plain/5222c21d179b0b291b379bab771199072df3ea35..refs/heads/master:/aslcommon/asl_common.c diff --git a/aslcommon/asl_common.c b/aslcommon/asl_common.c index ebe75c4..ea0a0aa 100644 --- a/aslcommon/asl_common.c +++ b/aslcommon/asl_common.c @@ -37,10 +37,12 @@ #include #include #include +#include #include #include #include #include "asl_common.h" +#include #define _PATH_ASL_CONF "/etc/asl.conf" #define _PATH_ASL_CONF_DIR "/etc/asl" @@ -51,7 +53,7 @@ #define PATH_LIBRARY_LOGS "/Library/Logs/" #define PATH_LIBRARY_LOGS_LEN 14 -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR #define _PATH_ASL_CONF_LOCAL_DIR "/usr/local/etc/asl" #endif @@ -553,7 +555,7 @@ _asl_common_make_dir_path(asl_out_module_t *mlist, uint32_t flags, const char *p status = mkdir(tmp, mode); umask(mask); -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR uid_t u = 0; gid_t g = 80; @@ -818,7 +820,7 @@ asl_out_dst_data_release(asl_out_dst_data_t *dst) free(dst->ext); free(dst->rotate_dir); free(dst->fmt); -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR free(dst->uid); free(dst->gid); #endif @@ -837,10 +839,10 @@ asl_out_dst_data_retain(asl_out_dst_data_t *dst) int asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst) { -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR uid_t fuid = 0; gid_t fgid = 80; -#if !TARGET_OS_EMBEDDED +#if !TARGET_OS_IPHONE int status; acl_t acl; uuid_t uuid; @@ -853,7 +855,7 @@ asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst) if (dst == NULL) return -1; if (fd < 0) return -1; -#if TARGET_IPHONE_SIMULATOR +#if TARGET_OS_SIMULATOR return fd; #else @@ -862,9 +864,12 @@ asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst) fchown(fd, fuid, fgid); -#if TARGET_OS_EMBEDDED +#if TARGET_OS_IPHONE return fd; #else + if (os_variant_is_basesystem("com.apple.syslog")) { + return fd; + } acl = acl_init(1); for (i = 0; i < dst->ngid; i++) @@ -944,8 +949,8 @@ asl_file_create_return: acl_free(acl); return fd; -#endif /* !TARGET_OS_EMBEDDED */ -#endif /* !TARGET_IPHONE_SIMULATOR */ +#endif /* !TARGET_OS_IPHONE */ +#endif /* !TARGET_OS_SIMULATOR */ } /* create a file with acls */ @@ -1203,7 +1208,7 @@ _asl_out_module_parse_set_param(asl_out_module_t *m, char *s) return out; } -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR static void _dst_add_uid(asl_out_dst_data_t *dst, char *s) { @@ -1215,6 +1220,17 @@ _dst_add_uid(asl_out_dst_data_t *dst, char *s) uid = atoi(s); +#if TARGET_OS_IPHONE + if (uid == 501) + { + struct passwd * pw = getpwnam("mobile"); + if (pw) + { + uid = pw->pw_uid; + } + } +#endif + for (i = 0 ; i < dst->nuid; i++) { if (dst->uid[i] == uid) return; @@ -1241,6 +1257,17 @@ _dst_add_gid(asl_out_dst_data_t *dst, char *s) gid = atoi(s); +#if TARGET_OS_IPHONE + if (gid == 501) + { + struct passwd * pw = getpwnam("mobile"); + if (pw) + { + gid = pw->pw_gid; + } + } +#endif + for (i = 0 ; i < dst->ngid; i++) { if (dst->gid[i] == gid) return; @@ -1255,7 +1282,7 @@ _dst_add_gid(asl_out_dst_data_t *dst, char *s) dst->gid[dst->ngid++] = gid; } -#endif /* !TARGET_IPHONE_SIMULATOR */ +#endif /* !TARGET_OS_SIMULATOR */ static char * _dst_format_string(char *s) @@ -1534,7 +1561,7 @@ _asl_out_module_parse_dst(asl_out_module_t *m, char *s, mode_t def_mode) char *t = path; const char *log_root = "/var/log"; -#if TARGET_IPHONE_SIMULATOR +#if TARGET_OS_SIMULATOR log_root = getenv("SIMULATOR_LOG_ROOT"); if (log_root == NULL) log_root = "/tmp/log"; #endif @@ -1607,7 +1634,7 @@ _asl_out_module_parse_dst(asl_out_module_t *m, char *s, mode_t def_mode) while (NULL != (p = next_word_from_string(&opts))) { if (KEYMATCH(p, "mode=")) dst->mode = strtol(p+5, NULL, 0); -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR else if (KEYMATCH(p, "uid=")) _dst_add_uid(dst, p+4); else if (KEYMATCH(p, "gid=")) _dst_add_gid(dst, p+4); #endif @@ -1622,7 +1649,6 @@ _asl_out_module_parse_dst(asl_out_module_t *m, char *s, mode_t def_mode) else if (KEYMATCH(p+9, "false")) dst->flags &= ~MODULE_FLAG_COALESCE; } else if (KEYMATCH(p, "compress")) dst->flags |= MODULE_FLAG_COMPRESS; - else if (KEYMATCH(p, "activity")) dst->flags |= MODULE_FLAG_ACTIVITY; else if (KEYMATCH(p, "extern")) dst->flags |= MODULE_FLAG_EXTERNAL; else if (KEYMATCH(p, "truncate")) dst->flags |= MODULE_FLAG_TRUNCATE; else if (KEYMATCH(p, "dir")) dst->flags |= MODULE_FLAG_TYPE_ASL_DIR; @@ -1672,12 +1698,16 @@ _asl_out_module_parse_dst(asl_out_module_t *m, char *s, mode_t def_mode) dst->ttl[x] = asl_core_str_to_time(p+5, SECONDS_PER_DAY); } } + else if (KEYMATCH(p, "size_only")) + { + dst->flags |= MODULE_FLAG_SIZE_ONLY; + } free(p); p = NULL; } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) /* check for crashreporter files */ if ((KEYMATCH(dst->path, _PATH_CRASHREPORTER)) || (KEYMATCH(dst->path, _PATH_CRASHREPORTER_MOBILE_1)) || (KEYMATCH(dst->path, _PATH_CRASHREPORTER_MOBILE_2))) { @@ -1719,6 +1749,18 @@ _asl_out_module_parse_dst(asl_out_module_t *m, char *s, mode_t def_mode) /* set file_max to all_max if it is zero */ if (dst->file_max == 0) dst->file_max = dst->all_max; + /* size_only option requires non-zero file_max and all_max settings */ + if ((dst->flags & MODULE_FLAG_SIZE_ONLY) && (dst->file_max == 0 || dst->all_max == 0)) + { + dst->flags &= ~MODULE_FLAG_SIZE_ONLY; + } + + /* size_only option cannot be used with crashlog option */ + if ((dst->flags & MODULE_FLAG_SIZE_ONLY) && (dst->flags & MODULE_FLAG_CRASHLOG)) + { + dst->flags &= ~MODULE_FLAG_SIZE_ONLY; + } + out->action = ACTION_OUT_DEST; out->dst = dst; @@ -1868,7 +1910,7 @@ _asl_out_module_parse_query_action(asl_out_module_t *m, char *s) out->dst->flags &= ~MODULE_FLAG_ROTATE; } -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR if (out->dst->nuid == 0) _dst_add_uid(out->dst, "0"); if (out->dst->ngid == 0) _dst_add_gid(out->dst, "80"); #endif @@ -2012,7 +2054,7 @@ asl_out_module_init(void) { asl_out_module_t *out = NULL; -#if TARGET_IPHONE_SIMULATOR +#if TARGET_OS_SIMULATOR char *sim_root_path, *sim_resources_path; char *asl_conf, *asl_conf_dir, *asl_conf_local_dir; @@ -2039,7 +2081,7 @@ asl_out_module_init(void) if (_asl_out_module_find(out, ASL_MODULE_NAME) == NULL) { /* system just has old-style /etc/asl.conf */ -#if TARGET_IPHONE_SIMULATOR +#if TARGET_OS_SIMULATOR FILE *f = fopen(asl_conf, "r"); free(asl_conf); #else @@ -2184,11 +2226,6 @@ asl_out_module_print(FILE *f, asl_out_module_t *m) fprintf(f, "%cexternal", c); c = ' '; } - if (o->flags & MODULE_FLAG_ACTIVITY) - { - fprintf(f, "%cactivity", c); - c = ' '; - } if (o->flags & MODULE_FLAG_CRASHLOG) { fprintf(f, "%ccrashlog", c); @@ -2204,6 +2241,11 @@ asl_out_module_print(FILE *f, asl_out_module_t *m) fprintf(f, "%casl_directory", c); c = ' '; } + if (o->flags & MODULE_FLAG_SIZE_ONLY) + { + fprintf(f, "%csize_only", c); + c = ' '; + } fprintf(f, ")"); } fprintf(f, "\n"); @@ -2251,7 +2293,7 @@ asl_out_module_print(FILE *f, asl_out_module_t *m) fprintf(f, " mode: 0%o\n", o->mode); fprintf(f, " file_max: %lu\n", o->file_max); fprintf(f, " all_max: %lu\n", o->all_max); -#if !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_SIMULATOR fprintf(f, " uid:"); for (i = 0; i < o->nuid; i++) fprintf(f, " %d", o->uid[i]); fprintf(f, "\n");