Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…_core into bs6-mako
  • Loading branch information
spezi77 committed May 8, 2016
2 parents 85f7316 + 806e7c4 commit 2548e3c
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 97 deletions.
12 changes: 6 additions & 6 deletions fs_mgr/fs_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ static void check_fs(char *blk_device, char *fs_type, char *target)
}
}
} else if (!strcmp(fs_type, "f2fs")) {
char *f2fs_fsck_argv[] = {
F2FS_FSCK_BIN,
"-a",
blk_device
};
INFO("Running %s on %s\n", F2FS_FSCK_BIN, blk_device);
char *f2fs_fsck_argv[] = {
F2FS_FSCK_BIN,
"-a",
blk_device
};
INFO("Running %s -a %s\n", F2FS_FSCK_BIN, blk_device);

ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv,
&status, true, LOG_KLOG | LOG_FILE,
Expand Down
5 changes: 5 additions & 0 deletions include/cutils/android_reboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef __CUTILS_ANDROID_REBOOT_H__
#define __CUTILS_ANDROID_REBOOT_H__

#include <mntent.h>

__BEGIN_DECLS

/* Commands */
Expand All @@ -28,6 +30,9 @@ __BEGIN_DECLS
#define ANDROID_RB_PROPERTY "sys.powerctl"

int android_reboot(int cmd, int flags, const char *arg);
int android_reboot_with_callback(
int cmd, int flags, const char *arg,
void (*cb_on_remount)(const struct mntent*));

__END_DECLS

Expand Down
71 changes: 70 additions & 1 deletion init/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include <errno.h>
#include <fcntl.h>
#include <mntent.h>
#include <net/if.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -38,6 +40,7 @@
#include <base/stringprintf.h>
#include <cutils/partition_utils.h>
#include <cutils/android_reboot.h>
#include <logwrap/logwrap.h>
#include <private/android_filesystem_config.h>

#include "init.h"
Expand All @@ -49,6 +52,8 @@
#include "log.h"

#define chmod DO_NOT_USE_CHMOD_USE_FCHMODAT_SYMLINK_NOFOLLOW
#define UNMOUNT_CHECK_MS 5000
#define UNMOUNT_CHECK_TIMES 10

int add_environment(const char *name, const char *value);

Expand Down Expand Up @@ -109,6 +114,67 @@ static void service_start_if_not_disabled(struct service *svc)
}
}

static void unmount_and_fsck(const struct mntent *entry)
{
if (strcmp(entry->mnt_type, "f2fs") && strcmp(entry->mnt_type, "ext4"))
return;

/* First, lazily unmount the directory. This unmount request finishes when
* all processes that open a file or directory in |entry->mnt_dir| exit.
*/
TEMP_FAILURE_RETRY(umount2(entry->mnt_dir, MNT_DETACH));

/* Next, kill all processes except init, kthreadd, and kthreadd's
* children to finish the lazy unmount. Killing all processes here is okay
* because this callback function is only called right before reboot().
* It might be cleaner to selectively kill processes that actually use
* |entry->mnt_dir| rather than killing all, probably by reusing a function
* like killProcessesWithOpenFiles() in vold/, but the selinux policy does
* not allow init to scan /proc/<pid> files which the utility function
* heavily relies on. The policy does not allow the process to execute
* killall/pkill binaries either. Note that some processes might
* automatically restart after kill(), but that is not really a problem
* because |entry->mnt_dir| is no longer visible to such new processes.
*/
service_for_each(service_stop);
TEMP_FAILURE_RETRY(kill(-1, SIGKILL));

int count = 0;
while (count++ < UNMOUNT_CHECK_TIMES) {
int fd = TEMP_FAILURE_RETRY(open(entry->mnt_fsname, O_RDONLY | O_EXCL));
if (fd >= 0) {
/* |entry->mnt_dir| has sucessfully been unmounted. */
close(fd);
break;
} else if (errno == EBUSY) {
/* Some processes using |entry->mnt_dir| are still alive. Wait for a
* while then retry.
*/
TEMP_FAILURE_RETRY(
usleep(UNMOUNT_CHECK_MS * 1000 / UNMOUNT_CHECK_TIMES));
continue;
} else {
/* Cannot open the device. Give up. */
return;
}
}

int st;
if (!strcmp(entry->mnt_type, "f2fs")) {
const char *f2fs_argv[] = {
"/system/bin/fsck.f2fs", "-f", entry->mnt_fsname,
};
android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv,
&st, true, LOG_KLOG, true, NULL);
} else if (!strcmp(entry->mnt_type, "ext4")) {
const char *ext4_argv[] = {
"/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname,
};
android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv,
&st, true, LOG_KLOG, true, NULL);
}
}

int do_class_start(int nargs, char **args)
{
char prop[PROP_NAME_MAX];
Expand Down Expand Up @@ -577,6 +643,7 @@ int do_powerctl(int nargs, char **args)
int len = 0;
int cmd = 0;
const char *reboot_target;
void (*callback_on_ro_remount)(const struct mntent*) = NULL;

res = expand_props(command, args[1], sizeof(command));
if (res) {
Expand All @@ -590,6 +657,7 @@ int do_powerctl(int nargs, char **args)
}
cmd = ANDROID_RB_POWEROFF;
len = 8;
callback_on_ro_remount = unmount_and_fsck;
} else if (strncmp(command, "reboot", 6) == 0) {
cmd = ANDROID_RB_RESTART2;
len = 6;
Expand All @@ -614,7 +682,8 @@ int do_powerctl(int nargs, char **args)
return -EINVAL;
}

return android_reboot(cmd, 0, reboot_target);
return android_reboot_with_callback(cmd, 0, reboot_target,
callback_on_ro_remount);
}

int do_trigger(int nargs, char **args)
Expand Down
16 changes: 0 additions & 16 deletions libbacktrace/Backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,8 @@ Backtrace::~Backtrace() {
}
}

extern "C" char* __cxa_demangle(const char* mangled, char* buf, size_t* len,
int* status);

std::string Backtrace::GetFunctionName(uintptr_t pc, uintptr_t* offset) {
std::string func_name = GetFunctionNameRaw(pc, offset);
if (!func_name.empty()) {
#if defined(__APPLE__)
// Mac OS' __cxa_demangle demangles "f" as "float"; last tested on 10.7.
if (func_name[0] != '_') {
return func_name;
}
#endif
char* name = __cxa_demangle(func_name.c_str(), 0, 0, 0);
if (name) {
func_name = name;
free(name);
}
}
return func_name;
}

Expand Down
Loading

0 comments on commit 2548e3c

Please sign in to comment.