From 98cbdd4fe46e09c6303b467e63684af0d21bcb95 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 4 May 2021 10:30:29 +0900 Subject: [PATCH 01/16] Delete unused code Change-Id: I5f447ad74320615b40e3b8fd0a95ede0b76053ac Signed-off-by: Youngjae Cho --- src/core/common.c | 226 ------------------------------------------------------ src/core/common.h | 3 - 2 files changed, 229 deletions(-) diff --git a/src/core/common.c b/src/core/common.c index 5854082..f3c5e98 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -40,26 +40,10 @@ #include "log.h" #include "common.h" -#define PERMANENT_DIR "/tmp/permanent" -#define VIP_DIR "/tmp/vip" #define BUFF_MAX 255 #define APP_ATTR_PATH "/proc/%d/attr/current" -/** - * Opens "/proc/$pid/oom_score_adj" file for w/r; - * Return: FILE pointer or NULL - */ -FILE *open_proc_oom_score_adj_file(int pid, const char *mode) -{ - char buf[32]; - FILE *fp; - - snprintf(buf, sizeof(buf), "/proc/%d/oom_score_adj", pid); - fp = fopen(buf, mode); - return fp; -} - int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) { int fd, ret; @@ -96,21 +80,6 @@ int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) return 0; } -int is_vip(int pid) -{ - if (pid < 1) - return -1; - - char buf[PATH_MAX]; - - snprintf(buf, PATH_MAX, "%s/%d", VIP_DIR, pid); - - if (access(buf, R_OK) == 0) - return 1; - else - return 0; -} - int is_app(pid_t pid) { char attr[64]; @@ -523,18 +492,6 @@ void resume_path(const char *frz_name, const char *path) thaw_processes_on_path(frz_name); } -void print_time(const char *prefix) -{ - struct timeval tv; - struct tm tm; - struct tm *ret; - gettimeofday(&tv, NULL); - ret = localtime_r(&(tv.tv_sec), &tm); - if (ret) - _D("'%s' %d:%02d:%02d %06ld", - prefix, tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec); -} - int get_privilege(pid_t pid, char *name, size_t len) { char path[PATH_MAX]; @@ -659,186 +616,3 @@ int do_copy_force(const char *src, const char *dst) return do_copy_internal(src, dst, 0644, true); } - -#if 0 -int print_open_files(const char *mount_point) -{ - DIR *dp; - struct dirent entry; - struct dirent *dentry; - - DIR *dp_child; - struct dirent entry_child; - struct dirent *dentry_child; - - int pid = -1, fd; - int ret; - char buf[PATH_MAX]; - char buf2[PATH_MAX]; - - char cmdline[PATH_MAX]; - char check_path[PATH_MAX]; - - int len = strlen(mount_point); - - dp = opendir("/proc"); - if (!dp) { - _E("FAIL: open /proc"); - return -1; - } - - while (1) { - ret = readdir_r(dp, &entry, &dentry); - if (ret != 0 || dentry == NULL) - break; - - if (!isdigit(dentry->d_name[0])) - continue; - - pid = atoi(dentry->d_name); - snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid); - - fd = open(buf, O_RDONLY); - if (fd < 0) - continue; - ret = read(fd, cmdline, PATH_MAX); - close(fd); - - if (ret < 0 || ret >= PATH_MAX) - continue; - cmdline[ret] = '\0'; - - snprintf(buf, PATH_MAX, "/proc/%d/fd", pid); - dp_child = opendir(buf); - if (!dp_child) - continue; - while (1) { - ret = readdir_r(dp_child, &entry_child, &dentry_child); - if (ret != 0 || dentry_child == NULL) - break; - - snprintf(check_path, PATH_MAX, "%s/%s", buf, dentry_child->d_name); - - if (readlink(check_path, buf2, PATH_MAX) < 0) - continue; - - if (strncmp(buf2, mount_point, len) == 0) - _D("Process %s : Opened files - %s", cmdline, buf2); - } - closedir(dp_child); - } - - closedir(dp); - return 0; -} - -int get_exec_pid(const char *execpath) -{ - DIR *dp; - struct dirent entry; - struct dirent *dentry; - int pid = -1, fd; - int ret; - int len; - char buf[PATH_MAX]; - char buf2[PATH_MAX]; - - dp = opendir("/proc"); - if (!dp) { - _E("FAIL: open /proc"); - return -1; - } - - len = strlen(execpath) + 1; - while (1) { - ret = readdir_r(dp, &entry, &dentry); - if (ret != 0 || dentry == NULL) - break; - - if (!isdigit(dentry->d_name[0])) - continue; - - pid = atoi(dentry->d_name); - - snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid); - fd = open(buf, O_RDONLY); - if (fd < 0) - continue; - ret = read(fd, buf2, PATH_MAX); - close(fd); - - if (ret < 0 || ret >= PATH_MAX) - continue; - - buf2[ret] = '\0'; - - if (!strncmp(buf2, execpath, len)) { - closedir(dp); - return pid; - } - } - - errno = ESRCH; - closedir(dp); - return -1; -} - -static int get_num_thawed_processes(const char *path) -{ - char *fuser_cmd = NULL; - FILE *fuser_fp; - char *line = NULL; - size_t len = 0; - int num_processes = 0; - int ret; - - ret = asprintf(&fuser_cmd, "fuser -m %s | grep -o '[0-9]*'", path); - if (ret < 0) - return -1; - - fuser_fp = popen(fuser_cmd, "r"); - free(fuser_cmd); - if (fuser_fp == NULL) - return -1; - - while (getline(&line, &len, fuser_fp) != -1) { - char *stat_cmd = NULL; - FILE *stat_fp; - int pid; - char comm[128]; - char state = 0; - int str_len; - int ret; - - str_len = strlen(line); - if (str_len > 0) - // To remove '\n' - *(line+str_len-1) = 0; - - ret = asprintf(&stat_cmd, "cat /proc/%s/stat", line); - if (ret < 0) { - num_processes++; - continue; - } - - stat_fp = popen(stat_cmd, "r"); - free(stat_cmd); - if (stat_fp == NULL) { - num_processes++; - continue; - } - - fscanf(stat_fp, "%d %128s %c", &pid, comm, &state); - pclose(stat_fp); - - // if thawed - if (state != 'D') num_processes++; - } - - free(line); - pclose(fuser_fp); - - return num_processes; -} -#endif - diff --git a/src/core/common.h b/src/core/common.h index 04597ff..890f837 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -178,10 +178,8 @@ static inline void __cleanup_fclose_func(FILE **f) { #define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func) #endif -FILE * open_proc_oom_score_adj_file(int pid, const char *mode); int get_exec_pid(const char *execpath); int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); -int is_vip(int pid); int is_app(pid_t pid); int run_child(int argc, const char *argv[]); int sys_check_node(char *path); @@ -193,7 +191,6 @@ int terminate_process(const char *partition, bool force); int mount_check(const char* path); void suspend_path(const char *frz_name, const char *path, const int max_retry); void resume_path(const char *frz_name, const char *path); -void print_time(const char *prefix); void umount_partition_by_kill(const char *path, const int max_retry); int get_privilege(pid_t pid, char *name, size_t len); bool is_emulator(void); -- 2.7.4 From 952ef801c50527b0ab2c65738666cdd745b09785 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 14 May 2021 16:15:18 +0200 Subject: [PATCH 02/16] common: Make sys_{read,write}_buf public In addition to making functions public (non-static) this commit makes them return amount of bytes written, not 0, in case of success. This change is needed by next patch in the series. Change-Id: I558d13b44999b892bfd6d42ee9e057ee8f4b5d27 --- src/core/common.c | 18 ++++++++---------- src/core/common.h | 2 ++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/common.c b/src/core/common.c index f3c5e98..ad9e7fb 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -123,11 +123,10 @@ int sys_check_node(char *path) return 0; } -static int sys_read_buf(char *file, char *buf, int len) +int sys_read_buf(char *file, char *buf, int len) { int fd; int r; - int ret = 0; fd = open(file, O_RDONLY); if (fd == -1) @@ -138,19 +137,18 @@ static int sys_read_buf(char *file, char *buf, int len) buf[r] = '\0'; else { buf[0] = '\0'; - ret = -EIO; + r = -EIO; } close(fd); - return ret; + return r; } -static int sys_write_buf(char *file, char *buf) +int sys_write_buf(char *file, char *buf) { int fd; int r; - int ret = 0; fd = open(file, O_WRONLY); if (fd == -1) @@ -158,11 +156,11 @@ static int sys_write_buf(char *file, char *buf) r = write(fd, buf, strlen(buf)); if (r < 0) - ret = -EIO; + r = -EIO; close(fd); - return ret; + return r; } int sys_get_int(char *fname, int *val) @@ -173,7 +171,7 @@ int sys_get_int(char *fname, int *val) if (!fname || !val) return -EINVAL; - if (sys_read_buf(fname, buf, sizeof(buf)) == 0) { + if (sys_read_buf(fname, buf, sizeof(buf)) > 0) { *val = atoi(buf); } else { *val = -1; @@ -190,7 +188,7 @@ int sys_set_int(char *fname, int val) snprintf(buf, sizeof(buf), "%d", val); - if (sys_write_buf(fname, buf) != 0) + if (sys_write_buf(fname, buf) < 0) ret = -EIO; return ret; diff --git a/src/core/common.h b/src/core/common.h index 890f837..3c82365 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -183,6 +183,8 @@ int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); int is_app(pid_t pid); int run_child(int argc, const char *argv[]); int sys_check_node(char *path); +int sys_read_buf(char *file, char *buf, int len); +int sys_write_buf(char *file, char *buf); int sys_get_int(char *fname, int *val); int sys_set_int(char *fname, int val); int sys_get_str(char *fname, char *str, int len); -- 2.7.4 From 4c04c382919ba7365f9a728d7c87f03a56a680f8 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 10 May 2021 15:44:22 +0200 Subject: [PATCH 03/16] Rework reboot/shutdown/poweroff/halt command The provided utilities did not support all cases in which reboot and similar utilities needs to support, ie. - running when dbus service is not running (eg. in upgrade target) - being invoked from vip handler when system must reboot immediately This commit drops deviced custom tools - systemd native tools should be used instead. To ensure deviced is used during shutdown following is added: - deviced-request-shutdown utility and related service files These are installed as dependencies of systemd-standard shutdown procedure, causing these to be pulled automatically. Separate utility is added as, eg. dbus-send might not be available on production images. - /run/systemd/reboot-param handling is added This file is written by standard systemd reboot tool, so we need to both + read this file for reboot param in deviced-shutdown (needed if deviced was not used during shutdown) + read this file for deviced PowerOff argument (needed for normal operation) Change-Id: Ic013e6fa1f4848a17abc025cf99cffeea9916542 --- CMakeLists.txt | 9 +- packaging/deviced.spec | 37 ++-- src/core/common.c | 14 ++ src/core/common.h | 3 + src/power-command/command.c | 333 ++---------------------------- src/power-shutdown/shutdown.c | 18 +- systemd/deviced-request-shutdown@.service | 24 +++ 7 files changed, 86 insertions(+), 352 deletions(-) create mode 100644 systemd/deviced-request-shutdown@.service diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a7515c..be6292a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,11 +247,12 @@ IF(POWER_MODULE STREQUAL on) SET(deviced-shutdown_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(deviced-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) INSTALL(TARGETS deviced-shutdown DESTINATION /usr/lib/systemd) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown@.service DESTINATION /usr/lib/systemd/system) - ADD_EXECUTABLE(deviced-power-command src/power-command/command.c) - SET(deviced-power-command_LDFLAGS ${pkgs_LDFLAGS}) - TARGET_LINK_LIBRARIES(deviced-power-command ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) - INSTALL(TARGETS deviced-power-command DESTINATION /usr/sbin) + ADD_EXECUTABLE(deviced-request-shutdown src/power-command/command.c src/core/common.c src/core/execute.c) + SET(deviced-request-shutdown_LDFLAGS ${pkgs_LDFLAGS}) + TARGET_LINK_LIBRARIES(deviced-request-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) + INSTALL(TARGETS deviced-request-shutdown DESTINATION /usr/sbin) ENDIF() INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 89ce53e..143dbbf 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -184,22 +184,18 @@ rm -rf %{buildroot} %install_service basic.target.wants sdb-prestart.service %endif +for i in reboot halt poweroff exit; do + D=%{buildroot}%{_unitdir}/systemd-${i}.service.wants + mkdir -p $D + ln -s ../deviced-request-shutdown@.service $D/deviced-request-shutdown@${i}.service +done + mkdir -p %{buildroot}%{TZ_SYS_DUMPGEN} install -m 775 scripts/dump_pmstate_log.sh %{buildroot}%{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh -# Assume power module is on (-DPOWER_MODULE=on) -touch %{buildroot}%{_sbindir}/reboot -touch %{buildroot}%{_sbindir}/halt -touch %{buildroot}%{_sbindir}/poweroff -touch %{buildroot}%{_sbindir}/shutdown - %post # Assume power module is on (-DPOWER_MODULE=on) update-alternatives --install %{_prefix}/lib/systemd/systemd-shutdown systemd-shutdown %{_prefix}/lib/systemd/deviced-shutdown 500 -update-alternatives --install %{_sbindir}/reboot reboot %{_sbindir}/deviced-power-command 500 -update-alternatives --install %{_sbindir}/halt halt %{_sbindir}/deviced-power-command 500 -update-alternatives --install %{_sbindir}/poweroff poweroff %{_sbindir}/deviced-power-command 500 -update-alternatives --install %{_sbindir}/shutdown shutdown %{_sbindir}/deviced-power-command 500 #memory type vconf key init users_gid=$(getent group %{TZ_SYS_USER_GROUP} | cut -f3 -d':') @@ -213,15 +209,17 @@ fi # Assume power module is on (-DPOWER_MODULE=on) if [ $1 -eq 0 ] ; then update-alternatives --remove systemd-shutdown %{_prefix}/lib/systemd/deviced-shutdown - update-alternatives --remove reboot %{_sbindir}/deviced-power-command - update-alternatives --remove halt %{_sbindir}/deviced-power-command - update-alternatives --remove poweroff %{_sbindir}/deviced-power-command - update-alternatives --remove shutdown %{_sbindir}/deviced-power-command systemctl daemon-reload systemctl stop deviced.service fi +%posttrans +update-alternatives --remove reboot %{_sbindir}/deviced-power-command || : +update-alternatives --remove halt %{_sbindir}/deviced-power-command || : +update-alternatives --remove poweroff %{_sbindir}/deviced-power-command || : +update-alternatives --remove shutdown %{_sbindir}/deviced-power-command || : + %post -n libdeviced -p /sbin/ldconfig %postun -n libdeviced -p /sbin/ldconfig @@ -282,12 +280,13 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %{_unitdir}/mtp-responder-dummy.service # Assume power module is on (-DPOWER_MODULE=on) +%{_unitdir}/deviced-request-shutdown@.service +%{_unitdir}/systemd-exit.service.wants/deviced-request-shutdown@exit.service +%{_unitdir}/systemd-halt.service.wants/deviced-request-shutdown@halt.service +%{_unitdir}/systemd-reboot.service.wants/deviced-request-shutdown@reboot.service +%{_unitdir}/systemd-poweroff.service.wants/deviced-request-shutdown@poweroff.service %{_prefix}/lib/systemd/deviced-shutdown -%{_sbindir}/deviced-power-command -%ghost %{_sbindir}/reboot -%ghost %{_sbindir}/halt -%ghost %{_sbindir}/poweroff -%ghost %{_sbindir}/shutdown +%{_sbindir}/deviced-request-shutdown %files -n libdeviced %manifest deviced.manifest diff --git a/src/core/common.c b/src/core/common.c index ad9e7fb..cee9f52 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -219,6 +219,20 @@ int sys_set_str(char *fname, char *val) return r; } +int get_systemd_reboot_param(char *buf, unsigned bufsize) +{ + int r = sys_read_buf("/run/systemd/reboot-param", buf, bufsize); + if (r < 0) + return r; + + if (r > 0 && buf[r - 1] == '\n') { + buf[r - 1] = '\0'; + r -= 1; + } + + return r; +} + static int terminate_processes_on_partition(const char *partition, bool force) { const char *argv[7] = {"/usr/bin/fuser", "-m", "-k", "-s", NULL, NULL, NULL}; diff --git a/src/core/common.h b/src/core/common.h index 3c82365..bd02047 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -117,6 +117,8 @@ #define DATA_VALUE_INT(x) (*(int *)(x)) #define DATA_VALUE_BOOL(x) (*(bool *)(x)) +#define REBOOT_PARAM_MAXLEN 256 /* max param for reboot(2) *arg(ument), value checked in kernel v5.10:linux/kernel/reboot.c */ + #ifndef safe_free #define safe_free(x) safe_free_memory((void**)&(x)) #endif @@ -189,6 +191,7 @@ int sys_get_int(char *fname, int *val); int sys_set_int(char *fname, int val); int sys_get_str(char *fname, char *str, int len); int sys_set_str(char *fname, char *val); +int get_systemd_reboot_param(char *buf, unsigned bufsize); int terminate_process(const char *partition, bool force); int mount_check(const char* path); void suspend_path(const char *frz_name, const char *path, const int max_retry); diff --git a/src/power-command/command.c b/src/power-command/command.c index 808aa18..9b70fee 100644 --- a/src/power-command/command.c +++ b/src/power-command/command.c @@ -16,274 +16,20 @@ * limitations under the License. */ +#include +#include #include -#include #include #include -#include #include +#include +#include +#include -enum application { - APP_UNKNOWN, - APP_SHUTDOWN, - APP_REBOOT, - APP_HALT, - APP_POWEROFF, -}; - -struct { - const char *name; - enum application application; -} apps[] = { - { .name = "reboot", .application = APP_REBOOT, }, - { .name = "halt", .application = APP_HALT, }, - { .name = "poweroff", .application = APP_POWEROFF, }, - { .name = "shutdown", .application = APP_SHUTDOWN, }, -}; - -enum application parse_path(const char *name) -{ - const char *base = strrchr(name, '/'); - base = base ? base + 1 : name; - for (size_t i = 0; i < ARRAY_SIZE(apps); ++i) { - const char *target = apps[i].name; - - /* NB: We only check if the prefix matches, - * so that we can run "reboot" as, for example "reboot-custom". */ - if (strncmp(base, target, strlen(target)) == 0) - return apps[i].application; - } - return APP_UNKNOWN; -} - -/* NB: we are emulating different programs: the "shutdown" program, and the trio of "reboot", "halt" - * and "poweroff". These two cases have different option sets, so they need separate parsing methods - * and separate usage strings. */ - -struct parse_result { - enum { - DO_NOTHING, - SHOW_SHUTDOWN_PARSE_ERROR, - SHOW_REBOOT_ET_AL_PARSE_ERROR, - SHOW_SHUTDOWN_HELP, - SHOW_REBOOT_ET_AL_HELP, - DO_POWEROFF, - DO_EXIT, - DO_REBOOT, - } operation; - - const char *extra_option; - - bool show_sync_warning; - bool show_timings_warning; - bool show_wall_warning; - bool show_wtmp_warning; -}; - -struct parse_result parse_shutdown(int argc, char **argv) { - enum { - ACT_HALT, - ACT_REBOOT, - ACT_POWEROFF, - } action = ACT_POWEROFF; - bool will_do_nothing = false; - bool show_timings_warning = false; - bool show_wall_warning = false; - - for (;;) { - switch (getopt_long(argc, argv, "HPrhkc", (struct option []) { - { "help", no_argument, NULL, 0, }, - { "no-wall", no_argument, NULL, 1, }, - { "halt", no_argument, NULL, 'H', }, - { "poweroff", no_argument, NULL, 'P', }, - { "reboot", no_argument, NULL, 'r', }, - { NULL, 0, NULL, 0, }, - }, NULL)) { - case -1: - switch (argc - optind) { - case 2: - show_wall_warning = true; - show_timings_warning = true; - break; - - case 1: - show_timings_warning = true; - break; - - case 0: - break; - - default: - return (struct parse_result) { .operation = SHOW_SHUTDOWN_PARSE_ERROR, }; - } - - return (struct parse_result) { - .operation = will_do_nothing ? DO_NOTHING - : action == ACT_REBOOT ? DO_REBOOT - : action == ACT_HALT ? DO_EXIT // don't ask difficult questions like "why not DO_HALT" - : DO_POWEROFF, - .extra_option = NULL, - .show_sync_warning = false, - .show_timings_warning = show_timings_warning, - .show_wall_warning = show_wall_warning, - .show_wtmp_warning = false, - }; - - case 0: - return (struct parse_result) { .operation = SHOW_SHUTDOWN_HELP, }; - - case 1: - show_wall_warning = true; - break; - - case 'H': - action = ACT_HALT; - break; - - case 'P': - action = ACT_POWEROFF; - break; - - case 'r': - action = ACT_REBOOT; - break; - - case 'h': - if (action == ACT_REBOOT) - action = ACT_POWEROFF; - break; - - case 'k': - will_do_nothing = true; - show_wall_warning = true; - break; - - case 'c': - will_do_nothing = true; - show_timings_warning = true; - break; - - case '?': - return (struct parse_result) { .operation = SHOW_SHUTDOWN_PARSE_ERROR, }; - - default: - assert(false); - } - } -} - -struct parse_result parse_reboot_et_al(enum application application, int argc, char **argv) { - enum { - ACT_HALT, - ACT_REBOOT, - ACT_POWEROFF, - } action; - switch (application) { - case APP_REBOOT: - action = ACT_REBOOT; - break; - - case APP_HALT: - action = ACT_HALT; - break; - - case APP_POWEROFF: - action = ACT_POWEROFF; - break; - - default: - assert(false); - } - - bool will_do_nothing = false; - bool show_sync_warning = false; - bool show_timings_warning = false; - bool show_wall_warning = false; - bool show_wtmp_warning = false; - char *extra_option = NULL; - - for (;;) { - switch (getopt_long(argc, argv, "-pfwdn", (struct option []) { - { "help", no_argument, NULL, 0, }, - /* 1 reserved for options not in -foo format */ - { "halt", no_argument, NULL, 2, }, - { "reboot", no_argument, NULL, 3, }, - { "no-wall", no_argument, NULL, 4, }, - { "poweroff", no_argument, NULL, 'p', }, - { "force", no_argument, NULL, 'f', }, - { "wtmp-only", no_argument, NULL, 'w', }, - { "no-wtmp", no_argument, NULL, 'd', }, - { "no-sync", no_argument, NULL, 'n', }, - { NULL, 0, NULL, 0, }, - }, NULL)) { - case -1: - if (optind != argc) - return (struct parse_result) { .operation = SHOW_REBOOT_ET_AL_PARSE_ERROR, }; - - return (struct parse_result) { - .operation = will_do_nothing ? DO_NOTHING - : action == ACT_REBOOT ? DO_REBOOT - : action == ACT_HALT ? DO_EXIT - : DO_POWEROFF, - .extra_option = extra_option, - .show_sync_warning = show_sync_warning, - .show_timings_warning = show_timings_warning, - .show_wall_warning = show_wall_warning, - .show_wtmp_warning = show_wtmp_warning, - }; - - case 0: - return (struct parse_result) { .operation = SHOW_REBOOT_ET_AL_HELP, }; - - case 1: - if (extra_option) - return (struct parse_result) { .operation = SHOW_REBOOT_ET_AL_PARSE_ERROR, }; - extra_option = optarg; - break; - - case 2: - action = ACT_HALT; - break; - - case 3: - action = ACT_REBOOT; - break; - - case 4: - show_wall_warning = true; - break; - - case 'p': - action = ACT_POWEROFF; - break; - - case 'f': - show_timings_warning = false; - break; - - case 'w': - will_do_nothing = true; - show_wtmp_warning = true; - break; - - case 'd': - show_wtmp_warning = true; - break; - - case 'n': - show_sync_warning = true; - break; - - case '?': - return (struct parse_result) { .operation = SHOW_REBOOT_ET_AL_PARSE_ERROR, }; - - default: - assert(false); - } - } -} +#include +#include -int call_deviced_poweroff(const char *type, const char *extra_option, const char *message) +int call_deviced_poweroff(const char *type, const char *extra_option) { int ret_dbus = extra_option ? gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOffWithOption", g_variant_new("(ss)", type, extra_option), NULL) @@ -293,69 +39,22 @@ int call_deviced_poweroff(const char *type, const char *extra_option, const char fprintf(stderr, "Error: %d", ret_dbus); return EXIT_FAILURE; } - - fprintf(stderr, "%s", message); - for (;;) - pause(); return EXIT_SUCCESS; } int main(int argc, char **argv) { - enum application application = parse_path(argv[0]); - struct parse_result parse_result; - switch (application) { - case APP_UNKNOWN: - fprintf(stderr, "This program can only be used as a symlink to 'reboot', 'halt', 'poweroff' or 'shutdown'.\n"); - return EXIT_FAILURE; + const char *option = argc > 2 ? argv[2] : NULL; + const char *action = argc > 1 ? argv[1] : NULL; + char buf[REBOOT_PARAM_MAXLEN] = {0, }; - case APP_SHUTDOWN: - parse_result = parse_shutdown(argc, argv); - break; - - case APP_REBOOT: - case APP_HALT: - case APP_POWEROFF: - parse_result = parse_reboot_et_al(application, argc, argv); - break; - - default: - // This shouldn't be needed, but GCC complains otherwise. - assert(false); + if (!action) { + fprintf(stderr, "Usage: %s {action} [extra]\n", argv[0]); return EXIT_FAILURE; } - if (parse_result.show_sync_warning) - fprintf(stderr, "Warning: Tizen always syncs, sync options ignored.\n"); - if (parse_result.show_timings_warning) - fprintf(stderr, "Warning: %s doesn't take care of delayed and pending operations on Tizen.\n", argv[0]); - if (parse_result.show_wall_warning) - fprintf(stderr, "Warning: %s doesn't take care of wall messages on Tizen.\n", argv[0]); - if (parse_result.show_wtmp_warning) - fprintf(stderr, "Warning: %s doesn't take care of wtmp entries on Tizen.\n", argv[0]); - - switch (parse_result.operation) { - case DO_NOTHING: - return EXIT_SUCCESS; - - case SHOW_SHUTDOWN_HELP: - case SHOW_SHUTDOWN_PARSE_ERROR: - fprintf(stderr, "Usage: %s [-HPrh]\n", argv[0]); - return parse_result.operation == SHOW_SHUTDOWN_HELP ? EXIT_SUCCESS : EXIT_FAILURE; - - case SHOW_REBOOT_ET_AL_HELP: - case SHOW_REBOOT_ET_AL_PARSE_ERROR: - fprintf(stderr, "Usage: %s [-p] [--halt|--poweroff|--reboot] [extra]\n", argv[0]); // FIXME: do we say something about the extras? if yes, do we mention deviced, the configs etc? - return parse_result.operation == SHOW_REBOOT_ET_AL_HELP ? EXIT_SUCCESS : EXIT_FAILURE; - - case DO_POWEROFF: - return call_deviced_poweroff("poweroff", parse_result.extra_option, "Shutting down...\n"); // should be "Powering off" really, "shutting down" is the generic term also encompassing halt/reboot >_> - case DO_EXIT: - return call_deviced_poweroff("exit", parse_result.extra_option, "Shutting down...\n"); // ditto: exit ultimately boils down to poweroff, too - case DO_REBOOT: - return call_deviced_poweroff("reboot", parse_result.extra_option, "Rebooting...\n"); - } + if (!option && get_systemd_reboot_param(buf, sizeof buf) > 0) + option = buf; - assert(false); // unreachable - return EXIT_FAILURE; + return call_deviced_poweroff(action, option); } diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c index 010ac0b..92c6532 100644 --- a/src/power-shutdown/shutdown.c +++ b/src/power-shutdown/shutdown.c @@ -24,6 +24,7 @@ */ #include +#include #include #include #include @@ -76,18 +77,11 @@ static void sigchld(int signo) static void autoboot(void) { - static char buf[4096] = {0,}; - int fd = open("/run/reboot", O_RDONLY); // XXX POWER_FLAG_REBOOT - int ret; - - if (fd >= 0) { - ret = read(fd, buf, sizeof(buf) - 1); - if (ret < 0) { - ret = -errno; - printf("%s: fail to read reboot data(%d)\n", progname, ret); - } - close(fd); - } + static char buf[REBOOT_PARAM_MAXLEN] = {0, }; + + int r = sys_read_buf("/run/reboot", buf, sizeof buf); + if (r <= 0) + r = get_systemd_reboot_param(buf, sizeof buf); printf("%s: reboot param is <%s>\n", progname, buf); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, diff --git a/systemd/deviced-request-shutdown@.service b/systemd/deviced-request-shutdown@.service new file mode 100644 index 0000000..a202742 --- /dev/null +++ b/systemd/deviced-request-shutdown@.service @@ -0,0 +1,24 @@ +[Unit] +Description=Shutdown via deviced +DefaultDependencies=no +Before=final.target + +[Service] +Type=oneshot +# +# Request shutdown to be performed by deviced. +# +ExecStart=/usr/sbin/deviced-request-shutdown %i +# +# /bin/sleep below will be called only if above dbus call succeeded. +# deviced shutdown procedure includes handling client-defined timers, +# which is ability for some user process to delay shutdown in order +# to perform its deinitialization/shutdown procedure. +# deviced hardcodes that timers can take at most 10 seconds (from all +# clients combined), so we have to wait a bit more here to be sure +# that both deviced timers and other actions are performed completely. +# +# If dbus-send failed, the command below will not be executed - and systemd +# fallback action will be called immiedetely. +# +ExecStart=/bin/sleep 15 -- 2.7.4 From 870a4ae343830ff412f3def1b4635be092523f66 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 17 May 2021 18:03:22 +0200 Subject: [PATCH 04/16] shutdown: Ensure that shutdown goes through deviced, if it's available Change-Id: I9bfad72d41f340abb99dc44c2ec0b9e243301450 --- src/power-command/command.c | 78 ++++++++++++++++++++++++++++--- systemd/deviced-request-shutdown@.service | 13 ------ 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/src/power-command/command.c b/src/power-command/command.c index 9b70fee..037ddc6 100644 --- a/src/power-command/command.c +++ b/src/power-command/command.c @@ -16,6 +16,7 @@ * limitations under the License. */ +#include #include #include #include @@ -26,20 +27,83 @@ #include #include +#include #include + #include +#include + +#define DEVICED_CALL_MAX_TRIES 60 +#define DEVICED_CALL_INTERVAL_SECONDS 2 +#define DEVICED_SERVICE_NAME "deviced.service" + +/* State can be checked manually by calling: + * dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/deviced_2eservice org.freedesktop.DBus.Properties.Get string:org.freedesktop.systemd1.Unit string:ActiveState + * Reference: https://wiki.freedesktop.org/www/Software/systemd/dbus/ + */ +static bool service_is_inactive(const char *service) +{ + assert(service); + + GVariant *v = systemd_get_unit_property(service, "ActiveState"); + if (!v) + return false; + + if (!g_variant_type_equal(g_variant_get_type(v), G_VARIANT_TYPE_STRING)) { + CRITICAL_LOG("Unable to get " DEVICED_SERVICE_NAME " state. Assuming it's running"); + g_variant_unref(v); + return true; + } + + const char *state = g_variant_get_string(v, NULL); + bool inactive = strcmp(state, "failed") == 0 || strcmp(state, "inactive") == 0; + + CRITICAL_LOG("%s state is: %s (inactive: %s)", service, state, inactive ? "yes" : "no"); -int call_deviced_poweroff(const char *type, const char *extra_option) + g_variant_unref(v); + return inactive; +} + +static bool deviced_call_poweroff_once(const char *action, const char *extra_option) { + assert(action); + int ret_dbus = extra_option - ? gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOffWithOption", g_variant_new("(ss)", type, extra_option), NULL) - : gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOff", g_variant_new("(s)", type), NULL) + ? gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOffWithOption", g_variant_new("(ss)", action, extra_option), NULL) + : gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOff", g_variant_new("(s)", action), NULL) ; if (ret_dbus < 0) { - fprintf(stderr, "Error: %d", ret_dbus); - return EXIT_FAILURE; + CRITICAL_LOG("Error while calling deviced: %d", ret_dbus); + return false; + } else + CRITICAL_LOG("Succesfully requested shutdown using deviced"); + return true; +} + +static bool deviced_call_poweroff(const char *action, const char *extra_option) +{ + for (int i = 0; i < DEVICED_CALL_MAX_TRIES; i++) { + if (service_is_inactive(DEVICED_SERVICE_NAME)) { + CRITICAL_LOG(DEVICED_SERVICE_NAME " is inactive, will not request shutdown to it"); + return false; + } + + if (deviced_call_poweroff_once(action, extra_option)) { + /* Don't exit yet as this will cause "normal" systemd poweroff to happen, + * likely before deviced poweroff completes + */ + for (;;) + pause(); + return true; + } + + CRITICAL_LOG("Failed to request shutdown to deviced (try %d of %d). Will sleep %d seconds.", + i, DEVICED_CALL_MAX_TRIES, DEVICED_CALL_INTERVAL_SECONDS); + sleep(DEVICED_CALL_INTERVAL_SECONDS); } - return EXIT_SUCCESS; + + CRITICAL_LOG("Failed to shutdown system using deviced - falling back to systemd shutdown"); + return false; } int main(int argc, char **argv) @@ -56,5 +120,5 @@ int main(int argc, char **argv) if (!option && get_systemd_reboot_param(buf, sizeof buf) > 0) option = buf; - return call_deviced_poweroff(action, option); + return deviced_call_poweroff(action, option) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/systemd/deviced-request-shutdown@.service b/systemd/deviced-request-shutdown@.service index a202742..dcc12bc 100644 --- a/systemd/deviced-request-shutdown@.service +++ b/systemd/deviced-request-shutdown@.service @@ -9,16 +9,3 @@ Type=oneshot # Request shutdown to be performed by deviced. # ExecStart=/usr/sbin/deviced-request-shutdown %i -# -# /bin/sleep below will be called only if above dbus call succeeded. -# deviced shutdown procedure includes handling client-defined timers, -# which is ability for some user process to delay shutdown in order -# to perform its deinitialization/shutdown procedure. -# deviced hardcodes that timers can take at most 10 seconds (from all -# clients combined), so we have to wait a bit more here to be sure -# that both deviced timers and other actions are performed completely. -# -# If dbus-send failed, the command below will not be executed - and systemd -# fallback action will be called immiedetely. -# -ExecStart=/bin/sleep 15 -- 2.7.4 From 0642a4c78d0251c4f63764d0717fa390958a5b3e Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 31 May 2021 10:44:30 +0900 Subject: [PATCH 05/16] Specify User, Group, and Smack in deviced-request-shutdown@.service Change-Id: I1d46ab57aa5033595c64b3fe8a93b28da18fa2b0 Signed-off-by: Hyotaek Shim --- systemd/deviced-request-shutdown@.service | 3 +++ 1 file changed, 3 insertions(+) diff --git a/systemd/deviced-request-shutdown@.service b/systemd/deviced-request-shutdown@.service index dcc12bc..9ed1ef8 100644 --- a/systemd/deviced-request-shutdown@.service +++ b/systemd/deviced-request-shutdown@.service @@ -5,6 +5,9 @@ Before=final.target [Service] Type=oneshot +User=system_fw +Group=system_fw +SmackProcessLabel=System # # Request shutdown to be performed by deviced. # -- 2.7.4 From 28d9ffb4ecd5b2815fa57008ff5891cc1a295128 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 9 Jun 2021 19:34:48 +0900 Subject: [PATCH 06/16] Remove final.target dependency from reboot sequence Change-Id: I1fbc7a5eda461f90202db92093a60edbb63d3941 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 11 ++++++++++- packaging/deviced.spec | 14 ++++---------- systemd/deviced-request-shutdown-exit.conf | 3 +++ systemd/deviced-request-shutdown-halt.conf | 3 +++ systemd/deviced-request-shutdown-poweroff.conf | 3 +++ systemd/deviced-request-shutdown-reboot.conf | 3 +++ 6 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 systemd/deviced-request-shutdown-exit.conf create mode 100644 systemd/deviced-request-shutdown-halt.conf create mode 100644 systemd/deviced-request-shutdown-poweroff.conf create mode 100644 systemd/deviced-request-shutdown-reboot.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index be6292a..a6dc088 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,7 +247,16 @@ IF(POWER_MODULE STREQUAL on) SET(deviced-shutdown_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(deviced-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) INSTALL(TARGETS deviced-shutdown DESTINATION /usr/lib/systemd) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown@.service DESTINATION /usr/lib/systemd/system) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown@.service + DESTINATION /usr/lib/systemd/system) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown-reboot.conf + DESTINATION /usr/lib/systemd/system/systemd-reboot.service.d) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown-poweroff.conf + DESTINATION /usr/lib/systemd/system/systemd-poweroff.service.d) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown-halt.conf + DESTINATION /usr/lib/systemd/system/systemd-halt.service.d) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown-exit.conf + DESTINATION /usr/lib/systemd/system/systemd-exit.service.d) ADD_EXECUTABLE(deviced-request-shutdown src/power-command/command.c src/core/common.c src/core/execute.c) SET(deviced-request-shutdown_LDFLAGS ${pkgs_LDFLAGS}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 143dbbf..53096aa 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -184,12 +184,6 @@ rm -rf %{buildroot} %install_service basic.target.wants sdb-prestart.service %endif -for i in reboot halt poweroff exit; do - D=%{buildroot}%{_unitdir}/systemd-${i}.service.wants - mkdir -p $D - ln -s ../deviced-request-shutdown@.service $D/deviced-request-shutdown@${i}.service -done - mkdir -p %{buildroot}%{TZ_SYS_DUMPGEN} install -m 775 scripts/dump_pmstate_log.sh %{buildroot}%{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh @@ -281,10 +275,10 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so # Assume power module is on (-DPOWER_MODULE=on) %{_unitdir}/deviced-request-shutdown@.service -%{_unitdir}/systemd-exit.service.wants/deviced-request-shutdown@exit.service -%{_unitdir}/systemd-halt.service.wants/deviced-request-shutdown@halt.service -%{_unitdir}/systemd-reboot.service.wants/deviced-request-shutdown@reboot.service -%{_unitdir}/systemd-poweroff.service.wants/deviced-request-shutdown@poweroff.service +%{_unitdir}/systemd-reboot.service.d/deviced-request-shutdown-reboot.conf +%{_unitdir}/systemd-poweroff.service.d/deviced-request-shutdown-poweroff.conf +%{_unitdir}/systemd-halt.service.d/deviced-request-shutdown-halt.conf +%{_unitdir}/systemd-exit.service.d/deviced-request-shutdown-exit.conf %{_prefix}/lib/systemd/deviced-shutdown %{_sbindir}/deviced-request-shutdown diff --git a/systemd/deviced-request-shutdown-exit.conf b/systemd/deviced-request-shutdown-exit.conf new file mode 100644 index 0000000..66e49cb --- /dev/null +++ b/systemd/deviced-request-shutdown-exit.conf @@ -0,0 +1,3 @@ +[Unit] +Wants=deviced-request-shutdown@exit.service +After=deviced-request-shutdown@exit.service diff --git a/systemd/deviced-request-shutdown-halt.conf b/systemd/deviced-request-shutdown-halt.conf new file mode 100644 index 0000000..467068d --- /dev/null +++ b/systemd/deviced-request-shutdown-halt.conf @@ -0,0 +1,3 @@ +[Unit] +Wants=deviced-request-shutdown@halt.service +After=deviced-request-shutdown@halt.service diff --git a/systemd/deviced-request-shutdown-poweroff.conf b/systemd/deviced-request-shutdown-poweroff.conf new file mode 100644 index 0000000..0586d9d --- /dev/null +++ b/systemd/deviced-request-shutdown-poweroff.conf @@ -0,0 +1,3 @@ +[Unit] +Wants=deviced-request-shutdown@poweroff.service +After=deviced-request-shutdown@poweroff.service diff --git a/systemd/deviced-request-shutdown-reboot.conf b/systemd/deviced-request-shutdown-reboot.conf new file mode 100644 index 0000000..a784a88 --- /dev/null +++ b/systemd/deviced-request-shutdown-reboot.conf @@ -0,0 +1,3 @@ +[Unit] +Wants=deviced-request-shutdown@reboot.service +After=deviced-request-shutdown@reboot.service -- 2.7.4 From 12a9ee142e194f4b7203125e7f7e810ba16d6f5c Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 10 Jun 2021 16:13:31 +0900 Subject: [PATCH 07/16] deviced-common-private: new shared library for common code Generate libdeviced-common-private.so which contains common source code for reusability and testability. core/common.c -> shared/common.h (moved) core/common.h -> shared/common.h (merged) Change-Id: I3b631bcba58aeabc437a974c06e560b08b72768b Signed-off-by: Youngjae Cho --- CMakeLists.txt | 28 ++-- packaging/deviced.spec | 1 + plugins/iot/display/CMakeLists.txt | 2 +- plugins/iot/display/core.c | 2 +- plugins/iot/display/device-interface.c | 2 +- plugins/iot/display/key-filter.c | 2 +- plugins/mobile/battery/CMakeLists.txt | 2 +- plugins/mobile/display/CMakeLists.txt | 2 +- plugins/mobile/display/core.c | 2 +- plugins/mobile/display/device-interface.c | 2 +- plugins/mobile/display/key-filter.c | 2 +- plugins/tv/display/CMakeLists.txt | 2 +- plugins/tv/display/core.c | 2 +- plugins/tv/display/device-interface.c | 2 +- plugins/tv/display/key-filter.c | 2 +- plugins/tv/display/state-tv.c | 2 +- plugins/wearable/battery/CMakeLists.txt | 2 +- plugins/wearable/display/CMakeLists.txt | 2 +- plugins/wearable/display/bezel.c | 2 +- plugins/wearable/display/core.c | 2 +- plugins/wearable/display/device-interface.c | 2 +- plugins/wearable/display/display-handler.c | 2 +- plugins/wearable/display/enhance.c | 2 +- plugins/wearable/display/hbm.c | 2 +- plugins/wearable/display/key-filter.c | 2 +- plugins/wearable/display/lbm.c | 2 +- plugins/wearable/display/powersaver.c | 2 +- plugins/wearable/display/weaks.h | 2 +- src/apps/apps.c | 2 +- src/apps/apps.h | 2 +- src/auto-test/CMakeLists.txt | 2 +- src/auto-test/result.c | 2 +- src/auto-test/test.h | 2 +- src/battery-monitor/battery-monitor.c | 2 +- src/battery/battery-ops.c | 2 +- src/battery/battery-ops.h | 2 +- src/battery/battery-time.c | 2 +- src/battery/config.c | 2 +- src/battery/lowbat-handler.c | 2 +- src/control/control.c | 2 +- src/core/bitmap.h | 2 +- src/core/common.h | 208 ---------------------------- src/core/device-notifier.c | 2 +- src/core/devices.c | 1 - src/core/devices.h | 2 +- src/core/event-handler.c | 2 +- src/core/launch.c | 2 +- src/core/main.c | 2 +- src/core/sig-handler.c | 2 +- src/cpu/pmqos.c | 2 +- src/devicectl/CMakeLists.txt | 2 +- src/devicectl/devicectl.c | 2 +- src/devicectl/usb.c | 2 +- src/display/display-actor.c | 2 +- src/display/display-actor.h | 2 +- src/display/display-dbus.c | 2 +- src/display/display-lock.c | 2 +- src/display/display-ops.c | 2 +- src/display/display-ops.h | 2 +- src/display/display.c | 2 +- src/display/slave-logging.c | 2 +- src/dump/dump.c | 2 +- src/extcon/extcon-count.h | 2 +- src/extcon/extcon.c | 2 +- src/extcon/extcon.h | 2 +- src/ir/ir.c | 2 +- src/led/rgb.c | 2 +- src/libdeviced/usbhost.c | 2 - src/power-command/command.c | 2 +- src/power-shutdown/shutdown.c | 2 +- src/power/boot.c | 2 +- src/power/power-control.c | 2 +- src/power/power-handler.c | 2 +- src/proc/cpu-info.c | 2 +- src/shared/CMakeLists.txt | 22 --- src/{core => shared}/common.c | 0 src/shared/common.h | 172 +++++++++++++++++++++++ src/shared/eventsystem.c | 2 +- src/time/time-handler.c | 2 +- src/touchscreen/sensitivity.c | 2 +- src/touchscreen/touchscreen.c | 2 +- src/tzip/tzip.c | 2 +- 82 files changed, 263 insertions(+), 319 deletions(-) delete mode 100644 src/core/common.h delete mode 100644 src/shared/CMakeLists.txt rename src/{core => shared}/common.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6dc088..260a022 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,6 @@ SET(VERSION 0.1.0) SET(SRCS src/apps/apps.c src/control/control.c - src/core/common.c src/core/device-idler.c src/core/device-notifier.c src/core/devices.c @@ -198,9 +197,9 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) ENDIF() INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) +pkg_check_modules(REQUIRED_PKGS REQUIRED ${PKG_MODULES}) -FOREACH(flag ${pkgs_CFLAGS}) +FOREACH(flag ${REQUIRED_PKGS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -237,15 +236,21 @@ ENDIF() ADD_DEFINITIONS("-DDEBUG") +# Build libdeviced-common-private.so +FILE(GLOB SHARED_SRC "src/shared/*.c") +ADD_LIBRARY(deviced-common-private SHARED ${SHARED_SRC}) +TARGET_LINK_LIBRARIES(deviced-common-private ${REQUIRED_PKGS_LDFLAGS}) +INSTALL(TARGETS deviced-common-private DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -SET(deviced_LDFLAGS ${pkgs_LDFLAGS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) +SET(deviced_LDFLAGS ${REQUIRED_PKGS_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private) 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) + ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/shared/common.c src/core/execute.c) + SET(deviced-shutdown_LDFLAGS ${REQUIRED_PKGS_LDFLAGS}) + TARGET_LINK_LIBRARIES(deviced-shutdown ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private) INSTALL(TARGETS deviced-shutdown DESTINATION /usr/lib/systemd) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown@.service DESTINATION /usr/lib/systemd/system) @@ -258,9 +263,9 @@ IF(POWER_MODULE STREQUAL on) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown-exit.conf DESTINATION /usr/lib/systemd/system/systemd-exit.service.d) - ADD_EXECUTABLE(deviced-request-shutdown src/power-command/command.c src/core/common.c src/core/execute.c) - SET(deviced-request-shutdown_LDFLAGS ${pkgs_LDFLAGS}) - TARGET_LINK_LIBRARIES(deviced-request-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) + ADD_EXECUTABLE(deviced-request-shutdown src/power-command/command.c src/shared/common.c src/core/execute.c) + SET(deviced-request-shutdown_LDFLAGS ${REQUIRED_PKGS_LDFLAGS}) + TARGET_LINK_LIBRARIES(deviced-request-shutdown ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private) INSTALL(TARGETS deviced-request-shutdown DESTINATION /usr/sbin) ENDIF() @@ -317,7 +322,6 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) ENDIF() ADD_SUBDIRECTORY(src/battery-monitor) -ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/libdeviced) ADD_SUBDIRECTORY(src/devicectl) IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 53096aa..7c31df3 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -248,6 +248,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %manifest %{name}.manifest %license LICENSE.Apache-2.0 %{_bindir}/deviced +%{_libdir}/libdeviced-common-private.so %{_unitdir}/multi-user.target.wants/deviced.service %{_unitdir}/deviced.service %{_datadir}/dbus-1/system-services/org.tizen.system.deviced.service diff --git a/plugins/iot/display/CMakeLists.txt b/plugins/iot/display/CMakeLists.txt index 7af71d9..bb28cc3 100644 --- a/plugins/iot/display/CMakeLists.txt +++ b/plugins/iot/display/CMakeLists.txt @@ -26,7 +26,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} deviced-common-private) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME iot-display) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index ef4c534..9927e68 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -50,7 +50,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" -#include "core/common.h" +#include "shared/common.h" #include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 7b8d8d0..68c032d 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -36,7 +36,7 @@ #include "power/power-control.h" #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "util.h" #include "device-interface.h" diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 1cd3892..01a9e07 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -33,7 +33,7 @@ #include "poll.h" #include "display-actor.h" #include "display-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" diff --git a/plugins/mobile/battery/CMakeLists.txt b/plugins/mobile/battery/CMakeLists.txt index e427f65..c7792f6 100644 --- a/plugins/mobile/battery/CMakeLists.txt +++ b/plugins/mobile/battery/CMakeLists.txt @@ -22,7 +22,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} deviced-common-private) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME mobile-battery) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/mobile/display/CMakeLists.txt b/plugins/mobile/display/CMakeLists.txt index 4c2cfa3..40e9dd0 100644 --- a/plugins/mobile/display/CMakeLists.txt +++ b/plugins/mobile/display/CMakeLists.txt @@ -26,7 +26,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} deviced-common-private) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME mobile-display) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 067ed82..9d1bb66 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -49,7 +49,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" -#include "core/common.h" +#include "shared/common.h" #include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 4a0ab80..856883d 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -35,7 +35,7 @@ #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "util.h" #include "device-interface.h" diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 0c834f7..64321fa 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -33,7 +33,7 @@ #include "poll.h" #include "display-actor.h" #include "display-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" diff --git a/plugins/tv/display/CMakeLists.txt b/plugins/tv/display/CMakeLists.txt index 9b1ee5b..b597429 100644 --- a/plugins/tv/display/CMakeLists.txt +++ b/plugins/tv/display/CMakeLists.txt @@ -26,7 +26,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} deviced-common-private) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME tv-display) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 7d611e2..fba894b 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -49,7 +49,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" -#include "core/common.h" +#include "shared/common.h" #include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 2142e48..3cb3077 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -35,7 +35,7 @@ #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "util.h" #include "device-interface.h" diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 2e88788..0be1d72 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -33,7 +33,7 @@ #include "poll.h" #include "display-actor.h" #include "display-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 8a1fcfe..a92a557 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -20,7 +20,7 @@ #include #include -#include "core/common.h" +#include "shared/common.h" #include "core/log.h" #include "core/device-notifier.h" #include "core/devices.h" diff --git a/plugins/wearable/battery/CMakeLists.txt b/plugins/wearable/battery/CMakeLists.txt index 1932820..9573fea 100644 --- a/plugins/wearable/battery/CMakeLists.txt +++ b/plugins/wearable/battery/CMakeLists.txt @@ -22,7 +22,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} deviced-common-private) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME wearable-battery) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/wearable/display/CMakeLists.txt b/plugins/wearable/display/CMakeLists.txt index 0a4f329..74c2816 100644 --- a/plugins/wearable/display/CMakeLists.txt +++ b/plugins/wearable/display/CMakeLists.txt @@ -26,7 +26,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared batterymonitor) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} deviced-common-private batterymonitor) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME wearable-display) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 9cec8b3..c6868bd 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -20,7 +20,7 @@ #include #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "display/util.h" #include "display/poll.h" diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index b1f17a7..2747156 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -50,7 +50,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" -#include "core/common.h" +#include "shared/common.h" #include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index d674764..12f00d7 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -35,7 +35,7 @@ #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "util.h" #include "device-interface.h" diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index d4d9441..3df1a22 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -26,7 +26,7 @@ #include "display/util.h" #include "display/core.h" #include "display/poll.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "display/display-actor.h" #include "display/display-ops.h" diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index 24c34a7..8ad1418 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -27,7 +27,7 @@ #include "display/display-ops.h" #include "core/devices.h" #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #define VCONF_HIGH_CONTRAST VCONFKEY_SETAPPL_ACCESSIBILITY_HIGH_CONTRAST diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index d9d1be2..4c4b18e 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -27,7 +27,7 @@ #include "display/core.h" #include "display/display-ops.h" #include "display/display-dpms.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #define BOARD_CONF_FILE "/etc/deviced/display.conf" diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index ac438cd..0affed0 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -33,7 +33,7 @@ #include "poll.h" #include "display-actor.h" #include "display-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index 7e34b36..3f74391 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -27,7 +27,7 @@ #include "display/util.h" #include "display/core.h" #include "display/display-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" diff --git a/plugins/wearable/display/powersaver.c b/plugins/wearable/display/powersaver.c index e4ef88b..7aa8f99 100644 --- a/plugins/wearable/display/powersaver.c +++ b/plugins/wearable/display/powersaver.c @@ -19,7 +19,7 @@ #include -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" #include "core/log.h" diff --git a/plugins/wearable/display/weaks.h b/plugins/wearable/display/weaks.h index e8c764e..caf8693 100644 --- a/plugins/wearable/display/weaks.h +++ b/plugins/wearable/display/weaks.h @@ -20,7 +20,7 @@ #ifndef __DISPLAY_WEAKS_H__ #define __DISPLAY_WEAKS_H__ -#include "core/common.h" +#include "shared/common.h" #include "display/core.h" bool __WEAK__ get_outdoor_setting(void); diff --git a/src/apps/apps.c b/src/apps/apps.c index 6c33fad..dfe0a32 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -18,7 +18,7 @@ #include #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "apps.h" #include "shared/plugin.h" #include "core/bitmap.h" diff --git a/src/apps/apps.h b/src/apps/apps.h index 7ae83e3..8e6ac23 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -21,7 +21,7 @@ #include #include -#include "core/common.h" +#include "shared/common.h" #include "display/poll.h" #include "display/display-ops.h" diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index 5f20caf..e75088c 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -45,7 +45,7 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DENABLE_TEST_DLOG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${deviced_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${deviced_LDFLAGS} deviced-common-private) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-test.conf DESTINATION /etc/deviced) diff --git a/src/auto-test/result.c b/src/auto-test/result.c index a16441f..18b82df 100644 --- a/src/auto-test/result.c +++ b/src/auto-test/result.c @@ -20,7 +20,7 @@ #include #include -#include "core/common.h" +#include "shared/common.h" #ifdef ENABLE_TEST_DLOG #define ENABLE_DLOG diff --git a/src/auto-test/test.h b/src/auto-test/test.h index 17056da..da1d423 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -28,7 +28,7 @@ #include #include -#include "core/common.h" +#include "shared/common.h" #include "core/udev.h" #ifdef ENABLE_TEST_DLOG diff --git a/src/battery-monitor/battery-monitor.c b/src/battery-monitor/battery-monitor.c index 3e693fd..46c4dad 100644 --- a/src/battery-monitor/battery-monitor.c +++ b/src/battery-monitor/battery-monitor.c @@ -24,7 +24,7 @@ #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "display/core.h" #define DBUS_DEVICED "org.tizen.system.deviced" diff --git a/src/battery/battery-ops.c b/src/battery/battery-ops.c index 1d41a02..5322655 100644 --- a/src/battery/battery-ops.c +++ b/src/battery/battery-ops.c @@ -22,7 +22,7 @@ #include #include "battery-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "shared/log-macro.h" static GList *batt_head; diff --git a/src/battery/battery-ops.h b/src/battery/battery-ops.h index b9be61b..faee811 100644 --- a/src/battery/battery-ops.h +++ b/src/battery/battery-ops.h @@ -21,7 +21,7 @@ #define __BATTERY_OPS_H__ #include -#include "core/common.h" +#include "shared/common.h" #include "power-supply.h" #include diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 74718c0..68557af 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -24,7 +24,7 @@ #include #include -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/log.h" #include "core/udev.h" diff --git a/src/battery/config.c b/src/battery/config.c index 7858f5a..6bb21a3 100644 --- a/src/battery/config.c +++ b/src/battery/config.c @@ -27,7 +27,7 @@ #include #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "core/udev.h" #include "battery.h" #include "config.h" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 783499d..2e30239 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -36,7 +36,7 @@ #include "core/launch.h" #include "core/devices.h" #include "core/device-notifier.h" -#include "core/common.h" +#include "shared/common.h" #include "core/udev.h" #include "shared/eventsystem.h" #include "shared/plugin.h" diff --git a/src/control/control.c b/src/control/control.c index 66d564a..b2acac8 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -25,7 +25,7 @@ #include #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "extcon/extcon.h" diff --git a/src/core/bitmap.h b/src/core/bitmap.h index 6135b7c..902a44d 100644 --- a/src/core/bitmap.h +++ b/src/core/bitmap.h @@ -21,7 +21,7 @@ #include -#include "common.h" +#include "shared/common.h" /* Align bits by size of long, and convert it to long, * for example, if long is 64bit then, diff --git a/src/core/common.h b/src/core/common.h deleted file mode 100644 index bd02047..0000000 --- a/src/core/common.h +++ /dev/null @@ -1,208 +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 __CORE_COMMON_H__ -#define __CORE_COMMON_H__ - -#include -#include -#include -#include -#include -#include - -#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) -#define BYTES_PER_LONG (sizeof(unsigned long)) -#define BITS_PER_LONG (BYTES_PER_LONG * 8) -#define OFFSET(x) ((x) & (BITS_PER_LONG - 1)) -#define BIT(x) (1UL << OFFSET(x)) -#define LONG(x) ((x) / BITS_PER_LONG) - -/* - * One byte digit has 3 position in decimal representation - * 2 - 5 - * 4 - 10 - * 8 - 20 - * >8 - compile time error - * plus 1 null termination byte - * plus 1 for negative prefix - */ -#define MAX_DEC_SIZE(type) \ - (2 + (sizeof(type) <= 1 ? 3 : \ - sizeof(type) <= 2 ? 5 : \ - sizeof(type) <= 4 ? 10 : \ - sizeof(type) <= 8 ? 20 : \ - sizeof(int[-2*(sizeof(type) > 8)]))) - -#ifndef __CONSTRUCTOR__ -#define __CONSTRUCTOR__ __attribute__ ((constructor)) -#endif - -#ifndef __DESTRUCTOR__ -#define __DESTRUCTOR__ __attribute__ ((destructor)) -#endif - -#ifndef __WEAK__ -#define __WEAK__ __attribute__ ((weak)) -#endif - -#ifndef max -#define max(a, b) \ - __extension__ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a > _b ? _a : _b; \ - }) -#endif - -#ifndef min -#define min(a, b) \ - __extension__ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a < _b ? _a : _b; \ - }) -#endif - -#ifndef clamp -#define clamp(x, low, high) \ - __extension__ ({ \ - typeof(x) _x = (x); \ - typeof(low) _low = (low); \ - typeof(high) _high = (high); \ - ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ - }) -#endif - -/* Round up x to a multiple of y. - * y must be a power of 2, if not, use roundup() */ -#ifndef round_up -#define round_up(x, y) ((((x) - 1 ) | (typeof(x))((y) - 1)) + 1) -#endif - -/* Round up n to a multiple of d. */ -#ifndef roundup -#define roundup(n, d) ((((n) + (d) - 1) / (d)) * (d)) -#endif - -#ifndef SEC_TO_MSEC -#define SEC_TO_MSEC(x) ((x)*1000) -#endif -#ifndef MSEC_TO_USEC -#define MSEC_TO_USEC(x) ((unsigned int)(x)*1000) -#endif -#ifndef NSEC_TO_MSEC -#define NSEC_TO_MSEC(x) ((double)x/1000000) -#endif -#ifndef USEC_TO_MSEC -#define USEC_TO_MSEC(x) ((double)x/1000) -#endif - -#define DATA_VALUE_INT(x) (*(int *)(x)) -#define DATA_VALUE_BOOL(x) (*(bool *)(x)) - -#define REBOOT_PARAM_MAXLEN 256 /* max param for reboot(2) *arg(ument), value checked in kernel v5.10:linux/kernel/reboot.c */ - -#ifndef safe_free -#define safe_free(x) safe_free_memory((void**)&(x)) -#endif - -static inline void safe_free_memory(void** mem) -{ - if (mem && *mem) { - free(*mem); - *mem = NULL; - } -} - -#define ret_value_if(expr, val) do { \ - if (expr) { \ - _E("(%s)", #expr); \ - return (val); \ - } \ -} while (0) - -#define ret_value_msg_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - return val; \ - } \ -} while (0) - -#define ret_msg_if(expr, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - return; \ - } \ -} while (0) - -#ifndef _cleanup_ -#define _cleanup_(x) __attribute__((cleanup(x))) -#endif - -#ifndef _cleanup_close_ -static inline void __cleanup_close_func(int *fd) { - if (*fd >= 0) - close(*fd); -} -#define _cleanup_close_ _cleanup_(__cleanup_close_func) -#endif - -#ifndef _cleanup_closedir_ -static inline void __cleanup_closedir_func(DIR **d) { - if (*d) - closedir(*d); -} -#define _cleanup_closedir_ _cleanup_(__cleanup_closedir_func) -#endif - -#ifndef _cleanup_fclose_ -static inline void __cleanup_fclose_func(FILE **f) { - if (*f) - fclose(*f); -} -#define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func) -#endif - -int get_exec_pid(const char *execpath); -int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); -int is_app(pid_t pid); -int run_child(int argc, const char *argv[]); -int sys_check_node(char *path); -int sys_read_buf(char *file, char *buf, int len); -int sys_write_buf(char *file, char *buf); -int sys_get_int(char *fname, int *val); -int sys_set_int(char *fname, int val); -int sys_get_str(char *fname, char *str, int len); -int sys_set_str(char *fname, char *val); -int get_systemd_reboot_param(char *buf, unsigned bufsize); -int terminate_process(const char *partition, bool force); -int mount_check(const char* path); -void suspend_path(const char *frz_name, const char *path, const int max_retry); -void resume_path(const char *frz_name, const char *path); -void umount_partition_by_kill(const char *path, const int max_retry); -int get_privilege(pid_t pid, char *name, size_t len); -bool is_emulator(void); -int do_mkdir(const char *path, mode_t mode); -int do_copy_force(const char *src, const char *dst); -void watchdog_notify(void); -int print_open_files(const char *mount_point); - -#endif /* __CORE_COMMON_H__ */ - diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index 6b7ddc7..a967f44 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -19,7 +19,7 @@ #include "log.h" #include "device-notifier.h" -#include "common.h" +#include "shared/common.h" #include "core/devices.h" #include #include diff --git a/src/core/devices.c b/src/core/devices.c index f12e557..30ddbe6 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -21,7 +21,6 @@ #include #include "log.h" -#include "common.h" #include "devices.h" static const struct device_ops default_ops = { diff --git a/src/core/devices.h b/src/core/devices.h index 506bb87..e1a149d 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -23,7 +23,7 @@ #include #include -#include "common.h" +#include "shared/common.h" enum device_priority { DEVICE_PRIORITY_NORMAL = 0, diff --git a/src/core/event-handler.c b/src/core/event-handler.c index 7629d59..460a9da 100644 --- a/src/core/event-handler.c +++ b/src/core/event-handler.c @@ -21,7 +21,7 @@ #include #include -#include "common.h" +#include "shared/common.h" #include "devices.h" #include "device-notifier.h" #include "log.h" diff --git a/src/core/launch.c b/src/core/launch.c index 68007ae..729a82a 100644 --- a/src/core/launch.c +++ b/src/core/launch.c @@ -30,7 +30,7 @@ #include "log.h" #include "launch.h" -#include "common.h" +#include "shared/common.h" #define MAX_ARGS 255 diff --git a/src/core/main.c b/src/core/main.c index 3c957e4..da76606 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -29,7 +29,7 @@ #include "display/core.h" #include "log.h" -#include "common.h" +#include "shared/common.h" #include "devices.h" #include "power/boot.h" #include "power/power-handler.h" diff --git a/src/core/sig-handler.c b/src/core/sig-handler.c index dfb8dd1..bf19021 100644 --- a/src/core/sig-handler.c +++ b/src/core/sig-handler.c @@ -23,7 +23,7 @@ #include "log.h" #include "devices.h" -#include "common.h" +#include "shared/common.h" static struct sigaction sig_child_old_act; static struct sigaction sig_pipe_old_act; diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index ebf387e..ff7c886 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -27,7 +27,7 @@ #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #define DEFAULT_PMQOS_TIMER 3000 diff --git a/src/devicectl/CMakeLists.txt b/src/devicectl/CMakeLists.txt index 59c5851..88dd89f 100644 --- a/src/devicectl/CMakeLists.txt +++ b/src/devicectl/CMakeLists.txt @@ -32,7 +32,7 @@ IF( $ENV{ARCH} MATCHES "arm" ) ENDIF() ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} deviced-common-private) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 143da13..66704fa 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include "usb.h" /* diff --git a/src/devicectl/usb.c b/src/devicectl/usb.c index 37bc468..268c8d8 100644 --- a/src/devicectl/usb.c +++ b/src/devicectl/usb.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "usb.h" diff --git a/src/display/display-actor.c b/src/display/display-actor.c index 5f42050..3b9a324 100644 --- a/src/display/display-actor.c +++ b/src/display/display-actor.c @@ -22,7 +22,7 @@ #include "util.h" #include "display-actor.h" -#include "core/common.h" +#include "shared/common.h" static GList *actor_head; diff --git a/src/display/display-actor.h b/src/display/display-actor.h index 301d9ce..17f1be6 100644 --- a/src/display/display-actor.h +++ b/src/display/display-actor.h @@ -21,7 +21,7 @@ #define __DISPLAY_ACTOR_H__ #include -#include "core/common.h" +#include "shared/common.h" enum display_actor_id { DISPLAY_ACTOR_POWER_KEY = 1, diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 2c5c101..c2fb7f1 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -33,7 +33,7 @@ #include "util.h" #include "core.h" #include "lock-detector.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-idler.h" #include "core/device-notifier.h" diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 641aede..9fb232f 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -21,7 +21,7 @@ * @brief Manage each state's lock. Lock blocks state transition by timeout. * */ -#include "core/common.h" +#include "shared/common.h" #include "device-interface.h" #include "poll.h" #include "display.h" diff --git a/src/display/display-ops.c b/src/display/display-ops.c index d3c0d6d..d459aec 100644 --- a/src/display/display-ops.c +++ b/src/display/display-ops.c @@ -22,7 +22,7 @@ #include "util.h" #include "display-ops.h" -#include "core/common.h" +#include "shared/common.h" static GList *disp_head; diff --git a/src/display/display-ops.h b/src/display/display-ops.h index 0c014a8..5235ce7 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -21,7 +21,7 @@ #define __DISPLAY_OPS_H__ #include -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "display.h" diff --git a/src/display/display.c b/src/display/display.c index 6820ec8..871816f 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -25,7 +25,7 @@ #include "core.h" #include "display-ops.h" #include "dd-display.h" -#include "core/common.h" +#include "shared/common.h" static int pm_cur_state; static int pm_old_state; diff --git a/src/display/slave-logging.c b/src/display/slave-logging.c index f02bcd0..4243804 100644 --- a/src/display/slave-logging.c +++ b/src/display/slave-logging.c @@ -19,7 +19,7 @@ #include -#include "core/common.h" +#include "shared/common.h" #include "core/log.h" #include "display/core.h" #include "display/poll.h" diff --git a/src/dump/dump.c b/src/dump/dump.c index a86136e..ffb6f78 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -21,7 +21,7 @@ #include #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include #include diff --git a/src/extcon/extcon-count.h b/src/extcon/extcon-count.h index 82047c0..74d28d1 100644 --- a/src/extcon/extcon-count.h +++ b/src/extcon/extcon-count.h @@ -19,7 +19,7 @@ #ifndef __EXTCON_COUNT_H__ #define __EXTCON_COUNT_H__ -#include "core/common.h" +#include "shared/common.h" typedef enum { EXTCON_TA = 0, diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 1c28ceb..391bc88 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -23,7 +23,7 @@ #include #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index bc16a75..e4a4826 100644 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -20,7 +20,7 @@ #ifndef __EXTCON_H__ #define __EXTCON_H__ -#include "core/common.h" +#include "shared/common.h" #include #include #include "extcon-count.h" diff --git a/src/ir/ir.c b/src/ir/ir.c index 05f9a0e..f2bb1f7 100644 --- a/src/ir/ir.c +++ b/src/ir/ir.c @@ -21,7 +21,7 @@ #include #include #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/log.h" static bool ir_dev_available = false; diff --git a/src/led/rgb.c b/src/led/rgb.c index 2e4b45b..5dc4901 100644 --- a/src/led/rgb.c +++ b/src/led/rgb.c @@ -28,7 +28,7 @@ #include #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/device-notifier.h" diff --git a/src/libdeviced/usbhost.c b/src/libdeviced/usbhost.c index 713aacd..4a590e9 100644 --- a/src/libdeviced/usbhost.c +++ b/src/libdeviced/usbhost.c @@ -26,8 +26,6 @@ #include "common.h" #include "dd-usbhost.h" -#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) - #define METHOD_OPEN_DEVICE "OpenDevice" #define METHOD_REQUEST_STORAGE_INFO_ALL "StorageInfoAll" #define METHOD_REQUEST_STORAGE_MOUNT "StorageMount" diff --git a/src/power-command/command.c b/src/power-command/command.c index 037ddc6..397174d 100644 --- a/src/power-command/command.c +++ b/src/power-command/command.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c index 92c6532..81a49c2 100644 --- a/src/power-shutdown/shutdown.c +++ b/src/power-shutdown/shutdown.c @@ -38,7 +38,7 @@ #include "dd-deviced.h" #include "core/log.h" -#include "core/common.h" +#include "shared/common.h" enum { CMD_REBOOT, diff --git a/src/power/boot.c b/src/power/boot.c index 0f38a39..e4121ae 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -25,7 +25,7 @@ #include "core/log.h" #include "core/device-notifier.h" -#include "core/common.h" +#include "shared/common.h" #include "display/poll.h" #include "display/display-ops.h" #include "shared/plugin.h" diff --git a/src/power/power-control.c b/src/power/power-control.c index fa013a1..360fade 100644 --- a/src/power/power-control.c +++ b/src/power/power-control.c @@ -34,7 +34,7 @@ #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "vconf.h" #include "display/display-dpms.h" diff --git a/src/power/power-handler.c b/src/power/power-handler.c index fdc1540..c529e82 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -42,7 +42,7 @@ #include "core/launch.h" #include "core/device-notifier.h" #include "core/device-idler.h" -#include "core/common.h" +#include "shared/common.h" #include "core/devices.h" #include "core/launch.h" #include "display/poll.h" diff --git a/src/proc/cpu-info.c b/src/proc/cpu-info.c index 2fb1a57..fed0c19 100644 --- a/src/proc/cpu-info.c +++ b/src/proc/cpu-info.c @@ -22,7 +22,7 @@ #include "core/log.h" #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #define METHOD_GET_REVISION "GetRevision" #define PATH_NAME "/proc/cpuinfo" diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt deleted file mode 100644 index e0c9dcc..0000000 --- a/src/shared/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - -SET(SHARED_SRCS - plugin.c - eventsystem.c -) - -INCLUDE(FindPkgConfig) -pkg_check_modules(libshared REQUIRED - glib-2.0 - gio-2.0 - gio-unix-2.0 - dlog - eventsystem) - -FOREACH(flag ${libshared_CFLAGS}) - SET(SHARED_LIB_CFLAGS "${SHARED_LIB_CFLAGS} ${flag}") -ENDFOREACH(flag) - -ADD_LIBRARY(shared STATIC ${SHARED_SRCS}) -TARGET_LINK_LIBRARIES(shared ${libshared_LDFLAGS} "-ldl") -SET_TARGET_PROPERTIES(shared PROPERTIES COMPILE_FLAGS "-fPIC") diff --git a/src/core/common.c b/src/shared/common.c similarity index 100% rename from src/core/common.c rename to src/shared/common.c diff --git a/src/shared/common.h b/src/shared/common.h index 5a3ef23..84fb5d8 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -21,6 +21,10 @@ #include #include +#include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -42,6 +46,174 @@ extern "C" { #define __DESTRUCTOR__ __attribute__ ((destructor)) #endif +#ifndef __WEAK__ +#define __WEAK__ __attribute__ ((weak)) +#endif + +#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) +#define BYTES_PER_LONG (sizeof(unsigned long)) +#define BITS_PER_LONG (BYTES_PER_LONG * 8) +#define OFFSET(x) ((x) & (BITS_PER_LONG - 1)) +#define BIT(x) (1UL << OFFSET(x)) +#define LONG(x) ((x) / BITS_PER_LONG) + +/* + * One byte digit has 3 position in decimal representation + * 2 - 5 + * 4 - 10 + * 8 - 20 + * >8 - compile time error + * plus 1 null termination byte + * plus 1 for negative prefix + */ +#define MAX_DEC_SIZE(type) \ + (2 + (sizeof(type) <= 1 ? 3 : \ + sizeof(type) <= 2 ? 5 : \ + sizeof(type) <= 4 ? 10 : \ + sizeof(type) <= 8 ? 20 : \ + sizeof(int[-2*(sizeof(type) > 8)]))) + +#ifndef max +#define max(a, b) \ + __extension__ ({ \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + _a > _b ? _a : _b; \ + }) +#endif + +#ifndef min +#define min(a, b) \ + __extension__ ({ \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) +#endif + +#ifndef clamp +#define clamp(x, low, high) \ + __extension__ ({ \ + typeof(x) _x = (x); \ + typeof(low) _low = (low); \ + typeof(high) _high = (high); \ + ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ + }) +#endif + +/* Round up x to a multiple of y. + * y must be a power of 2, if not, use roundup() */ +#ifndef round_up +#define round_up(x, y) ((((x) - 1 ) | (typeof(x))((y) - 1)) + 1) +#endif + +/* Round up n to a multiple of d. */ +#ifndef roundup +#define roundup(n, d) ((((n) + (d) - 1) / (d)) * (d)) +#endif + +#ifndef SEC_TO_MSEC +#define SEC_TO_MSEC(x) ((x)*1000) +#endif +#ifndef MSEC_TO_USEC +#define MSEC_TO_USEC(x) ((unsigned int)(x)*1000) +#endif +#ifndef NSEC_TO_MSEC +#define NSEC_TO_MSEC(x) ((double)x/1000000) +#endif +#ifndef USEC_TO_MSEC +#define USEC_TO_MSEC(x) ((double)x/1000) +#endif + +#define DATA_VALUE_INT(x) (*(int *)(x)) +#define DATA_VALUE_BOOL(x) (*(bool *)(x)) + +#define REBOOT_PARAM_MAXLEN 256 /* max param for reboot(2) *arg(ument), value checked in kernel v5.10:linux/kernel/reboot.c */ + +#ifndef safe_free +#define safe_free(x) safe_free_memory((void**)&(x)) +#endif + +static inline void safe_free_memory(void** mem) +{ + if (mem && *mem) { + free(*mem); + *mem = NULL; + } +} + +#define ret_value_if(expr, val) do { \ + if (expr) { \ + _E("(%s)", #expr); \ + return (val); \ + } \ +} while (0) + +#define ret_value_msg_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + _E(fmt, ##arg); \ + return val; \ + } \ +} while (0) + +#define ret_msg_if(expr, fmt, arg...) do { \ + if (expr) { \ + _E(fmt, ##arg); \ + return; \ + } \ +} while (0) + +#ifndef _cleanup_ +#define _cleanup_(x) __attribute__((cleanup(x))) +#endif + +#ifndef _cleanup_close_ +static inline void __cleanup_close_func(int *fd) { + if (*fd >= 0) + close(*fd); +} +#define _cleanup_close_ _cleanup_(__cleanup_close_func) +#endif + +#ifndef _cleanup_closedir_ +static inline void __cleanup_closedir_func(DIR **d) { + if (*d) + closedir(*d); +} +#define _cleanup_closedir_ _cleanup_(__cleanup_closedir_func) +#endif + +#ifndef _cleanup_fclose_ +static inline void __cleanup_fclose_func(FILE **f) { + if (*f) + fclose(*f); +} +#define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func) +#endif + +int get_exec_pid(const char *execpath); +int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); +int is_app(pid_t pid); +int run_child(int argc, const char *argv[]); +int sys_check_node(char *path); +int sys_read_buf(char *file, char *buf, int len); +int sys_write_buf(char *file, char *buf); +int sys_get_int(char *fname, int *val); +int sys_set_int(char *fname, int val); +int sys_get_str(char *fname, char *str, int len); +int sys_set_str(char *fname, char *val); +int get_systemd_reboot_param(char *buf, unsigned bufsize); +int terminate_process(const char *partition, bool force); +int mount_check(const char* path); +void suspend_path(const char *frz_name, const char *path, const int max_retry); +void resume_path(const char *frz_name, const char *path); +void umount_partition_by_kill(const char *path, const int max_retry); +int get_privilege(pid_t pid, char *name, size_t len); +bool is_emulator(void); +int do_mkdir(const char *path, mode_t mode); +int do_copy_force(const char *src, const char *dst); +void watchdog_notify(void); +int print_open_files(const char *mount_point); #ifdef __cplusplus } diff --git a/src/shared/eventsystem.c b/src/shared/eventsystem.c index 05f45c1..b0e86f7 100644 --- a/src/shared/eventsystem.c +++ b/src/shared/eventsystem.c @@ -20,7 +20,7 @@ #include #include "eventsystem.h" -#include "core/common.h" +#include "shared/common.h" #include "log.h" static bundle *b; diff --git a/src/time/time-handler.c b/src/time/time-handler.c index fcf6a3d..b510fe8 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -38,7 +38,7 @@ #include "display/poll.h" #include "display/core.h" #include "display/display-ops.h" -#include "core/common.h" +#include "shared/common.h" #include "core/device-notifier.h" #include "shared/plugin.h" diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c index 13c75b7..3b383f4 100644 --- a/src/touchscreen/sensitivity.c +++ b/src/touchscreen/sensitivity.c @@ -22,7 +22,7 @@ #include #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/log.h" #include "core/device-notifier.h" diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 21032a1..621c977 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -23,7 +23,7 @@ #include #include #include "core/devices.h" -#include "core/common.h" +#include "shared/common.h" #include "core/log.h" #include "core/device-notifier.h" #include "battery/power-supply.h" diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 88c4802..edf7faa 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -41,7 +41,7 @@ #include "core/log.h" #include "core/devices.h" #include "core/device-notifier.h" -#include "core/common.h" +#include "shared/common.h" #include "tzip-utility.h" #define PACKAGE_UNPACK_PATH "/opt/usr/share/package-unpacked" -- 2.7.4 From 5291bc71935a53a6919f60f07f3fa828662b59e5 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 10 Jun 2021 18:42:58 +0900 Subject: [PATCH 08/16] usb-host-test: fix resource leak Change-Id: I86a76faca13ffd9a930d947fe92be58328586e25 --- src/usb-host-test/usb-host-test.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index aeccc82..aa85476 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -81,17 +81,20 @@ static int load_module(const char *name, const char *options) ret = kmod_module_get_initstate(mod); if (ret >= 0) { + kmod_module_unref(mod); _I("module(%s) already loaded.", name); goto out; /* already loaded */ } ret = kmod_module_probe_insert_module(mod, 0, options, NULL, NULL, NULL); if (ret < 0) { + kmod_module_unref(mod); _E("Module(%s) insert error.", name); goto out; } ++n; + kmod_module_unref(mod); } if (n == 0) { @@ -161,16 +164,20 @@ static int unload_module(const char *name) } ret = kmod_module_get_initstate(mod); - if (ret < 0) + if (ret < 0) { + kmod_module_unref(mod); goto out; /* not loaded */ + } ret = remove_module(mod); if (ret < 0) { + kmod_module_unref(mod); _E("Module(%s) remove error.", name); goto out; } ++n; + kmod_module_unref(mod); } if (n == 0) { -- 2.7.4 From 19cdcd0124772c2d657dc6e269149d0e87bf2662 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 11 Jun 2021 13:28:23 +0900 Subject: [PATCH 09/16] Fix build warning Change-Id: I3a913e36e3482255f81a658ec8e28e25b24c1b97 Signed-off-by: Youngjae Cho --- packaging/deviced.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 7c31df3..8261d44 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -141,7 +141,7 @@ Plugin libraries for IoT devices %define battery_module on -%cmake \ +%cmake . \ -DTZ_SYS_ETC=%TZ_SYS_ETC \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ -DARCH=%{ARCH} \ -- 2.7.4 From 8d3e996a621b4b4283312d12ec7d8bb4bb95e146 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 11 Jun 2021 15:02:51 +0900 Subject: [PATCH 10/16] common: move file IO to libsyscommon Change-Id: Id9d27b95808d8a8c540cd46c67db1996007944db Signed-off-by: Youngjae Cho --- src/shared/common.c | 96 ----------------------------------------------------- src/shared/common.h | 7 +--- 2 files changed, 1 insertion(+), 102 deletions(-) diff --git a/src/shared/common.c b/src/shared/common.c index cee9f52..af6e980 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -123,102 +123,6 @@ int sys_check_node(char *path) return 0; } -int sys_read_buf(char *file, char *buf, int len) -{ - int fd; - int r; - - fd = open(file, O_RDONLY); - if (fd == -1) - return -ENOENT; - - r = read(fd, buf, len); - if ((r >= 0) && (r < len)) - buf[r] = '\0'; - else { - buf[0] = '\0'; - r = -EIO; - } - - close(fd); - - return r; -} - -int sys_write_buf(char *file, char *buf) -{ - int fd; - int r; - - fd = open(file, O_WRONLY); - if (fd == -1) - return -ENOENT; - - r = write(fd, buf, strlen(buf)); - if (r < 0) - r = -EIO; - - close(fd); - - return r; -} - -int sys_get_int(char *fname, int *val) -{ - char buf[BUFF_MAX]; - int ret = 0; - - if (!fname || !val) - return -EINVAL; - - if (sys_read_buf(fname, buf, sizeof(buf)) > 0) { - *val = atoi(buf); - } else { - *val = -1; - ret = -EIO; - } - - return ret; -} - -int sys_set_int(char *fname, int val) -{ - char buf[BUFF_MAX]; - int ret = 0; - - snprintf(buf, sizeof(buf), "%d", val); - - if (sys_write_buf(fname, buf) < 0) - ret = -EIO; - - return ret; -} - -int sys_get_str(char *fname, char *str, int len) -{ - int ret; - - if (!fname || !str || len < 0) - return -EINVAL; - - ret = sys_read_buf(fname, str, len); - if (ret < 0) - return ret; - return 0; -} - -int sys_set_str(char *fname, char *val) -{ - int r = -1; - - if (val != NULL) { - if (sys_write_buf(fname, val) == 0) - r = 0; - } - - return r; -} - int get_systemd_reboot_param(char *buf, unsigned bufsize) { int r = sys_read_buf("/run/systemd/reboot-param", buf, bufsize); diff --git a/src/shared/common.h b/src/shared/common.h index 84fb5d8..a912486 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -196,12 +197,6 @@ int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); int is_app(pid_t pid); int run_child(int argc, const char *argv[]); int sys_check_node(char *path); -int sys_read_buf(char *file, char *buf, int len); -int sys_write_buf(char *file, char *buf); -int sys_get_int(char *fname, int *val); -int sys_set_int(char *fname, int val); -int sys_get_str(char *fname, char *str, int len); -int sys_set_str(char *fname, char *val); int get_systemd_reboot_param(char *buf, unsigned bufsize); int terminate_process(const char *partition, bool force); int mount_check(const char* path); -- 2.7.4 From 4237b62aa734e21356f59d659c05ea59d8bc4253 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 14 Jun 2021 11:07:00 +0900 Subject: [PATCH 11/16] board: renaming get_device_serial_number Change-Id: Ic25d4697a90da5a71a9a93ccd6d081491bc3214e Signed-off-by: Youngjae Cho --- src/board/board-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/board/board-info.c b/src/board/board-info.c index eb2710d..b656596 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -60,7 +60,7 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, GVariant *result; char *serial = NULL; - ret = hal_device_board_get_device_serial(&serial); + ret = hal_device_board_get_device_serial_number(&serial); if (!board_dev_available || (ret == -ENODEV)) { _E("GetSerial not supported."); ret = -ENOTSUP; @@ -95,7 +95,7 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, GVariant *result; char *num = NULL; - ret = hal_device_board_get_device_serial(&num); + ret = hal_device_board_get_device_serial_number(&num); if (!board_dev_available || (ret == -ENODEV)) { _E("GetNum not supported."); ret = -ENOTSUP; -- 2.7.4 From 382352ee8799cff282dc663ab7afc475e814d2d2 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 15 Jun 2021 15:16:43 +0900 Subject: [PATCH 12/16] Change timeout way of reboot command Change-Id: I92f4f05a367c6229e6781f29457c89682d45de14 Signed-off-by: taemin.yeom --- src/power-command/command.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/power-command/command.c b/src/power-command/command.c index 397174d..868a666 100644 --- a/src/power-command/command.c +++ b/src/power-command/command.c @@ -33,9 +33,11 @@ #include #include -#define DEVICED_CALL_MAX_TRIES 60 -#define DEVICED_CALL_INTERVAL_SECONDS 2 -#define DEVICED_SERVICE_NAME "deviced.service" +#include + +#define DEVICED_CALL_MAX_SECONDS 120 +#define DEVICED_CALL_INTERVAL_SECONDS 1 +#define DEVICED_SERVICE_NAME "deviced.service" /* State can be checked manually by calling: * dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/deviced_2eservice org.freedesktop.DBus.Properties.Get string:org.freedesktop.systemd1.Unit string:ActiveState @@ -66,8 +68,12 @@ static bool service_is_inactive(const char *service) static bool deviced_call_poweroff_once(const char *action, const char *extra_option) { + static bool reboot_triggered = false; assert(action); + if (reboot_triggered) + return true; + int ret_dbus = extra_option ? gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOffWithOption", g_variant_new("(ss)", action, extra_option), NULL) : gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOff", g_variant_new("(s)", action), NULL) @@ -77,29 +83,30 @@ static bool deviced_call_poweroff_once(const char *action, const char *extra_opt return false; } else CRITICAL_LOG("Succesfully requested shutdown using deviced"); + + reboot_triggered = true; return true; } static bool deviced_call_poweroff(const char *action, const char *extra_option) { - for (int i = 0; i < DEVICED_CALL_MAX_TRIES; i++) { + struct timespec begin, now; + device_power_request_lock(POWER_LOCK_CPU, 0); + clock_gettime(CLOCK_MONOTONIC, &begin); + + while (true) { if (service_is_inactive(DEVICED_SERVICE_NAME)) { CRITICAL_LOG(DEVICED_SERVICE_NAME " is inactive, will not request shutdown to it"); return false; } - if (deviced_call_poweroff_once(action, extra_option)) { - /* Don't exit yet as this will cause "normal" systemd poweroff to happen, - * likely before deviced poweroff completes - */ - for (;;) - pause(); - return true; - } - - CRITICAL_LOG("Failed to request shutdown to deviced (try %d of %d). Will sleep %d seconds.", - i, DEVICED_CALL_MAX_TRIES, DEVICED_CALL_INTERVAL_SECONDS); + deviced_call_poweroff_once(action, extra_option); + CRITICAL_LOG("Deviced call poweroff and will sleep %d second.", DEVICED_CALL_INTERVAL_SECONDS); sleep(DEVICED_CALL_INTERVAL_SECONDS); + + clock_gettime(CLOCK_MONOTONIC, &now); + if ((now.tv_sec - begin.tv_sec) >= DEVICED_CALL_MAX_SECONDS) + break; } CRITICAL_LOG("Failed to shutdown system using deviced - falling back to systemd shutdown"); -- 2.7.4 From 198b243d72907f43d5f056db536427cdf2151761 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 18 Jun 2021 19:45:49 +0900 Subject: [PATCH 13/16] board: fix parameter of get_deviec_serial_number() Change-Id: I4c9d3adbe0226afafd35c8597cb1d8787b70f428 Signed-off-by: Hyotaek Shim --- src/board/board-info.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/board/board-info.c b/src/board/board-info.c index b656596..1ab3986 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -23,6 +23,7 @@ #include "core/devices.h" #include +#define SERIAL_MAX 128 static bool board_dev_available = false; static GVariant *dbus_revision_handler(GDBusConnection *conn, @@ -58,9 +59,9 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, { int ret; GVariant *result; - char *serial = NULL; + char serial[SERIAL_MAX] = {0, }; - ret = hal_device_board_get_device_serial_number(&serial); + ret = hal_device_board_get_device_serial_number(serial, SERIAL_MAX); if (!board_dev_available || (ret == -ENODEV)) { _E("GetSerial not supported."); ret = -ENOTSUP; @@ -75,13 +76,10 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, _D("Num(%s) len(%zu).", serial, strlen(serial)); num_out: - if (serial == NULL) - serial = strdup(""); - - result = g_variant_new("(si)", serial, ret); - - if (serial) - free(serial); + if (ret < 0) + result = g_variant_new("(si)", strdup(""), ret); + else + result = g_variant_new("(si)", serial, ret); return result; } @@ -93,9 +91,9 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, int ret; char *p; GVariant *result; - char *num = NULL; + char serial[SERIAL_MAX] = {0, }; - ret = hal_device_board_get_device_serial_number(&num); + ret = hal_device_board_get_device_serial_number(serial, SERIAL_MAX); if (!board_dev_available || (ret == -ENODEV)) { _E("GetNum not supported."); ret = -ENOTSUP; @@ -107,20 +105,17 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, goto seiral_out; } - p = strchr(num, ','); + p = strchr(serial, ','); if (p) *p = '\0'; - _D("Serial(%s) len(%zu).", num, strlen(num)); + _D("Serial(%s) len(%zu).", serial, strlen(serial)); seiral_out: - if (num == NULL) - num = strdup(""); - - result = g_variant_new("(si)", num, ret); - - if (num) - free(num); + if (ret < 0) + result = g_variant_new("(si)", strdup(""), ret); + else + result = g_variant_new("(si)", serial, ret); return result; } -- 2.7.4 From 2c30543ef0dc25c2739fea9bb155162f1bf637f6 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 21 Jun 2021 12:27:40 +0900 Subject: [PATCH 14/16] board: fix memory leak Change-Id: Icc8d5138643557b83acbba7b7d5df8b26f4b092e Signed-off-by: Hyotaek Shim --- src/board/board-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/board/board-info.c b/src/board/board-info.c index 1ab3986..f44264c 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -77,7 +77,7 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, num_out: if (ret < 0) - result = g_variant_new("(si)", strdup(""), ret); + result = g_variant_new("(si)", "", ret); else result = g_variant_new("(si)", serial, ret); @@ -113,7 +113,7 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, seiral_out: if (ret < 0) - result = g_variant_new("(si)", strdup(""), ret); + result = g_variant_new("(si)", "", ret); else result = g_variant_new("(si)", serial, ret); -- 2.7.4 From 49637ff12757aa16823c2b81d500e5e853d03d9d Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Wed, 21 Jul 2021 10:16:49 +0900 Subject: [PATCH 15/16] udev: change the name of udev monitor buffer size Change-Id: Ibf9f2a76da7483751ab921c8e5ae38ac1c1a4d1b --- src/core/udev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/udev.c b/src/core/udev.c index 9209c2b..34fe171 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -31,7 +31,7 @@ #define KERNEL "kernel" #define UDEV "udev" -#define UDEV_MONITOR_SIZE (128*1024) +#define UDEV_MONITOR_BUFFER_SIZE (128*1024) struct uevent_info { struct udev_monitor *mon; @@ -130,9 +130,9 @@ static int uevent_control_start(const char *type, goto stop; } - _I("Set udev monitor buffer size(%d).", UDEV_MONITOR_SIZE); + _I("Set udev monitor buffer size(%d).", UDEV_MONITOR_BUFFER_SIZE); ret = udev_monitor_set_receive_buffer_size(info->mon, - UDEV_MONITOR_SIZE); + UDEV_MONITOR_BUFFER_SIZE); if (ret != 0) { _E("Failed to set receive buffer size."); goto stop; -- 2.7.4 From bac7f031b3e9ab7bc0322f33f214935af6d36b1f Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 21 Jul 2021 11:50:45 +0900 Subject: [PATCH 16/16] battery: bug fix regarding pm_lock_internal() check Change-Id: Ic119e32dfe3513910dcb2660e26ab2a25dade34c Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f42b8aa..bf09758 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -750,20 +750,20 @@ static void update_battery_cycle(void) static void process_power_supply(void *data) { bool broadcasted = true; - int lock = -1; + int ret_lock = -1; int ret_val; _D("process_power_supply()"); - if (disp_plgn->pm_lock_internal) { - lock = disp_plgn->pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + ret_lock = disp_plgn->pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); + if (old_battery.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { - ret_val = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); - if (ret_val < 0) - _E("Failed to set vconf value for battery charge now: %d", vconf_get_ext_errno()); + ret_val = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); + if (ret_val < 0) + _E("Failed to set vconf value for battery charge now: %d", vconf_get_ext_errno()); - if (power_supply_broadcast(CHARGE_NOW_SIGNAL, battery.charge_now) < 0) - broadcasted = false; - } + if (power_supply_broadcast(CHARGE_NOW_SIGNAL, battery.charge_now) < 0) + broadcasted = false; } if (!strcmp(old_battery.status_s, CHARGEFULL_NAME) && @@ -860,9 +860,11 @@ static void process_power_supply(void *data) } update_capacity_full(); update_battery_cycle(); - if (lock == 0) { - if (disp_plgn->pm_unlock_internal) + + if (disp_plgn->pm_unlock_internal) { + if (ret_lock == 0) { disp_plgn->pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); + } } } -- 2.7.4