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

Commit 1dee489c authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Stop using #if for conditional compilation."

parents 27d28d3b c0e919c9
Loading
Loading
Loading
Loading
+18 −11
Original line number Original line Diff line number Diff line
@@ -3,6 +3,24 @@
LOCAL_PATH:= $(call my-dir)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
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:= \
LOCAL_SRC_FILES:= \
    bootchart.cpp \
    bootchart.cpp \
    builtins.cpp \
    builtins.cpp \
@@ -25,17 +43,6 @@ LOCAL_CPPFLAGS += \
    -Werror -Wno-error=deprecated-declarations \
    -Werror -Wno-error=deprecated-declarations \
    -Wno-unused-parameter \
    -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_MODULE:= init


LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_FORCE_STATIC_EXECUTABLE := true
+12 −12
Original line number Original line Diff line number Diff line
@@ -59,21 +59,21 @@ proc_read(const char* filename, char* buff, size_t buffsize)


#define FILE_BUFF_SIZE    65536
#define FILE_BUFF_SIZE    65536


typedef struct {
struct FileBuff {
    int   count;
    int   count;
    int   fd;
    int   fd;
    char  data[FILE_BUFF_SIZE];
    char  data[FILE_BUFF_SIZE];
} FileBuffRec, *FileBuff;
};


static void
static void
file_buff_open( FileBuff  buff, const char*  path )
file_buff_open( FileBuff*  buff, const char*  path )
{
{
    buff->count = 0;
    buff->count = 0;
    buff->fd    = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0755);
    buff->fd    = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0755);
}
}


static void
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) {
    while (len > 0) {
        int  avail = sizeof(buff->data) - buff->count;
        int  avail = sizeof(buff->data) - buff->count;
@@ -93,7 +93,7 @@ file_buff_write( FileBuff buff, const void* src, int len )
}
}


static void
static void
file_buff_done( FileBuff  buff )
file_buff_done( FileBuff*  buff )
{
{
    if (buff->count > 0) {
    if (buff->count > 0) {
        TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count));
        TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count));
@@ -152,7 +152,7 @@ log_header(void)
}
}


static void
static void
do_log_uptime(FileBuff  log)
do_log_uptime(FileBuff*  log)
{
{
    char  buff[65];
    char  buff[65];
    int   len;
    int   len;
@@ -163,14 +163,14 @@ do_log_uptime(FileBuff log)
}
}


static void
static void
do_log_ln(FileBuff  log)
do_log_ln(FileBuff*  log)
{
{
    file_buff_write(log, "\n", 1);
    file_buff_write(log, "\n", 1);
}
}




static void
static void
do_log_file(FileBuff  log, const char*  procfile)
do_log_file(FileBuff*  log, const char*  procfile)
{
{
    char   buff[1024];
    char   buff[1024];
    int    fd;
    int    fd;
@@ -196,7 +196,7 @@ do_log_file(FileBuff log, const char* procfile)
}
}


static void
static void
do_log_procs(FileBuff  log)
do_log_procs(FileBuff*  log)
{
{
    DIR*  dir = opendir("/proc");
    DIR*  dir = opendir("/proc");
    struct dirent*  entry;
    struct dirent*  entry;
@@ -248,9 +248,9 @@ do_log_procs(FileBuff log)
    do_log_ln(log);
    do_log_ln(log);
}
}


static FileBuffRec  log_stat[1];
static FileBuff  log_stat[1];
static FileBuffRec  log_procs[1];
static FileBuff  log_procs[1];
static FileBuffRec  log_disks[1];
static FileBuff  log_disks[1];


/* called to setup bootcharting */
/* called to setup bootcharting */
int   bootchart_init( void )
int   bootchart_init( void )
+0 −4
Original line number Original line Diff line number Diff line
@@ -17,10 +17,6 @@
#ifndef _BOOTCHART_H
#ifndef _BOOTCHART_H
#define _BOOTCHART_H
#define _BOOTCHART_H


#ifndef BOOTCHART
# define  BOOTCHART  0
#endif

extern int   bootchart_init(void);
extern int   bootchart_init(void);
extern int   bootchart_step(void);
extern int   bootchart_step(void);
extern void  bootchart_finish(void);
extern void  bootchart_finish(void);
+12 −22
Original line number Original line Diff line number Diff line
@@ -366,8 +366,6 @@ static int find_pci_device_prefix(const char *path, char *buf, ssize_t buf_sz)
    return 0;
    return 0;
}
}


#if LOG_UEVENTS

static inline suseconds_t get_usecs(void)
static inline suseconds_t get_usecs(void)
{
{
    struct timeval tv;
    struct timeval tv;
@@ -375,15 +373,6 @@ static inline suseconds_t get_usecs(void)
    return tv.tv_sec * (suseconds_t) 1000000 + tv.tv_usec;
    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)
static void parse_event(const char *msg, struct uevent *uevent)
{
{
    uevent->action = "";
    uevent->action = "";
@@ -432,10 +421,12 @@ static void parse_event(const char *msg, struct uevent *uevent)
            ;
            ;
    }
    }


    log_event_print("event { '%s', '%s', '%s', '%s', %d, %d }\n",
    if (LOG_UEVENTS) {
        INFO("event { '%s', '%s', '%s', '%s', %d, %d }\n",
             uevent->action, uevent->path, uevent->subsystem,
             uevent->action, uevent->path, uevent->subsystem,
             uevent->firmware, uevent->major, uevent->minor);
             uevent->firmware, uevent->major, uevent->minor);
    }
    }
}


static char **get_character_device_symlinks(struct uevent *uevent)
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);
        process_firmware_event(uevent);
        _exit(EXIT_SUCCESS);
        _exit(EXIT_SUCCESS);
    } else if (pid < 0) {
    } 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));
    }
    }
}
}


@@ -1046,12 +1037,11 @@ void device_init(void)
        t1 = get_usecs();
        t1 = get_usecs();
        fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000);
        fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000);
        close(fd);
        close(fd);
        log_event_print("coldboot %ld uS\n", ((long) (t1 - t0)));
        if (LOG_UEVENTS) {
        // t0 & t1 are unused if the log isn't doing anything.
            INFO("coldboot %ld uS\n", ((long) (t1 - t0)));
        (void)t0;
        }
        (void)t1;
    } else if (LOG_UEVENTS) {
    } else {
        INFO("skipping coldboot, already done\n");
        log_event_print("skipping coldboot, already done\n");
    }
    }
}
}


+61 −67
Original line number Original line Diff line number Diff line
@@ -63,10 +63,8 @@ struct selabel_handle *sehandle_prop;


static int property_triggers_enabled = 0;
static int property_triggers_enabled = 0;


#if BOOTCHART
static int   bootchart_count;
static int   bootchart_count;
static long long bootchart_time = 0;
static long long bootchart_time = 0;
#endif


static char console[32];
static char console[32];
static char bootmode[32];
static char bootmode[32];
@@ -292,14 +290,14 @@ void service_start(struct service *svc, const char *dynamic_args)
            zap_stdio();
            zap_stdio();
        }
        }


#if 0
        if (false) {
        for (n = 0; svc->args[n]; n++) {
            for (size_t n = 0; svc->args[n]; n++) {
            INFO("args[%d] = '%s'\n", n, svc->args[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());
        setpgid(0, getpid());


@@ -859,7 +857,6 @@ static int queue_property_triggers_action(int nargs, char **args)
    return 0;
    return 0;
}
}


#if BOOTCHART
static int bootchart_init_action(int nargs, char **args)
static int bootchart_init_action(int nargs, char **args)
{
{
    bootchart_count = bootchart_init();
    bootchart_count = bootchart_init();
@@ -873,7 +870,6 @@ static int bootchart_init_action(int nargs, char **args)


    return 0;
    return 0;
}
}
#endif


void selinux_init_all_handles(void)
void selinux_init_all_handles(void)
{
{
@@ -884,45 +880,41 @@ void selinux_init_all_handles(void)


static bool selinux_is_disabled(void)
static bool selinux_is_disabled(void)
{
{
#ifdef ALLOW_DISABLE_SELINUX
    if (ALLOW_DISABLE_SELINUX) {
    char tmp[PROP_VALUE_MAX];

        if (access("/sys/fs/selinux", F_OK) != 0) {
        if (access("/sys/fs/selinux", F_OK) != 0) {
        /* SELinux is not compiled into the kernel, or has been disabled
            // SELinux is not compiled into the kernel, or has been disabled
         * via the kernel command line "selinux=0".
            // via the kernel command line "selinux=0".
         */
            return true;
            return true;
        }
        }


        char tmp[PROP_VALUE_MAX];
        if ((property_get("ro.boot.selinux", tmp) != 0) && (strcmp(tmp, "disabled") == 0)) {
        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. */
            // SELinux is compiled into the kernel, but we've been told to disable it.
            return true;
            return true;
        }
        }
#endif
    }


    return false;
    return false;
}
}


static bool selinux_is_enforcing(void)
static bool selinux_is_enforcing(void)
{
{
#ifdef ALLOW_DISABLE_SELINUX
    if (ALLOW_DISABLE_SELINUX) {
        char tmp[PROP_VALUE_MAX];
        char tmp[PROP_VALUE_MAX];

        if (property_get("ro.boot.selinux", tmp) == 0) {
        if (property_get("ro.boot.selinux", tmp) == 0) {
        /* Property is not set.  Assume enforcing */
            // Property is not set.  Assume enforcing.
            return true;
            return true;
        }
        }


        if (strcmp(tmp, "permissive") == 0) {
        if (strcmp(tmp, "permissive") == 0) {
        /* SELinux is in the kernel, but we've been told to go into permissive mode */
            // SELinux is in the kernel, but we've been told to go into permissive mode.
            return false;
            return false;
        }
        }


        if (strcmp(tmp, "enforcing") != 0) {
        if (strcmp(tmp, "enforcing") != 0) {
            ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp);
            ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp);
        }
        }

    }
#endif
    return true;
    return true;
}
}


@@ -1097,9 +1089,9 @@ int main(int argc, char **argv)
    queue_builtin_action(queue_property_triggers_action, "queue_property_triggers");
    queue_builtin_action(queue_property_triggers_action, "queue_property_triggers");




#if BOOTCHART
    if (BOOTCHART) {
        queue_builtin_action(bootchart_init_action, "bootchart_init");
        queue_builtin_action(bootchart_init_action, "bootchart_init");
#endif
    }


    for(;;) {
    for(;;) {
        int nr, i, timeout = -1;
        int nr, i, timeout = -1;
@@ -1135,10 +1127,11 @@ int main(int argc, char **argv)
                timeout = 0;
                timeout = 0;
        }
        }


        if (!action_queue_empty() || cur_action)
        if (!action_queue_empty() || cur_action) {
            timeout = 0;
            timeout = 0;
        }


#if BOOTCHART
        if (BOOTCHART) {
            if (bootchart_count > 0) {
            if (bootchart_count > 0) {
                long long current_time;
                long long current_time;
                int elapsed_time, remaining_time;
                int elapsed_time, remaining_time;
@@ -1161,11 +1154,12 @@ int main(int argc, char **argv)
                }
                }
                if (bootchart_count > 0) {
                if (bootchart_count > 0) {
                    remaining_time = BOOTCHART_POLLING_MS - elapsed_time;
                    remaining_time = BOOTCHART_POLLING_MS - elapsed_time;
                if (timeout < 0 || timeout > remaining_time)
                    if (timeout < 0 || timeout > remaining_time) {
                        timeout = remaining_time;
                        timeout = remaining_time;
                    }
                    }
                }
                }
#endif
            }
        }


        nr = poll(ufds, fd_count, timeout);
        nr = poll(ufds, fd_count, timeout);
        if (nr <= 0)
        if (nr <= 0)
Loading