From 08716711448426cd2858da03e4af217aa1bda344 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Dec 2018 10:42:47 +0900 Subject: [PATCH 01/16] Remove executable flag from non-executable files Change-Id: I6b848799d6a5f568350becac14c3d85c10b6b3e9 Signed-off-by: lokilee73 --- CMakeLists.txt | 0 packaging/deviced.spec | 0 plugins/iot/display/ambient-mode.c | 0 plugins/iot/display/core.c | 0 plugins/iot/display/device-interface.c | 0 plugins/iot/display/display-dbus.c | 0 plugins/iot/display/input.c | 0 plugins/iot/display/setting.c | 0 plugins/mobile/display/ambient-mode.c | 0 plugins/mobile/display/core.c | 0 plugins/mobile/display/device-interface.c | 0 plugins/mobile/display/display-dbus.c | 0 plugins/mobile/display/input.c | 0 plugins/mobile/display/setting.c | 0 plugins/tv/display/ambient-mode.c | 0 plugins/tv/display/core.c | 0 plugins/tv/display/device-interface.c | 0 plugins/tv/display/display-dbus.c | 0 plugins/tv/display/input.c | 0 plugins/tv/display/setting.c | 0 plugins/wearable/display/ambient-mode.c | 0 plugins/wearable/display/core.c | 0 plugins/wearable/display/device-interface.c | 0 plugins/wearable/display/display-dbus.c | 0 plugins/wearable/display/input.c | 0 plugins/wearable/display/setting.c | 0 src/apps/apps.c | 0 src/apps/apps.h | 0 src/auto-test/battery.c | 0 src/auto-test/display.c | 0 src/auto-test/proc.c | 0 src/battery/lowbat-handler.c | 0 src/battery/power-supply.c | 0 src/battery/power-supply.h | 0 src/core/common.c | 0 src/core/device-notifier.c | 0 src/core/launch.c | 0 src/core/main.c | 0 src/core/udev.h | 0 src/deviced/dd-deviced.h | 0 src/display/device-interface.h | 0 src/extcon/earjack.c | 0 src/extcon/extcon.h | 0 src/extcon/extcon_count.c | 0 src/extcon/extcon_count.h | 0 src/extcon/hdmi.c | 0 src/led/rgb.c | 0 src/libdeviced/CMakeLists.txt | 0 src/libdeviced/deviced-noti.c | 0 src/libdeviced/display.c | 0 src/power/power-handler.c | 0 src/power/power-handler.h | 0 src/shared/deviced-priv.h | 0 src/shared/plugin.h | 0 src/thermal/thermal.c | 0 src/time/time-handler.c | 0 src/tzip/tzip-utility.c | 0 src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c | 0 src/usb-host-test/usb-host-test.c | 0 src/usb/usb-dbus.c | 0 src/usb/usb-debug.c | 0 src/usb/usb-state.c | 0 src/usb/usb-tethering.c | 0 src/usb/usb.c | 0 src/usb/usb.h | 0 src/usbhost/usb-host.c | 0 66 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 CMakeLists.txt mode change 100755 => 100644 packaging/deviced.spec mode change 100755 => 100644 plugins/iot/display/ambient-mode.c mode change 100755 => 100644 plugins/iot/display/core.c mode change 100755 => 100644 plugins/iot/display/device-interface.c mode change 100755 => 100644 plugins/iot/display/display-dbus.c mode change 100755 => 100644 plugins/iot/display/input.c mode change 100755 => 100644 plugins/iot/display/setting.c mode change 100755 => 100644 plugins/mobile/display/ambient-mode.c mode change 100755 => 100644 plugins/mobile/display/core.c mode change 100755 => 100644 plugins/mobile/display/device-interface.c mode change 100755 => 100644 plugins/mobile/display/display-dbus.c mode change 100755 => 100644 plugins/mobile/display/input.c mode change 100755 => 100644 plugins/mobile/display/setting.c mode change 100755 => 100644 plugins/tv/display/ambient-mode.c mode change 100755 => 100644 plugins/tv/display/core.c mode change 100755 => 100644 plugins/tv/display/device-interface.c mode change 100755 => 100644 plugins/tv/display/display-dbus.c mode change 100755 => 100644 plugins/tv/display/input.c mode change 100755 => 100644 plugins/tv/display/setting.c mode change 100755 => 100644 plugins/wearable/display/ambient-mode.c mode change 100755 => 100644 plugins/wearable/display/core.c mode change 100755 => 100644 plugins/wearable/display/device-interface.c mode change 100755 => 100644 plugins/wearable/display/display-dbus.c mode change 100755 => 100644 plugins/wearable/display/input.c mode change 100755 => 100644 plugins/wearable/display/setting.c mode change 100755 => 100644 src/apps/apps.c mode change 100755 => 100644 src/apps/apps.h mode change 100755 => 100644 src/auto-test/battery.c mode change 100755 => 100644 src/auto-test/display.c mode change 100755 => 100644 src/auto-test/proc.c mode change 100755 => 100644 src/battery/lowbat-handler.c mode change 100755 => 100644 src/battery/power-supply.c mode change 100755 => 100644 src/battery/power-supply.h mode change 100755 => 100644 src/core/common.c mode change 100755 => 100644 src/core/device-notifier.c mode change 100755 => 100644 src/core/launch.c mode change 100755 => 100644 src/core/main.c mode change 100755 => 100644 src/core/udev.h mode change 100755 => 100644 src/deviced/dd-deviced.h mode change 100755 => 100644 src/display/device-interface.h mode change 100755 => 100644 src/extcon/earjack.c mode change 100755 => 100644 src/extcon/extcon.h mode change 100755 => 100644 src/extcon/extcon_count.c mode change 100755 => 100644 src/extcon/extcon_count.h mode change 100755 => 100644 src/extcon/hdmi.c mode change 100755 => 100644 src/led/rgb.c mode change 100755 => 100644 src/libdeviced/CMakeLists.txt mode change 100755 => 100644 src/libdeviced/deviced-noti.c mode change 100755 => 100644 src/libdeviced/display.c mode change 100755 => 100644 src/power/power-handler.c mode change 100755 => 100644 src/power/power-handler.h mode change 100755 => 100644 src/shared/deviced-priv.h mode change 100755 => 100644 src/shared/plugin.h mode change 100755 => 100644 src/thermal/thermal.c mode change 100755 => 100644 src/time/time-handler.c mode change 100755 => 100644 src/tzip/tzip-utility.c mode change 100755 => 100644 src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c mode change 100755 => 100644 src/usb-host-test/usb-host-test.c mode change 100755 => 100644 src/usb/usb-dbus.c mode change 100755 => 100644 src/usb/usb-debug.c mode change 100755 => 100644 src/usb/usb-state.c mode change 100755 => 100644 src/usb/usb-tethering.c mode change 100755 => 100644 src/usb/usb.c mode change 100755 => 100644 src/usb/usb.h mode change 100755 => 100644 src/usbhost/usb-host.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/packaging/deviced.spec b/packaging/deviced.spec old mode 100755 new mode 100644 diff --git a/plugins/iot/display/ambient-mode.c b/plugins/iot/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/input.c b/plugins/iot/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/setting.c b/plugins/iot/display/setting.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/ambient-mode.c b/plugins/mobile/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/input.c b/plugins/mobile/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/setting.c b/plugins/mobile/display/setting.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/ambient-mode.c b/plugins/tv/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/input.c b/plugins/tv/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/setting.c b/plugins/tv/display/setting.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/ambient-mode.c b/plugins/wearable/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/input.c b/plugins/wearable/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/setting.c b/plugins/wearable/display/setting.c old mode 100755 new mode 100644 diff --git a/src/apps/apps.c b/src/apps/apps.c old mode 100755 new mode 100644 diff --git a/src/apps/apps.h b/src/apps/apps.h old mode 100755 new mode 100644 diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c old mode 100755 new mode 100644 diff --git a/src/auto-test/display.c b/src/auto-test/display.c old mode 100755 new mode 100644 diff --git a/src/auto-test/proc.c b/src/auto-test/proc.c old mode 100755 new mode 100644 diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c old mode 100755 new mode 100644 diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c old mode 100755 new mode 100644 diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h old mode 100755 new mode 100644 diff --git a/src/core/common.c b/src/core/common.c old mode 100755 new mode 100644 diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c old mode 100755 new mode 100644 diff --git a/src/core/launch.c b/src/core/launch.c old mode 100755 new mode 100644 diff --git a/src/core/main.c b/src/core/main.c old mode 100755 new mode 100644 diff --git a/src/core/udev.h b/src/core/udev.h old mode 100755 new mode 100644 diff --git a/src/deviced/dd-deviced.h b/src/deviced/dd-deviced.h old mode 100755 new mode 100644 diff --git a/src/display/device-interface.h b/src/display/device-interface.h old mode 100755 new mode 100644 diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c old mode 100755 new mode 100644 diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h old mode 100755 new mode 100644 diff --git a/src/extcon/extcon_count.c b/src/extcon/extcon_count.c old mode 100755 new mode 100644 diff --git a/src/extcon/extcon_count.h b/src/extcon/extcon_count.h old mode 100755 new mode 100644 diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c old mode 100755 new mode 100644 diff --git a/src/led/rgb.c b/src/led/rgb.c old mode 100755 new mode 100644 diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c old mode 100755 new mode 100644 diff --git a/src/libdeviced/display.c b/src/libdeviced/display.c old mode 100755 new mode 100644 diff --git a/src/power/power-handler.c b/src/power/power-handler.c old mode 100755 new mode 100644 diff --git a/src/power/power-handler.h b/src/power/power-handler.h old mode 100755 new mode 100644 diff --git a/src/shared/deviced-priv.h b/src/shared/deviced-priv.h old mode 100755 new mode 100644 diff --git a/src/shared/plugin.h b/src/shared/plugin.h old mode 100755 new mode 100644 diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c old mode 100755 new mode 100644 diff --git a/src/time/time-handler.c b/src/time/time-handler.c old mode 100755 new mode 100644 diff --git a/src/tzip/tzip-utility.c b/src/tzip/tzip-utility.c old mode 100755 new mode 100644 diff --git a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c b/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c old mode 100755 new mode 100644 diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-debug.c b/src/usb/usb-debug.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-tethering.c b/src/usb/usb-tethering.c old mode 100755 new mode 100644 diff --git a/src/usb/usb.c b/src/usb/usb.c old mode 100755 new mode 100644 diff --git a/src/usb/usb.h b/src/usb/usb.h old mode 100755 new mode 100644 diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c old mode 100755 new mode 100644 -- 2.7.4 From a00b3923d873a8a1a94f1b519aa211d8161c8fbe Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 3 Jan 2019 19:23:51 +0900 Subject: [PATCH 02/16] sensitivity: merge sensitivity Change-Id: I3a6e0336d699f9a006cbe47fa920603e33d2d956 Signed-off-by: sanghyeok.oh --- CMakeLists.txt | 4 + packaging/deviced.spec | 1 + src/touchscreen/sensitivity.c | 220 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 src/touchscreen/sensitivity.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d55168c..bd1b986 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,10 @@ IF(TOUCHSCREEN_MODULE STREQUAL on) SET(SRCS ${SRCS} ${TOUCHSCREEN_SRCS}) ENDIF() +IF(TOUCH_SENSITIVITY_MODULE STREQUAL on) + SET(SRCS ${SRCS} src/touchscreen/sensitivity.c) +ENDIF() + IF(TZIP_MODULE STREQUAL on) ADD_SOURCE(src/tzip TZIP_SRCS) SET(SRCS ${SRCS} ${TZIP_SRCS}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b92bd02..d2d988b 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -155,6 +155,7 @@ Plugin libraries for IoT devices -DTIZEN_FEATURE_CPU_MODULE=on \ -DTIZEN_FEATURE_USBHOST_TEST=on \ -DTIZEN_FEATURE_BATTERY_OVER_TEMPERATURE=on \ + -DTOUCH_SENSITIVITY_MODULE=on \ #eol %build diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c new file mode 100644 index 0000000..8f1bd25 --- /dev/null +++ b/src/touchscreen/sensitivity.c @@ -0,0 +1,220 @@ +/* + * deviced + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "core/devices.h" +#include "core/common.h" +#include "core/log.h" +#include "core/device-notifier.h" + + +#ifndef VCONFKEY_SETAPPL_TOUCH_SENSITIVITY +#define VCONFKEY_SETAPPL_TOUCH_SENSITIVITY "db/setting/enhance_touch_sensitivity" +#endif + +#define DISABLE_SENSITIVITY_SIGNAL "DisableSensitivity" + +#define TOUCH_SENSITIVITY_DISABLE_INTERVAL 1 + +#ifndef TOUCHSENSITIVITY_GLOVE_MODE_OFF +#define TOUCHSENSITIVITY_GLOVE_MODE_OFF 0 +#endif +#ifndef TOUCHSENSITIVITY_GLOVE_MODE_ON +#define TOUCHSENSITIVITY_GLOVE_MODE_ON 1 +#endif + +static guint disable_timer; + +static struct touchsensitivity_device *touchsensitivity_dev; + +static int check_dev(void) +{ + if (!touchsensitivity_dev || + !touchsensitivity_dev->glove_mode_set_state || + !touchsensitivity_dev->glove_mode_get_state) + return -ENODEV; + return 0; +} + +static gboolean disable_sensitivity(void *data) +{ + int ret; + int status; + + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + return G_SOURCE_REMOVE; + } + + if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SENSITIVITY, &status) != 0 || + status == TOUCHSENSITIVITY_GLOVE_MODE_ON) + return G_SOURCE_REMOVE; + + ret = touchsensitivity_dev->glove_mode_set_state(TOUCHSENSITIVITY_GLOVE_MODE_OFF); + _I("%s change auto touch sensitivity disable", ret ? "fail" : "set"); + return G_SOURCE_REMOVE; +} + +static void disable_touch_sensitivity_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + disable_timer = g_timeout_add_seconds(TOUCH_SENSITIVITY_DISABLE_INTERVAL, disable_sensitivity, NULL); + if (disable_timer == 0) + _E("fail to add battery init timer during booting"); +} + +static GVariant *get_touch_sensitivity(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int val = -1, ret; + + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + goto out; + } + ret = touchsensitivity_dev->glove_mode_get_state(&val); + _I("%s touch sensitivity %d", ret ? "fail" : "get", val); +out: + return g_variant_new("(i)", val); +} + +static GVariant *set_touch_sensitivity(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int val = -1, ret = -ESRCH; + + g_variant_get(param, "(i)", &val); + + if (disable_timer) { + g_source_remove(disable_timer); + disable_timer = 0; + } + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + ret = -EINVAL; + goto error; + } + ret = touchsensitivity_dev->glove_mode_set_state(val); + +error: + _I("%s touch sensitivity %d", ret ? "fail" : "set", val); + + return g_variant_new("(i)", ret); +} + +static const dbus_method_s dbus_methods[] = { + { "GetSensitivity", NULL, "i", get_touch_sensitivity }, + { "SetSensitivity", "i", "i", set_touch_sensitivity }, + /* Add methods here */ +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_TOUCH, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; + +static int booting_done(void *data) +{ + static int done; + int ret; + int status = TOUCHSENSITIVITY_GLOVE_MODE_OFF; + + if (data == NULL) + goto out; + + done = *(int *)data; + + if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SENSITIVITY, &status) != 0 || + status == TOUCHSENSITIVITY_GLOVE_MODE_OFF) + goto out; + + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + goto out; + } + ret = touchsensitivity_dev->glove_mode_set_state(TOUCHSENSITIVITY_GLOVE_MODE_ON); + _I("%s change auto touch sensitivity enable", ret ? "fail" : "set"); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); +out: + return done; +} + +static void sensitivity_init(void *data) +{ + int ret; + struct hw_info *info; + + if (touchsensitivity_dev) + return; + + ret = hw_get_info(TOUCHSENSITIVITY_HARDWARE_DEVICE_ID, + (const struct hw_info **)&info); + if (ret < 0) { + _E("Fail to load touch sensitivity shared library (%d)", ret); + return; + } + + if (!info->open) { + _E("fail to open touch sensitivity device : open(NULL)"); + return; + } + + ret = info->open(info, NULL, (struct hw_common **)&touchsensitivity_dev); + if (ret < 0) { + _E("fail to get touch sensitivity device structure : (%d)", ret); + return; + } + + _I("touch sensitivity device structure load success"); + + /* init dbus interface */ + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_TOUCH, &dbus_interface); + if (ret < 0) + _E("fail to init dbus method(%d)", ret); + + subscribe_dbus_signal(NULL, + DEVICED_PATH_TOUCH, + DEVICED_INTERFACE_TOUCH, + DISABLE_SENSITIVITY_SIGNAL, + disable_touch_sensitivity_handler, + NULL, NULL); + + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); +} + +static const struct device_ops sensitivity_device_ops = { + .name = "sensitivity", + .init = sensitivity_init, +}; + +DEVICE_OPS_REGISTER(&sensitivity_device_ops) + -- 2.7.4 From 38227a89678df5c8b7ed376c69d6f7739b38b6b8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 9 Jan 2019 11:22:49 +0900 Subject: [PATCH 03/16] dbus: modify to use send with reply change dbus function to fix errors in media and battery Change-Id: I4d91ad3419dab43c74d72fd58d767c5fdbe91d21 Signed-off-by: lokilee73 --- src/apps/apps.c | 10 ++++++---- src/battery/power-supply.c | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/apps/apps.c b/src/apps/apps.c index 53bb751..cd4a654 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -107,11 +107,12 @@ int launch_message_post(char *type) if (!type) return -EINVAL; - ret = dbus_handle_method_async_var(POPUP_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME, POPUP_PATH_NOTI, POPUP_INTERFACE_NOTI, "MessagePostOn", - g_variant_new("(s)", type)); + g_variant_new("(s)", type), + __cb, -1, NULL); if (disp_plgn.pm_change_internal) disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); @@ -160,8 +161,9 @@ int remove_notification(char *type, int id) if (!type || id < 0) return -EINVAL; - return dbus_handle_method_async_var(POPUP_BUS_NAME, + return dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME, POPUP_PATH_NOTI, POPUP_INTERFACE_NOTI, - type, g_variant_new("(i)", id)); + type, g_variant_new("(i)", id), + __cb, -1, NULL); } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f3d0c5b..9b4bb7a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -193,6 +193,21 @@ out: g_variant_unref(var); } +static void noti_off_cb(GVariant *var, void *user_data, GError *err) +{ + int ret= 0; + + if (!dh_get_param_from_var(var, "(i)", &ret)) { + _E("no message [%s]", g_variant_get_type_string(var)); + goto out; + } + + _D("Noti Off : %d", ret); + +out: + g_variant_unref(var); +} + static int check_power_supply_noti(void) { #ifdef MICRO_DD @@ -239,11 +254,12 @@ static int send_full_noti(enum charge_full_type state) if (noti_id <= 0) return -EPERM; for (retry = RETRY_MAX; retry > 0; retry--) { - ret = dbus_handle_method_async_var(POPUP_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME, POPUP_PATH_NOTI, POPUP_INTERFACE_NOTI, METHOD_FULL_NOTI_OFF, - g_variant_new("(i)", noti_id)); + g_variant_new("(i)", noti_id), + noti_off_cb, -1, NULL); if (ret == 0) { _D("Deleted battery full noti"); noti_id = 0; -- 2.7.4 From edbfbd744fb6ec32804ad550935b9196c806cee6 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 10 Jan 2019 21:08:51 +0900 Subject: [PATCH 04/16] Apply conf file and change thermal structure Firstly, thermal value depends on hardware. So, we have to apply different temp table for each targets. Secondly, change the name on temp table as products. ex) Critical -> Limt Danger -> Shutdown Lastly, change condition in thermal_get_temp_enum Change-Id: If25be071e000dfaa1d5e68d205538cd2332d1d9b Signed-off-by: lokilee73 --- CMakeLists.txt | 5 ++ conf/temperature.conf | 6 ++ conf/wearable-temperature.conf | 6 ++ packaging/deviced.spec | 5 ++ src/thermal/thermal.c | 143 +++++++++++++++++++++++++++-------------- src/thermal/thermal.h | 49 ++++++++++++++ 6 files changed, 165 insertions(+), 49 deletions(-) create mode 100644 conf/temperature.conf create mode 100644 conf/wearable-temperature.conf create mode 100644 src/thermal/thermal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bd1b986..013b1f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,11 @@ IF(POWER_MODULE STREQUAL on) INSTALL_CONF(conf power) ENDIF() +IF(THERMAL_MODULE STREQUAL on) + INSTALL_CONF(conf temperature) + INSTALL_CONF(conf wearable-temperature) +ENDIF() + # USB connection IF(USB_MODULE STREQUAL on) # USB (Manual setting) diff --git a/conf/temperature.conf b/conf/temperature.conf new file mode 100644 index 0000000..db8a158 --- /dev/null +++ b/conf/temperature.conf @@ -0,0 +1,6 @@ +[THERMAL] +#Level is Celsius +Normal=70 +Warning=75 +Limit=80 +Shutdown=85 diff --git a/conf/wearable-temperature.conf b/conf/wearable-temperature.conf new file mode 100644 index 0000000..ceb68b2 --- /dev/null +++ b/conf/wearable-temperature.conf @@ -0,0 +1,6 @@ +[THERMAL] +#Level is Celsius +Normal=44 +Warning=46 +Limit=48 +Shutdown=53 diff --git a/packaging/deviced.spec b/packaging/deviced.spec index d2d988b..2606afa 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -207,6 +207,7 @@ cat %{_sysconfdir}/deviced/wearable-display.conf >> %{_sysconfdir}/deviced/displ rm -rf %{_sysconfdir}/deviced/wearable-display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so +mv %{_sysconfdir}/deviced/wearable-temperature.conf %{_sysconfdir}/deviced/temperature.conf %post plugin-profile-tv mkdir -p %{_libdir}/deviced @@ -272,6 +273,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/mobile-display.conf +%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/mobile-display.so %files plugin-profile-wearable @@ -279,16 +281,19 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/wearable-display.conf +%config %{_sysconfdir}/deviced/wearable-temperature.conf %{_libdir}/wearable-display.so %files plugin-profile-tv %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/tv-display.so %files plugin-profile-iot %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/iot-display.so diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 6dd8b22..794b186 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -27,35 +27,19 @@ #include "core/log.h" #include "core/device-notifier.h" #include "core/devices.h" +#include "thermal.h" +#include "core/config-parser.h" static struct thermal_device *thermal_dev; static int noti; -/* Action types */ -#define RELEASE_ACTION "ReleaseAction" -#define WARNING_ACTION "WarningAction" -#define LIMIT_ACTION "LimitAction" -#define SHUTDOWN_ACTION "ShutdownAction" +#define THERMAL_CONF_FILE "/etc/deviced/temperature.conf" -#define SIGNAL_OVERHEAT_TIME "TimeUpdate" -#define OVERHEAT_CALLBACK_TIME 1 //seconds -#define OVERHEAT_POWEROFF_TIME 30 - -#define SAMPLE_CNT 4 - -enum thermal_enum_type { - NORMAL, - WARNING, - CRITICAL, - DANGER -}; - -static int ap_temp_table[DANGER + 1] = { -/* [Lv] = {Celsius degree} */ - 44, - 46, - 48, - 53, +static struct thermal_config_info thermal_table = { + .normal = TEMPERATURE_NORMAL, + .warning = TEMPERATURE_WARNING, + .limit = TEMPERATURE_LIMIT, + .shutdown = TEMPERATURE_SHUTDOWN }; static int power_off(void) @@ -206,18 +190,17 @@ static void thermal_action(int state) break; case WARNING: - thermal_remove_popup(); - thermal_add_noti(); + _I("State is WARNING"); action = strdup(WARNING_ACTION); break; - case CRITICAL: + case LIMIT: thermal_remove_popup(); thermal_add_noti(); action = strdup(LIMIT_ACTION); break; - case DANGER: + case SHUTDOWN: thermal_remove_popup(); thermal_remove_noti(); thermal_overheat_popup(); @@ -229,21 +212,46 @@ static void thermal_action(int state) free(action); } -static bool is_thermal_updated(int old_state, int new_state) +/* Action Table +-------------------------------------------------- +Current Previous Action +-------------------------------------------------- +NORMAL NORMAL X + WARNING X + LIMIT ReleaseAction + SHUTDOWN X +-------------------------------------------------- +WARNING NORMAL print log + WARNING X + LIMIT X + SHUTDOWN X +-------------------------------------------------- +LIMIT NORMAL LimitAction + WARNING LimitAction + LIMIT X + SHUTDOWN X +-------------------------------------- +SHUTDOWN NORMAL ShutdownAction + WARNING ShutdownAction + LIMIT ShutdownAction + SHUTDOWN X +-------------------------------------------------- +*/ +static bool is_action_needed(int old_state, int new_state) { bool ret = false; if (new_state == NORMAL) { - if (old_state == WARNING || old_state == CRITICAL) + if (old_state == WARNING || old_state == LIMIT) ret = true; } else if (new_state == WARNING) { - if (old_state == NORMAL || old_state == CRITICAL) + if (old_state == NORMAL) ret = true; - } else if (new_state == CRITICAL) { + } else if (new_state == LIMIT) { if (old_state == NORMAL || old_state == WARNING) ret = true; - } else if (new_state == DANGER) { - if (old_state != DANGER) + } else if (new_state == SHUTDOWN) { + if (old_state != SHUTDOWN) ret = true; } @@ -252,17 +260,18 @@ static bool is_thermal_updated(int old_state, int new_state) static int thermal_get_temp_enum(int temp) { - int i; + int ret = -1; - if (temp > ap_temp_table[DANGER]) - return DANGER; + if (temp <= thermal_table.normal) + ret = NORMAL; + else if (temp >= thermal_table.shutdown) + ret = SHUTDOWN; + else if (temp >= thermal_table.limit) + ret = LIMIT; + else if (temp >= thermal_table.warning) + ret = WARNING; - for (i = 0; i < DANGER + 1; i++) { - if (temp <= ap_temp_table[i]) - break; - } - - return i; + return ret; } static int thermal_get_average(int temp) @@ -285,18 +294,18 @@ static void thermal_handler(struct thermal_info *info, void *data) { static int old_state = NORMAL; int avg_temp, new_state; - bool updated = false; + bool action_needed = false; avg_temp = thermal_get_average(info->temp); new_state = thermal_get_temp_enum(avg_temp); - if (new_state < NORMAL || new_state > DANGER) { - _E("Invalid thermal state : %d", new_state); + if (new_state == -1) { + _I("Keep current state : %d", old_state); return; } - updated = is_thermal_updated(old_state, new_state); - _I("Last updated(%d) old_state(%d) new_state(%d)", updated, old_state, new_state); - if (updated) + action_needed = is_action_needed(old_state, new_state); + _I("Action(%d) old_state(%d) new_state(%d)", action_needed, old_state, new_state); + if (action_needed) thermal_action(new_state); old_state = new_state; @@ -350,10 +359,46 @@ static int booting_done(void *data) return done; } +static int load_config(struct parse_result *result, void *user_data) +{ + struct thermal_config_info *info = user_data; + char *name; + char *value; + + _D("%s,%s,%s", result->section, result->name, result->value); + + if (!info) + return -EINVAL; + + if (!MATCH(result->section, "THERMAL")) + return -EINVAL; + + name = result->name; + value = result->value; + if (MATCH(name, "Normal")) + info->normal = atoi(value); + else if (MATCH(name, "Warning")) + info->warning = atoi(value); + else if (MATCH(name, "Limit")) + info->limit = atoi(value); + else if (MATCH(name, "Shutdown")) + info->shutdown = atoi(value); + + return 0; +} + static void thermal_init(void *data) { int ret; + /* load thermal configuration file */ + ret = config_parse(THERMAL_CONF_FILE, load_config, &thermal_table); + if (ret < 0) + _E("Failed to load power off config (%d)", ret); + + _I("temperature conf %d %d %d %d", thermal_table.normal, thermal_table.warning, + thermal_table.limit, thermal_table.shutdown); + ret = register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); if (ret < 0) _E("Fail to register booting done Notifier"); diff --git a/src/thermal/thermal.h b/src/thermal/thermal.h new file mode 100644 index 0000000..19b8d3b --- /dev/null +++ b/src/thermal/thermal.h @@ -0,0 +1,49 @@ +/* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/* Action types */ +#define RELEASE_ACTION "ReleaseAction" +#define WARNING_ACTION "WarningAction" +#define LIMIT_ACTION "LimitAction" +#define SHUTDOWN_ACTION "ShutdownAction" + +#define SIGNAL_OVERHEAT_TIME "TimeUpdate" +#define OVERHEAT_CALLBACK_TIME 1 //seconds +#define OVERHEAT_POWEROFF_TIME 30 + +#define SAMPLE_CNT 4 + +#define TEMPERATURE_NORMAL 70 +#define TEMPERATURE_WARNING 75 +#define TEMPERATURE_LIMIT 80 +#define TEMPERATURE_SHUTDOWN 85 + +enum thermal_enum_type { + NORMAL, + WARNING, + LIMIT, + SHUTDOWN +}; + +struct thermal_config_info { + int normal; + int warning; + int limit; + int shutdown; +}; -- 2.7.4 From a5d9163c90d3bab0bbc2c54952dbaccec8fc5574 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 17 Jan 2019 18:02:44 +0900 Subject: [PATCH 05/16] Fix integer overflow in extcon_count.c Change-Id: I83ac1617238aa664f1c5c6d1cff0c6945f5b1940 Signed-off-by: lokilee73 --- src/extcon/extcon_count.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/extcon/extcon_count.c b/src/extcon/extcon_count.c index 6e5df02..bb9914b 100644 --- a/src/extcon/extcon_count.c +++ b/src/extcon/extcon_count.c @@ -47,6 +47,7 @@ int extcon_update_count(int index, unsigned long count) int r; int ret = 0; char buf[BUF_MAX]; + unsigned long value; fd = open(extcon_devices[index].str, O_RDWR | O_CREAT, 0644); if (fd < 0) { @@ -62,9 +63,15 @@ int extcon_update_count(int index, unsigned long count) } buf[r] = '\0'; - extcon_devices[index].count = strtoul(buf, NULL, 10); - extcon_devices[index].count += count; - + value = strtoul(buf, NULL, 10); + if (value == ULONG_MAX && errno == ERANGE) + _E("converted value is over ULONG MAX(%lu)!", ULONG_MAX); + else if (value > ULONG_MAX - count) + value = ULONG_MAX; + else + value += count; + + extcon_devices[index].count = value; lseek(fd, 0, SEEK_SET); _I("ext(%d) count %lu", index, extcon_devices[index].count); snprintf(buf, sizeof(buf), "%lu", extcon_devices[index].count); -- 2.7.4 From 9f4dd859afeeda3f8f59b041f8a13bad4a471d18 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 18 Jan 2019 11:47:46 +0900 Subject: [PATCH 06/16] Change the way to make display.conf To make display.conf by using 'cat' can add duplicated contents in it. So, change the way by file replacement Change-Id: I69215787e89012ac8183899cea16b4215c73d65b Signed-off-by: lokilee73 --- conf/mobile-display.conf | 36 ++++++++++++++++++++++++++++++++++++ conf/wearable-display.conf | 36 ++++++++++++++++++++++++++++++++++++ packaging/deviced.spec | 9 ++++----- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/conf/mobile-display.conf b/conf/mobile-display.conf index 05e20d8..59af551 100644 --- a/conf/mobile-display.conf +++ b/conf/mobile-display.conf @@ -1,2 +1,38 @@ +[Display] +# deviced is pending lcd on until lock screen shows. +# This is the maximum pending time. +# LockScreenWaitingTime=0.3 (second) + +# Power-off popup is launched when power key is long pressed. +# This is duration of pressing power key. +# LongPressInterval=2 (second) + +# This is polling time of auto brightness. +# LightSensorSamplingInterval=1 (second) + +# display state is changed to SLEEP state after this time. +# If this value is large, it causes power consumption problem. +# LCDOffTimeout=500 (milli second) + +# This is n step of auto brightness. +# If brightness is change from a to b, brightness's changed n times from a to b. +# BrightnessChangeStep=10 + +# Just below application only allow to change display frame rate. +# refer to enum refresh_app +# ChangedFrameRateAllowed=setting (setting or all) +# ControlDisplay=(yes or no) + +# LCD is not turned off when this value is yes and key double pressed +# PowerKeyDoublePressSupport=(yes or no) + +# If this value is yes, LCD is always on except pressing power key. +# Default value is no, LCD is turned off by lcd timeout. +# LCDAlwaysOn=(yes or no) + +# If this value is yes, LCD is turned off by lcd timeout. +# If this value is no, LCD is turned off just by external requests. +# TimeoutEnable=(yes or no) + LCDAlwaysOn=no TimeoutEnable=yes diff --git a/conf/wearable-display.conf b/conf/wearable-display.conf index 8075ab9..3c190ae 100644 --- a/conf/wearable-display.conf +++ b/conf/wearable-display.conf @@ -1,3 +1,39 @@ +[Display] +# deviced is pending lcd on until lock screen shows. +# This is the maximum pending time. +# LockScreenWaitingTime=0.3 (second) + +# Power-off popup is launched when power key is long pressed. +# This is duration of pressing power key. +# LongPressInterval=2 (second) + +# This is polling time of auto brightness. +# LightSensorSamplingInterval=1 (second) + +# display state is changed to SLEEP state after this time. +# If this value is large, it causes power consumption problem. +# LCDOffTimeout=500 (milli second) + +# This is n step of auto brightness. +# If brightness is change from a to b, brightness's changed n times from a to b. +# BrightnessChangeStep=10 + +# Just below application only allow to change display frame rate. +# refer to enum refresh_app +# ChangedFrameRateAllowed=setting (setting or all) +# ControlDisplay=(yes or no) + +# LCD is not turned off when this value is yes and key double pressed +# PowerKeyDoublePressSupport=(yes or no) + +# If this value is yes, LCD is always on except pressing power key. +# Default value is no, LCD is turned off by lcd timeout. +# LCDAlwaysOn=(yes or no) + +# If this value is yes, LCD is turned off by lcd timeout. +# If this value is no, LCD is turned off just by external requests. +# TimeoutEnable=(yes or no) + LCDAlwaysOn=no TimeoutEnable=yes ControlDisplay=no diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 2606afa..b3713e1 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -197,14 +197,12 @@ fi %postun -n libdeviced -p /sbin/ldconfig %post plugin-profile-mobile -cat %{_sysconfdir}/deviced/mobile-display.conf >> %{_sysconfdir}/deviced/display.conf -rm -rf %{_sysconfdir}/deviced/mobile-display.conf +mv %{_sysconfdir}/deviced/mobile-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/mobile-display.so %{_libdir}/deviced/display.so %post plugin-profile-wearable -cat %{_sysconfdir}/deviced/wearable-display.conf >> %{_sysconfdir}/deviced/display.conf -rm -rf %{_sysconfdir}/deviced/wearable-display.conf +mv %{_sysconfdir}/deviced/wearable-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so mv %{_sysconfdir}/deviced/wearable-temperature.conf %{_sysconfdir}/deviced/temperature.conf @@ -232,7 +230,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %config %{_sysconfdir}/deviced/cpu.conf %config %{_sysconfdir}/deviced/power.conf %config %{_sysconfdir}/deviced/battery.conf -%config %{_sysconfdir}/deviced/display.conf # usbhost_test %{_sysconfdir}/deviced/usb-host-test/test_gadget.gs %{_bindir}/usb-host-ffs-test-daemon @@ -288,6 +285,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/display.conf %config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/tv-display.so @@ -295,5 +293,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/display.conf %config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/iot-display.so -- 2.7.4 From c14fb65f6a5c970f83915b6bafd2e0c095b3689e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 30 Jan 2019 11:16:26 +0900 Subject: [PATCH 07/16] Remove extcon_count.c and extcon_count.h Because they have dependency with products Change-Id: I1fe49f9b0089f85ad09d4d7c21e5c609195be7eb Signed-off-by: lokilee73 --- src/battery/power-supply.c | 21 +------- src/extcon/earjack.c | 4 -- src/extcon/extcon_count.c | 131 --------------------------------------------- src/extcon/extcon_count.h | 32 ----------- 4 files changed, 1 insertion(+), 187 deletions(-) delete mode 100644 src/extcon/extcon_count.c delete mode 100644 src/extcon/extcon_count.h diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 9b4bb7a..f303cbe 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -36,7 +36,6 @@ #include "apps/apps.h" #include "power-supply.h" #include "battery.h" -#include "extcon/extcon_count.h" #define BATTERY_NAME "battery" #define CHARGEFULL_NAME "Full" @@ -195,7 +194,7 @@ out: static void noti_off_cb(GVariant *var, void *user_data, GError *err) { - int ret= 0; + int ret = 0; if (!dh_get_param_from_var(var, "(i)", &ret)) { _E("no message [%s]", g_variant_get_type_string(var)); @@ -559,7 +558,6 @@ static void check_online(void) old_online = VCONFKEY_SYSMAN_CHARGER_CONNECTED; vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); - extcon_update_count(EXTCON_TA, 1); check_power_supply(old_online); charger_state_send_system_event(CHARGE_STATUS_CONNECTED); if (charge_status != old_charge_status) @@ -676,22 +674,6 @@ static void check_capacity_status(const char *env_value) battery.capacity = atoi(env_value); } -static void update_capacity_full(void) -{ - static int old; - int delta; - - if (battery.online <= POWER_SUPPLY_TYPE_BATTERY || - old == 0 || - old >= battery.capacity) { - old = battery.capacity; - return; - } - delta = battery.capacity - old; - old = battery.capacity; - extcon_update_count(EXTCON_BATTERY_FULL, delta); -} - static void process_power_supply(void *data) { if (old_battery.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { @@ -713,7 +695,6 @@ static void process_power_supply(void *data) check_battery_status(); device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL); device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now); - update_capacity_full(); } static void battery_state(struct battery_info *info) diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index 05e247a..fcb9d52 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -26,7 +26,6 @@ #include "display/poll.h" #include "display/display-ops.h" #include "extcon/extcon.h" -#include "extcon/extcon_count.h" #define SIGNAL_EARJACK_STATE "ChangedEarjack" #define GET_EARJACK_STATE "Earjack" @@ -74,9 +73,6 @@ static int earjack_update(int status) disp_plgn.pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL); } - if (CONNECTED(status)) - extcon_update_count(EXTCON_EARJACK, 1); - return 0; } diff --git a/src/extcon/extcon_count.c b/src/extcon/extcon_count.c deleted file mode 100644 index bb9914b..0000000 --- a/src/extcon/extcon_count.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include "core/log.h" -#include "core/list.h" -#include "core/common.h" -#include "core/devices.h" -#include "extcon_count.h" - -#define BUF_MAX 256 - -// TODO : storage location should be configurable by configuration file -static struct extcon_device { - const enum extcon_type type; - const char *str; - unsigned long count; -} extcon_devices[] = { - { EXTCON_TA, "/opt/share/batt_cable_count", 0}, - { EXTCON_EARJACK, "/opt/share/earjack_count", 0}, - { EXTCON_BATTERY_FULL, "/opt/share/battery_full_count", 0}, -}; - -int extcon_update_count(int index, unsigned long count) -{ - int fd; - int r; - int ret = 0; - char buf[BUF_MAX]; - unsigned long value; - - fd = open(extcon_devices[index].str, O_RDWR | O_CREAT, 0644); - if (fd < 0) { - _E("cannot open file(%s)", extcon_devices[index].str); - return -ENOENT; - } - - r = read(fd, buf, BUF_MAX); - if (r < 0 || r >= BUF_MAX) { - close(fd); - ret = -EIO; - return ret; - } - - buf[r] = '\0'; - value = strtoul(buf, NULL, 10); - if (value == ULONG_MAX && errno == ERANGE) - _E("converted value is over ULONG MAX(%lu)!", ULONG_MAX); - else if (value > ULONG_MAX - count) - value = ULONG_MAX; - else - value += count; - - extcon_devices[index].count = value; - lseek(fd, 0, SEEK_SET); - _I("ext(%d) count %lu", index, extcon_devices[index].count); - snprintf(buf, sizeof(buf), "%lu", extcon_devices[index].count); - - r = write(fd, buf, strlen(buf)); - if (r < 0) - ret = -EIO; - - close(fd); - return ret; -} - -static int extcon_create_count(int index) -{ - int fd; - int r; - int ret = 0; - char buf[BUF_MAX]; - fd = open(extcon_devices[index].str, O_RDWR | O_CREAT, 0644); - if (fd < 0) { - _E("cannot open file(%s)", extcon_devices[index].str); - return -ENOENT; - } - snprintf(buf, sizeof(buf), "%lu", extcon_devices[index].count); - r = write(fd, buf, strlen(buf)); - if (r < 0) - ret = -EIO; - - if (ret != 0) { - close(fd); - _E("cannot write file(%s)", extcon_devices[index].str); - return ret; - } - - _I("create extcon(%d:%x) %s", - index, fd, extcon_devices[index].str); - close(fd); - return ret; -} - -static void extcon_count_init(void *data) -{ - int i, ret; - - for (i = 0; i < ARRAY_SIZE(extcon_devices); i++) { - ret = extcon_create_count(i); - if (ret < 0) - break; - } -} - -static const struct device_ops extcon_count_ops = { - .name = "extcon_count", - .init = extcon_count_init, -}; - -DEVICE_OPS_REGISTER(&extcon_count_ops) diff --git a/src/extcon/extcon_count.h b/src/extcon/extcon_count.h deleted file mode 100644 index 8c489af..0000000 --- a/src/extcon/extcon_count.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __EXTCON_COUNT_H__ -#define __EXTCON_COUNT_H__ - -#include "core/common.h" - -enum extcon_type { - EXTCON_TA = 0, - EXTCON_EARJACK, - EXTCON_BATTERY_FULL, -}; - -int extcon_update_count(int index, unsigned long count); -#endif /* __EXTCON_COUNT_H__ */ -- 2.7.4 From 51849e1cad17ba09bc95d72c82c590a406530c35 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 10 Jan 2019 00:11:44 +0000 Subject: [PATCH 08/16] power: Rework handling of repeated poweroff/reboot request MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This commit generalizes "repeated poweroff/reboot" code path to use same state variables as dbus requests (poweroff_opt var). Additionally, multiple constructs are simplified. Change-Id: I989c7fdbf021da0d69d9062507a05fd8692846a5 Signed-off-by: Paweł Szewczyk Signed-off-by: Hyotaek Shim --- src/core/main.c | 8 +- src/power/power-handler.c | 218 +++++++++++++++------------------------------- src/power/power-handler.h | 11 ++- 3 files changed, 86 insertions(+), 151 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index bf798f4..64d44c8 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -93,8 +93,14 @@ static int deviced_main(int argc, char **argv) mainloop = g_main_loop_new(NULL, FALSE); ret = check_power_flag(); - if (ret) + if (ret) { + /* assume reboot was requested and deviced was + * killed/terminated in middle of it - resume + * procedure + */ + poweroff_procedure(); return 0; + } handle = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, FALSE); if (!handle) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index b8fc0a3..d63a29e 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -72,20 +72,44 @@ #define POWER_CONF_FILE "/etc/deviced/power.conf" -struct power_flag { - enum poweroff_type type; - const char *path; -} power_flags[] = { - { POWER_OFF_DIRECT, POWER_FLAG_POWEROFF }, - { POWER_OFF_RESTART, POWER_FLAG_REBOOT }, -}; - static struct timeval tv_start_poweroff; static dd_list *poweroff_options; static struct power_option poweroff_opt; static bool during_poweroff; static dd_list *poweroff_handles; +static char *poweroff_type_flagpaths[] = { // index denotes type + [POWER_OFF_DIRECT] = POWER_FLAG_POWEROFF, + [POWER_OFF_REBOOT] = POWER_FLAG_REBOOT, +}; +static char *poweroff_type_names[] = { // index denotes type + [POWER_OFF_POWEROFF] = POWER_POWEROFF, + [POWER_OFF_POPUP] = PWROFF_POPUP, + [POWER_OFF_REBOOT] = POWER_REBOOT, + [POWER_OFF_DIRECT] = "", +}; + +static char *poweroff_type_to_name(enum poweroff_type type) +{ + if (type >= ARRAY_SIZE(poweroff_type_names)) + return NULL; + + return poweroff_type_names[type]; +} + +static enum poweroff_type poweroff_name_to_type(char *name) +{ + if (!name) + goto out; + + for (int i = 0; i < ARRAY_SIZE(poweroff_type_names); i++) { + if (poweroff_type_names[i] && strcmp(poweroff_type_names[i], name) == 0) + return i; + } +out: + return POWER_OFF_INVALID; +} + static void poweroff_start_animation(void) { int ret; @@ -146,9 +170,6 @@ static int disable_systemd_journald(void) _E("failed to stop 'systemd-journald.service'"); return ret; } - _I("done %s with %s option", - poweroff_opt.name ? poweroff_opt.name : "NULL", - poweroff_opt.option ? poweroff_opt.option : "NULL"); return 0; } @@ -246,12 +267,8 @@ static void restart(char *option) } } -static int poweroff_procedure(void) +int poweroff_procedure(void) { - _I("%s option(%s)", - poweroff_opt.name ? poweroff_opt.name : "NULL", - poweroff_opt.option ? poweroff_opt.option : "NULL"); - powerdown(); if (poweroff_opt.type == POWER_OFF_DIRECT) { @@ -271,48 +288,15 @@ static int poweroff_procedure(void) int check_power_flag(void) { - char buf[32] = { 0, }; - char *option = NULL; - int i, index; - int fd; - ssize_t len; - - index = -1; - for (i = 0 ; i < ARRAY_SIZE(power_flags) ; i++) { - if (access(power_flags[i].path, F_OK) == 0) { - index = i; - break; - } - } - if (index < 0) - return 0; - - if (power_flags[index].type == POWER_OFF_DIRECT) { - poweroff(); - return 1; - } - - fd = open(power_flags[index].path, O_RDONLY); - if (fd >= 0) { - len = read(fd, buf, sizeof(buf) - 1); - close(fd); - if (len < 0) { - len = errno; - _E("read() failed (%zd)", len); - return 0; + for (int i = 0; i < ARRAY_SIZE(poweroff_type_flagpaths); i++) { + if (access(poweroff_type_flagpaths[i], F_OK) == 0) { + poweroff_opt.type = i; + poweroff_opt.option = NULL; + return 1; } - while (len > 0 && buf[len - 1] == '\n') - len--; - buf[len] = '\0'; - _I("reboot option (%s)", buf); } - if (strlen(buf) > 0) - option = buf; - - restart(option); - - return 1; + return 0; } static void make_power_flag(enum poweroff_type type, char *option) @@ -320,15 +304,11 @@ static void make_power_flag(enum poweroff_type type, char *option) const char *path; int fd; ssize_t len; - int i; - path = NULL; - for (i = 0 ; i < ARRAY_SIZE(power_flags) ; i++) { - if (power_flags[i].type == type) { - path = power_flags[i].path; - break; - } - } + if (type <= 0 || type >= ARRAY_SIZE(poweroff_type_flagpaths)) + return; + + path = poweroff_type_flagpaths[type]; if (!path) return; @@ -385,19 +365,14 @@ static gboolean poweroff_timeout_cb(void *data) } _D("No timer left"); - if (!poweroff_opt.name) { - _E("There is no option"); + char *name = poweroff_type_to_name(poweroff_opt.type); + if (!name) { + _E("Invalid type (%d)", poweroff_opt.type); goto out; } watchdog_notify(); - if (poweroff_opt.type != POWER_OFF_DIRECT && - poweroff_opt.type != POWER_OFF_RESTART) { - _E("Invalid type (%d)", poweroff_opt.type); - goto out; - } - during_poweroff = true; make_power_flag(poweroff_opt.type, poweroff_opt.option); @@ -412,7 +387,7 @@ static gboolean poweroff_timeout_cb(void *data) ret = poweroff_procedure(); if (ret < 0) - _E("Failed to %s (%d)", poweroff_opt.name, ret); + _E("Failed to %s (%d)", name, ret); out: if (disp_plgn.update_pm_setting) @@ -488,53 +463,15 @@ static int pwroff_popup(void) return launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); } -static int get_poweroff_type_enum(char *type, enum poweroff_type *val) +static int poweroff_option_valid(enum poweroff_type type_e, char *option) { - size_t len; - - if (!type || !val) - return -EINVAL; - - len = strlen(type) + 1; - - if (!strncmp(POWER_POWEROFF, type, len)) { - *val = POWER_OFF_DIRECT; - return 0; - } - - if (!strncmp(PWROFF_POPUP, type, len)) { - *val = POWER_OFF_POPUP; - return 0; - } - - if (!strncmp(POWER_REBOOT, type, len)) { - *val = POWER_OFF_RESTART; - return 0; - } - - _E("Invalid poweroff type (%s)", type); - return -EINVAL; -} - -static int find_poweroff_option(char *type, char *option) -{ - int ret; dd_list *l; struct power_option *elem; - enum poweroff_type type_e; - - if (!type) - return -EINVAL; - - ret = get_poweroff_type_enum(type, &type_e); - if (ret < 0) { - _E("Failed to get type enum value (%d)", ret); - return ret; - } DD_LIST_FOREACH(poweroff_options, l, elem) { if (elem->type != type_e) continue; + if (option) { if (elem->option == NULL) continue; @@ -544,21 +481,10 @@ static int find_poweroff_option(char *type, char *option) if (elem->option != NULL) continue; } - poweroff_opt.type = elem->type; - if (poweroff_opt.name) { - free(poweroff_opt.name); - poweroff_opt.name = NULL; - } - poweroff_opt.name = (elem->name ? strdup(elem->name) : NULL); - if (poweroff_opt.option) { - free(poweroff_opt.option); - poweroff_opt.option = NULL; - } - poweroff_opt.option = (option ? strdup(option) : NULL); - return 0; + return 1; } - return -ENOENT; + return 0; } static void poweroff_send_broadcast(int status) @@ -579,6 +505,7 @@ static void poweroff_send_broadcast(int status) g_variant_new("(i)", status)); } + static int power_execute_pid(char *type, char *option, pid_t pid) { int ret; @@ -588,25 +515,29 @@ static int power_execute_pid(char *type, char *option, pid_t pid) return -EINVAL; } - if (!type) + enum poweroff_type type_e = poweroff_name_to_type(type); + if (type_e == POWER_OFF_INVALID) { + _E("Failed to get type enum value (%d)", type_e); + return -EINVAL; + } + if (poweroff_option_valid(type_e, option)) { + poweroff_opt.type = type_e; + free(poweroff_opt.option); + poweroff_opt.option = NULL; + if (option) + poweroff_opt.option = strdup(option); + } else { + _E("Failed to find supported %s option %s", type, (option ? option : "NULL")); return -EINVAL; - - ret = find_poweroff_option(type, option); - if (ret < 0) { - _E("Failed to find supported %s option %s (%d)", type, (option ? option : "NULL"), ret); - return ret; } - if (strncmp(PWROFF_POPUP, poweroff_opt.name, PWROFF_POPUP_LEN) == 0) { + if (poweroff_opt.type == POWER_OFF_POPUP) { _D("request popup"); - if (poweroff_opt.type == POWER_OFF_POPUP) { - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type); - pwroff_popup(); - } + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type); + pwroff_popup(); return 0; } - poweroff_opt.pid = pid; /* Poweroff event broadcasting */ system_shutdown_send_system_event(); poweroff_send_broadcast(poweroff_opt.type); @@ -806,13 +737,8 @@ static int add_poweroff_option(enum poweroff_type type, char *option) struct power_option *opt; char *name; - if (type == POWER_OFF_POPUP) - name = PWROFF_POPUP; - else if (type == POWER_OFF_DIRECT) - name = POWER_POWEROFF; - else if (type == POWER_OFF_RESTART) - name = POWER_REBOOT; - else { + name = poweroff_type_to_name(type); + if (!name) { _E("Invalid type (%d)", type); return -EINVAL; } @@ -824,12 +750,11 @@ static int add_poweroff_option(enum poweroff_type type, char *option) } opt->type = type; - opt->name = strdup(name); opt->option = (option ? strdup(option) : NULL); DD_LIST_APPEND(poweroff_options, opt); - _D("Add %s option (%s)", opt->name, opt->option); + _D("Add %s option (%s)", name, opt->option); return 0; } @@ -883,6 +808,7 @@ static void power_init(void *data) register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + add_poweroff_option(POWER_OFF_POWEROFF, NULL); add_poweroff_option(POWER_OFF_DIRECT, NULL); add_poweroff_option(POWER_OFF_RESTART, NULL); add_poweroff_option(POWER_OFF_POPUP, NULL); diff --git a/src/power/power-handler.h b/src/power/power-handler.h index ae545a0..1406b3f 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -28,17 +28,19 @@ #define PWROFF_POPUP "pwroff-popup" #define PWROFF_POPUP_LEN 12 + enum poweroff_type { - POWER_OFF_NONE = 0, + POWER_OFF_INVALID = 0, + POWER_OFF_NONE = POWER_OFF_INVALID, // compat only POWER_OFF_POPUP, + POWER_OFF_POWEROFF, /* replaces POWER_OFF_DIRECT */ + POWER_OFF_REBOOT, + POWER_OFF_RESTART = POWER_OFF_REBOOT, // compat only POWER_OFF_DIRECT, - POWER_OFF_RESTART, }; struct power_option { - pid_t pid; enum poweroff_type type; - char *name; char *option; }; @@ -49,5 +51,6 @@ struct poweroff_handle { }; int check_power_flag(void); +int poweroff_procedure(void); #endif /* __POWER_HANDLE_H__ */ -- 2.7.4 From 621089c73c7819e6ba57fce0cc3f72201c9d59b7 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 10 Jan 2019 00:17:22 +0000 Subject: [PATCH 09/16] power: Add deviced-shutdown This commit provides special binary that is going to handle Tizen system shutdown. This utility is called by systemd, not deviced. The final shutdown scheme is going to look like following: 1. deviced receivies request to shutdown/reboot the system, - preparation is performed (send signals, etc) - operation start is marked in /run/ - hardcoded actions are started - depending on shutdown type following is performed: + direct shutdown: system is rebooted immidietly (end of flow) + other: dbus request to systemd is sent 2. systemd receives the "poweroff" request - supported requests are Reboot, PowerOff & Halt - systemd (pid1) replaces it's own process with shutdown binary (execve("/usr/lib/systemd/systemd-shutdown")) - shutdown binary is provided by deviced package by alternatives mechanism # ls -l systemd-shutdown systemd-shutdown -> /etc/alternatives/systemd-shutdown # ls -l /etc/alternatives/systemd-shutdown /etc/alternatives/systemd-shutdown -> /usr/lib/systemd/deviced-shutdown (alternatives allow both systemd and deviced to "provide" same binary, with deviced having higher priority being selected as the one to use) 3. /usr/lib/systemd/systemd-shutdown becomes pid1 - original systemd1 manager is no longer available, meaning no restart, watchdog, socket/path/etc activation is handled. - depending on systemd-provided params it performs reboot or poweroff Change-Id: I46b4d0f375a1a6e7fc3e1d74b0530d7ec73ccb12 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 7 ++ packaging/deviced.spec | 15 ++++- src/power-shutdown/shutdown.c | 150 ++++++++++++++++++++++++++++++++++++++++++ src/power/power-handler.c | 80 +++++++++------------- src/power/power-handler.h | 2 + 5 files changed, 204 insertions(+), 50 deletions(-) create mode 100644 src/power-shutdown/shutdown.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 013b1f2..66ebf37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,6 +227,13 @@ SET(deviced_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +IF(POWER_MODULE STREQUAL on) + ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/core/common.c src/core/execute.c) + SET(deviced-shutdown_LDFLAGS ${pkgs_LDFLAGS}) + TARGET_LINK_LIBRARIES(deviced-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) + INSTALL(TARGETS deviced-shutdown DESTINATION lib/systemd) +ENDIF() + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING PATTERN "*_doc.h" EXCLUDE diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b3713e1..6a7b35f 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -41,9 +41,11 @@ BuildRequires: pkgconfig(capi-system-device) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} Requires(post): /usr/bin/vconftool +Requires(post): %{_sbindir}/update-alternatives +Requires(preun): %{_sbindir}/update-alternatives %description -deviced +Deviced %package -n libdeviced Summary: Deviced library @@ -178,6 +180,9 @@ mkdir -p %{buildroot}%{TZ_SYS_DUMPGEN} install -m 775 scripts/dump_pmstate_log.sh %{buildroot}%{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh %post +# Assume power module is on (-DPOWER_MODULE=on) +update-alternatives --install %{_libdir}/systemd/systemd-shutdown systemd-shutdown %{_libdir}/systemd/deviced-shutdown 500 + #memory type vconf key init users_gid=$(getent group %{TZ_SYS_USER_GROUP} | cut -f3 -d':') @@ -186,6 +191,10 @@ if [ "$1" == "1" ]; then systemctl restart deviced.service fi +%preun +# Assume power module is on (-DPOWER_MODULE=on) +update-alternatives --remove %{_libdir}/systemd/systemd-shutdown systemd-shutdown %{_libdir}/systemd/deviced-shutdown + %postun systemctl daemon-reload if [ "$1" == "0" ]; then @@ -238,6 +247,10 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %{_sysconfdir}/deviced/usb-host-test/descs %{_sysconfdir}/deviced/usb-host-test/strs +# Assume power module is on (-DPOWER_MODULE=on) +%{_libdir}/systemd/deviced-shutdown + + %files -n libdeviced %manifest deviced.manifest %license LICENSE.Apache-2.0 diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c new file mode 100644 index 0000000..0ac97c5 --- /dev/null +++ b/src/power-shutdown/shutdown.c @@ -0,0 +1,150 @@ +/* + * deviced-shutdown: deviced's replacement for systemd-shutdown binary + * + * This binary is supposed to be called on Tizen system by systemd + * manager during shutdown, as result of eg. dbus call to Reboot + * method, test via: + * + * # dbus-send --print-reply --system --dest=org.freedesktop.systemd1 --type=method_call /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.(Reboot|PowerOff) + * + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dd-deviced.h" +#include "core/log.h" +#include "core/common.h" + +#define UMOUNT_RW_PATH_USER "/opt/usr" +#define UMOUNT_RW_PATH_SYSTEM "/opt" +#define MAX_UMOUNT_KILL_RETRY 4 + +char *progname; + +static int usage(void) +{ + printf("%s: Invalid command specified (supported are: reboot, halt|poweroff, exit)\n", progname); + return 0; +} + +static void umount_partitions(void) +{ + umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); + umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); +} + +static void sigchld(int signo) +{ + int wstatus; + int r; + + do + r = waitpid(-1, &wstatus, WNOHANG); + while (r > 0); +} + +static void autoboot(void) +{ + static char buf[4096] = {0,}; + int fd = open("/run/reboot", O_RDONLY); // XXX POWER_FLAG_REBOOT + if (fd >= 0) { + (void)read(fd, buf, sizeof(buf)); + close(fd); + } + + printf("%s: reboot param is <%s>\n", progname, buf); + syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + buf[0] != 0 ? LINUX_REBOOT_CMD_RESTART2 : LINUX_REBOOT_CMD_RESTART, + &buf); +} + +int main(int ac, char *av[]) +{ + enum { + ARG_LOGLEVEL, + ARG_LOGTARGET, + ARG_LOGCOLOR, + ARG_LOGLOCATION, + ARG_EXITCODE + }; + static struct option opts[] = { + {"log-level", required_argument, NULL, ARG_LOGLEVEL}, + {"log-target", required_argument, NULL, ARG_LOGTARGET}, + {"log-color", optional_argument, NULL, ARG_LOGCOLOR}, + {"log-location", optional_argument, NULL, ARG_LOGLOCATION}, + {"exit-code", required_argument, NULL, ARG_EXITCODE}, + {}, + }; + + progname = av[0]; + + int c; + while ((c = getopt_long(ac, av, "", opts, NULL)) >= 0) + ; // not supported for now + + int cmd; + char *cmd_name = av[optind]; + if (optind >= ac || !cmd_name) + return usage(); + + if (strcmp(cmd_name, "reboot") == 0) + cmd = RB_AUTOBOOT; + else if (strcmp(cmd_name, "halt") == 0 || strcmp(cmd_name, "poweroff") == 0) + cmd = RB_POWER_OFF; + else if (strcmp(cmd_name, "exit") == 0) + exit(0); + else + // XXX this is critical failure - we are pid1 already + // and can't perform requested action - exit below + // will cause system to panic() and, hopefully, reboot + // (depends on sysctls) + return usage(); + + printf("%s: executing %s action\n", progname, cmd_name); + + (void)signal(SIGCHLD, sigchld); + (void)signal(SIGHUP, SIG_IGN); + (void)signal(SIGTERM, SIG_IGN); + + if (!is_emulator()) { + printf("%s: unmounting rw partitions\n", progname); + umount_partitions(); + } + + printf("%s: flushing filesystems\n", progname); + + sync(); + + printf("%s: performing %s\n", progname, cmd_name); + + if (cmd == RB_AUTOBOOT) + autoboot(); + else + reboot(cmd); + + return 1; +} diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d63a29e..a084cc7 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -61,14 +61,9 @@ #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ #define POWEROFF_WAIT_MAX 10 /* 10 seconds */ -#define SIGNAL_POWEROFF_STATE "ChangeState" - -#define UMOUNT_RW_PATH_USER "/opt/usr" -#define UMOUNT_RW_PATH_SYSTEM "/opt" -#define MAX_UMOUNT_KILL_RETRY 4 +#define POWEROFF_WAIT_SYSTEMD_MS (30 * 1000/*ms*/) /* 30 seconds */ -#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF -#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT +#define SIGNAL_POWEROFF_STATE "ChangeState" #define POWER_CONF_FILE "/etc/deviced/power.conf" @@ -194,14 +189,6 @@ static bool disable_coredump_handler(void) return is_ok; } -/* umount usr data partition */ -static void unmount_rw_partition(void) -{ - umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); - umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); - sync(); -} - static void powerdown(void) { static int wait; @@ -236,52 +223,49 @@ static void powerdown(void) } watchdog_notify(); - - if (!is_emulator()) - unmount_rw_partition(); } -static void reboot_with_option(int cmd, char *option) +static void poweroff_request_shutdown() { - if (!cmd) + _I("Requested power off via systemd"); + + char *method; + + if (poweroff_opt.type == POWER_OFF_REBOOT) + method = "Reboot"; + else if (poweroff_opt.type == POWER_OFF_POWEROFF) + method = "PowerOff"; + else { + _E("poweroff invalid type (%d)", poweroff_opt.type); return; - if (syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, - cmd, (void *)option) < 0) - _E("Failed to reboot with option (%d)", errno); -} + } -static void poweroff(void) -{ - _I("Power off !!!"); - reboot_with_option(LINUX_REBOOT_CMD_POWER_OFF, NULL); + dbus_handle_method_sync_timeout(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + SYSTEMD_DBUS_IFACE_MANAGER, + method, + NULL, + NULL, + POWEROFF_WAIT_SYSTEMD_MS); } -static void restart(char *option) +static void poweroff_direct(void) { - if (option) { - _I("Restart with option %s !!!", option); - reboot_with_option(LINUX_REBOOT_CMD_RESTART2, option); - } else { - _I("Restart !!!"); - reboot_with_option(LINUX_REBOOT_CMD_RESTART, NULL); - } + _I("Requested power off without systemd (direct call)"); + if (syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + LINUX_REBOOT_CMD_POWER_OFF, NULL) < 0) + _E("Failed to poweroff (%d)", errno); } int poweroff_procedure(void) { - powerdown(); - - if (poweroff_opt.type == POWER_OFF_DIRECT) { - poweroff(); - return 0; - } - if (poweroff_opt.type == POWER_OFF_RESTART) { - restart(poweroff_opt.option); - return 0; - } + powerdown(); - _E("poweroff invalid type (%d)", poweroff_opt.type); + if (poweroff_opt.type == POWER_OFF_DIRECT) + poweroff_direct(); + else + poweroff_request_shutdown(); return 0; } @@ -508,8 +492,6 @@ static void poweroff_send_broadcast(int status) static int power_execute_pid(char *type, char *option, pid_t pid) { - int ret; - if (during_poweroff) { _E("during poweroff"); return -EINVAL; diff --git a/src/power/power-handler.h b/src/power/power-handler.h index 1406b3f..968e17a 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -28,6 +28,8 @@ #define PWROFF_POPUP "pwroff-popup" #define PWROFF_POPUP_LEN 12 +#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF +#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT enum poweroff_type { POWER_OFF_INVALID = 0, -- 2.7.4 From c4546512bb84cf1f6f6cd4120ecf644afc83f32b Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 31 Jan 2019 11:58:47 +0900 Subject: [PATCH 10/16] Version 5.5.0 Change-Id: I5bfa2097c864342fccd20c0660524a0c35ac5580 Signed-off-by: Hyotaek Shim --- packaging/deviced.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 6a7b35f..db995fd 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -5,7 +5,7 @@ Name: deviced Summary: Deviced -Version: 5.0.0 +Version: 5.5.0 Release: 1 Group: System/Management License: Apache-2.0 -- 2.7.4 From 29b553d5134ad23966c1686558e7cfd50071fe2e Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 31 Jan 2019 17:01:24 +0900 Subject: [PATCH 11/16] Fix 64-bit build errors, /lib64/systemd/ Change-Id: I7170c14e46cdd8ccbbcfcede18232bb10a62c8e9 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66ebf37..daba64d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,7 +231,7 @@ IF(POWER_MODULE STREQUAL on) ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/core/common.c src/core/execute.c) SET(deviced-shutdown_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(deviced-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) - INSTALL(TARGETS deviced-shutdown DESTINATION lib/systemd) + INSTALL(TARGETS deviced-shutdown DESTINATION ${LIB_INSTALL_DIR}/systemd) ENDIF() INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} -- 2.7.4 From 6b9a6abc130ba77a4371f9f3aeda648cc098b1b0 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 31 Jan 2019 20:21:30 +0900 Subject: [PATCH 12/16] Remove unused edbus-handler Change-Id: I5a95dc4c181ca2c22793264f98198340cd0cfb40 Signed-off-by: Hyotaek Shim --- src/core/edbus-handler.c | 893 ----------------------------------------------- src/core/edbus-handler.h | 67 ---- 2 files changed, 960 deletions(-) delete mode 100644 src/core/edbus-handler.c delete mode 100644 src/core/edbus-handler.h diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c deleted file mode 100644 index ddc5944..0000000 --- a/src/core/edbus-handler.c +++ /dev/null @@ -1,893 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "core/log.h" -#include "core/common.h" -#include "core/device-idler.h" -#include "core/device-notifier.h" -#include "core/list.h" - -#define EDBUS_INIT_RETRY_COUNT 5 -#define NAME_OWNER_CHANGED "NameOwnerChanged" -#define NAME_OWNER_MATCH "type='signal',sender='org.freedesktop.DBus'," \ - "path='/org/freedesktop/DBus',interface='org.freedesktop.DBus'," \ - "member='NameOwnerChanged',arg0='%s'" - -/* -1 is a default timeout value, it's converted to 25*1000 internally. */ -#define DBUS_REPLY_TIMEOUT (-1) -#define RETRY_MAX 5 - -struct edbus_list { - char *signal_name; - E_DBus_Signal_Handler *handler; -}; - -static struct edbus_object { - char *path; - char *interface; - E_DBus_Object *obj; - E_DBus_Interface *iface; -} edbus_objects[] = { - { DEVICED_PATH_CORE , DEVICED_INTERFACE_CORE , NULL, NULL }, - { DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, NULL, NULL }, - { DEVICED_PATH_POWER , DEVICED_INTERFACE_POWER , NULL, NULL }, - { DEVICED_PATH_LOWPOWER, DEVICED_INTERFACE_LOWPOWER, NULL, NULL }, - { DEVICED_PATH_REBOOT , DEVICED_INTERFACE_REBOOT , NULL, NULL }, - { DEVICED_PATH_STORAGE, DEVICED_INTERFACE_STORAGE, NULL, NULL }, - { DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, NULL, NULL }, - { DEVICED_PATH_KEY , DEVICED_INTERFACE_KEY , NULL, NULL }, - { DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, NULL, NULL }, - { DEVICED_PATH_USB , DEVICED_INTERFACE_USB , NULL, NULL }, - /* Add new object & interface here*/ -}; - -struct watch_func_info { - bool deleted; - void (*func)(const char *sender, void *data); - void *data; -}; - -struct watch_info { - bool deleted; - char *sender; - dd_list *func_list; -}; - -static dd_list *edbus_object_list; -static dd_list *edbus_owner_list; -static dd_list *edbus_handler_list; -static dd_list *edbus_watch_list; -static int edbus_init_val; -static DBusConnection *conn; -static E_DBus_Connection *edbus_conn; -static DBusPendingCall *edbus_request_name; - -static DBusHandlerResult message_filter(DBusConnection *connection, - DBusMessage *message, void *data); - -DBusConnection *get_dbus_connection(void) -{ - return conn; -} - -E_DBus_Object *register_edbus_object(const char *object_path, void *data) -{ - E_DBus_Object *object; - - if (!object_path) { - _E("invalid parameter"); - return NULL; - } - - object = e_dbus_object_add(edbus_conn, object_path, data); - if (!object) { - _E("fail to add object for %s", object_path); - return NULL; - } - - return object; -} - -void unregister_edbus_object(E_DBus_Object *object) -{ - if (!object) - return; - - e_dbus_object_free(object); -} - -static int register_edbus_interface(struct edbus_object *object) -{ - if (!object) { - _E("object is invalid value!"); - return -1; - } - - object->obj = e_dbus_object_add(edbus_conn, object->path, NULL); - if (!object->obj) { - _E("fail to add edbus obj"); - return -1; - } - - object->iface = e_dbus_interface_new(object->interface); - if (!object->iface) { - _E("fail to add edbus interface"); - return -1; - } - - e_dbus_object_interface_attach(object->obj, object->iface); - - return 0; -} - -E_DBus_Interface *get_edbus_interface(const char *path) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) - if (!strcmp(path, edbus_objects[i].path)) - return edbus_objects[i].iface; - - return NULL; -} - -pid_t get_edbus_sender_pid(DBusMessage *msg) -{ - const char *sender; - DBusMessage *send_msg; - DBusPendingCall *pending; - DBusMessageIter iter; - int ret; - pid_t pid; - - if (!msg) { - _E("invalid argument!"); - return -1; - } - - sender = dbus_message_get_sender(msg); - if (!sender) { - _E("invalid sender!"); - return -1; - } - - send_msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "GetConnectionUnixProcessID"); - if (!send_msg) { - _E("invalid send msg!"); - return -1; - } - - ret = dbus_message_append_args(send_msg, DBUS_TYPE_STRING, - &sender, DBUS_TYPE_INVALID); - if (!ret) { - _E("fail to append args!"); - dbus_message_unref(send_msg); - return -1; - } - - pending = e_dbus_message_send(edbus_conn, send_msg, NULL, -1, NULL); - if (!pending) { - _E("pending is null!"); - dbus_message_unref(send_msg); - return -1; - } - - dbus_message_unref(send_msg); - - /* block until reply is received */ - dbus_pending_call_block(pending); - - msg = dbus_pending_call_steal_reply(pending); - dbus_pending_call_unref(pending); - if (!msg) { - _E("reply msg is null!"); - return -1; - } - - dbus_message_iter_init(msg, &iter); - dbus_message_iter_get_basic(&iter, &pid); - dbus_message_unref(msg); - - return pid; -} - -static void unregister_edbus_signal_handle(void) -{ - dd_list *tmp, *next; - struct edbus_list *entry; - - DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) { - if (!entry->handler) - continue; - e_dbus_signal_handler_del(edbus_conn, entry->handler); - DD_LIST_REMOVE(edbus_handler_list, entry); - free(entry->signal_name); - free(entry); - } -} - -int register_edbus_signal_handler(const char *path, const char *interface, - const char *name, E_DBus_Signal_Cb cb) -{ - dd_list *tmp; - struct edbus_list *entry; - E_DBus_Signal_Handler *handler; - - DD_LIST_FOREACH(edbus_handler_list, tmp, entry) { - if (strncmp(entry->signal_name, name, strlen(name)) == 0) - return -EEXIST; - } - - handler = e_dbus_signal_handler_add(edbus_conn, NULL, path, - interface, name, cb, NULL); - - if (!handler) { - _E("fail to add edbus handler"); - return -ENOMEM; - } - - entry = malloc(sizeof(struct edbus_list)); - - if (!entry) { - e_dbus_signal_handler_del(edbus_conn, handler); - _E("Malloc failed"); - return -ENOMEM; - } - - entry->signal_name = strndup(name, strlen(name)); - - if (!entry->signal_name) { - _E("Malloc failed"); - e_dbus_signal_handler_del(edbus_conn, handler); - free(entry); - return -ENOMEM; - } - - entry->handler = handler; - DD_LIST_PREPEND(edbus_handler_list, entry); - if (!edbus_handler_list) { - _E("dd_list_prepend failed"); - e_dbus_signal_handler_del(edbus_conn, handler); - free(entry->signal_name); - free(entry); - return -ENOMEM; - } - return 0; -} - -int unregister_edbus_signal_handler(const char *path, const char *interface, - const char *name) -{ - dd_list *tmp, *next; - struct edbus_list *entry; - - DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) { - if (strncmp(entry->signal_name, name, strlen(name) + 1) == 0) { - e_dbus_signal_handler_del(edbus_conn, entry->handler); - DD_LIST_REMOVE(edbus_handler_list, entry); - free(entry->signal_name); - free(entry); - return 0; - } - } - - return -1; -} - -int broadcast_edbus_signal(const char *path, const char *interface, - const char *name, const char *sig, char *param[]) -{ - DBusMessage *msg; - DBusMessageIter iter; - int r; - - msg = dbus_message_new_signal(path, interface, name); - if (!msg) { - _E("fail to allocate new %s.%s signal", interface, name); - return -EPERM; - } - - dbus_message_iter_init_append(msg, &iter); - /*r = append_variant(&iter, sig, param); - if (r < 0) { - _E("append_variant error(%d)", r); - return -EPERM; - }*/ - - r = dbus_connection_send(conn, msg, NULL); - dbus_message_unref(msg); - - if (r != TRUE) { - _E("dbus_connection_send error(%s:%s-%s)", - path, interface, name); - return -ECOMM; - } - - return 0; -} - -static void print_watch_item(void) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - dd_list *e; - - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - _D("watch sender : %s, deleted : %d", - watch->sender, watch->deleted); - DD_LIST_FOREACH(watch->func_list, e, finfo) - _D("\tfunc : %p, deleted : %d", - finfo->func, finfo->deleted); - } -} - -static bool get_valid_watch_item(void) -{ - struct watch_info *watch; - dd_list *elem; - - DD_LIST_FOREACH(edbus_watch_list, elem, watch) { - if (!watch->deleted) - return true; - } - - return false; -} - -static void watch_idler_cb(void *data) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - dd_list *next; - dd_list *elem; - dd_list *enext; - char match[256]; - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - if (!watch->deleted) - continue; - - /* remove dbus match */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_remove_match(conn, match, NULL); - - _I("%s is not watched by dbus!", watch->sender); - - /* remove watch func list */ - DD_LIST_FOREACH_SAFE(watch->func_list, elem, enext, finfo) - free(finfo); - - /* remove watch item */ - DD_LIST_FREE_LIST(watch->func_list); - DD_LIST_REMOVE_LIST(edbus_watch_list, n); - free(watch->sender); - free(watch); - } - - /* if the last request, remove message filter */ - if (!get_valid_watch_item()) - dbus_connection_remove_filter(conn, message_filter, NULL); -} - -static DBusHandlerResult message_filter(DBusConnection *connection, - DBusMessage *message, void *data) -{ - int ret; - const char *iface, *member; - const char *sender; - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - int len; - - if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - iface = dbus_message_get_interface(message); - member = dbus_message_get_member(message); - - if (strncmp(iface, DBUS_INTERFACE_DBUS, - sizeof(DBUS_INTERFACE_DBUS))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - if (strncmp(member, NAME_OWNER_CHANGED, - sizeof(NAME_OWNER_CHANGED))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - ret = dbus_message_get_args(message, NULL, - DBUS_TYPE_STRING, &sender, - DBUS_TYPE_INVALID); - if (!ret) { - _E("no message"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - len = strlen(sender) + 1; - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (!watch->deleted && - !strncmp(watch->sender, sender, len)) - break; - } - - if (!watch) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - DD_LIST_FOREACH(watch->func_list, n, finfo) { - if (!finfo->deleted && - finfo->func) - finfo->func(watch->sender, finfo->data); - } - - /* no interest in this item anymore */ - watch->deleted = true; - - print_watch_item(); - add_idle_request(watch_idler_cb, NULL); - return DBUS_HANDLER_RESULT_HANDLED; -} - -static struct watch_info *get_matched_watch_item(const char *sender) -{ - int len; - dd_list *n; - struct watch_info *watch; - - if (!sender) - return NULL; - - len = strlen(sender) + 1; - /* check the sender&type is already registered */ - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (!watch->deleted && - !strncmp(watch->sender, sender, len)) - return watch; - } - - return NULL; -} - -static struct watch_info *add_watch_item(const char *sender) -{ - DBusError err; - struct watch_info *watch; - char match[256]; - int ret; - - if (!sender) - return NULL; - - watch = calloc(1, sizeof(struct watch_info)); - if (!watch) - return NULL; - - watch->sender = strdup(sender); - if (!watch->sender) - goto out; - - dbus_error_init(&err); - /* add name owner changed match string */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_add_match(conn, match, &err); - - if (dbus_error_is_set(&err)) { - _E("fail to add match for %s [%s:%s]", - sender, err.name, err.message); - dbus_error_free(&err); - goto out; - } - - /* if the first request, add message filter */ - if (!get_valid_watch_item()) { - ret = dbus_connection_add_filter(conn, - message_filter, NULL, NULL); - if (!ret) { - _E("fail to add message filter!"); - dbus_bus_remove_match(conn, match, NULL); - goto out; - } - _I("success to add message filter!"); - } - - /* Add watch to watch list */ - DD_LIST_APPEND(edbus_watch_list, watch); - _I("%s is watched by dbus!", sender); - return watch; - -out: - if (watch) { - free(watch->sender); - free(watch); - } - - return NULL; -} - -int register_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data), void *data) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *elem; - bool isnew = false; - - if (!sender || !func) { - _E("invalid argument : sender(NULL) || func(NULL)"); - return -EINVAL; - } - - watch = get_matched_watch_item(sender); - if (!watch) { - /* create new watch item */ - watch = add_watch_item(sender); - if (!watch) { - _E("fail to add watch item"); - return -EPERM; - } - isnew = true; - } - - /* find the same callback */ - DD_LIST_FOREACH(watch->func_list, elem, finfo) { - if (finfo->func == func) { - _E("there is already the same callback"); - goto out; - } - } - - finfo = calloc(1, sizeof(struct watch_func_info)); - if (!finfo) { - _E("fail to allocate watch func info"); - goto out; - } - - finfo->func = func; - finfo->data = data; - - /* add callback function to the watch list */ - DD_LIST_APPEND(watch->func_list, finfo); - - _I("register watch func(%p) of %s", func, sender); - return 0; -out: - if (isnew) - watch->deleted = true; - - return -EPERM; -} - -int unregister_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data)) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *elem; - bool matched = false; - - if (!sender || !func) { - _E("invalid argument : sender(NULL) || func(NULL)"); - return -EINVAL; - } - - watch = get_matched_watch_item(sender); - if (!watch) { - _E("fail to get matched watch item"); - return -ENODEV; - } - - /* check the no interest function */ - DD_LIST_FOREACH(watch->func_list, elem, finfo) { - if (finfo->func == func) - finfo->deleted = true; - if (!finfo->deleted) - matched = true; - } - - /* if it is the last item */ - if (!matched) - watch->deleted = true; - - _I("unregister watch func(%p) of %s", func, sender); - return 0; -} - -static void unregister_edbus_watch_all(void) -{ - dd_list *n, *next; - struct watch_info *watch; - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) - watch->deleted = true; - - add_idle_request(watch_idler_cb, NULL); -} - -static int register_method(E_DBus_Interface *iface, - const struct edbus_method *edbus_methods, int size) -{ - int ret; - int i; - - assert(iface); - assert(edbus_methods); - - for (i = 0; i < size; i++) { - ret = e_dbus_interface_method_add(iface, - edbus_methods[i].member, - edbus_methods[i].signature, - edbus_methods[i].reply_signature, - edbus_methods[i].func); - if (!ret) { - _E("fail to add method %s!", edbus_methods[i].member); - return -EINVAL; - } - } - - return 0; -} - -int register_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size) -{ - struct edbus_object *obj; - dd_list *elem; - int ret; - - if (!path || !interface || !edbus_methods || size < 1) { - _E("invalid parameter"); - return -EINVAL; - } - - /* find matched obj */ - DD_LIST_FOREACH(edbus_object_list, elem, obj) { - if (strncmp(obj->path, path, strlen(obj->path)) == 0 && - strncmp(obj->interface, interface, strlen(obj->interface)) == 0) { - _I("found matched item : obj(%p)", obj); - break; - } - } - - /* if there is no matched obj */ - if (!obj) { - obj = malloc(sizeof(struct edbus_object)); - if (!obj) { - _E("fail to allocate %s interface", path); - return -ENOMEM; - } - - obj->path = strdup(path); - obj->interface = strdup(interface); - - ret = register_edbus_interface(obj); - if (ret < 0) { - _E("fail to register %s interface(%d)", obj->path, ret); - free(obj->path); - free(obj->interface); - free(obj); - return ret; - } - - DD_LIST_APPEND(edbus_object_list, obj); - } - - ret = register_method(obj->iface, edbus_methods, size); - if (ret < 0) { - _E("fail to register %s method(%d)", obj->path, ret); - return ret; - } - - return 0; -} - -int unregister_edbus_interface_all(void) -{ - struct edbus_object *obj; - dd_list *elem, *n; - - DD_LIST_FOREACH_SAFE(edbus_object_list, elem, n, obj) { - DD_LIST_REMOVE(edbus_object_list, obj); - free(obj->path); - free(obj->interface); - free(obj); - } - - return 0; -} - -int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size) -{ - E_DBus_Interface *iface; - int ret; - - if (!path || !edbus_methods || size < 1) { - _E("invalid parameter"); - return -EINVAL; - } - - iface = get_edbus_interface(path); - if (!iface) { - _E("fail to get edbus interface!"); - return -ENODEV; - } - - ret = register_method(iface, edbus_methods, size); - if (ret < 0) { - _E("fail to register %s method(%d)", path, ret); - return ret; - } - - return 0; -} - -static void request_name_cb(GVariant *var, void *user_data, GError *err) -{ - unsigned int val; - - if (!var) { - _D("invalid DBusMessage!"); - return; - } - - if (!dh_get_param_from_var(var, "(u)", &val)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _I("Request Name reply : %d", val); - -out: - g_variant_unref(var); -} - -static void check_owner_name(void) -{ - GVariant *msg; - char exe_name[PATH_MAX]; - char *entry; - dd_list *n; - int pid; - - DD_LIST_FOREACH(edbus_owner_list, n, entry) { - msg = dbus_method_sync_with_reply_var(E_DBUS_FDO_BUS, - E_DBUS_FDO_PATH, - E_DBUS_FDO_INTERFACE, - "GetConnectionUnixProcessID", g_variant_new("(s)", entry)); - - if (!msg) { - _E("invalid DBusMessage!"); - return; - } - - if (!dh_get_param_from_var(msg, "(i)", &pid)) { - _E("fail (%s): no message", "GetConnectionUnixProcessID"); - goto out; - } - - if (get_cmdline_name(pid, exe_name, PATH_MAX) != 0) - goto out; - _I("%s(%d)", exe_name, pid); - -out: - g_variant_unref(msg); - } -} - -static void check_owner_list(void) -{ - DBusError err; - DBusMessage *msg; - DBusMessageIter array, item; - char *pa[1]; - char *name; - char *entry; - - pa[0] = DEVICED_BUS_NAME; - msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, - E_DBUS_FDO_PATH, - E_DBUS_FDO_INTERFACE, - "ListQueuedOwners", "s", pa); - - if (!msg) { - _E("invalid DBusMessage!"); - return; - } - - dbus_error_init(&err); - dbus_message_iter_init(msg, &array); - - if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) - goto out; - dbus_message_iter_recurse(&array, &item); - while (dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_STRING) { - dbus_message_iter_get_basic(&item, &name); - entry = strndup(name, strlen(name)); - DD_LIST_APPEND(edbus_owner_list, entry); - if (!edbus_owner_list) { - _E("append failed"); - free(entry); - goto out; - } - dbus_message_iter_next(&item); - } - -out: - dbus_message_unref(msg); - dbus_error_free(&err); -} - -void edbus_init(void *data) -{ - int retry = 0; - int i, ret; - - dbus_handle_h handle; - - for (int i = 0 ; i < EDBUS_INIT_RETRY_COUNT; ++i) { - handle = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, FALSE); - if (handle) - break; - _E("fail to get dbus:retry %d", i); - } - if (!handle) { - _E("fail to get dbus"); - goto out1; - } - - for (int i = 0 ; i < EDBUS_INIT_RETRY_COUNT; ++i) { - ret = dbus_handle_request_bus_name(handle, DEVICED_BUS_NAME, NULL, NULL); - if (ret > 0) - break; - _E("failed to request bus name:retry %d", i); - } - if (ret <= 0) - goto out1; - - //check_owner_list(); - //check_owner_name(); - - return; - -out3: - //e_dbus_connection_close(edbus_conn); - return ; - -out2: - //dbus_connection_set_exit_on_disconnect(conn, FALSE); - return ; - -out1: - //e_dbus_shutdown(); - return ; -} - -void edbus_exit(void *data) -{ - unregister_edbus_signal_handle(); - unregister_edbus_watch_all(); - unregister_edbus_interface_all(); - e_dbus_connection_close(edbus_conn); - e_dbus_shutdown(); -} diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h deleted file mode 100644 index 9dfa21b..0000000 --- a/src/core/edbus-handler.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __EDBUS_HANDLE_H__ -#define __EDBUS_HANDLE_H__ - -#include -#include -#include - -struct edbus_method { - const char *member; - const char *signature; - const char *reply_signature; - E_DBus_Method_Cb func; -}; - -//static inline DBusMessage *make_reply_message(DBusMessage *msg, int ret) -//{ -// DBusMessageIter iter; -// DBusMessage *reply; -// reply = dbus_message_new_method_return(msg); -// dbus_message_iter_init_append(reply, &iter); -// dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); -// return reply; -//} - -DBusConnection *get_dbus_connection(void); -E_DBus_Object *register_edbus_object(const char *object_path, void *data); -void unregister_edbus_object(E_DBus_Object *object); -int register_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size); -int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size); -int register_edbus_signal_handler(const char *path, const char *interface, - const char *name, E_DBus_Signal_Cb cb); -int unregister_edbus_signal_handler(const char *path, const char *interface, - const char *name); -E_DBus_Interface *get_edbus_interface(const char *path); -pid_t get_edbus_sender_pid(DBusMessage *msg); -int broadcast_edbus_signal(const char *path, const char *interface, - const char *name, const char *sig, char *param[]); -int register_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data), void *data); -int unregister_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data)); - -void edbus_init(void *data); -void edbus_exit(void *data); - -#endif /* __EDBUS_HANDLE_H__ */ -- 2.7.4 From e7b237f6a720a632bf1b5b2bb00311ccd3b4bc03 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 1 Feb 2019 11:15:50 +0900 Subject: [PATCH 13/16] Coverity: 'handle' going out of scope Change-Id: Ib055cb0f12fd23d6c9750ef977b76c3d166203f8 Signed-off-by: Hyotaek Shim --- src/display/display-ops.h | 1 + src/shared/plugin.c | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/display/display-ops.h b/src/display/display-ops.h index 0477e71..93f8abe 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -47,6 +47,7 @@ void remove_display(const struct display_ops *disp); const struct display_ops *find_display_feature(const char *name); struct display_plugin { + void *handle; int (*pm_lock_internal) (pid_t pid, int s_bits, int flag, int timeout); int (*pm_unlock_internal) (pid_t pid, int s_bits, int flag); int (*pm_change_internal) (pid_t pid, int s_bits); diff --git a/src/shared/plugin.c b/src/shared/plugin.c index ba96073..72f291d 100644 --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -46,25 +46,26 @@ int load_plugin(const char *id, void **h) char path[PATH_MAX]; void *handle; - if (!id) + if (!id || !h) { + _E("Wrong parameters"); return -EINVAL; + } /* Find matched module path */ snprintf(path, sizeof(path), "%s/%s.so", MODULE_PATH, id); if (access(path, R_OK) != 0) { - _E("there is no %s device", id); + _E("There is no %s device", id); return -ENODEV; } /* Load module */ handle = dlopen(path, RTLD_NOW|RTLD_GLOBAL); if (!handle) { - _E("fail to open module : %s", dlerror()); + _E("Failed to open module: %s", dlerror()); return -ENOENT; } - if (h) - *h = handle; + *h = handle; return 0; } @@ -79,7 +80,7 @@ int unload_plugin(void *h) void load_plugins() { - load_plugin("display", NULL); + load_plugin("display", &disp_plgn.handle); return; } -- 2.7.4 From 220157bf923401b5eae46f43fb0c4d33fb5669f7 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 1 Feb 2019 13:54:32 +0900 Subject: [PATCH 14/16] Add dump module to get debug infomation for devices When dump signal is received, dump logs are saved under /var/log/deviced.log Change-Id: Idde9ce3bb02430e5373dbd953134e8e4acf46616 Signed-off-by: lokilee73 --- CMakeLists.txt | 4 ++ packaging/deviced.spec | 1 + src/core/devices.h | 2 + src/dump/dump.c | 127 ++++++++++++++++++++++++++++++++++++++++++ src/shared/log-macro.h | 3 + src/touchscreen/touchscreen.c | 21 +++++++ 6 files changed, 158 insertions(+) create mode 100644 src/dump/dump.c diff --git a/CMakeLists.txt b/CMakeLists.txt index daba64d..929c273 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,10 @@ IF(TOUCH_SENSITIVITY_MODULE STREQUAL on) SET(SRCS ${SRCS} src/touchscreen/sensitivity.c) ENDIF() +IF(DUMP_MODULE STREQUAL on) + SET(SRCS ${SRCS} src/dump/dump.c) +ENDIF() + IF(TZIP_MODULE STREQUAL on) ADD_SOURCE(src/tzip TZIP_SRCS) SET(SRCS ${SRCS} ${TZIP_SRCS}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index db995fd..893cdd9 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -158,6 +158,7 @@ Plugin libraries for IoT devices -DTIZEN_FEATURE_USBHOST_TEST=on \ -DTIZEN_FEATURE_BATTERY_OVER_TEMPERATURE=on \ -DTOUCH_SENSITIVITY_MODULE=on \ + -DDUMP_MODULE=on \ #eol %build diff --git a/src/core/devices.h b/src/core/devices.h index 8b7de5a..9e90422 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -58,6 +58,8 @@ struct device_ops { int (*execute) (void *data); void (*suspend) (void); void (*resume) (void); + int (*dump) (FILE *fp, int mode, void *dump_data); + void *dump_data; }; enum device_ops_status { diff --git a/src/dump/dump.c b/src/dump/dump.c new file mode 100644 index 0000000..f16e617 --- /dev/null +++ b/src/dump/dump.c @@ -0,0 +1,127 @@ +/* + * deviced + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include "core/log.h" +#include "core/list.h" +#include "core/common.h" +#include "core/devices.h" +#include + +#define SERVICE_NAME "deviced" +#define DUMP_SIGNAL "Dump" +#define DUMP_START_SIGNAL "Start" +#define DUMP_FINISH_SIGNAL "Finish" +#define DEFAULT_DUMP_PATH "/var/log" + +static void send_dump_signal(char *signal) +{ + int ret; + pid_t pid; + + pid = getpid(); + + ret = dbus_handle_broadcast_dbus_signal_var(DUMP_SERVICE_OBJECT_PATH, + DUMP_SERVICE_INTERFACE_NAME, signal, + g_variant_new("(i)", pid)); + if (ret < 0) + _E("Failed to send dbus signal(%s)", signal); +} + +static void dump_all_devices(int mode, char *path) +{ + dd_list *head = get_device_list_head(); + dd_list *elem; + FILE *fp = NULL; + char fname[PATH_MAX]; + const struct device_ops *dev; + + /* send start signal to dump service */ + send_dump_signal(DUMP_START_SIGNAL); + + /* open saved file */ + snprintf(fname, PATH_MAX, "%s/%s.log", path, SERVICE_NAME); + + if (path) + fp = fopen(fname, "w+"); + if (!fp) + _I("Failed to open %s, print to DLOG", fname); + + /* save dump each device ops */ + DD_LIST_FOREACH(head, elem, dev) { + if (dev->dump) { + _D("[%s] get dump", dev->name); + LOG_DUMP(fp, "\n==== %s\n\n", dev->name); + dev->dump(fp, mode, dev->dump_data); + } + } + + /* close file */ + if (fp) + fclose(fp); + + /* send finish signal to dump service */ + send_dump_signal(DUMP_FINISH_SIGNAL); + + _D("%s(%d) dump is saved!", fname, mode); +} + +static void dump_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) + +{ + int mode = 0; + char *log_path = NULL; + + g_variant_get(param, "(is)", &mode, &log_path); + _D("mode(%d) path(%s)", mode, log_path); + + dump_all_devices(mode, log_path); + g_free(log_path); +} + +static void dump_init(void *data) +{ + int ret; + + /* register dump signal */ + ret = subscribe_dbus_signal(NULL, + DUMP_SERVICE_OBJECT_PATH, + DUMP_SERVICE_INTERFACE_NAME, + DUMP_SIGNAL, + dump_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler! %d", ret); +} + +static const struct device_ops dump_device_ops = { + .name = "dump", + .init = dump_init, +}; + +DEVICE_OPS_REGISTER(&dump_device_ops) + diff --git a/src/shared/log-macro.h b/src/shared/log-macro.h index 8532b37..cb309af 100644 --- a/src/shared/log-macro.h +++ b/src/shared/log-macro.h @@ -48,4 +48,7 @@ #define _SW(...) do { } while (0) #define _SE(...) do { } while (0) #endif + +#define LOG_DUMP(fp, fmt, arg...) \ + do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while(0) #endif diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 64b62ca..1621c00 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -112,12 +112,33 @@ static int touchscreen_stop(enum device_flags flags) return touchscreen_set_state(TOUCHSCREEN_OFF); } +static int touchscreen_dump(FILE *fp, int mode, void *dump_data) +{ + int ret; + enum touchscreen_state state; + + if (!touchscreen_dev) + return 0; + + ret = touchscreen_dev->get_state(&state); + if (ret < 0) + _E("Failed to get touchscreen state : %d", ret); + + if (state == TOUCHSCREEN_ON) + LOG_DUMP(fp, "Touchscreen is enabled\n"); + else + LOG_DUMP(fp, "Touchscreen is disabled\n"); + + return 0; +} + static const struct device_ops touchscreen_device_ops = { .name = "touchscreen", .probe = touchscreen_probe, .exit = touchscreen_exit, .start = touchscreen_start, .stop = touchscreen_stop, + .dump = touchscreen_dump, }; DEVICE_OPS_REGISTER(&touchscreen_device_ops) -- 2.7.4 From a647a64ba1db2504683712aed7c5ec3f12185d18 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 1 Feb 2019 17:13:56 +0900 Subject: [PATCH 15/16] Plugin Architecture - for device module adaptation Change-Id: I5aef481d44b13c9cd3f8529cc04596d56a683f1c Signed-off-by: Hyotaek Shim --- src/core/devices.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/devices.c b/src/core/devices.c index 6dba16c..c196d14 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -36,19 +36,25 @@ dd_list *get_device_list_head(void) return dev_head; } +void remove_device(const struct device_ops *dev) +{ + DD_LIST_REMOVE(dev_head, dev); +} + void add_device(const struct device_ops *dev) { + const struct device_ops *ops = NULL; + + ops = find_device(dev->name); + if (ops != &default_ops) + remove_device(dev); + if (dev->priority == DEVICE_PRIORITY_HIGH) DD_LIST_PREPEND(dev_head, dev); else DD_LIST_APPEND(dev_head, dev); } -void remove_device(const struct device_ops *dev) -{ - DD_LIST_REMOVE(dev_head, dev); -} - const struct device_ops *find_device(const char *name) { dd_list *elem; -- 2.7.4 From c38d08fe9b8af07a063802da311982ae58d56a8e Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 1 Feb 2019 17:32:24 +0900 Subject: [PATCH 16/16] Fix deviced-shutdown installation The location should be /usr/lib/systemd/deviced-shutdown (for both 32-bit and 64-bit build) Change-Id: Ic31de51f4b2f848d2602f1dbc42d34283cc0f624 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 2 +- packaging/deviced.spec | 5 ++--- src/core/devices.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 929c273..4e5afc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,7 +235,7 @@ IF(POWER_MODULE STREQUAL on) ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/core/common.c src/core/execute.c) SET(deviced-shutdown_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(deviced-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) - INSTALL(TARGETS deviced-shutdown DESTINATION ${LIB_INSTALL_DIR}/systemd) + INSTALL(TARGETS deviced-shutdown DESTINATION /usr/lib/systemd) ENDIF() INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 893cdd9..91a1bc8 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -194,7 +194,7 @@ fi %preun # Assume power module is on (-DPOWER_MODULE=on) -update-alternatives --remove %{_libdir}/systemd/systemd-shutdown systemd-shutdown %{_libdir}/systemd/deviced-shutdown +update-alternatives --remove %{_prefix}/lib/systemd/systemd-shutdown systemd-shutdown %{_prefix}/lib/systemd/deviced-shutdown %postun systemctl daemon-reload @@ -249,8 +249,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %{_sysconfdir}/deviced/usb-host-test/strs # Assume power module is on (-DPOWER_MODULE=on) -%{_libdir}/systemd/deviced-shutdown - +%{_prefix}/lib/systemd/deviced-shutdown %files -n libdeviced %manifest deviced.manifest diff --git a/src/core/devices.c b/src/core/devices.c index c196d14..4785111 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -43,7 +43,7 @@ void remove_device(const struct device_ops *dev) void add_device(const struct device_ops *dev) { - const struct device_ops *ops = NULL; + const struct device_ops *ops; ops = find_device(dev->name); if (ops != &default_ops) -- 2.7.4