From 1dd0f11bdcced508edb495e7220da5e27ebdd6fc Mon Sep 17 00:00:00 2001 From: Byungsoo Kim Date: Fri, 22 Feb 2013 20:00:19 +0900 Subject: [PATCH] umount all ext4 partitions with rw permission for preventing to access filesystem during power off previously we used to write /proc/sysrq-trigger in order to remount all rw partition with only ro permission. But emergency remount was not general approach. So we sent sigterm signal to all processes using each rw partition and unmount it. Change-Id: Ie520aeeaa8391889749a908ae3b18fc2fbb54677 Signed-off-by: Byungsoo Kim --- ss_predefine.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/ss_predefine.c b/ss_predefine.c index 38ee8de..89a67f4 100644 --- a/ss_predefine.c +++ b/ss_predefine.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include "ss_log.h" #include "ss_launch.h" @@ -188,14 +190,33 @@ static void make_memps_log(char *file, pid_t pid, char *victim_name) static void remount_ro() { - FILE *f; - f = fopen("/proc/sysrq-trigger", "w"); - if (!f) { + struct mntent* mnt; + const char* table = "/etc/mtab"; + const char mmtpoint[10][64]; + FILE* fp; + int r = -1, foundmount=0; + char buf[256]; + fp = setmntent(table, "r"); + + if (!fp) return; + + while (mnt=getmntent(fp)) { + if (foundmount >= 10) + continue; + if (!strcmp(mnt->mnt_type, "ext4") && strstr(mnt->mnt_opts, "rw")) { + memset(mmtpoint[foundmount], 0, 64); + strncpy(mmtpoint[foundmount], mnt->mnt_dir, 63); + foundmount++; + } + } + endmntent(fp); + while (foundmount) { + foundmount--; + snprintf(buf, sizeof(buf), "fuser -c %s -k -15", mmtpoint[foundmount]); + sleep(1); + umount2(mmtpoint[foundmount], MNT_DETACH); } - if (fwrite("u", 1, 1, f) != 1) - return; - fclose(f); } static int lowmem_get_victim_pid() @@ -458,7 +479,6 @@ Eina_Bool powerdown_ap_by_force(void *data) PRT_TRACE("Power off by force\n"); /* give a chance to be terminated for each process */ power_off = 1; - sleep(1); sync(); remount_ro(); reboot(RB_POWER_OFF); @@ -498,7 +518,6 @@ static void powerdown_ap(TapiHandle *handle, const char *noti_id, void *data, vo /* give a chance to be terminated for each process */ power_off = 1; - sleep(1); sync(); remount_ro(); reboot(RB_POWER_OFF); -- 2.7.4