Skip to content

Commit

Permalink
Stop using #if for conditional compilation.
Browse files Browse the repository at this point in the history
Use regular 'if' to prevent bitrot.

Also remove remaining typedefs.

Change-Id: I2e6ca928e2db29b88b643cf990ff05cfb0be94a6
  • Loading branch information
enh-google committed Feb 5, 2015
1 parent 27d28d3 commit c0e919c
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 185 deletions.
29 changes: 18 additions & 11 deletions init/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions init/bootchart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -152,7 +152,7 @@ log_header(void)
}

static void
do_log_uptime(FileBuff log)
do_log_uptime(FileBuff* log)
{
char buff[65];
int len;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 0 additions & 4 deletions init/bootchart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 12 additions & 22 deletions init/devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,24 +366,13 @@ 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;
gettimeofday(&tv, 0);
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 = "";
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
}
}

Expand Down
Loading

0 comments on commit c0e919c

Please sign in to comment.