From 97944a0e4b0f04341925fbacafcb4147d81301b2 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 19 Aug 2021 17:41:20 +0900 Subject: [PATCH] Remove unused code Change-Id: Idcb99ab59dc44fee23d0fcbedfa80ade62ead57f Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 - plugins/iot-headed/display/core.c | 1 - plugins/mobile/display/core.c | 1 - plugins/tv/display/core.c | 1 - plugins/wearable/display/core.c | 1 - src/battery/lowbat-handler.c | 1 - src/core/launch.c | 356 -------------------------------------- src/core/launch.h | 32 ---- src/devicectl/usb.c | 1 - src/power/power-handler.c | 2 - 10 files changed, 397 deletions(-) delete mode 100644 src/core/launch.c delete mode 100644 src/core/launch.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 58e9a1e..a848a96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,6 @@ SET(SRCS src/core/devices.c src/core/event-handler.c src/core/execute.c - src/core/launch.c src/core/log.c src/core/main.c src/core/sig-handler.c diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 4974dec..f211259 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -51,7 +51,6 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 079351f..d381e31 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -50,7 +50,6 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 51b6f5d..47f74b0 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -50,7 +50,6 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 08fc114..9b58369 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -51,7 +51,6 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "core/launch.h" #include "apps/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 22a7415..66c324f 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -33,7 +33,6 @@ #include "battery.h" #include "config.h" #include "core/log.h" -#include "core/launch.h" #include "core/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" diff --git a/src/core/launch.c b/src/core/launch.c deleted file mode 100644 index 729a82a..0000000 --- a/src/core/launch.c +++ /dev/null @@ -1,356 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "log.h" -#include "launch.h" -#include "shared/common.h" - -#define MAX_ARGS 255 - -#define _S(str) ((str == NULL) ? "" : str) - -static int set_current_lang(void) -{ - char *lang; - int ret; - - lang = vconf_get_str(VCONFKEY_LANGSET); - if (lang == NULL) { - _E("Failed to get vconf value for langset: %d", vconf_get_ext_errno()); - return -1; - } - - ret = setenv("LANG", lang, 1); - free(lang); - if (ret < 0) - return -1; - else - return 0; -} - - -static void prepare_exec(void) -{ - int i; - int maxfd; - - maxfd = getdtablesize(); - for (i = 3; i < maxfd; i++) - close(i); - - for (i = 0; i < _NSIG; i++) - signal(i, SIG_DFL); -} - -static int parse_cmd(const char *cmdline, char **argv, int max_args) -{ - const char *p; - char *buf, *bufp; - int nargs = 0; - int escape = 0, squote = 0, dquote = 0; - int bufsize; - - if (cmdline == NULL || cmdline[0] == '\0') - return -1; - bufsize = strlen(cmdline)+1; - bufp = buf = malloc(bufsize); - if (bufp == NULL || buf == NULL) - return -1; - memset(buf, 0, bufsize); - p = cmdline; - - while (*p) { - if (escape) { - *bufp++ = *p; - escape = 0; - } else { - switch (*p) { - case '\\': - escape = 1; - break; - case '"': - if (squote) - *bufp++ = *p; - else - dquote = !dquote; - break; - case '\'': - if (dquote) - *bufp++ = *p; - else - squote = !squote; - break; - case ' ': - if (!squote && !dquote) { - *bufp = '\0'; - if (nargs < max_args) - argv[nargs++] = strdup(buf); - bufp = buf; - break; - } - default: - *bufp++ = *p; - break; - } - } - p++; - } - - if (bufp != buf) { - *bufp = '\0'; - if (nargs < max_args) - argv[nargs++] = strdup(buf); - } - - argv[nargs++] = NULL; - - free(buf); - return nargs; -} - -int launch_app_with_nice(const char *file, char *const argv[], pid_t *pid, int _nice) -{ - int ret; - int _pid; - int fd; - - if (file == NULL) { - _E("launch app error: There is no file"); - errno = EINVAL; - return -1; - } - - fd = open(file, O_RDONLY); - if (fd == -1) { - _E("launch app error: Invalid file"); - errno = EIO; - return -1; - } - close(fd); - - if (pid && (*pid > 0 && kill(*pid, 0) != -1)) - return *pid; - - _pid = fork(); - - if (_pid == -1) { - _E("Failed to fork: %d", errno); - /* keep errno */ - return -1; - } - - if (_pid > 0) { /* parent */ - if (pid) - *pid = _pid; - return _pid; - } - - /* child */ - prepare_exec(); - - ret = nice(_nice); - - if (ret == -1 && errno != 0) - _E("Failed to nice: %d", errno); - - ret = execvp(file, argv); - - /* If failed... */ - _E("Failed to exec: %d", errno); - return -2; -} - -int launch_app_cmd_with_nice(const char *cmdline, int _nice) -{ - int i; - int nargs; - int ret; - char *argv[MAX_ARGS + 1]; - - nargs = parse_cmd(cmdline, argv, MAX_ARGS + 1); - if (nargs == -1) { - _E("Launch app error: Invalid input"); - errno = EINVAL; - return -1; - } - - ret = launch_app_with_nice(argv[0], argv, NULL, _nice); - - for (i = 0; i < nargs; i++) - free(argv[i]); - - return ret; -} - -int launch_app_cmd(const char *cmdline) -{ - return launch_app_cmd_with_nice(cmdline, 0); -} - -#if 0 -int launch_if_noexist(const char *execpath, const char *arg, ...) -{ - char *buf; - int pid; - int nice_value = 0; - int flag = 0; - int buf_size = -1; - va_list argptr; - - if (execpath == NULL) { - errno = EINVAL; - return -1; - } - pid = get_exec_pid(execpath); - if (pid > 0) - return pid; - - va_start(argptr, arg); - flag = va_arg(argptr, int); - - if (flag & LAUNCH_NICE) - nice_value = va_arg(argptr, int); - - va_end(argptr); - - set_current_lang(); - arg = _S(arg); - - buf_size = strlen(execpath) + strlen(arg) + 10; - buf = malloc(buf_size); - if (buf == NULL) { - /* Do something for not enought memory error */ - _E("Malloc failed"); - return -1; - } - - snprintf(buf, buf_size, "%s %s", execpath, arg); - pid = launch_app_cmd_with_nice(buf, nice_value); - if (pid == -2) - exit(EXIT_FAILURE); - free(buf); - - return pid; -} -#endif - -int launch_evenif_exist(const char *execpath, const char *arg, ...) -{ - char *buf; - int pid; - int nice_value = 0; - int flag = 0; - int buf_size = -1; - - va_list argptr; - - if (execpath == NULL) { - errno = EINVAL; - return -1; - } - - va_start(argptr, arg); - flag = va_arg(argptr, int); - - if (flag & LAUNCH_NICE) - nice_value = va_arg(argptr, int); - - va_end(argptr); - - set_current_lang(); - - arg = _S(arg); - - buf_size = strlen(execpath) + strlen(arg) + 10; - buf = malloc(buf_size); - if (buf == NULL) { - _E("Failed to malloc."); - return -1; - } - - snprintf(buf, buf_size, "%s %s", execpath, arg); - pid = launch_app_cmd_with_nice(buf, nice_value); - if (pid == -2) - exit(EXIT_FAILURE); - free(buf); - - return pid; -} - -#if 0 -int launch_after_kill_if_exist(const char *execpath, const char *arg, ...) -{ - char *buf; - int pid; - int flag; - int buf_size; - int exist_pid; - va_list argptr; - int nice_value = 0; - - if (execpath == NULL) { - errno = EINVAL; - return -1; - } - - exist_pid = get_exec_pid(execpath); - if (exist_pid > 0) - kill(exist_pid, SIGTERM); - - va_start(argptr, arg); - flag = va_arg(argptr, int); - - if (flag & LAUNCH_NICE) - nice_value = va_arg(argptr, int); - - va_end(argptr); - - set_current_lang(); - - arg = _S(arg); - - buf_size = strlen(execpath) + strlen(arg) + 10; - buf = malloc(buf_size); - if (buf == NULL) { - /* Do something for not enought memory error */ - _E("Malloc Failed"); - return -1; - } - - snprintf(buf, buf_size, "%s %s", execpath, arg); - pid = launch_app_cmd_with_nice(buf, nice_value); - if (pid == -2) /* It means that the 'execvp' return -1 */ - exit(EXIT_FAILURE); - free(buf); - - return pid; - -} -#endif diff --git a/src/core/launch.h b/src/core/launch.h deleted file mode 100644 index 7c6d0dd..0000000 --- a/src/core/launch.h +++ /dev/null @@ -1,32 +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 __LAUNCH_H__ -#define __LAUNCH_H__ - -#define LAUNCH_NICE 0x0002 - -int launch_if_noexist(const char *execpath, const char *arg, ...); -int launch_evenif_exist(const char *execpath, const char *arg, ...); -int launch_after_kill_if_exist(const char *execpath, const char *arg, ...); - -int launch_app_cmd(const char *cmdline); -int launch_app_cmd_with_nice(const char *cmdline, int _nice); - -#endif /* __LAUNCH_H__ */ diff --git a/src/devicectl/usb.c b/src/devicectl/usb.c index 268c8d8..652f9e1 100644 --- a/src/devicectl/usb.c +++ b/src/devicectl/usb.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "usb.h" #define USB_SDB "sdb" diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 1d78523..df53032 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -39,12 +39,10 @@ #include "dd-deviced.h" #include "core/log.h" -#include "core/launch.h" #include "shared/device-notifier.h" #include "core/device-idler.h" #include "shared/common.h" #include "core/devices.h" -#include "core/launch.h" #include "display/poll.h" #include "display/setting.h" #include "display/core.h" -- 2.7.4