summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-02-04 10:25:09 -0800
committerElliott Hughes <enh@google.com>2015-02-04 10:25:09 -0800
commit24627906bfee8c4a9eede3deefd12365a78351bf (patch)
tree022000219c43e6c8e49dae701b3d2a7e60a93512 /init
parent798219e9e9137db272585f5dc5683df91ed5beb1 (diff)
downloadsystem_core-24627906bfee8c4a9eede3deefd12365a78351bf.zip
system_core-24627906bfee8c4a9eede3deefd12365a78351bf.tar.gz
system_core-24627906bfee8c4a9eede3deefd12365a78351bf.tar.bz2
Use TEMP_FAILURE_RETRY, always build bootchart.cpp.
Also switch the revision parsing over to sscanf as promised. I haven't done the hardware parsing because I don't yet know whether we actually need to keep the space-stripping code. Change-Id: Ic33378345cd515cb08d00c543acf44eb72673396
Diffstat (limited to 'init')
-rw-r--r--init/Android.mk6
-rw-r--r--init/bootchart.cpp61
-rw-r--r--init/bootchart.h10
-rw-r--r--init/builtins.cpp10
-rw-r--r--init/signal_handler.cpp3
-rw-r--r--init/util.cpp5
6 files changed, 25 insertions, 70 deletions
diff --git a/init/Android.mk b/init/Android.mk
index 01ce4da..ae472bd 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -4,6 +4,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
+ bootchart.cpp \
builtins.cpp \
devices.cpp \
init.cpp \
@@ -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
diff --git a/init/bootchart.cpp b/init/bootchart.cpp
index 44a2437..3d294cf 100644
--- a/init/bootchart.cpp
+++ b/init/bootchart.cpp
@@ -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
@@ -48,28 +45,12 @@
#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;
@@ -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;
}
}
@@ -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;
}
}
@@ -171,23 +152,6 @@ log_header(void)
}
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)
{
char buff[65];
@@ -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;
@@ -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);
@@ -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);
diff --git a/init/bootchart.h b/init/bootchart.h
index ed65e8a..fcd20b1 100644
--- a/init/bootchart.h
+++ b/init/bootchart.h
@@ -21,17 +21,13 @@
# define BOOTCHART 0
#endif
-#if BOOTCHART
-
extern int bootchart_init(void);
extern int bootchart_step(void);
extern void bootchart_finish(void);
extern long long bootchart_gettime(void);
-# define BOOTCHART_POLLING_MS 200 /* polling period in ms */
-# 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 */
+#define BOOTCHART_POLLING_MS 200 /* polling period in ms */
+#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_H */
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 6c4d9c4..9ead340 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -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) {
@@ -132,7 +130,7 @@ static int __ifupdown(const char *interface, int up)
ifr.ifr_flags &= ~IFF_UP;
ret = ioctl(s, SIOCSIFFLAGS, &ifr);
-
+
done:
close(s);
return ret;
@@ -735,7 +733,7 @@ int do_sysclktz(int nargs, char **args)
return -1;
memset(&tz, 0, sizeof(tz));
- tz.tz_minuteswest = atoi(args[1]);
+ tz.tz_minuteswest = atoi(args[1]);
if (settimeofday(NULL, &tz))
return -1;
return 0;
@@ -768,7 +766,7 @@ int do_copy(int nargs, char **args)
if (nargs != 3)
return -1;
- if (stat(args[1], &info) < 0)
+ if (stat(args[1], &info) < 0)
return -1;
if ((fd1 = open(args[1], O_RDONLY|O_CLOEXEC)) < 0)
diff --git a/init/signal_handler.cpp b/init/signal_handler.cpp
index 952f970..c0898fb 100644
--- a/init/signal_handler.cpp
+++ b/init/signal_handler.cpp
@@ -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;
@@ -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);
diff --git a/init/util.cpp b/init/util.cpp
index c484168..84fe536 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -431,10 +431,7 @@ void get_hardware_name(char *hardware, unsigned int *revision) {
hardware[n] = 0;
}
} else if (strncmp(buf, "Revision", 8) == 0) {
- const char* rev = strstr(buf, ": ");
- if (rev) {
- *revision = strtoul(rev + 2, 0, 16);
- }
+ sscanf(buf, "Revision : %ux", revision);
}
}
fclose(fp);