Merge "Stop using #if for conditional compilation."

This commit is contained in:
Elliott Hughes 2015-02-05 01:16:29 +00:00 committed by Gerrit Code Review
commit 1dee489cea
11 changed files with 164 additions and 187 deletions

View file

@ -3,6 +3,24 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# --
ifeq ($(strip $(INIT_BOOTCHART)),true)
LOCAL_CPPFLAGS += -DBOOTCHART=1
else
LOCAL_CPPFLAGS += -DBOOTCHART=0
endif
ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
LOCAL_CPPFLAGS += -DALLOW_LOCAL_PROP_OVERRIDE=1 -DALLOW_DISABLE_SELINUX=1
else
LOCAL_CPPFLAGS += -DALLOW_LOCAL_PROP_OVERRIDE=0 -DALLOW_DISABLE_SELINUX=0
endif
LOCAL_CPPFLAGS += -DLOG_UEVENTS=0
# --
LOCAL_SRC_FILES:= \
bootchart.cpp \
builtins.cpp \
@ -25,17 +43,6 @@ LOCAL_CPPFLAGS += \
-Werror -Wno-error=deprecated-declarations \
-Wno-unused-parameter \
ifeq ($(strip $(INIT_BOOTCHART)),true)
LOCAL_CPPFLAGS += -DBOOTCHART=1
endif
ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
LOCAL_CPPFLAGS += -DALLOW_LOCAL_PROP_OVERRIDE=1 -DALLOW_DISABLE_SELINUX=1
endif
# Enable ueventd logging
#LOCAL_CPPFLAGS += -DLOG_UEVENTS=1
LOCAL_MODULE:= init
LOCAL_FORCE_STATIC_EXECUTABLE := true

View file

@ -59,21 +59,21 @@ proc_read(const char* filename, char* buff, size_t buffsize)
#define FILE_BUFF_SIZE 65536
typedef struct {
struct FileBuff {
int count;
int fd;
char data[FILE_BUFF_SIZE];
} FileBuffRec, *FileBuff;
};
static void
file_buff_open( FileBuff buff, const char* path )
file_buff_open( FileBuff* buff, const char* path )
{
buff->count = 0;
buff->fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0755);
}
static void
file_buff_write( FileBuff buff, const void* src, int len )
file_buff_write( FileBuff* buff, const void* src, int len )
{
while (len > 0) {
int avail = sizeof(buff->data) - buff->count;
@ -93,7 +93,7 @@ file_buff_write( FileBuff buff, const void* src, int len )
}
static void
file_buff_done( FileBuff buff )
file_buff_done( FileBuff* buff )
{
if (buff->count > 0) {
TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count));
@ -152,7 +152,7 @@ log_header(void)
}
static void
do_log_uptime(FileBuff log)
do_log_uptime(FileBuff* log)
{
char buff[65];
int len;
@ -163,14 +163,14 @@ do_log_uptime(FileBuff log)
}
static void
do_log_ln(FileBuff log)
do_log_ln(FileBuff* log)
{
file_buff_write(log, "\n", 1);
}
static void
do_log_file(FileBuff log, const char* procfile)
do_log_file(FileBuff* log, const char* procfile)
{
char buff[1024];
int fd;
@ -196,7 +196,7 @@ do_log_file(FileBuff log, const char* procfile)
}
static void
do_log_procs(FileBuff log)
do_log_procs(FileBuff* log)
{
DIR* dir = opendir("/proc");
struct dirent* entry;
@ -248,9 +248,9 @@ do_log_procs(FileBuff log)
do_log_ln(log);
}
static FileBuffRec log_stat[1];
static FileBuffRec log_procs[1];
static FileBuffRec log_disks[1];
static FileBuff log_stat[1];
static FileBuff log_procs[1];
static FileBuff log_disks[1];
/* called to setup bootcharting */
int bootchart_init( void )

View file

@ -17,10 +17,6 @@
#ifndef _BOOTCHART_H
#define _BOOTCHART_H
#ifndef BOOTCHART
# define BOOTCHART 0
#endif
extern int bootchart_init(void);
extern int bootchart_step(void);
extern void bootchart_finish(void);

View file

@ -366,8 +366,6 @@ static int find_pci_device_prefix(const char *path, char *buf, ssize_t buf_sz)
return 0;
}
#if LOG_UEVENTS
static inline suseconds_t get_usecs(void)
{
struct timeval tv;
@ -375,15 +373,6 @@ static inline suseconds_t get_usecs(void)
return tv.tv_sec * (suseconds_t) 1000000 + tv.tv_usec;
}
#define log_event_print(x...) INFO(x)
#else
#define log_event_print(fmt, args...) do { } while (0)
#define get_usecs() 0
#endif
static void parse_event(const char *msg, struct uevent *uevent)
{
uevent->action = "";
@ -432,9 +421,11 @@ static void parse_event(const char *msg, struct uevent *uevent)
;
}
log_event_print("event { '%s', '%s', '%s', '%s', %d, %d }\n",
uevent->action, uevent->path, uevent->subsystem,
uevent->firmware, uevent->major, uevent->minor);
if (LOG_UEVENTS) {
INFO("event { '%s', '%s', '%s', '%s', %d, %d }\n",
uevent->action, uevent->path, uevent->subsystem,
uevent->firmware, uevent->major, uevent->minor);
}
}
static char **get_character_device_symlinks(struct uevent *uevent)
@ -933,7 +924,7 @@ static void handle_firmware_event(struct uevent *uevent)
process_firmware_event(uevent);
_exit(EXIT_SUCCESS);
} else if (pid < 0) {
log_event_print("could not fork to process firmware event: %s\n", strerror(errno));
ERROR("could not fork to process firmware event: %s\n", strerror(errno));
}
}
@ -972,7 +963,7 @@ void handle_device_fd()
**
** We drain any pending events from the netlink socket every time
** we poke another uevent file to make sure we don't overrun the
** socket's buffer.
** socket's buffer.
*/
static void do_coldboot(DIR *d)
@ -1046,12 +1037,11 @@ void device_init(void)
t1 = get_usecs();
fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000);
close(fd);
log_event_print("coldboot %ld uS\n", ((long) (t1 - t0)));
// t0 & t1 are unused if the log isn't doing anything.
(void)t0;
(void)t1;
} else {
log_event_print("skipping coldboot, already done\n");
if (LOG_UEVENTS) {
INFO("coldboot %ld uS\n", ((long) (t1 - t0)));
}
} else if (LOG_UEVENTS) {
INFO("skipping coldboot, already done\n");
}
}

View file

@ -63,10 +63,8 @@ struct selabel_handle *sehandle_prop;
static int property_triggers_enabled = 0;
#if BOOTCHART
static int bootchart_count;
static long long bootchart_time = 0;
#endif
static char console[32];
static char bootmode[32];
@ -292,14 +290,14 @@ void service_start(struct service *svc, const char *dynamic_args)
zap_stdio();
}
#if 0
for (n = 0; svc->args[n]; n++) {
INFO("args[%d] = '%s'\n", n, svc->args[n]);
if (false) {
for (size_t n = 0; svc->args[n]; n++) {
INFO("args[%zu] = '%s'\n", n, svc->args[n]);
}
for (size_t n = 0; ENV[n]; n++) {
INFO("env[%zu] = '%s'\n", n, ENV[n]);
}
}
for (n = 0; ENV[n]; n++) {
INFO("env[%d] = '%s'\n", n, ENV[n]);
}
#endif
setpgid(0, getpid());
@ -859,7 +857,6 @@ static int queue_property_triggers_action(int nargs, char **args)
return 0;
}
#if BOOTCHART
static int bootchart_init_action(int nargs, char **args)
{
bootchart_count = bootchart_init();
@ -873,7 +870,6 @@ static int bootchart_init_action(int nargs, char **args)
return 0;
}
#endif
void selinux_init_all_handles(void)
{
@ -884,45 +880,41 @@ void selinux_init_all_handles(void)
static bool selinux_is_disabled(void)
{
#ifdef ALLOW_DISABLE_SELINUX
char tmp[PROP_VALUE_MAX];
if (ALLOW_DISABLE_SELINUX) {
if (access("/sys/fs/selinux", F_OK) != 0) {
// SELinux is not compiled into the kernel, or has been disabled
// via the kernel command line "selinux=0".
return true;
}
if (access("/sys/fs/selinux", F_OK) != 0) {
/* SELinux is not compiled into the kernel, or has been disabled
* via the kernel command line "selinux=0".
*/
return true;
char tmp[PROP_VALUE_MAX];
if ((property_get("ro.boot.selinux", tmp) != 0) && (strcmp(tmp, "disabled") == 0)) {
// SELinux is compiled into the kernel, but we've been told to disable it.
return true;
}
}
if ((property_get("ro.boot.selinux", tmp) != 0) && (strcmp(tmp, "disabled") == 0)) {
/* SELinux is compiled into the kernel, but we've been told to disable it. */
return true;
}
#endif
return false;
}
static bool selinux_is_enforcing(void)
{
#ifdef ALLOW_DISABLE_SELINUX
char tmp[PROP_VALUE_MAX];
if (ALLOW_DISABLE_SELINUX) {
char tmp[PROP_VALUE_MAX];
if (property_get("ro.boot.selinux", tmp) == 0) {
// Property is not set. Assume enforcing.
return true;
}
if (property_get("ro.boot.selinux", tmp) == 0) {
/* Property is not set. Assume enforcing */
return true;
if (strcmp(tmp, "permissive") == 0) {
// SELinux is in the kernel, but we've been told to go into permissive mode.
return false;
}
if (strcmp(tmp, "enforcing") != 0) {
ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp);
}
}
if (strcmp(tmp, "permissive") == 0) {
/* SELinux is in the kernel, but we've been told to go into permissive mode */
return false;
}
if (strcmp(tmp, "enforcing") != 0) {
ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp);
}
#endif
return true;
}
@ -1097,9 +1089,9 @@ int main(int argc, char **argv)
queue_builtin_action(queue_property_triggers_action, "queue_property_triggers");
#if BOOTCHART
queue_builtin_action(bootchart_init_action, "bootchart_init");
#endif
if (BOOTCHART) {
queue_builtin_action(bootchart_init_action, "bootchart_init");
}
for(;;) {
int nr, i, timeout = -1;
@ -1135,37 +1127,39 @@ int main(int argc, char **argv)
timeout = 0;
}
if (!action_queue_empty() || cur_action)
if (!action_queue_empty() || cur_action) {
timeout = 0;
}
#if BOOTCHART
if (bootchart_count > 0) {
long long current_time;
int elapsed_time, remaining_time;
current_time = bootchart_gettime();
elapsed_time = current_time - bootchart_time;
if (elapsed_time >= BOOTCHART_POLLING_MS) {
/* count missed samples */
while (elapsed_time >= BOOTCHART_POLLING_MS) {
elapsed_time -= BOOTCHART_POLLING_MS;
bootchart_count--;
}
/* count may be negative, take a sample anyway */
bootchart_time = current_time;
if (bootchart_step() < 0 || bootchart_count <= 0) {
bootchart_finish();
bootchart_count = 0;
}
}
if (BOOTCHART) {
if (bootchart_count > 0) {
remaining_time = BOOTCHART_POLLING_MS - elapsed_time;
if (timeout < 0 || timeout > remaining_time)
timeout = remaining_time;
long long current_time;
int elapsed_time, remaining_time;
current_time = bootchart_gettime();
elapsed_time = current_time - bootchart_time;
if (elapsed_time >= BOOTCHART_POLLING_MS) {
/* count missed samples */
while (elapsed_time >= BOOTCHART_POLLING_MS) {
elapsed_time -= BOOTCHART_POLLING_MS;
bootchart_count--;
}
/* count may be negative, take a sample anyway */
bootchart_time = current_time;
if (bootchart_step() < 0 || bootchart_count <= 0) {
bootchart_finish();
bootchart_count = 0;
}
}
if (bootchart_count > 0) {
remaining_time = BOOTCHART_POLLING_MS - elapsed_time;
if (timeout < 0 || timeout > remaining_time) {
timeout = remaining_time;
}
}
}
}
#endif
nr = poll(ufds, fd_count, timeout);
if (nr <= 0)

View file

@ -73,6 +73,45 @@ static struct {
#define kw_func(kw) (keyword_info[kw].func)
#define kw_nargs(kw) (keyword_info[kw].nargs)
void dump_parser_state() {
if (false) {
struct listnode* node;
list_for_each(node, &service_list) {
service* svc = node_to_item(node, struct service, slist);
INFO("service %s\n", svc->name);
INFO(" class '%s'\n", svc->classname);
INFO(" exec");
for (int n = 0; n < svc->nargs; n++) {
INFO(" '%s'", svc->args[n]);
}
INFO("\n");
for (socketinfo* si = svc->sockets; si; si = si->next) {
INFO(" socket %s %s 0%o\n", si->name, si->type, si->perm);
}
}
list_for_each(node, &action_list) {
action* act = node_to_item(node, struct action, alist);
INFO("on ");
char name_str[256] = "";
build_triggers_string(name_str, sizeof(name_str), act);
INFO("%s", name_str);
INFO("\n");
struct listnode* node2;
list_for_each(node2, &act->commands) {
command* cmd = node_to_item(node2, struct command, clist);
INFO(" %p", cmd->func);
for (int n = 0; n < cmd->nargs; n++) {
INFO(" %s", cmd->args[n]);
}
INFO("\n");
}
INFO("\n");
}
}
}
static int lookup_keyword(const char *s)
{
switch (*s++) {
@ -403,7 +442,7 @@ int init_parse_config_file(const char *fn)
if (!data) return -1;
parse_config(fn, data);
DUMP();
dump_parser_state();
return 0;
}

View file

@ -1,64 +1,17 @@
#include <stdio.h>
#include "parser.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "parser.h"
#include "log.h"
#define RAW(x...) log_write(6, x)
void DUMP(void)
{
#if 0
struct service *svc;
struct action *act;
struct command *cmd;
struct listnode *node;
struct listnode *node2;
char name_str[256] = "";
struct socketinfo *si;
int n;
list_for_each(node, &service_list) {
svc = node_to_item(node, struct service, slist);
RAW("service %s\n", svc->name);
RAW(" class '%s'\n", svc->classname);
RAW(" exec");
for (n = 0; n < svc->nargs; n++) {
RAW(" '%s'", svc->args[n]);
}
RAW("\n");
for (si = svc->sockets; si; si = si->next) {
RAW(" socket %s %s 0%o\n", si->name, si->type, si->perm);
}
}
list_for_each(node, &action_list) {
act = node_to_item(node, struct action, alist);
RAW("on ");
build_triggers_string(name_str, sizeof(name_str), act);
RAW("%s", name_str);
RAW("\n");
list_for_each(node2, &act->commands) {
cmd = node_to_item(node2, struct command, clist);
RAW(" %p", cmd->func);
for (n = 0; n < cmd->nargs; n++) {
RAW(" %s", cmd->args[n]);
}
RAW("\n");
}
RAW("\n");
}
#endif
}
void parse_error(struct parse_state *state, const char *fmt, ...)
{
va_list ap;
char buf[128];
int off;
snprintf(buf, 128, "%s: %d: ", state->filename, state->line);
buf[127] = 0;
off = strlen(buf);

View file

@ -33,7 +33,7 @@ struct parse_state
void *priv;
};
void DUMP(void);
void dump_parser_state(void);
int next_token(struct parse_state *state);
void parse_error(struct parse_state *state, const char *fmt, ...);

View file

@ -56,10 +56,10 @@ static int property_area_inited = 0;
static int property_set_fd = -1;
typedef struct {
struct workspace {
size_t size;
int fd;
} workspace;
};
static int init_workspace(workspace *w, size_t size)
{
@ -503,15 +503,13 @@ int properties_inited(void)
}
static void load_override_properties() {
#ifdef ALLOW_LOCAL_PROP_OVERRIDE
char debuggable[PROP_VALUE_MAX];
int ret;
ret = property_get("ro.debuggable", debuggable);
if (ret && (strcmp(debuggable, "1") == 0)) {
load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE, NULL);
if (ALLOW_LOCAL_PROP_OVERRIDE) {
char debuggable[PROP_VALUE_MAX];
int ret = property_get("ro.debuggable", debuggable);
if (ret && (strcmp(debuggable, "1") == 0)) {
load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE, NULL);
}
}
#endif /* ALLOW_LOCAL_PROP_OVERRIDE */
}

View file

@ -70,12 +70,12 @@ int ueventd_main(int argc, char **argv)
open_devnull_stdio();
klog_init();
#if LOG_UEVENTS
/* Ensure we're at a logging level that will show the events */
if (klog_get_level() < KLOG_INFO_LEVEL) {
klog_set_level(KLOG_INFO_LEVEL);
if (LOG_UEVENTS) {
/* Ensure we're at a logging level that will show the events */
if (klog_get_level() < KLOG_INFO_LEVEL) {
klog_set_level(KLOG_INFO_LEVEL);
}
}
#endif
union selinux_callback cb;
cb.func_log = log_callback;

View file

@ -235,7 +235,7 @@ int ueventd_parse_config_file(const char *fn)
if (!data) return -1;
parse_config(fn, data);
DUMP();
dump_parser_state();
return 0;
}