Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cc75a68 authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge "logd: Allow flags "eng" and "svelte" in boolean"

parents 2427d341 9c66a58f
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -101,9 +101,10 @@ void LogBuffer::init() {
    if (!default_size) {
    if (!default_size) {
        default_size = property_get_size(global_default);
        default_size = property_get_size(global_default);
        if (!default_size) {
        if (!default_size) {
            default_size = property_get_bool("ro.config.low_ram", false) ?
            default_size = property_get_bool("ro.config.low_ram",
                LOG_BUFFER_MIN_SIZE : // 64K
                                             BOOL_DEFAULT_FALSE)
                LOG_BUFFER_SIZE;      // 256K
                ? LOG_BUFFER_MIN_SIZE // 64K
                : LOG_BUFFER_SIZE;    // 256K
        }
        }
    }
    }


+8 −1
Original line number Original line Diff line number Diff line
@@ -44,7 +44,14 @@ bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid);
bool clientHasLogCredentials(SocketClient *cli);
bool clientHasLogCredentials(SocketClient *cli);


// Furnished in main.cpp
// Furnished in main.cpp
bool property_get_bool(const char *key, bool def);
#define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
#define BOOL_DEFAULT_FALSE       0x0     // false if property not present
#define BOOL_DEFAULT_TRUE        0x1     // true if property not present
#define BOOL_DEFAULT_FLAG_PERSIST    0x2 // <key>, persist.<key>, ro.<key>
#define BOOL_DEFAULT_FLAG_ENG        0x4 // off for user
#define BOOL_DEFAULT_FLAG_SVELTE     0x8 // off for low_ram

bool property_get_bool(const char *key, int def);


static inline bool worstUidEnabledForLogid(log_id_t id) {
static inline bool worstUidEnabledForLogid(log_id_t id) {
    return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) || (id == LOG_ID_RADIO);
    return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) || (id == LOG_ID_RADIO);
+41 −25
Original line number Original line Diff line number Diff line
The properties that logd responds to are:
The properties that logd responds to are:


name                       type default  description
name                       type default  description
logd.auditd                 bool  true   Enable selinux audit daemon
ro.logd.auditd             bool   true   Enable selinux audit daemon
logd.auditd.dmesg           bool  true   selinux audit messages duplicated and
ro.logd.auditd.dmesg       bool   true   selinux audit messages duplicated and
                                         sent on to dmesg log
                                         sent on to dmesg log
logd.klogd                  bool depends Enable klogd daemon
persist.logd.security      bool   false  Enable security buffer.
logd.statistics             bool depends Enable logcat -S statistics.
ro.device_owner            bool   false  Override persist.logd.security to false
ro.config.low_ram           bool  false  if true, logd.statistics & logd.klogd
ro.logd.kernel             bool+ svelte+ Enable klogd daemon
                                         default false
ro.logd.statistics         bool+ svelte+ Enable logcat -S statistics.
ro.build.type               string       if user, logd.statistics & logd.klogd
ro.build.type              string        if user, logd.statistics &
                                         default false
                                         ro.logd.kernel default false.
persist.logd.logpersistd   string        Enable logpersist daemon, "logcatd"
persist.logd.logpersistd   string        Enable logpersist daemon, "logcatd"
                                         turns on logcat -f in logd context
                                         turns on logcat -f in logd context
persist.logd.size          number 256K   Global default size of the buffer for
persist.logd.size          number  ro    Global default size of the buffer for
                                         all log ids at initial startup, at
                                         all log ids at initial startup, at
                                         runtime use: logcat -b all -G <value>
                                         runtime use: logcat -b all -G <value>
persist.logd.size.main     number 256K   Size of the buffer for the main log
ro.logd.size               number svelte default for persist.logd.size
persist.logd.size.system   number 256K   Size of the buffer for the system log
persist.logd.size.<buffer> number  ro    Size of the buffer for <buffer> log
persist.logd.size.radio    number 256K   Size of the buffer for the radio log
ro.logd.size.<buffer>      number svelte default for persist.logd.size.<buffer>
persist.logd.size.event    number 256K   Size of the buffer for the event log
ro.config.low_ram          bool   false  if true, logd.statistics, logd.kernel
persist.logd.size.crash    number 256K   Size of the buffer for the crash log
                                         default false, logd.size 64K instead
persist.logd.filter         string       Pruning filter to optimize content,
                                         of 256K.
                                         default is ro.logd.filter or
persist.logd.filter        string        Pruning filter to optimize content.
                                         "~!" which means to prune the oldest
                                         At runtime use: logcat -P "<string>"
                                         entries of chattiest UID. At runtime
ro.logd.filter             string "~!"   default for persist.logd.filter.
                                         use: logcat -P "<string>"
                                         This default means to prune the
persist.logd.timestamp      string       The recording timestamp source. Default
                                         oldest entries of chattiest UID.
                                         is ro.logd.timestamp. "m[onotonic]" is
persist.logd.timestamp     string  ro    The recording timestamp source.
                                         the only supported key character,
                                         "m[onotonic]" is the only supported
                                         otherwise assumes realtime.
                                         key character, otherwise realtime.
ro.logd.timestamp        string realtime default for persist.logd.timestamp
log.tag                   string persist The global logging level, VERBOSE,
                                         DEBUG, INFO, WARN, ERROR, ASSERT or
                                         SILENT. Only the first character is
                                         the key character.
persist.log.tag            string build  default for log.tag
log.tag.<tag>             string persist The <tag> specific logging level.
persist.log.tag.<tag>      string build  default for log.tag.<tag>


NB:
NB:
- Number support multipliers (K or M) for convenience. Range is limited
- bool+ - "true", "false" and comma separated list of "eng" (forced false if
  ro.build.type is "user") or "svelte" (forced false if ro.config.low_ram is
  true).
- svelte - see ro.config.low_ram for details.
- svelte+ - see ro.config.low_ram and ro.build.type for details.
- ro - <base property> temporary override, ro.<base property> platform default.
- persist - <base property> override, persist.<base property> platform default.
- build - VERBOSE for native, DEBUG for jvm isLoggable, or developer option.
- number - support multipliers (K or M) for convenience. Range is limited
  to between 64K and 256M for log buffer sizes. Individual log buffer ids
  to between 64K and 256M for log buffer sizes. Individual log buffer ids
  such as main, system, ... override global default.
  such as main, system, ... override global default.
- Pruning filter is of form of a space-separated list of [~][UID][/PID]
- Pruning filter is of form of a space-separated list of [~][UID][/PID]
+79 −23
Original line number Original line Diff line number Diff line
@@ -143,18 +143,72 @@ static int drop_privs() {
}
}


// Property helper
// Property helper
bool property_get_bool(const char *key, bool def) {
static bool check_flag(const char *prop, const char *flag) {
    char property[PROPERTY_VALUE_MAX];
    const char *cp = strcasestr(prop, flag);
    property_get(key, property, "");
    if (!cp) {
        return false;
    }
    // We only will document comma (,)
    static const char sep[] = ",:;|+ \t\f";
    if ((cp != prop) && !strchr(sep, cp[-1])) {
        return false;
    }
    cp += strlen(flag);
    return !*cp || !!strchr(sep, *cp);
}


    if (!strcasecmp(property, "true")) {
bool property_get_bool(const char *key, int flag) {
    char def[PROPERTY_VALUE_MAX];
    char property[PROPERTY_VALUE_MAX];
    def[0] = '\0';
    if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
        char newkey[PROPERTY_KEY_MAX];
        snprintf(newkey, sizeof(newkey), "ro.%s", key);
        property_get(newkey, property, "");
        // persist properties set by /data require innoculation with
        // logd-reinit. They may be set in init.rc early and function, but
        // otherwise are defunct unless reset. Do not rely on persist
        // properties for startup-only keys unless you are willing to restart
        // logd daemon (not advised).
        snprintf(newkey, sizeof(newkey), "persist.%s", key);
        property_get(newkey, def, property);
    }

    property_get(key, property, def);

    if (check_flag(property, "true")) {
        return true;
        return true;
    }
    }
    if (!strcasecmp(property, "false")) {
    if (check_flag(property, "false")) {
        return false;
    }
    if (check_flag(property, "eng")) {
       flag |= BOOL_DEFAULT_FLAG_ENG;
    }
    // this is really a "not" flag
    if (check_flag(property, "svelte")) {
       flag |= BOOL_DEFAULT_FLAG_SVELTE;
    }

    // Sanity Check
    if (flag & (BOOL_DEFAULT_FLAG_SVELTE | BOOL_DEFAULT_FLAG_ENG)) {
        flag &= ~BOOL_DEFAULT_FLAG_TRUE_FALSE;
        flag |= BOOL_DEFAULT_TRUE;
    }

    if ((flag & BOOL_DEFAULT_FLAG_SVELTE)
            && property_get_bool("ro.config.low_ram",
                                 BOOL_DEFAULT_FALSE)) {
        return false;
    }
    if (flag & BOOL_DEFAULT_FLAG_ENG) {
        property_get("ro.build.type", property, "");
        if (!strcmp(property, "user")) {
            return false;
            return false;
        }
        }
    }


    return def;
    return (flag & BOOL_DEFAULT_FLAG_TRUE_FALSE) != BOOL_DEFAULT_FALSE;
}
}


// Remove the static, and use this variable
// Remove the static, and use this variable
@@ -266,17 +320,6 @@ const char *android::tagToName(uint32_t tag) {
    return android_lookupEventTag(map, tag);
    return android_lookupEventTag(map, tag);
}
}


static bool property_get_bool_svelte(const char *key) {
    bool not_user;
    {
        char property[PROPERTY_VALUE_MAX];
        property_get("ro.build.type", property, "");
        not_user = !!strcmp(property, "user");
    }
    return property_get_bool(key, not_user
            && !property_get_bool("ro.config.low_ram", false));
}

static void readDmesg(LogAudit *al, LogKlog *kl) {
static void readDmesg(LogAudit *al, LogKlog *kl) {
    if (!al && !kl) {
    if (!al && !kl) {
        return;
        return;
@@ -325,7 +368,11 @@ static void readDmesg(LogAudit *al, LogKlog *kl) {
// transitory per-client threads are created for each reader.
// transitory per-client threads are created for each reader.
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
    int fdPmesg = -1;
    int fdPmesg = -1;
    bool klogd = property_get_bool_svelte("logd.klogd");
    bool klogd = property_get_bool("logd.kernel",
                                   BOOL_DEFAULT_TRUE |
                                   BOOL_DEFAULT_FLAG_PERSIST |
                                   BOOL_DEFAULT_FLAG_ENG |
                                   BOOL_DEFAULT_FLAG_SVELTE);
    if (klogd) {
    if (klogd) {
        fdPmesg = open("/proc/kmsg", O_RDONLY | O_NDELAY);
        fdPmesg = open("/proc/kmsg", O_RDONLY | O_NDELAY);
    }
    }
@@ -405,7 +452,11 @@ int main(int argc, char *argv[]) {


    signal(SIGHUP, reinit_signal_handler);
    signal(SIGHUP, reinit_signal_handler);


    if (property_get_bool_svelte("logd.statistics")) {
    if (property_get_bool("logd.statistics",
                          BOOL_DEFAULT_TRUE |
                          BOOL_DEFAULT_FLAG_PERSIST |
                          BOOL_DEFAULT_FLAG_ENG |
                          BOOL_DEFAULT_FLAG_SVELTE)) {
        logBuf->enableStatistics();
        logBuf->enableStatistics();
    }
    }


@@ -439,12 +490,17 @@ int main(int argc, char *argv[]) {
    // initiated log messages. New log entries are added to LogBuffer
    // initiated log messages. New log entries are added to LogBuffer
    // and LogReader is notified to send updates to connected clients.
    // and LogReader is notified to send updates to connected clients.


    bool auditd = property_get_bool("logd.auditd", true);
    bool auditd = property_get_bool("logd.auditd",

                                    BOOL_DEFAULT_TRUE |
                                    BOOL_DEFAULT_FLAG_PERSIST);
    LogAudit *al = NULL;
    LogAudit *al = NULL;
    if (auditd) {
    if (auditd) {
        bool dmesg = property_get_bool("logd.auditd.dmesg", true);
        al = new LogAudit(logBuf, reader,
        al = new LogAudit(logBuf, reader, dmesg ? fdDmesg : -1);
                          property_get_bool("logd.auditd.dmesg",
                                            BOOL_DEFAULT_TRUE |
                                            BOOL_DEFAULT_FLAG_PERSIST)
                              ? fdDmesg
                              : -1);
    }
    }


    LogKlog *kl = NULL;
    LogKlog *kl = NULL;