Stop using #if for conditional compilation.

Use regular 'if' to prevent bitrot.

Also remove remaining typedefs.

Change-Id: I2e6ca928e2db29b88b643cf990ff05cfb0be94a6
diff --git a/init/Android.mk b/init/Android.mk
index ae472bd..bf8dea5 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -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 @@
     -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
diff --git a/init/bootchart.cpp b/init/bootchart.cpp
index 3d294cf..d275096 100644
--- a/init/bootchart.cpp
+++ b/init/bootchart.cpp
@@ -59,21 +59,21 @@
 
 #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 @@
 }
 
 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 @@
 }
 
 static void
-do_log_uptime(FileBuff  log)
+do_log_uptime(FileBuff*  log)
 {
     char  buff[65];
     int   len;
@@ -163,14 +163,14 @@
 }
 
 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 @@
 }
 
 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_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 )
diff --git a/init/bootchart.h b/init/bootchart.h
index fcd20b1..9ba3c40 100644
--- a/init/bootchart.h
+++ b/init/bootchart.h
@@ -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);
diff --git a/init/devices.cpp b/init/devices.cpp
index 28f2ec0..b55933c 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -366,8 +366,6 @@
     return 0;
 }
 
-#if LOG_UEVENTS
-
 static inline suseconds_t get_usecs(void)
 {
     struct timeval tv;
@@ -375,15 +373,6 @@
     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 @@
             ;
     }
 
-    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 @@
         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 @@
 **
 ** 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 @@
         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");
     }
 }
 
diff --git a/init/init.cpp b/init/init.cpp
index 06a7326..da3fe96 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -63,10 +63,8 @@
 
 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 @@
             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 @@
     return 0;
 }
 
-#if BOOTCHART
 static int bootchart_init_action(int nargs, char **args)
 {
     bootchart_count = bootchart_init();
@@ -873,7 +870,6 @@
 
     return 0;
 }
-#endif
 
 void selinux_init_all_handles(void)
 {
@@ -884,45 +880,41 @@
 
 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 @@
     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 @@
                 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)
diff --git a/init/init_parser.cpp b/init/init_parser.cpp
index c8f2ea7..facb0cf 100644
--- a/init/init_parser.cpp
+++ b/init/init_parser.cpp
@@ -73,6 +73,45 @@
 #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 @@
     if (!data) return -1;
 
     parse_config(fn, data);
-    DUMP();
+    dump_parser_state();
     return 0;
 }
 
diff --git a/init/parser.cpp b/init/parser.cpp
index 80bfb09..8193729 100644
--- a/init/parser.cpp
+++ b/init/parser.cpp
@@ -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);
diff --git a/init/parser.h b/init/parser.h
index a58272a..95e1164 100644
--- a/init/parser.h
+++ b/init/parser.h
@@ -33,7 +33,7 @@
     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, ...);
 
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 4f0a46c..cc1ee34 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -56,10 +56,10 @@
 
 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 @@
 }
 
 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 */
 }
 
 
diff --git a/init/ueventd.cpp b/init/ueventd.cpp
index 86621cd..d56b91a 100644
--- a/init/ueventd.cpp
+++ b/init/ueventd.cpp
@@ -70,12 +70,12 @@
 
     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;
diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp
index f54a90b..2ae251f 100644
--- a/init/ueventd_parser.cpp
+++ b/init/ueventd_parser.cpp
@@ -235,7 +235,7 @@
     if (!data) return -1;
 
     parse_config(fn, data);
-    DUMP();
+    dump_parser_state();
     return 0;
 }