Loading init/Android.mk +4 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ bootchart.cpp \ builtins.cpp \ devices.cpp \ init.cpp \ Loading @@ -17,13 +18,14 @@ LOCAL_SRC_FILES:= \ util.cpp \ watchdogd.cpp \ #LOCAL_CLANG := true LOCAL_CPPFLAGS += \ -Wall \ -Wall -Wextra \ -Werror -Wno-error=deprecated-declarations \ -Wno-unused-parameter \ ifeq ($(strip $(INIT_BOOTCHART)),true) LOCAL_SRC_FILES += bootchart.cpp LOCAL_CPPFLAGS += -DBOOTCHART=1 endif Loading init/bootchart.cpp +12 −49 Original line number Diff line number Diff line Loading @@ -20,20 +20,17 @@ * some C code that is run right from the init script. */ #include <stdio.h> #include <time.h> #include "bootchart.h" #include <dirent.h> #include <unistd.h> #include <fcntl.h> #include <unistd.h> #include <fcntl.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include "bootchart.h" #include <time.h> #include <unistd.h> #define VERSION "0.8" #define SAMPLE_PERIOD 0.2 Loading @@ -47,29 +44,13 @@ #define LOG_STARTFILE "/data/bootchart-start" #define LOG_STOPFILE "/data/bootchart-stop" static int unix_read(int fd, void* buff, int len) { int ret; do { ret = read(fd, buff, len); } while (ret < 0 && errno == EINTR); return ret; } static int unix_write(int fd, const void* buff, int len) { int ret; do { ret = write(fd, buff, len); } while (ret < 0 && errno == EINTR); return ret; } static int proc_read(const char* filename, char* buff, size_t buffsize) { int len = 0; int fd = open(filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, buffsize-1); len = TEMP_FAILURE_RETRY(read(fd, buff, buffsize-1)); close(fd); } buff[len > 0 ? len : 0] = 0; Loading Loading @@ -105,7 +86,7 @@ file_buff_write( FileBuff buff, const void* src, int len ) buff->count += avail; if (buff->count == FILE_BUFF_SIZE) { unix_write( buff->fd, buff->data, buff->count ); TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count)); buff->count = 0; } } Loading @@ -115,7 +96,7 @@ static void file_buff_done( FileBuff buff ) { if (buff->count > 0) { unix_write( buff->fd, buff->data, buff->count ); TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count)); buff->count = 0; } } Loading Loading @@ -170,23 +151,6 @@ log_header(void) fclose(out); } static void open_log_file(int* plogfd, const char* logfile) { int logfd = *plogfd; /* create log file if needed */ if (logfd < 0) { logfd = open(logfile,O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0755); if (logfd < 0) { *plogfd = -2; return; } *plogfd = logfd; } } static void do_log_uptime(FileBuff log) { Loading Loading @@ -217,8 +181,7 @@ do_log_file(FileBuff log, const char* procfile) fd = open(procfile,O_RDONLY|O_CLOEXEC); if (fd >= 0) { for (;;) { int ret; ret = unix_read(fd, buff, sizeof(buff)); int ret = TEMP_FAILURE_RETRY(read(fd, buff, sizeof(buff))); if (ret <= 0) break; Loading Loading @@ -259,7 +222,7 @@ do_log_procs(FileBuff log) snprintf(filename,sizeof(filename),"/proc/%d/stat",pid); fd = open(filename,O_RDONLY|O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, sizeof(buff)-1); len = TEMP_FAILURE_RETRY(read(fd, buff, sizeof(buff)-1)); close(fd); if (len > 0) { int len2 = strlen(cmdline); Loading Loading @@ -325,7 +288,7 @@ int bootchart_init( void ) count = (timeout*1000 + BOOTCHART_POLLING_MS-1)/BOOTCHART_POLLING_MS; do {ret=mkdir(LOG_ROOT,0755);}while (ret < 0 && errno == EINTR); ret = TEMP_FAILURE_RETRY(mkdir(LOG_ROOT,0755)); file_buff_open(log_stat, LOG_STAT); file_buff_open(log_procs, LOG_PROCS); Loading init/bootchart.h +3 −7 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ # define BOOTCHART 0 #endif #if BOOTCHART extern int bootchart_init(void); extern int bootchart_step(void); extern void bootchart_finish(void); Loading @@ -32,6 +30,4 @@ extern long long bootchart_gettime(void); #define BOOTCHART_DEFAULT_TIME_SEC (2*60) /* default polling time in seconds */ #define BOOTCHART_MAX_TIME_SEC (10*60) /* max polling time in seconds */ #endif /* BOOTCHART */ #endif /* _BOOTCHART_H */ init/builtins.cpp +4 −6 Original line number Diff line number Diff line Loading @@ -67,9 +67,7 @@ static int write_file(const char *path, const char *value) len = strlen(value); do { ret = write(fd, value, len); } while (ret < 0 && errno == EINTR); ret = TEMP_FAILURE_RETRY(write(fd, value, len)); close(fd); if (ret < 0) { Loading init/signal_handler.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ static void sigchld_handler(int s) static int wait_for_one_process(int block) { pid_t pid; int status; struct service *svc; struct socketinfo *si; Loading @@ -51,7 +50,7 @@ static int wait_for_one_process(int block) struct listnode *node; struct command *cmd; while ( (pid = waitpid(-1, &status, block ? 0 : WNOHANG)) == -1 && errno == EINTR ); pid_t pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, block ? 0 : WNOHANG)); if (pid <= 0) return -1; INFO("waitpid returned pid %d, status = %08x\n", pid, status); Loading Loading
init/Android.mk +4 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ bootchart.cpp \ builtins.cpp \ devices.cpp \ init.cpp \ Loading @@ -17,13 +18,14 @@ LOCAL_SRC_FILES:= \ util.cpp \ watchdogd.cpp \ #LOCAL_CLANG := true LOCAL_CPPFLAGS += \ -Wall \ -Wall -Wextra \ -Werror -Wno-error=deprecated-declarations \ -Wno-unused-parameter \ ifeq ($(strip $(INIT_BOOTCHART)),true) LOCAL_SRC_FILES += bootchart.cpp LOCAL_CPPFLAGS += -DBOOTCHART=1 endif Loading
init/bootchart.cpp +12 −49 Original line number Diff line number Diff line Loading @@ -20,20 +20,17 @@ * some C code that is run right from the init script. */ #include <stdio.h> #include <time.h> #include "bootchart.h" #include <dirent.h> #include <unistd.h> #include <fcntl.h> #include <unistd.h> #include <fcntl.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include "bootchart.h" #include <time.h> #include <unistd.h> #define VERSION "0.8" #define SAMPLE_PERIOD 0.2 Loading @@ -47,29 +44,13 @@ #define LOG_STARTFILE "/data/bootchart-start" #define LOG_STOPFILE "/data/bootchart-stop" static int unix_read(int fd, void* buff, int len) { int ret; do { ret = read(fd, buff, len); } while (ret < 0 && errno == EINTR); return ret; } static int unix_write(int fd, const void* buff, int len) { int ret; do { ret = write(fd, buff, len); } while (ret < 0 && errno == EINTR); return ret; } static int proc_read(const char* filename, char* buff, size_t buffsize) { int len = 0; int fd = open(filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, buffsize-1); len = TEMP_FAILURE_RETRY(read(fd, buff, buffsize-1)); close(fd); } buff[len > 0 ? len : 0] = 0; Loading Loading @@ -105,7 +86,7 @@ file_buff_write( FileBuff buff, const void* src, int len ) buff->count += avail; if (buff->count == FILE_BUFF_SIZE) { unix_write( buff->fd, buff->data, buff->count ); TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count)); buff->count = 0; } } Loading @@ -115,7 +96,7 @@ static void file_buff_done( FileBuff buff ) { if (buff->count > 0) { unix_write( buff->fd, buff->data, buff->count ); TEMP_FAILURE_RETRY(write(buff->fd, buff->data, buff->count)); buff->count = 0; } } Loading Loading @@ -170,23 +151,6 @@ log_header(void) fclose(out); } static void open_log_file(int* plogfd, const char* logfile) { int logfd = *plogfd; /* create log file if needed */ if (logfd < 0) { logfd = open(logfile,O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0755); if (logfd < 0) { *plogfd = -2; return; } *plogfd = logfd; } } static void do_log_uptime(FileBuff log) { Loading Loading @@ -217,8 +181,7 @@ do_log_file(FileBuff log, const char* procfile) fd = open(procfile,O_RDONLY|O_CLOEXEC); if (fd >= 0) { for (;;) { int ret; ret = unix_read(fd, buff, sizeof(buff)); int ret = TEMP_FAILURE_RETRY(read(fd, buff, sizeof(buff))); if (ret <= 0) break; Loading Loading @@ -259,7 +222,7 @@ do_log_procs(FileBuff log) snprintf(filename,sizeof(filename),"/proc/%d/stat",pid); fd = open(filename,O_RDONLY|O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, sizeof(buff)-1); len = TEMP_FAILURE_RETRY(read(fd, buff, sizeof(buff)-1)); close(fd); if (len > 0) { int len2 = strlen(cmdline); Loading Loading @@ -325,7 +288,7 @@ int bootchart_init( void ) count = (timeout*1000 + BOOTCHART_POLLING_MS-1)/BOOTCHART_POLLING_MS; do {ret=mkdir(LOG_ROOT,0755);}while (ret < 0 && errno == EINTR); ret = TEMP_FAILURE_RETRY(mkdir(LOG_ROOT,0755)); file_buff_open(log_stat, LOG_STAT); file_buff_open(log_procs, LOG_PROCS); Loading
init/bootchart.h +3 −7 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ # define BOOTCHART 0 #endif #if BOOTCHART extern int bootchart_init(void); extern int bootchart_step(void); extern void bootchart_finish(void); Loading @@ -32,6 +30,4 @@ extern long long bootchart_gettime(void); #define BOOTCHART_DEFAULT_TIME_SEC (2*60) /* default polling time in seconds */ #define BOOTCHART_MAX_TIME_SEC (10*60) /* max polling time in seconds */ #endif /* BOOTCHART */ #endif /* _BOOTCHART_H */
init/builtins.cpp +4 −6 Original line number Diff line number Diff line Loading @@ -67,9 +67,7 @@ static int write_file(const char *path, const char *value) len = strlen(value); do { ret = write(fd, value, len); } while (ret < 0 && errno == EINTR); ret = TEMP_FAILURE_RETRY(write(fd, value, len)); close(fd); if (ret < 0) { Loading
init/signal_handler.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ static void sigchld_handler(int s) static int wait_for_one_process(int block) { pid_t pid; int status; struct service *svc; struct socketinfo *si; Loading @@ -51,7 +50,7 @@ static int wait_for_one_process(int block) struct listnode *node; struct command *cmd; while ( (pid = waitpid(-1, &status, block ? 0 : WNOHANG)) == -1 && errno == EINTR ); pid_t pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, block ? 0 : WNOHANG)); if (pid <= 0) return -1; INFO("waitpid returned pid %d, status = %08x\n", pid, status); Loading