Merge "Implement Reboot bootloader via bootloader_message"
diff --git a/init/action.cpp b/init/action.cpp
index ed88f6d..a12f225 100644
--- a/init/action.cpp
+++ b/init/action.cpp
@@ -118,14 +118,16 @@
Timer t;
int result = command.InvokeFunc();
- // TODO: this should probably be changed to "if (failed || took a long time)"...
- if (android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
+ double duration_ms = t.duration() * 1000;
+ // Any action longer than 50ms will be warned to user as slow operation
+ if (duration_ms > 50.0 ||
+ android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
std::string trigger_name = BuildTriggersString();
std::string cmd_str = command.BuildCommandString();
std::string source = command.BuildSourceString();
LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << source
- << " returned " << result << " took " << t.duration() << "s";
+ << " returned " << result << " took " << duration_ms << "ms.";
}
}
diff --git a/init/util.cpp b/init/util.cpp
index ab6837d..ff46e4f 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -38,6 +38,7 @@
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <android-base/unique_fd.h>
/* for ANDROID_SOCKET_* */
#include <cutils/sockets.h>
@@ -89,10 +90,6 @@
int create_socket(const char *name, int type, mode_t perm, uid_t uid,
gid_t gid, const char *socketcon)
{
- struct sockaddr_un addr;
- int fd, ret, savederrno;
- char *filecon;
-
if (socketcon) {
if (setsockcreatecon(socketcon) == -1) {
PLOG(ERROR) << "setsockcreatecon(\"" << socketcon << "\") failed";
@@ -100,52 +97,49 @@
}
}
- fd = socket(PF_UNIX, type, 0);
+ android::base::unique_fd fd(socket(PF_UNIX, type, 0));
if (fd < 0) {
PLOG(ERROR) << "Failed to open socket '" << name << "'";
return -1;
}
- if (socketcon)
- setsockcreatecon(NULL);
+ if (socketcon) setsockcreatecon(NULL);
+ struct sockaddr_un addr;
memset(&addr, 0 , sizeof(addr));
addr.sun_family = AF_UNIX;
snprintf(addr.sun_path, sizeof(addr.sun_path), ANDROID_SOCKET_DIR"/%s",
name);
- ret = unlink(addr.sun_path);
- if (ret != 0 && errno != ENOENT) {
+ if ((unlink(addr.sun_path) != 0) && (errno != ENOENT)) {
PLOG(ERROR) << "Failed to unlink old socket '" << name << "'";
- goto out_close;
+ return -1;
}
- filecon = NULL;
+ char *filecon = NULL;
if (sehandle) {
- ret = selabel_lookup(sehandle, &filecon, addr.sun_path, S_IFSOCK);
- if (ret == 0)
+ if (selabel_lookup(sehandle, &filecon, addr.sun_path, S_IFSOCK) == 0) {
setfscreatecon(filecon);
+ }
}
- ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
- savederrno = errno;
+ int ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
+ int savederrno = errno;
setfscreatecon(NULL);
freecon(filecon);
if (ret) {
- errno = savederrno;
+ errno = savederrno;
PLOG(ERROR) << "Failed to bind socket '" << name << "'";
goto out_unlink;
}
- ret = lchown(addr.sun_path, uid, gid);
- if (ret) {
+ if (lchown(addr.sun_path, uid, gid)) {
PLOG(ERROR) << "Failed to lchown socket '" << addr.sun_path << "'";
goto out_unlink;
}
- ret = fchmodat(AT_FDCWD, addr.sun_path, perm, AT_SYMLINK_NOFOLLOW);
- if (ret) {
+ if (fchmodat(AT_FDCWD, addr.sun_path, perm, AT_SYMLINK_NOFOLLOW)) {
PLOG(ERROR) << "Failed to fchmodat socket '" << addr.sun_path << "'";
goto out_unlink;
}
@@ -155,12 +149,10 @@
<< ", user " << uid
<< ", group " << gid;
- return fd;
+ return fd.release();
out_unlink:
unlink(addr.sun_path);
-out_close:
- close(fd);
return -1;
}
@@ -173,7 +165,6 @@
gid_t gid, const char *filecon)
{
char *secontext = NULL;
- int ret;
if (filecon) {
if (setsockcreatecon(filecon) == -1) {
@@ -181,18 +172,17 @@
return -1;
}
} else if (sehandle) {
- ret = selabel_lookup(sehandle, &secontext, path, perm);
- if (ret != -1) {
- ret = setfscreatecon(secontext);
- if (ret == -1) {
- freecon(secontext);
+ if (selabel_lookup(sehandle, &secontext, path, perm) != -1) {
+ if (setfscreatecon(secontext) == -1) {
+ freecon(secontext); // does not upset errno value
PLOG(ERROR) << "setfscreatecon(\"" << secontext << "\") failed";
return -1;
}
}
}
- int fd = TEMP_FAILURE_RETRY(open(path, flags | O_NDELAY, perm));
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, flags | O_NDELAY, perm)));
+ int savederrno = errno;
if (filecon) {
setsockcreatecon(NULL);
@@ -202,23 +192,22 @@
freecon(secontext);
}
- if (fd == -1) {
+ if (fd < 0) {
+ errno = savederrno;
PLOG(ERROR) << "Failed to open/create file '" << path << "'";
- goto out_close;
+ return -1;
}
if (!(flags & O_NDELAY)) fcntl(fd, F_SETFD, flags);
- ret = lchown(path, uid, gid);
- if (ret) {
+ if (lchown(path, uid, gid)) {
PLOG(ERROR) << "Failed to lchown file '" << path << "'";
- goto out_close;
+ return -1;
}
if (perm != static_cast<mode_t>(-1)) {
- ret = fchmodat(AT_FDCWD, path, perm, AT_SYMLINK_NOFOLLOW);
- if (ret) {
+ if (fchmodat(AT_FDCWD, path, perm, AT_SYMLINK_NOFOLLOW)) {
PLOG(ERROR) << "Failed to fchmodat file '" << path << "'";
- goto out_close;
+ return -1;
}
}
@@ -227,11 +216,7 @@
<< ", user " << uid
<< ", group " << gid;
- return fd;
-
-out_close:
- if (fd >= 0) close(fd);
- return -1;
+ return fd.release();
}
bool read_file(const char* path, std::string* content) {
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index c481e36..157bd88 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -189,7 +189,7 @@
__android_log_unlock();
#if defined(__BIONIC__)
- android_closeEventTagMap(m);
+ if (m != (EventTagMap *)(uintptr_t)-1LL) android_closeEventTagMap(m);
#endif
}
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 4c49791..4e766bb 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -566,7 +566,7 @@
on nonencrypted
# A/B update verifier that marks a successful boot.
- exec - root -- /system/bin/update_verifier nonencrypted
+ exec - root cache -- /system/bin/update_verifier nonencrypted
class_start main
class_start late_start
@@ -589,12 +589,12 @@
on property:vold.decrypt=trigger_restart_min_framework
# A/B update verifier that marks a successful boot.
- exec - root -- /system/bin/update_verifier trigger_restart_min_framework
+ exec - root cache -- /system/bin/update_verifier trigger_restart_min_framework
class_start main
on property:vold.decrypt=trigger_restart_framework
# A/B update verifier that marks a successful boot.
- exec - root -- /system/bin/update_verifier trigger_restart_framework
+ exec - root cache -- /system/bin/update_verifier trigger_restart_framework
class_start main
class_start late_start