Port DeviceD poweroff signal handler 53/212453/3
authorMichal Bloch <m.bloch@partner.samsung.com>
Wed, 21 Aug 2019 15:00:16 +0000 (17:00 +0200)
committerMichal Bloch <m.bloch@partner.samsung.com>
Thu, 12 Sep 2019 18:19:00 +0000 (18:19 +0000)
Change-Id: Ie57f88a42b0433df0989a91b42ef656b36ad2ef0

src/proc-stat/proc-monitor.c

index c8fe2b1..fa1e4cc 100644 (file)
@@ -56,6 +56,7 @@
 #define INIT_PID       1
 #define INIT_PROC_VAL  -1
 #define HZ     100
+#define POWER_OFF_DIRECT  2
 
 static int current_lcd_state;
 
@@ -164,14 +165,18 @@ static void turn_off_vip()
        _I("disabled VIP by unmounting VIP cgroup");
 }
 
-static void dbus_pre_poweroff(GDBusMethodInvocation *invocation, GVariant *params)
+static void proc_poweroff()
 {
        _D("pre power off: unmounting cgroup fs");
 
        proc_sweep_memory(PROC_SWEEP_EXCLUDE_ACTIVE, INIT_PID);
        resourced_notify(RESOURCED_NOTIFIER_POWER_OFF, NULL);
        turn_off_vip();
+}
 
+static void dbus_pre_poweroff(GDBusMethodInvocation *invocation, GVariant *params)
+{
+       proc_poweroff();
        g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", -1));
 }
 
@@ -762,6 +767,23 @@ static void low_battery_signal_handler(GVariant *params)
        resourced_notify(RESOURCED_NOTIFIER_LOW_BATTERY, NULL);
 }
 
+static void poweroff_signal_handler(GVariant *params)
+{
+       int response;
+
+       do_expr_unless_g_variant_get_typechecked(return, params, "(i)", &response);
+
+       /* This code does not check for values which could be too high.
+        * This is for legacy reasons (we inherited the code without such
+        * checks so potentially somebody might be using it that way). */
+       if (response < POWER_OFF_DIRECT) {
+               _D("Invalid power off status: %d", response);
+               return;
+       }
+
+       proc_poweroff();
+}
+
 static void systemtime_changed_signal_handler(GVariant *params)
 {
        resourced_notify(RESOURCED_NOTIFIER_SYSTEMTIME_CHANGED, NULL);
@@ -1046,6 +1068,8 @@ static const struct d_bus_signal dbus_signals[] = {
           on purpose - DeviceD sends the signal earlier than supposed to. Nothing
           is lost though because at some point DeviceD also sends a SIGTERM,
           which is handled the same way (i.e. quits the main loop). */
+       {DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF,
+           SIGNAL_DEVICED_POWEROFF_STATE, poweroff_signal_handler, NULL},
        {DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY,
            SIGNAL_DEVICED_LOW_BATTERY, low_battery_signal_handler, NULL},
        {DUMP_SERVICE_OBJECT_PATH, DUMP_SERVICE_INTERFACE_NAME,