From: jy910.yun Date: Wed, 19 Jun 2013 13:27:34 +0000 (+0900) Subject: merge sysman library in system-server repo X-Git-Tag: submit/tizen/20141222.083159~198 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c98e211a7097f62669f3da68c12d4e14a2694d7c;p=platform%2Fcore%2Fsystem%2Fdeviced.git merge sysman library in system-server repo previous patch merged power-manager into system-server and it will be "deviced" daemon. a daemon provides a library for daemon if it doesn't have any special reason. So this patch merge sysman into libdeviced. and before long other library such as libslp-pm(pmapi) and devman merged into a libdeviced. Signed-off-by: giyeol.ok Change-Id: Idd5077216894ba41de91959a74d04844306f9e41 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6330c9d..ef8f15e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ SET(DEVICED_SRCS SET(DEVICED_HEADERS src/deviced/dd-battery.h) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/display) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/display ${CMAKE_CURRENT_SOURCE_DIR}/sysman) # libdeviced INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) @@ -62,7 +62,6 @@ pkg_check_modules(pkgs REQUIRED ecore-x edbus eina - sysman vconf heynoti pmapi @@ -139,3 +138,4 @@ ADD_SUBDIRECTORY(sys_event) ADD_SUBDIRECTORY(pm_event) ADD_SUBDIRECTORY(sys_device_noti) ADD_SUBDIRECTORY(sys_pci_noti) +ADD_SUBDIRECTORY(sysman) diff --git a/display/setting.c b/display/setting.c index 24e39d4..9e5a20d 100644 --- a/display/setting.c +++ b/display/setting.c @@ -18,7 +18,7 @@ #include #include -#include +#include "util.h" #include "setting.h" #include "conf.h" diff --git a/packaging/sysman.manifest b/packaging/sysman.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/sysman.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/system-server.spec b/packaging/system-server.spec index 10d056b..ec35d2e 100755 --- a/packaging/system-server.spec +++ b/packaging/system-server.spec @@ -6,14 +6,14 @@ Release: 7 Group: Framework/system License: Apache License, Version 2.0 Source0: system-server-%{version}.tar.gz -Source2: system-server.manifest -Source3: deviced.manifest +Source1: system-server.manifest +Source2: deviced.manifest +Source3: sysman.manifest BuildRequires: cmake BuildRequires: libattr-devel BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(heynoti) BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(sysman) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(pmapi) BuildRequires: pkgconfig(edbus) @@ -36,7 +36,45 @@ Requires(post): /usr/bin/vconftool Requires(postun): /usr/bin/systemctl %description -Description: System server +system server + +%package system-server +Summary: system-server daemon +Group: main +Requires: %{name} = %{version}-%{release} + +%description system-server +system server daemon. + +%package -n sysman +Summary: sysman library +License: LGPL +Group: main +Requires: %{name} = %{version}-%{release} +#Provides: sysman + +%description -n sysman +sysman library. + +%package -n sysman-devel +Summary: sysman devel library +License: LGPL +Group: main +Requires: %{name} = %{version}-%{release} +#Provides: sysman-devel + +%description -n sysman-devel +sysman devel library. + +%package -n sysman-internal-devel +Summary: sysman internal devel library +License: LGPL +Group: main +Requires: %{name} = %{version}-%{release} +#Provides: sysman-internal-devel + +%description -n sysman-internal-devel +sysman internal devel library. %package -n libdeviced Summary: Deviced library @@ -58,6 +96,7 @@ Deviced library for device control (devel) cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} %build +cp %{SOURCE1} . cp %{SOURCE2} . cp %{SOURCE3} . make %{?jobs:-j%jobs} @@ -144,7 +183,7 @@ fi systemctl daemon-reload -%files +%files -n system-server %manifest system-server.manifest %{_bindir}/system_server /opt/etc/smack/accesses.d/system-server.rule @@ -170,6 +209,26 @@ systemctl daemon-reload %{_datadir}/system-server/sys_pci_noti/res/locale/*/LC_MESSAGES/*.mo %config %{_sysconfdir}/dbus-1/system.d/system-server.conf +%files -n sysman +%manifest sysman.manifest +%defattr(-,root,root,-) +%{_libdir}/libsysman.so.* +%{_bindir}/regpmon +%{_bindir}/set_pmon + +%files -n sysman-devel +%defattr(-,root,root,-) +%{_includedir}/sysman/sysman.h + +%{_includedir}/sysman/sysman_managed.h +%{_includedir}/sysman/SLP_sysman_PG.h +%{_libdir}/pkgconfig/sysman.pc +%{_libdir}/libsysman.so + +%files -n sysman-internal-devel +%defattr(-,root,root,-) +%{_includedir}/sysman/sysman-internal.h + %files -n libdeviced %defattr(-,root,root,-) %{_libdir}/libdeviced.so.* diff --git a/ss_bs.c b/ss_bs.c index 20a2c3e..4d4f3b5 100644 --- a/ss_bs.c +++ b/ss_bs.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/ss_common.c b/ss_common.c index fff43aa..0ce536d 100644 --- a/ss_common.c +++ b/ss_common.c @@ -1,5 +1,21 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ss_log.h" + +#define PERMANENT_DIR "/tmp/permanent" +#define VIP_DIR "/tmp/vip" /** * Opens "/proc/$pid/oom_adj" file for w/r; @@ -21,3 +37,91 @@ FILE * open_proc_oom_adj_file(int pid, const char *mode) return fp; } +int get_exec_pid(const char *execpath) +{ + DIR *dp; + struct dirent *dentry; + int pid = -1, fd; + char buf[PATH_MAX]; + char buf2[PATH_MAX]; + + dp = opendir("/proc"); + if (!dp) { + PRT_TRACE_ERR("open /proc"); + return -1; + } + + while ((dentry = readdir(dp)) != NULL) { + 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; + if (read(fd, buf2, PATH_MAX) < 0) { + close(fd); + continue; + } + close(fd); + + if (!strcmp(buf2, execpath)) { + closedir(dp); + return pid; + } + } + + errno = ESRCH; + closedir(dp); + return -1; +} + +int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) +{ + int fd, ret; + char buf[PATH_MAX + 1]; + char *filename; + + snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); + fd = open(buf, O_RDONLY); + if (fd < 0) { + errno = ESRCH; + return -1; + } + + ret = read(fd, buf, PATH_MAX); + close(fd); + buf[PATH_MAX] = '\0'; + + filename = strrchr(buf, '/'); + if (filename == NULL) + filename = buf; + else + filename = filename + 1; + + if (cmdline_size < strlen(filename) + 1) { + errno = EOVERFLOW; + return -1; + } + + strncpy(cmdline, filename, cmdline_size - 1); + cmdline[cmdline_size - 1] = '\0'; + 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; +} \ No newline at end of file diff --git a/ss_common.h b/ss_common.h index a7af544..51cebcb 100644 --- a/ss_common.h +++ b/ss_common.h @@ -2,6 +2,9 @@ #define _SS_COMMON_H FILE * open_proc_oom_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); #endif /* _SS_COMMON_H */ diff --git a/ss_core.c b/ss_core.c index a5fb577..06cfc1c 100644 --- a/ss_core.c +++ b/ss_core.c @@ -15,7 +15,6 @@ */ -#include #include "include/ss_data.h" #include "ss_queue.h" #include "ss_log.h" diff --git a/ss_device_change_handler.c b/ss_device_change_handler.c index 34d11e9..20c875a 100755 --- a/ss_device_change_handler.c +++ b/ss_device_change_handler.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include #include #include +#include "sysman.h" #include #include "ss_queue.h" #include "ss_log.h" diff --git a/ss_launch.c b/ss_launch.c index 24b77c8..ae72fb6 100644 --- a/ss_launch.c +++ b/ss_launch.c @@ -27,6 +27,7 @@ #include "vconf-keys.h" #include "ss_log.h" #include "ss_launch.h" +#include "ss_common.h" #define MAX_ARGS 255 @@ -211,7 +212,7 @@ int ss_launch_if_noexist(const char *execpath, const char *arg, ...) errno = EINVAL; return -1; } - if (pid = sysman_get_pid(execpath) > 0) + if (pid = get_exec_pid(execpath) > 0) return pid; va_start(argptr, arg); @@ -303,7 +304,7 @@ int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...) return -1; } - if ((exist_pid = sysman_get_pid(execpath)) > 0) + if ((exist_pid = get_exec_pid(execpath)) > 0) kill(exist_pid, SIGTERM); va_start(argptr, arg); diff --git a/ss_lowbat_handler.c b/ss_lowbat_handler.c index b827d85..934320a 100755 --- a/ss_lowbat_handler.c +++ b/ss_lowbat_handler.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include "ss_log.h" diff --git a/ss_lowmem_handler.c b/ss_lowmem_handler.c index fb6db58..5fd4ddd 100644 --- a/ss_lowmem_handler.c +++ b/ss_lowmem_handler.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/ss_pmon_handler.c b/ss_pmon_handler.c index c5476be..01e031f 100644 --- a/ss_pmon_handler.c +++ b/ss_pmon_handler.c @@ -15,7 +15,6 @@ */ -#include #include #include #include @@ -95,7 +94,7 @@ static int pmon_process(int pid, void *ad) int fd; int r; - if (sysconf_is_vip(pid)) { + if (is_vip(pid)) { PRT_TRACE_ERR("======================================="); PRT_TRACE_ERR("[Process MON] VIP process dead."); PRT_TRACE_ERR("======================================="); diff --git a/ss_predefine.c b/ss_predefine.c index 44e8d28..e1b4fb9 100644 --- a/ss_predefine.c +++ b/ss_predefine.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include +#include "sysman.h" #include "ss_log.h" #include "ss_launch.h" #include "ss_queue.h" @@ -242,8 +242,8 @@ int lowmem_def_predefine_action(int argc, char **argv) if (!strcmp(argv[0], OOM_MEM_ACT)) { pid = lowmem_get_victim_pid(); - if (pid > 0 && pid != sysman_get_pid(LOWMEM_EXEC_PATH) && pid != sysman_get_pid(MEMPS_EXEC_PATH)) { - if ((sysman_get_cmdline_name(pid, appname, PATH_MAX)) == + if (pid > 0 && pid != get_exec_pid(LOWMEM_EXEC_PATH) && pid != get_exec_pid(MEMPS_EXEC_PATH)) { + if ((get_cmdline_name(pid, appname, PATH_MAX)) == 0) { PRT_TRACE_EM ("we will kill, lowmem lv2 = %d (%s)\n", diff --git a/ss_procmgr.c b/ss_procmgr.c index 2d48c7b..01748ef 100755 --- a/ss_procmgr.c +++ b/ss_procmgr.c @@ -22,7 +22,6 @@ #include #include -#include #include "include/ss_data.h" #include "ss_queue.h" #include "ss_log.h" @@ -60,7 +59,7 @@ int set_app_oomadj(pid_t pid, int new_oomadj) int old_oomadj; char exe_name[PATH_MAX]; - if (sysman_get_cmdline_name(pid, exe_name, PATH_MAX) < 0) + if (get_cmdline_name(pid, exe_name, PATH_MAX) < 0) snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); diff --git a/ss_queue.c b/ss_queue.c index 4269d104..1706525 100644 --- a/ss_queue.c +++ b/ss_queue.c @@ -15,7 +15,6 @@ */ -#include #include #include "include/ss_data.h" #include "ss_core.h" diff --git a/ss_sysnoti.c b/ss_sysnoti.c index bca9617..5dd045a 100755 --- a/ss_sysnoti.c +++ b/ss_sysnoti.c @@ -15,7 +15,6 @@ */ -#include #include #include #include @@ -24,6 +23,7 @@ #include "include/ss_data.h" #include "ss_log.h" #include "ss_queue.h" +#include "ss_common.h" #define SYSNOTI_SOCKET_PATH "/tmp/sn" #define RETRY_READ_COUNT 5 @@ -42,7 +42,7 @@ static void print_sysnoti_msg(const char *title, struct sysnoti *msg) int i; char exe_name[PATH_MAX]; - if (sysman_get_cmdline_name(msg->pid, exe_name, PATH_MAX) < 0) + if (get_cmdline_name(msg->pid, exe_name, PATH_MAX) < 0) snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); PRT_TRACE_ERR("pid : %d name: %s cmd : %d type : %s path : %s", diff --git a/ss_ta_handler.c b/ss_ta_handler.c index ac1e38a..447a9af 100644 --- a/ss_ta_handler.c +++ b/ss_ta_handler.c @@ -17,7 +17,6 @@ #include #include -#include #include "device-node.h" #include "ss_log.h" diff --git a/ss_timemgr.c b/ss_timemgr.c index cecbbb1..08238e8 100644 --- a/ss_timemgr.c +++ b/ss_timemgr.c @@ -24,7 +24,6 @@ #include #include -#include #include "include/ss_data.h" #include "ss_queue.h" #include "ss_log.h" diff --git a/ss_usb_handler.c b/ss_usb_handler.c index 815aca7..6e1022e 100644 --- a/ss_usb_handler.c +++ b/ss_usb_handler.c @@ -17,7 +17,6 @@ #include #include -#include #include "ss_log.h" #include "device-node.h" diff --git a/sysman/CMakeLists.txt b/sysman/CMakeLists.txt new file mode 100755 index 0000000..e830d90 --- /dev/null +++ b/sysman/CMakeLists.txt @@ -0,0 +1,49 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sysman C) + +SET(SRCS + sysnoti.c + sysconf.c + sysman-util.c ) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.2.0") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED vconf dlog) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -fvisibility=hidden") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DSLP_DEBUG -DENABLE_DLOG_OUT") + +SET(CMAKE_LDFLAGS "-Wl,zdefs") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sysman.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sysman_managed.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sysman-internal.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/SLP_sysman_PG.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) +ADD_SUBDIRECTORY(set_pmon) + diff --git a/sysman/SLP_sysman_PG.h b/sysman/SLP_sysman_PG.h new file mode 100644 index 0000000..1c036ae --- /dev/null +++ b/sysman/SLP_sysman_PG.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2012 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. + */ + + +/** + * + * @ingroup SLP_PG + * @defgroup SLP_PG_SYSMAN System Manager + * @{ + +

Introduction

+ +

Purpose

+The purpose of the document is to describe how applications can use the System Manager APIs. This document gives programming guidelines to application engineers. + +

Scope

+The scope of this document is limited to System Manager API usage. + +
+

System Manager Library Overview

+Sysman library provides convenience functions to get data about processes or to run processes. +It reads the proc file system to check whether a process exists or not, gets a command line and execution path, gets the pid of a process etc. +Some APIs of the sysman library use some device files also. If processes which call APIs of sysman library don't have the correct permission, they will fail. +Most functions return -1 on failure and the errno will be set.
+Please refer the manual pages of proc(Linux Programmer's Manual - PROC(5) http://www.kernel.org/doc/man-pages/man5/proc.5.html) +or errno(Linux Programmer's Manual - ERRNO(3) http://www.kernel.org/doc/man-pages/man3/errno.3.html) for more details. + +

System Manager Funtions

+ +

System Manager APIs

+API : sysman_get_pid +
Parameter In : const char *execpath +
Return : int +
Functionality : This API is used to get the pid of the process which has the specified execpath.
+Internally, this API searches /proc/{pid}/cmdline and compares the parameter execpath with 1st argument of cmdline. +If there is no process that has same execpath in /proc/{pid}/cmdline, it will return (-1). +

+API : sysman_get_cmdline_name +
Parameter In : pid_t pid +
Parameter Out : char *cmdline +
Parameter In : size_t cmdline_size +
Return : int +
Functionality :This API is used to get the file name in the command line.
+Caller process MUST allocate enough memory for the cmdline parameter. Its size should be assigned to cmdline_size.
+Internally it reads the 1st argument of /proc/{pid}/cmdline and copies it to cmdline.
+The function returns 0 on success and a negative value (-1) on failure. +

+API : sysman_get_apppath +
Parameter In : pid_t pid +
Parameter Out : char *app_path +
Parameter In : size_t app_path_size +
Return : int +
Functionality : This API is used to get the execution path of the process specified by the pid parameter.
+Caller process MUST allocate enough memory for the app_path parameter. Its size should be assigned to app_path_size.
+Internally it reads a link of /proc/{pid}/exe and copies the path to app_path.
+The function returns 0 on success and a negative value (-1) on failure. +

+API : sysconf_set_mempolicy +
Parameter In : enum mem_policy mempol +
Return : int +
Functionality : This API is used to set the policy of the caller process for the situation of low available memory.
+The function returns 0 on success and a negative value (-1) on failure.
+If the caller process has no permission, it will be failed. + +Enumerate values +@code +enum mem_policy { + OOM_LIKELY , // For micelloneous applications + OOM_NORMAL , // For fundamental applications + OOM_IGNORE // For daemon +}; +@endcode + + @} +**/ diff --git a/sysman/TC/build.sh b/sysman/TC/build.sh new file mode 100755 index 0000000..98ebeff --- /dev/null +++ b/sysman/TC/build.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +export TET_INSTALL_PATH=/scratchbox/tetware # local tetware path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/sysman/TC/execute.sh b/sysman/TC/execute.sh new file mode 100755 index 0000000..6720da0 --- /dev/null +++ b/sysman/TC/execute.sh @@ -0,0 +1,19 @@ +#!/bin/sh +export TET_INSTALL_PATH=/mnt/nfs/tetware +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH + +export TET_ROOT=$TET_TARGET_PATH + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/sysman/TC/tet_code b/sysman/TC/tet_code new file mode 100644 index 0000000..a2cf6c1 --- /dev/null +++ b/sysman/TC/tet_code @@ -0,0 +1,12 @@ +# TET reserved codes +0 "PASS" +1 "FAIL" +2 "UNRESOLVED" +3 "NOTINUSE" +4 "UNSUPPORTED" +5 "UNTESTED" +6 "UNINITIATED" +7 "NORESULT" + +# Test suite additional codes +33 "INSPECT" diff --git a/sysman/TC/tet_scen b/sysman/TC/tet_scen new file mode 100644 index 0000000..43cbc9b --- /dev/null +++ b/sysman/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/unit/tslist diff --git a/sysman/TC/tetbuild.cfg b/sysman/TC/tetbuild.cfg new file mode 100644 index 0000000..6192c78 --- /dev/null +++ b/sysman/TC/tetbuild.cfg @@ -0,0 +1,3 @@ +TET_OUTPUT_CAPTURE=False +TET_BUILD_TOOL=make +TET_PASS_TC_NAME=True diff --git a/sysman/TC/tetclean.cfg b/sysman/TC/tetclean.cfg new file mode 100644 index 0000000..c66eda4 --- /dev/null +++ b/sysman/TC/tetclean.cfg @@ -0,0 +1,2 @@ +TET_OUTPUT_CAPTURE=False +TET_CLEAN_TOOL=make clean diff --git a/sysman/TC/tetexec.cfg b/sysman/TC/tetexec.cfg new file mode 100644 index 0000000..0d9d39a --- /dev/null +++ b/sysman/TC/tetexec.cfg @@ -0,0 +1 @@ +TET_OUTPUT_CAPTURE=False diff --git a/sysman/TC/unit/Makefile b/sysman/TC/unit/Makefile new file mode 100644 index 0000000..7bb6092 --- /dev/null +++ b/sysman/TC/unit/Makefile @@ -0,0 +1,31 @@ +CC ?= gcc + +TARGETS = utc_SystemFW_sysconf_is_vip_func \ + utc_SystemFW_sysconf_set_mempolicy_bypid_func \ + utc_SystemFW_sysconf_set_mempolicy_func \ + utc_SystemFW_sysconf_set_permanent_bypid_func \ + utc_SystemFW_sysconf_set_permanent_func \ + utc_SystemFW_sysconf_set_vip_func \ + utc_SystemFW_sysman_get_apppath_func \ + utc_SystemFW_sysman_get_cmdline_name_func \ + utc_SystemFW_sysman_get_pid_func \ + utc_SystemFW_sysman_set_datetime_func \ + +PKGS = sysman + +LDFLAGS = `pkg-config --libs $(PKGS)` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s + +CFLAGS = -I. `pkg-config --cflags $(PKGS)` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +all: $(TARGETS) + +$(TARGETS): %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TARGETS) diff --git a/sysman/TC/unit/tc_gen.sh b/sysman/TC/unit/tc_gen.sh new file mode 100755 index 0000000..54f482d --- /dev/null +++ b/sysman/TC/unit/tc_gen.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +TMPSTR=$0 +SCRIPT=${TMPSTR##*/} + +if [ $# -lt 2 ]; then + echo "Usage) $SCRIPT module_name api_name" + exit 1 +fi + +MODULE=$1 +API=$2 +TEMPLATE=utc_MODULE_API_func.c.in +TESTCASE=utc_${MODULE}_${API}_func + +sed -e ' + s^@API@^'"$API"'^g + s^@MODULE@^'"$MODULE"'^g + ' $TEMPLATE > $TESTCASE.c + +if [ ! -e "$TESTCASE.c" ]; then + echo "Failed" + exit 1 +fi +echo "Testcase file is $TESTCASE.c" +echo "Done" +echo "please put \"$TESTCASE\" as Target in Makefile" +echo "please put \"/unit/$TESTCASE\" in tslist" diff --git a/sysman/TC/unit/tslist b/sysman/TC/unit/tslist new file mode 100644 index 0000000..9f6d985 --- /dev/null +++ b/sysman/TC/unit/tslist @@ -0,0 +1,8 @@ +/unit/utc_SystemFW_sysconf_is_vip_func +/unit/utc_SystemFW_sysconf_set_permanent_bypid_func +/unit/utc_SystemFW_sysconf_set_permanent_func +/unit/utc_SystemFW_sysman_get_apppath_func +/unit/utc_SystemFW_sysman_get_cmdline_name_func +/unit/utc_SystemFW_sysman_get_pid_func +/unit/utc_SystemFW_sysman_set_datetime_func + diff --git a/sysman/TC/unit/utc_MODULE_API_func.c.in b/sysman/TC/unit/utc_MODULE_API_func.c.in new file mode 100644 index 0000000..b235fa3 --- /dev/null +++ b/sysman/TC/unit/utc_MODULE_API_func.c.in @@ -0,0 +1,64 @@ +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_@MODULE@_@API@_func_01(void); +static void utc_@MODULE@_@API@_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_@MODULE@_@API@_func_01, POSITIVE_TC_IDX }, + { utc_@MODULE@_@API@_func_02, NEGATIVE_TC_IDX }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of @API@() + */ +static void utc_@MODULE@_@API@_func_01(void) +{ + int r = 0; + +/* + r = @API@(...); +*/ + if (r) { + tet_infoline("@API@() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init @API@() + */ +static void utc_@MODULE@_@API@_func_02(void) +{ + int r = 0; + +/* + r = @API@(...); +*/ + if (r) { + tet_infoline("@API@() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysconf_is_vip_func.c b/sysman/TC/unit/utc_SystemFW_sysconf_is_vip_func.c new file mode 100644 index 0000000..a57cf0b --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysconf_is_vip_func.c @@ -0,0 +1,64 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysconf_is_vip_func_01(void); +static void utc_SystemFW_sysconf_is_vip_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysconf_is_vip_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysconf_is_vip_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysconf_is_vip() + */ +static void utc_SystemFW_sysconf_is_vip_func_01(void) +{ + int ret_val = 0; + int pid = getpid(); + + ret_val = sysconf_is_vip(pid); + if(ret_val < 0) { + tet_infoline("sysconf_is_vip() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysconf_is_vip() + */ +static void utc_SystemFW_sysconf_is_vip_func_02(void) +{ + int r = 0; + + r = sysconf_is_vip(-1); + + if (r>=0) { + tet_infoline("sysconf_is_vip() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_bypid_func.c b/sysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_bypid_func.c new file mode 100644 index 0000000..e1f6fab --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_bypid_func.c @@ -0,0 +1,66 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysconf_set_mempolicy_bypid_func_01(void); +static void utc_SystemFW_sysconf_set_mempolicy_bypid_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysconf_set_mempolicy_bypid_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysconf_set_mempolicy_bypid_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysconf_set_mempolicy_bypid() + */ +static void utc_SystemFW_sysconf_set_mempolicy_bypid_func_01(void) +{ + int ret_val = 0; + int pid = getpid(); + int mempol = OOM_NORMAL; + + ret_val = sysconf_set_mempolicy_bypid(pid, mempol); + if(ret_val < 0) { + tet_infoline("sysconf_set_mempolicy_bypid() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysconf_set_mempolicy_bypid() + */ +static void utc_SystemFW_sysconf_set_mempolicy_bypid_func_02(void) +{ + int r = 0; + int mempol = OOM_NORMAL; + + r = sysconf_set_mempolicy_bypid(-1, mempol); + + if (r>=0) { + tet_infoline("sysconf_set_mempolicy_bypid() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_func.c b/sysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_func.c new file mode 100644 index 0000000..baf5a4b --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_func.c @@ -0,0 +1,64 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysconf_set_mempolicy_func_01(void); +static void utc_SystemFW_sysconf_set_mempolicy_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysconf_set_mempolicy_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysconf_set_mempolicy_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysconf_set_mempolicy() + */ +static void utc_SystemFW_sysconf_set_mempolicy_func_01(void) +{ + int ret_val = 0; + int mempol = OOM_NORMAL; + + ret_val = sysconf_set_mempolicy(mempol); + if(ret_val < 0) { + tet_infoline("sysconf_set_mempolicy() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysconf_set_mempolicy() + */ +static void utc_SystemFW_sysconf_set_mempolicy_func_02(void) +{ + int r = 0; + + r = sysconf_set_mempolicy(-1); + + if (r>=0) { + tet_infoline("sysconf_set_mempolicy() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysconf_set_permanent_bypid_func.c b/sysman/TC/unit/utc_SystemFW_sysconf_set_permanent_bypid_func.c new file mode 100644 index 0000000..d44f985 --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysconf_set_permanent_bypid_func.c @@ -0,0 +1,64 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysconf_set_permanent_bypid_func_01(void); +static void utc_SystemFW_sysconf_set_permanent_bypid_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysconf_set_permanent_bypid_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysconf_set_permanent_bypid_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysconf_set_permanent_bypid() + */ +static void utc_SystemFW_sysconf_set_permanent_bypid_func_01(void) +{ + int ret_val = 0; + int pid = getpid(); + + ret_val = sysconf_set_permanent_bypid(pid); + if(ret_val < 0) { + tet_infoline("sysconf_set_permanent_bypid() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysconf_set_permanent_bypid() + */ +static void utc_SystemFW_sysconf_set_permanent_bypid_func_02(void) +{ + int r = 0; + + r = sysconf_set_permanent_bypid(-1); + + if (r>=0) { + tet_infoline("sysconf_set_permanent_bypid() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysconf_set_permanent_func.c b/sysman/TC/unit/utc_SystemFW_sysconf_set_permanent_func.c new file mode 100644 index 0000000..0bf38be --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysconf_set_permanent_func.c @@ -0,0 +1,65 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysconf_set_permanent_func_01(void); +//static void utc_SystemFW_sysconf_set_permanent_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysconf_set_permanent_func_01, POSITIVE_TC_IDX }, +// { utc_SystemFW_sysconf_set_permanent_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysconf_set_permanent() + */ +static void utc_SystemFW_sysconf_set_permanent_func_01(void) +{ + + int r = 0; + + r = sysconf_set_permanent(); + + if (r<0) { + tet_infoline("sysconf_set_permanent() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysconf_set_permanent() + +static void utc_SystemFW_sysconf_set_permanent_func_02(void) +{ + int r = 0; + + r = sysconf_set_permanent(); + + if (r>=0) { + tet_infoline("sysconf_set_permanent() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +}*/ diff --git a/sysman/TC/unit/utc_SystemFW_sysconf_set_vip_func.c b/sysman/TC/unit/utc_SystemFW_sysconf_set_vip_func.c new file mode 100644 index 0000000..955e73f --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysconf_set_vip_func.c @@ -0,0 +1,65 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysconf_set_vip_func_01(void); +static void utc_SystemFW_sysconf_set_vip_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysconf_set_vip_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysconf_set_vip_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ + system("mv /usr/bin/restarter /usr/bin/restarter1"); +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysconf_set_vip() + */ +static void utc_SystemFW_sysconf_set_vip_func_01(void) +{ + int ret_val = 0; + int pid = getpid(); + + ret_val = sysconf_set_vip(pid); + if(ret_val < 0) { + tet_infoline("sysconf_set_vip() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysconf_set_vip() + */ +static void utc_SystemFW_sysconf_set_vip_func_02(void) +{ + int r = 0; + + r = sysconf_set_vip(-1); + + if (r>=0) { + tet_infoline("sysconf_set_vip() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysman_get_apppath_func.c b/sysman/TC/unit/utc_SystemFW_sysman_get_apppath_func.c new file mode 100644 index 0000000..609c8fa --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysman_get_apppath_func.c @@ -0,0 +1,66 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysman_get_apppath_func_01(void); +static void utc_SystemFW_sysman_get_apppath_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysman_get_apppath_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysman_get_apppath_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysman_get_apppath() + */ +static void utc_SystemFW_sysman_get_apppath_func_01(void) +{ + int ret_val = 0; + char* app_path[255] = {'\0',}; + + ret_val = sysman_get_apppath(1, app_path, 100); + if(ret_val <0) { + tet_infoline("sysman_get_apppath() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysman_get_apppath() + */ +static void utc_SystemFW_sysman_get_apppath_func_02(void) +{ + int ret_val = 0; + char* app_path[255] = {'\0',}; + + int pid = -1; + + ret_val = sysman_get_apppath(pid, app_path, 100); + if(ret_val >= 0) { + tet_infoline("sysman_get_apppath() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysman_get_cmdline_name_func.c b/sysman/TC/unit/utc_SystemFW_sysman_get_cmdline_name_func.c new file mode 100644 index 0000000..6ad5f45 --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysman_get_cmdline_name_func.c @@ -0,0 +1,64 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysman_get_cmdline_name_func_01(void); +static void utc_SystemFW_sysman_get_cmdline_name_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysman_get_cmdline_name_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysman_get_cmdline_name_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysman_get_cmdline_name() + */ +static void utc_SystemFW_sysman_get_cmdline_name_func_01(void) +{ + char name[50]={'\0',}; + int ret_val = 0; + + ret_val = sysman_get_cmdline_name(1,name,50); + if(ret_val < 0) { + tet_infoline("sysman_get_cmdline_name() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysman_get_cmdline_name() + */ +static void utc_SystemFW_sysman_get_cmdline_name_func_02(void) +{ + char name[50]={'\0',}; + int ret_val = 0; + + ret_val = sysman_get_cmdline_name(-1,name,50); + if(ret_val >= 0) { + tet_infoline("sysman_get_cmdline_name() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysman_get_pid_func.c b/sysman/TC/unit/utc_SystemFW_sysman_get_pid_func.c new file mode 100644 index 0000000..4e4efae --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysman_get_pid_func.c @@ -0,0 +1,64 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysman_get_pid_func_01(void); +static void utc_SystemFW_sysman_get_pid_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysman_get_pid_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysman_get_pid_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysman_get_pid() + */ +static void utc_SystemFW_sysman_get_pid_func_01(void) +{ + int ret_val = 0; + char* execpath = "init"; + + ret_val = sysman_get_pid(execpath); + if(ret_val < 0) { + tet_infoline("sysman_get_pid() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysman_get_pid() + */ +static void utc_SystemFW_sysman_get_pid_func_02(void) +{ + int ret_val = 0; + char* execpath = "xxxyyyzzz"; + + ret_val = sysman_get_pid(execpath); + if(ret_val >= 0) { + tet_infoline("sysman_get_pid() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/TC/unit/utc_SystemFW_sysman_set_datetime_func.c b/sysman/TC/unit/utc_SystemFW_sysman_set_datetime_func.c new file mode 100644 index 0000000..d09f7dc --- /dev/null +++ b/sysman/TC/unit/utc_SystemFW_sysman_set_datetime_func.c @@ -0,0 +1,64 @@ +#include +#include + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SystemFW_sysman_set_datetime_func_01(void); +static void utc_SystemFW_sysman_set_datetime_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SystemFW_sysman_set_datetime_func_01, POSITIVE_TC_IDX }, + { utc_SystemFW_sysman_set_datetime_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of sysman_set_datetime() + */ +static void utc_SystemFW_sysman_set_datetime_func_01(void) +{ + int ret_val = 0; + time_t timet = time(NULL); + + ret_val = sysman_set_datetime(timet); + if(ret_val < 0) { + tet_infoline("sysman_set_datetime() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init sysman_set_datetime() + */ +static void utc_SystemFW_sysman_set_datetime_func_02(void) +{ + int r = 0; + + r = sysman_set_datetime(NULL); + + if (r>=0) { + tet_infoline("sysman_set_datetime() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/sysman/set_pmon/CMakeLists.txt b/sysman/set_pmon/CMakeLists.txt new file mode 100644 index 0000000..34195e4 --- /dev/null +++ b/sysman/set_pmon/CMakeLists.txt @@ -0,0 +1,10 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +set(SET_PMON set_pmon) + +SET(SRCS set_pmon.c) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +ADD_EXECUTABLE(${SET_PMON} ${SRCS}) +TARGET_LINK_LIBRARIES(${SET_PMON} ${PROJECT_NAME}) +INSTALL(TARGETS ${SET_PMON} DESTINATION bin) +INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/regpmon DESTINATION bin) diff --git a/sysman/set_pmon/pmon b/sysman/set_pmon/pmon new file mode 100755 index 0000000..f389e5f --- /dev/null +++ b/sysman/set_pmon/pmon @@ -0,0 +1,5 @@ +#!/bin/sh + +# clean up vip process history +rm -f /tmp/vip/* + diff --git a/sysman/set_pmon/regpmon b/sysman/set_pmon/regpmon new file mode 100755 index 0000000..3aa71e8 --- /dev/null +++ b/sysman/set_pmon/regpmon @@ -0,0 +1,12 @@ +#!/bin/sh + +# Don't regist processes on hibernation capturing sequence +if [ -e /opt/etc/.hib_capturing ] ; then + exit 0 +elif [ -e /opt/etc/.hib_capturing_firstboot ]; then + exit 0 +fi + +set_pmon -v Xorg enlightenment dbus-daemon libsqlfs_mount telephony-server pulseaudio +set_pmon -p wifid phonebook-engine voice-calld menu-daemon input_router indicator dlog-daemon ss-server media-server sf_server security-server dnet quickpanel sound_server audio-session-mgr-server launchpad_preloading_preinitializing_daemon voip-daemon drm_server calendar-serviced wrt_launchpad_daemon + diff --git a/sysman/set_pmon/set_pmon.c b/sysman/set_pmon/set_pmon.c new file mode 100644 index 0000000..96bb151 --- /dev/null +++ b/sysman/set_pmon/set_pmon.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2012 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 + +#define BUFF_MAX 255 + +int set_oomadj(int pid, int oomadj_val) +{ + char buf[BUFF_MAX]; + FILE *fp; + + snprintf(buf, BUFF_MAX, "/proc/%d/oom_adj", pid); + fp = fopen(buf, "w"); + if (fp == NULL) + return -1; + fprintf(fp, "%d", oomadj_val); + fclose(fp); + + return 0; +} + +int check_and_setpmon(int pid, int idx, char **argv, char type) +{ + int fd; + char buf[BUFF_MAX]; + char *filename; + + snprintf(buf, BUFF_MAX, "/proc/%d/cmdline", pid); + fd = open(buf, O_RDONLY); + if (fd < 0) + return -1; + + read(fd, buf, BUFF_MAX-1); + close(fd); + + buf[BUFF_MAX-1]='\0'; + + filename = strrchr(buf, '/'); + if (filename == NULL) + filename = buf; + else + filename = filename + 1; + + while (idx > 1) { /* argv[1] is monitoring type */ + if (!strcmp(argv[idx], filename)) { + switch (type) { + case 'v': + printf("====> found, %s - set vip\n", + argv[idx]); + set_oomadj(pid, -17); + sysconf_set_vip(pid); + return 0; + case 'p': + printf("====> found, %s - set permanent\n", + argv[idx]); + sysconf_set_permanent_bypid(pid); + return 0; + default: + break; + } + } + idx--; + } + return -1; +} + +int main(int argc, char **argv) +{ + int pid = -1; + char type; + DIR *dp; + struct dirent *dentry; + + if (argc < 3 || + argv[1][0] != '-' || + argv[1][1] == '\0' || (argv[1][1] != 'v' && argv[1][1] != 'p')) { + printf("Usage: %s \n", argv[0]); + printf("Monitoring types: -v \t VIP process\n"); + printf(" -p \t Permanent process\n"); + return 1; + } + + dp = opendir("/proc"); + if (!dp) { + printf("open /proc : %s\n", strerror(errno)); + return 1; + } + type = argv[1][1]; + + while ((dentry = readdir(dp)) != NULL) { + if (!isdigit(dentry->d_name[0])) + continue; + + pid = atoi(dentry->d_name); + check_and_setpmon(pid, argc - 1, argv, type); + } + + closedir(dp); + return 0; +} diff --git a/sysman/sysconf.c b/sysman/sysconf.c new file mode 100644 index 0000000..c7495ca --- /dev/null +++ b/sysman/sysconf.c @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2012 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 "sysman.h" +#include "sysman-priv.h" + +#define PERMANENT_DIR "/tmp/permanent" +#define VIP_DIR "/tmp/vip" + +#define OOMADJ_SET "oomadj_set" +#define PROCESS_GROUP_SET "process_group_set" +#define PROCESS_VIP "process_vip" +#define PROCESS_PERMANENT "process_permanent" + +enum mp_entry_type { + MP_VIP, + MP_PERMANENT, + MP_NONE +}; + +int util_oomadj_set(int pid, int oomadj_val) +{ + char buf1[255]; + char buf2[255]; + + snprintf(buf1, sizeof(buf1), "%d", pid); + snprintf(buf2, sizeof(buf2), "%d", oomadj_val); + return sysman_call_predef_action(OOMADJ_SET, 2, buf1, buf2); +} + +int util_process_group_set(const char* name, int pid) +{ + char buf[255]; + + if (strncmp(PROCESS_VIP, name, strlen(name)) != 0 && + strncmp(PROCESS_PERMANENT, name, strlen(name)) != 0) { + ERR("fail to insert at %s group", name); + return -1; + } + + snprintf(buf, sizeof(buf), "%d", pid); + ERR("pid(%d) is inserted at vip", pid); + + return sysman_call_predef_action(PROCESS_GROUP_SET, 2, buf, name); +} + +API int sysconf_set_mempolicy_bypid(int pid, enum mem_policy mempol) +{ + if (pid < 1) + return -1; + + int oomadj_val = 0; + + switch (mempol) { + case OOM_LIKELY: + oomadj_val = 1; + break; + case OOM_IGNORE: + oomadj_val = -17; + break; + default: + return -1; + } + + return util_oomadj_set(pid, oomadj_val); +} + +API int sysconf_set_mempolicy(enum mem_policy mempol) +{ + return sysconf_set_mempolicy_bypid(getpid(), mempol); +} + +static int already_permanent(int pid) +{ + char buf[BUFF_MAX]; + + snprintf(buf, BUFF_MAX, "%s/%d", PERMANENT_DIR, pid); + + if (access(buf, R_OK) == 0) { + DBG("already_permanent process : %d", pid); + return 1; + } + return 0; +} + +static int copy_cmdline(int pid) +{ + char buf[PATH_MAX]; + char filepath[PATH_MAX]; + int fd; + int cnt; + int r; + + if (access(PERMANENT_DIR, R_OK) < 0) { + DBG("no predefined matrix dir = %s, so created", PERMANENT_DIR); + r = mkdir(PERMANENT_DIR, 0777); + if(r < 0) { + ERR("permanent directory mkdir is failed"); + return -1; + } + } + + snprintf(filepath, PATH_MAX, "/proc/%d/cmdline", pid); + + fd = open(filepath, O_RDONLY); + if (fd == -1) { + DBG("Failed to open"); + return -1; + } + + cnt = read(fd, buf, PATH_MAX); + close(fd); + + if (cnt <= 0) { + /* Read /proc//cmdline error */ + DBG("Failed to read"); + return -1; + } + + snprintf(filepath, PATH_MAX, "%s/%d", PERMANENT_DIR, pid); + + fd = open(filepath, O_CREAT | O_WRONLY, 0644); + if (fd == -1) { + DBG("Failed to open"); + return -1; + } + + if (write(fd, buf, cnt) == -1) { + DBG("Failed to write"); + close(fd); + return -1; + } + close(fd); + + return 0; +} + +API int sysconf_set_vip(int pid) +{ + char buf[BUFF_MAX]; + int fd; + int r; + + if (pid < 1) + return -1; + + if (access(VIP_DIR, R_OK) < 0) { + DBG("no predefined matrix dir = %s, so created", VIP_DIR); + r = mkdir(VIP_DIR, 0777); + if(r < 0) { + ERR("sysconf_set_vip vip mkdir is failed"); + return -1; + } + } + + snprintf(buf, BUFF_MAX, "%s/%d", VIP_DIR, pid); + fd = open(buf, O_CREAT | O_RDWR, 0644); + if (fd < 0) { + ERR("sysconf_set_vip fd open failed"); + return -1; + } + close(fd); + if (util_process_group_set(PROCESS_VIP, pid) < 0) { + ERR("set vip failed"); + return -1; + } + + return 0; +} + +API int sysconf_is_vip(int pid) +{ + if (pid < 1) + return -1; + + char buf[BUFF_MAX]; + + snprintf(buf, BUFF_MAX, "%s/%d", VIP_DIR, pid); + + if (access(buf, R_OK) == 0) + return 1; + else + return 0; +} + +API int sysconf_set_permanent_bypid(int pid) +{ + int fd; + if (already_permanent(pid)) + goto MEMPOL_SET; + + if (copy_cmdline(pid) < 0) + return -1; + + if (util_process_group_set(PROCESS_PERMANENT, pid) < 0) { + ERR("set vip failed"); + return -1; + } + + MEMPOL_SET: + util_oomadj_set(pid, -17); + + return 0; +} + +API int sysconf_set_permanent() +{ + pid_t pid = getpid(); + return sysconf_set_permanent_bypid(pid); +} diff --git a/sysman/sysman-internal.h b/sysman/sysman-internal.h new file mode 100644 index 0000000..4f3130a --- /dev/null +++ b/sysman/sysman-internal.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 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 ___SYSMAN_INTERNAL___ +#define ___SYSMAN_INTERNAL___ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* This file will be removed */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* ___SYSMAN_INTERNAL___ */ diff --git a/sysman/sysman-priv.h b/sysman/sysman-priv.h new file mode 100644 index 0000000..203921d --- /dev/null +++ b/sysman/sysman-priv.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012 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 ___SYSNMAN_PRIVATE___ +#define ___SYSNMAN_PRIVATE___ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef API +#define API __attribute__ ((visibility("default"))) +#endif + +#define __PRTD(fmt, arg...) \ + do { \ + if (getenv("SLP_DEBUG")) { \ + fprintf(stdout, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } \ + } while (0) +#define _NOUT(fmt, arg...) do { } while (0) + +#ifdef SLP_DEBUG +# define DBG _PRTD +#else +# define DBG _NOUT +#endif + +#define ENABLE_DLOG_OUT 1 +#ifdef ENABLE_DLOG_OUT +# define LOG_TAG "LIBSYSMAN" +# include +# define _PRTD SLOGD +# define ERR SLOGE +# define INFO SLOGI +#else +# define _PRTD __PRTD +# define ERR perror +# define INFO(fmt, arg...) \ + do { fprintf(stdout, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); } while (0) +#endif + +#define SYSMAN_MAXARG 16 +#define SYSMAN_MAXSTR 100 +#define BUFF_MAX 255 + + struct sysnoti { + int pid; + int cmd; + char *type; + char *path; + int argc; + char *argv[SYSMAN_MAXARG]; + }; + + int util_launch_app_cmd(const char *cmdline); + +#ifdef __cplusplus +} +#endif +#endif /* ___SYSMAN_PRIVATE___ */ diff --git a/sysman/sysman-util.c b/sysman/sysman-util.c new file mode 100644 index 0000000..fb5f8d1 --- /dev/null +++ b/sysman/sysman-util.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sysman.h" +#include "sysman-priv.h" + +API int sysman_get_pid(const char *execpath) +{ + DIR *dp; + struct dirent *dentry; + int pid = -1, fd; + char buf[BUFF_MAX]; + char buf2[BUFF_MAX]; + + dp = opendir("/proc"); + if (!dp) { + ERR("open /proc"); + return -1; + } + + while ((dentry = readdir(dp)) != NULL) { + if (!isdigit(dentry->d_name[0])) + continue; + + pid = atoi(dentry->d_name); + + snprintf(buf, BUFF_MAX, "/proc/%d/cmdline", pid); + fd = open(buf, O_RDONLY); + if (fd < 0) + continue; + if (read(fd, buf2, BUFF_MAX) < 0) { + close(fd); + continue; + } + close(fd); + + if (!strcmp(buf2, execpath)) { + closedir(dp); + return pid; + } + } + + errno = ESRCH; + closedir(dp); + return -1; +} + +API int sysman_get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) +{ + int fd, ret; + char buf[PATH_MAX + 1]; + char *filename; + + snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); + fd = open(buf, O_RDONLY); + if (fd < 0) { + errno = ESRCH; + return -1; + } + + ret = read(fd, buf, PATH_MAX); + close(fd); + buf[PATH_MAX] = '\0'; + + filename = strrchr(buf, '/'); + if (filename == NULL) + filename = buf; + else + filename = filename + 1; + + if (cmdline_size < strlen(filename) + 1) { + errno = EOVERFLOW; + return -1; + } + + strncpy(cmdline, filename, cmdline_size - 1); + cmdline[cmdline_size - 1] = '\0'; + return 0; +} + +API int sysman_get_apppath(pid_t pid, char *app_path, size_t app_path_size) +{ + char buf[PATH_MAX]; + int ret; + + snprintf(buf, PATH_MAX, "/proc/%d/exe", pid); + if (app_path == NULL + || (ret = readlink(buf, app_path, app_path_size)) == -1) + return -1; + if (app_path_size == ret) { + app_path[ret - 1] = '\0'; + errno = EOVERFLOW; + return -1; + } + + app_path[ret] = '\0'; + return 0; +} + diff --git a/sysman/sysman.h b/sysman/sysman.h new file mode 100755 index 0000000..54ba0e8 --- /dev/null +++ b/sysman/sysman.h @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2012 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 ___SYSMAN___ +#define ___SYSMAN___ + +#include +#include +#include +#include +#include "sysman_managed.h" + +#ifndef DEPRECATED +#define DEPRECATED __attribute__((deprecated)) +#endif + +/** + * @file sysman.h + * @ingroup libsysman System Manager library + * @brief This library provides APIs related with memory, performance, processes, and so on. + * @author SLP2.0 + * @date 2010-01-24 + * @version 0.1 + */ + +/** + * @defgroup libsysman System Manager library + * @ingroup SYSTEM_FRAMEWORK + * @brief System manager library + * + * This library provides APIs related with memory, performance, processes, and so on. + *
Please use libslp-sysman-dev debian package and sysman.pc file for development. + *
And include sysman.h file at your source codes as following. + * @addtogroup libsysman System Manager library + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @breif Policy for low memory + */ + enum mem_policy { + OOM_LIKELY, /**< For miscellaneous applications */ + OOM_IGNORE /**< For daemons */ + }; + +/* sysman_util */ + +/** + * @fn int sysman_get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) + * @brief This API is used to get the file name of command line of the process from the proc fs. + * Caller process MUST allocate enough memory for the cmdline parameter. \n + * Its size should be assigned to cmdline_size. \n + * Internally it reads the 1st argument of /proc/{pid}/cmdline and copies it to cmdline. + * @param[in] pid pid of the process that you want to get the file name of command line + * @param[out] cmdline command line of the process that you want to get the file name
+ * Callers should allocate memory to this parameter before calling this function. + * The allocated memory size must be large enough to store the file name. + * The result will include the terminating null byte('\0') at the end of the string. + * @return 0 on success, -1 if failed. If the size of cmdline is smaller than the result, + * it will return -1 and errno will be set as EOVERFLOW. + */ + int sysman_get_cmdline_name(pid_t pid, char *cmdline, + size_t cmdline_size); + +/** + * @fn char *sysman_get_apppath(pid_t pid, char *app_path, size_t app_path_size) + * @brief This API is used to get the execution path of the process specified by the pid parameter.\n + * Caller process MUST allocate enough memory for the app_path parameter. \n + * Its size should be assigned to app_path_size. \n + * Internally it reads a link of /proc/{pid}/exe and copies the path to app_path. + * @param[in] pid pid of the process that you want to get the executed path + * @param[out] app_path the executed file path of the process
+ * Callers should allocate memory to this parameter before calling this function. + * The allocated memory size must be large enough to store the executed file path. + * The result will include the terminating null byte('\0') at the end of the string. + * @param[in] app_path_size allocated memory size of char *app_path + * @return 0 on success, -1 if failed. If the size of app_path is smaller than the result, + * it will return -1 and errno will be set as EOVERFLOW. + */ + int sysman_get_apppath(pid_t pid, char *app_path, size_t app_path_size); + +/* sysconf */ + +/** + * @fn int sysconf_set_mempolicy(enum mem_policy mempol) + * @brief This API is used to set the policy of the caller process when the phone has low available memory. + * @param[in] mempol oom adjust value which you want to set + * @return 0 on success, -1 if failed. + * @see sysconf_set_mempolicy_bypid() + */ + int sysconf_set_mempolicy(enum mem_policy mempol); + +/** + * @fn int sysconf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol) + * @brief This API is used to set the policy of the process when the phone has low available memory. + * @param[in] pid process id which you want to set + * @param[in] mempol oom adjust value which you want to set + * @return 0 on success, -1 if failed. + */ + int sysconf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol); + +/** + * @fn int sysconf_set_permanent(void) + * @brief This API is used to set itself as a permanent process.\n + * If the permanent process is dead, system server will relaunch the process automatically. + * @return 0 on success, -1 if failed. + * @see sysconf_set_permanent_bypid() + * @par Example + * @code + * ... + * ret = sysconf_set_permanent(); + * if( ret < 0 ) + * printf("Fail to set a process as permanent\n"); + * ... + * @endcode + */ + int sysconf_set_permanent(void); + +/** + * @fn int sysconf_set_permanent_bypid(pid_t pid) + * @brief This API is used to set a process which has pid as a permanent process.\n + * If the permanent process is dead, system server will relaunch the process automatically. + * @return 0 on success, -1 if failed. + * @see sysconf_set_permanent() + * @par Example + * @code + * ... + * ret = sysconf_set_permanent_bypid(pid); + * if( ret < 0 ) + * printf("Fail to set a process(%d) as permanent\n",pid); + * ... + * @endcode + */ + int sysconf_set_permanent_bypid(pid_t pid); + +/** + * @fn int sysconf_set_vip(pid_t pid) + * @brief This API is used to set a process which has pid as Very Important Process(VIP) .\n + * If the VIP process is dead, restarter program will be run. \n + * Restarter program may kill almost processes and run rc.local scripts again. + * @param[in] pid process id to be vip + * @return 0 on success, -1 if failed. + * @see sysconf_is_vip + * @par Example + * @code + * ... + * ret = sysconf_set_vip(pid); + * if( ret < 0 ) + * printf("Fail to set a process(%d) as VIP\n",pid); + * ... + * @endcode + */ + int sysconf_set_vip(pid_t pid); + +/** + * @fn int sysconf_is_vip(pid_t pid) + * @brief This API is used to verify that process which has pid is Very Important Process(VIP) or not. + * @param[in] pid process id to be vip + * @return 1 on success, 0 if failed. + * @see sysconf_set_vip + * @par Example + * @code + * ... + * ret = sysconf_is_vip(pid); + * if(ret) + * printf("process(%d) is Very Important Process\n",pid); + * ... + * @endcode + */ + int sysconf_is_vip(pid_t pid); + + int sysman_set_timezone(char *tzpath_str); + + int sysman_call_predef_action(const char *type, int num, ...); + + int sysman_inform_foregrd(void); + int sysman_inform_backgrd(void); + int sysman_inform_active(pid_t pid); + int sysman_inform_inactive(pid_t pid); + + int sysman_request_poweroff(void); + int sysman_request_entersleep(void); + int sysman_request_leavesleep(void); + int sysman_request_reboot(void); + + int sysman_request_set_cpu_max_frequency(int val); + int sysman_request_set_cpu_min_frequency(int val); + + int sysman_release_cpu_max_frequency(void); + int sysman_release_cpu_min_frequency(void); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* ___SYSMAN___ */ diff --git a/sysman/sysman.pc.in b/sysman/sysman.pc.in new file mode 100644 index 0000000..a461b64 --- /dev/null +++ b/sysman/sysman.pc.in @@ -0,0 +1,15 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: libsysman +Description: system manager interface library +Version: @VERSION@ +Requires: +Libs: -L${libdir} -lsysman +Cflags: -I${includedir} + + diff --git a/sysman/sysman_managed.h b/sysman/sysman_managed.h new file mode 100755 index 0000000..f993ef6 --- /dev/null +++ b/sysman/sysman_managed.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2012 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 ___SYSMAN_MANAGED___ +#define ___SYSMAN_MANAGED___ + +#include + +/** + * @file sysman_managed.h + * @ingroup libsysman System Manager library + * @brief This library provides APIs related with memory, performance, processes, and so on. + * @author SLP2.0 + * @date 2010-01-24 + * @version 0.1 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @fn int sysman_get_pid(const char *execpath) + * @brief This API is used to get the pid of the process which has the specified execpath.\n + * Internally, this API searches /proc/{pid}/cmdline and compares the parameter execpath with 1st argument of cmdline. \n + * If there is no process that has same execpath in /proc/{pid}/cmdline, it will return -1. + * @param[in] execpath program path which you want to know whether it is run or not + * @return pid when the program is running, -1 if it is not. + */ + int sysman_get_pid(const char *execpath); + +/** + * @fn int sysman_set_datetime(time_t timet) + * @brief This API is used to set date time.\n + * Internally, this API call predefined action API. That is send a notify message. \n + * @param[in] time_t type of time which you want to set. + * @return pid when the program is running, -1 if param is less than 0 or when failed set datetime. + */ + int sysman_set_datetime(time_t timet); + +/** + * @brief This structure defines the data for receive result of mmc operations(mount/unmount/format) + */ + struct mmc_contents { + void (*mmc_cb) (int result, void* data);/**< user callback function for receive result of mmc operations */ + void* user_data;/**< input data for callback function's second-param(data) */ + }; + +/** + * @fn int sysman_request_mount_mmc(struct mmc_contents *mmc_data) + * @brief This API is used to mount mmc.\n + * Internally, this API call predefined action API. That is send a notify message. \n + * and when mount operation is finished, cb of mmc_content struct is called with cb's param1(result). \n + * means of param1 - 0(mount success) , -2(already mounted), non-zero except (-2) (mount fail) \n + * [mount fail value] \n + * 1 : operation not permmitted \n + * 2 : no such file or directory \n + * 6 : no such device or address \n + * 12 : out of memory \n + * 13 : A component of a path was not searchable \n + * 14 : bad address \n + * 15 : block device is requested \n + * 16 : device or resource busy \n + * 19 : filesystemtype not configured in the kernel \n + * 20 : target, or a prefix of source, is not a directory \n + * 22 : point does not exist \n + * 24 : table of dummy devices is full \n + * 36 : requested name is too long \n + * 40 : Too many links encountered during pathname resolution. \n + * Or, a move was attempted, while target is a descendant of source \n + * @param[in] mmc_data for receive result of mount operation + * @return non-zero on success message sending, -1 if message sending is failed. + */ + int sysman_request_mount_mmc(struct mmc_contents *mmc_data); + +/** + * @fn int sysman_request_unmount_mmc(struct mmc_contents *mmc_data,int option) + * @brief This API is used to unmount mmc.\n + * Internally, this API call predefined action API. That is send a notify message. \n + * and when unmount opeation is finished, cb of mmc_content struct is called with cb's param1(result). \n + * means of param1 - 0(unmount success) , non-zero(unmount fail) \n + * [unmount fail value] \n + * 1 : operation not permmitted \n + * 2 : no such file or directory \n + * 11 : try again \n + * 12 : out of memory \n + * 14 : bad address \n + * 16 : device or resource busy \n + * 22 : point does not exist \n + * 36 : requested name is too long \n + * @param[in] mmc_data for receive result of unmount operation + * @param[in] option is must be 1(just only support for force unmount) + * @return non-zero on success message sending, -1 if message sending is failed. + */ + int sysman_request_unmount_mmc(struct mmc_contents *mmc_data, int option); +/** + * @fn int sysman_request_format_mmc(struct mmc_contents *mmc_data) + * @brief This API is used to format mmc.\n + * Internally, this API call predefined action API. That is send a notify message. \n + * and when format opeation is finished, cb of mmc_content struct is called with cb's param1(result). \n + * means of param1 - 0(format success) , -1(format fail) + * @param[in] mmc_data for receive result of format operation + * @return non-zero on success message sending, -1 if message sending is failed. + */ + int sysman_request_format_mmc(struct mmc_contents *mmc_data); + +#ifdef __cplusplus +} +#endif +#endif /* ___SYSMAN_MANAGED___ */ diff --git a/sysman/sysnoti.c b/sysman/sysnoti.c new file mode 100644 index 0000000..e5aaa22 --- /dev/null +++ b/sysman/sysnoti.c @@ -0,0 +1,386 @@ +/* + * Copyright (c) 2012 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 "sysman.h" +#include "sysman-priv.h" + +#define PREDEF_PWROFF_POPUP "pwroff-popup" +#define PREDEF_ENTERSLEEP "entersleep" +#define PREDEF_LEAVESLEEP "leavesleep" +#define PREDEF_REBOOT "reboot" +#define PREDEF_BACKGRD "backgrd" +#define PREDEF_FOREGRD "foregrd" +#define PREDEF_ACTIVE "active" +#define PREDEF_INACTIVE "inactive" +#define PREDEF_SET_DATETIME "set_datetime" +#define PREDEF_SET_TIMEZONE "set_timezone" +#define PREDEF_MOUNT_MMC "mountmmc" +#define PREDEF_UNMOUNT_MMC "unmountmmc" +#define PREDEF_FORMAT_MMC "formatmmc" + +#define PREDEF_SET_MAX_FREQUENCY "set_max_frequency" +#define PREDEF_SET_MIN_FREQUENCY "set_min_frequency" +#define PREDEF_RELEASE_MAX_FREQUENCY "release_max_frequency" +#define PREDEF_RELEASE_MIN_FREQUENCY "release_min_frequency" + +enum sysnoti_cmd { + ADD_SYSMAN_ACTION, + CALL_SYSMAN_ACTION +}; + +#define SYSNOTI_SOCKET_PATH "/tmp/sn" +#define RETRY_READ_COUNT 10 + +static inline int send_int(int fd, int val) +{ + return write(fd, &val, sizeof(int)); +} + +static inline int send_str(int fd, char *str) +{ + int len; + int ret; + if (str == NULL) { + len = 0; + ret = write(fd, &len, sizeof(int)); + } else { + len = strlen(str); + if (len > SYSMAN_MAXSTR) + len = SYSMAN_MAXSTR; + write(fd, &len, sizeof(int)); + ret = write(fd, str, len); + } + return ret; +} + +static int sysnoti_send(struct sysnoti *msg) +{ + ERR("--- %s: start", __FUNCTION__); + int client_len; + int client_sockfd; + int result; + int r; + int retry_count = 0; + struct sockaddr_un clientaddr; + int i; + + client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (client_sockfd == -1) { + ERR("%s: socket create failed\n", __FUNCTION__); + return -1; + } + bzero(&clientaddr, sizeof(clientaddr)); + clientaddr.sun_family = AF_UNIX; + strncpy(clientaddr.sun_path, SYSNOTI_SOCKET_PATH, sizeof(clientaddr.sun_path) - 1); + client_len = sizeof(clientaddr); + + if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < + 0) { + ERR("%s: connect failed\n", __FUNCTION__); + close(client_sockfd); + return -1; + } + + send_int(client_sockfd, msg->pid); + send_int(client_sockfd, msg->cmd); + send_str(client_sockfd, msg->type); + send_str(client_sockfd, msg->path); + send_int(client_sockfd, msg->argc); + for (i = 0; i < msg->argc; i++) + send_str(client_sockfd, msg->argv[i]); + + ERR("--- %s: read", __FUNCTION__); + while (retry_count < RETRY_READ_COUNT) { + r = read(client_sockfd, &result, sizeof(int)); + if (r < 0) { + if (errno == EINTR) { + ERR("Re-read for error(EINTR)"); + retry_count++; + continue; + } + ERR("Read fail for str length"); + result = -1; + break; + + } + break; + } + if (retry_count == RETRY_READ_COUNT) { + ERR("Read retry failed"); + } + + close(client_sockfd); + ERR("--- %s: end", __FUNCTION__); + return result; +} + +API int sysman_call_predef_action(const char *type, int num, ...) +{ + ERR("--- %s: start", __FUNCTION__); + struct sysnoti *msg; + int ret; + va_list argptr; + + int i; + char *args = NULL; + + if (type == NULL || num > SYSMAN_MAXARG) { + errno = EINVAL; + return -1; + } + + msg = malloc(sizeof(struct sysnoti)); + + if (msg == NULL) { + /* Do something for not enought memory error */ + return -1; + } + + msg->pid = getpid(); + msg->cmd = CALL_SYSMAN_ACTION; + msg->type = (char *)type; + msg->path = NULL; + + msg->argc = num; + va_start(argptr, num); + for (i = 0; i < num; i++) { + args = va_arg(argptr, char *); + msg->argv[i] = args; + } + va_end(argptr); + + ERR("--- %s: send msg", __FUNCTION__); + ret = sysnoti_send(msg); + free(msg); + + ERR("--- %s: end", __FUNCTION__); + return ret; +} + +API int sysman_inform_foregrd(void) +{ + char buf[255]; + snprintf(buf, sizeof(buf), "%d", getpid()); + return sysman_call_predef_action(PREDEF_FOREGRD, 1, buf); +} + +API int sysman_inform_backgrd(void) +{ + char buf[255]; + snprintf(buf, sizeof(buf), "%d", getpid()); + return sysman_call_predef_action(PREDEF_BACKGRD, 1, buf); +} + +API int sysman_inform_active(pid_t pid) +{ + char buf[255]; + snprintf(buf, sizeof(buf), "%d", pid); + return sysman_call_predef_action(PREDEF_ACTIVE, 1, buf); +} + +API int sysman_inform_inactive(pid_t pid) +{ + char buf[255]; + snprintf(buf, sizeof(buf), "%d", pid); + return sysman_call_predef_action(PREDEF_INACTIVE, 1, buf); +} + +API int sysman_request_poweroff(void) +{ + return sysman_call_predef_action(PREDEF_PWROFF_POPUP, 0); +} + +API int sysman_request_entersleep(void) +{ + return sysman_call_predef_action(PREDEF_ENTERSLEEP, 0); +} + +API int sysman_request_leavesleep(void) +{ + return sysman_call_predef_action(PREDEF_LEAVESLEEP, 0); +} + +API int sysman_request_reboot(void) +{ + return sysman_call_predef_action(PREDEF_REBOOT, 0); +} + +API int sysman_set_datetime(time_t timet) +{ + if (timet < 0L) + return -1; + char buf[255] = { 0 }; + snprintf(buf, sizeof(buf), "%ld", timet); + return sysman_call_predef_action(PREDEF_SET_DATETIME, 1, buf); +} + +API int sysman_set_timezone(char *tzpath_str) +{ + if (tzpath_str == NULL) + return -1; + char buf[255]; + snprintf(buf, sizeof(buf), "%s", tzpath_str); + return sysman_call_predef_action(PREDEF_SET_TIMEZONE, 1, buf); +} + +static int sysnoti_mount_mmc_cb(keynode_t *key_nodes, void *data) +{ + struct mmc_contents *mmc_data; + int mmc_err = 0; + mmc_data = (struct mmc_contents *)data; + DBG("mountmmc_cb called"); + if (vconf_keynode_get_int(key_nodes) == + VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED) { + DBG("mount ok"); + (mmc_data->mmc_cb)(0, mmc_data->user_data); + } else if (vconf_keynode_get_int(key_nodes) == + VCONFKEY_SYSMAN_MMC_MOUNT_ALREADY) { + DBG("mount already"); + (mmc_data->mmc_cb)(-2, mmc_data->user_data); + } else { + DBG("mount fail"); + vconf_get_int(VCONFKEY_SYSMAN_MMC_ERR_STATUS, &mmc_err); + (mmc_data->mmc_cb)(mmc_err, mmc_data->user_data); + } + vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT, + (void *)sysnoti_mount_mmc_cb); + return 0; +} + +API int sysman_request_mount_mmc(struct mmc_contents *mmc_data) +{ + if (mmc_data != NULL && mmc_data->mmc_cb != NULL) + vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_MOUNT, + (void *)sysnoti_mount_mmc_cb, (void *)mmc_data); + return sysman_call_predef_action(PREDEF_MOUNT_MMC, 0); +} + +static int sysnoti_unmount_mmc_cb(keynode_t *key_nodes, void *data) +{ + struct mmc_contents *mmc_data; + int mmc_err = 0; + mmc_data = (struct mmc_contents *)data; + DBG("unmountmmc_cb called"); + if (vconf_keynode_get_int(key_nodes) == + VCONFKEY_SYSMAN_MMC_UNMOUNT_COMPLETED) { + DBG("unmount ok"); + (mmc_data->mmc_cb)(0, mmc_data->user_data); + } else { + DBG("unmount fail"); + vconf_get_int(VCONFKEY_SYSMAN_MMC_ERR_STATUS, &mmc_err); + (mmc_data->mmc_cb)(mmc_err, mmc_data->user_data); + } + vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_UNMOUNT, + (void *)sysnoti_unmount_mmc_cb); + return 0; +} + +API int sysman_request_unmount_mmc(struct mmc_contents *mmc_data, int option) +{ + char buf[255]; + if (option != 1 && option != 2) { + DBG("option is wrong. default option 1 will be used"); + option = 1; + } + snprintf(buf, sizeof(buf), "%d", option); + + if (mmc_data != NULL && mmc_data->mmc_cb != NULL) + vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_UNMOUNT, + (void *)sysnoti_unmount_mmc_cb, + (void *)mmc_data); + return sysman_call_predef_action(PREDEF_UNMOUNT_MMC, 1, buf); +} + +static int sysnoti_format_mmc_cb(keynode_t *key_nodes, void *data) +{ + struct mmc_contents *mmc_data; + mmc_data = (struct mmc_contents *)data; + DBG("format_cb called"); + if (vconf_keynode_get_int(key_nodes) == + VCONFKEY_SYSMAN_MMC_FORMAT_COMPLETED) { + DBG("format ok"); + (mmc_data->mmc_cb)(0, mmc_data->user_data); + + } else { + DBG("format fail"); + (mmc_data->mmc_cb)(-1, mmc_data->user_data); + } + vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, + (void *)sysnoti_format_mmc_cb); + return 0; +} + +API int sysman_request_format_mmc(struct mmc_contents *mmc_data) +{ + if (mmc_data != NULL && mmc_data->mmc_cb != NULL) + vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, + (void *)sysnoti_format_mmc_cb, + (void *)mmc_data); + return sysman_call_predef_action(PREDEF_FORMAT_MMC, 0); +} + +API int sysman_request_set_cpu_max_frequency(int val) +{ + char buf_pid[8]; + char buf_freq[256]; + + // to do - need to check new frequncy is valid + snprintf(buf_pid, sizeof(buf_pid), "%d", getpid()); + snprintf(buf_freq, sizeof(buf_freq), "%d", val * 1000); + + return sysman_call_predef_action(PREDEF_SET_MAX_FREQUENCY, 2, buf_pid, buf_freq); +} + +API int sysman_request_set_cpu_min_frequency(int val) +{ + char buf_pid[8]; + char buf_freq[256]; + + // to do - need to check new frequncy is valid + snprintf(buf_pid, sizeof(buf_pid), "%d", getpid()); + snprintf(buf_freq, sizeof(buf_freq), "%d", val * 1000); + + return sysman_call_predef_action(PREDEF_SET_MIN_FREQUENCY, 2, buf_pid, buf_freq); +} + +API int sysman_release_cpu_max_frequency() +{ + char buf_pid[8]; + + snprintf(buf_pid, sizeof(buf_pid), "%d", getpid()); + + return sysman_call_predef_action(PREDEF_RELEASE_MAX_FREQUENCY, 1, buf_pid); +} + +API int sysman_release_cpu_min_frequency() +{ + char buf_pid[8]; + + snprintf(buf_pid, sizeof(buf_pid), "%d", getpid()); + + return sysman_call_predef_action(PREDEF_RELEASE_MIN_FREQUENCY, 1, buf_pid); +}