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 <giyeol.ok@samsung.com>
Change-Id: Idd5077216894ba41de91959a74d04844306f9e41
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)
ecore-x
edbus
eina
- sysman
vconf
heynoti
pmapi
ADD_SUBDIRECTORY(pm_event)
ADD_SUBDIRECTORY(sys_device_noti)
ADD_SUBDIRECTORY(sys_pci_noti)
+ADD_SUBDIRECTORY(sysman)
#include <stdio.h>
#include <stdlib.h>
-#include <util.h>
+#include "util.h"
#include "setting.h"
#include "conf.h"
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
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)
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
cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
%build
+cp %{SOURCE1} .
cp %{SOURCE2} .
cp %{SOURCE3} .
make %{?jobs:-j%jobs}
systemctl daemon-reload
-%files
+%files -n system-server
%manifest system-server.manifest
%{_bindir}/system_server
/opt/etc/smack/accesses.d/system-server.rule
%{_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.*
#include <fcntl.h>
#include <errno.h>
#include <string.h>
-#include <sysman.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <poll.h>
+#include "ss_log.h"
+
+#define PERMANENT_DIR "/tmp/permanent"
+#define VIP_DIR "/tmp/vip"
/**
* Opens "/proc/$pid/oom_adj" file for w/r;
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
#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 */
*/
-#include <sysman.h>
#include "include/ss_data.h"
#include "ss_queue.h"
#include "ss_log.h"
#include <dirent.h>
#include <errno.h>
#include <vconf.h>
-#include <sysman.h>
#include <pmapi.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <aul.h>
#include <bundle.h>
#include <dirent.h>
+#include "sysman.h"
#include <libudev.h>
#include "ss_queue.h"
#include "ss_log.h"
#include "vconf-keys.h"
#include "ss_log.h"
#include "ss_launch.h"
+#include "ss_common.h"
#define MAX_ARGS 255
errno = EINVAL;
return -1;
}
- if (pid = sysman_get_pid(execpath) > 0)
+ if (pid = get_exec_pid(execpath) > 0)
return pid;
va_start(argptr, 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);
#include <limits.h>
#include <heynoti.h>
#include <vconf.h>
-#include <sysman.h>
#include <fcntl.h>
#include "ss_log.h"
#include <fcntl.h>
#include <assert.h>
#include <limits.h>
-#include <sysman.h>
#include <heynoti.h>
#include <vconf.h>
#include <sys/types.h>
*/
-#include <sysman.h>
#include <fcntl.h>
#include <assert.h>
#include <limits.h>
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("=======================================");
#include <limits.h>
#include <fcntl.h>
#include <dirent.h>
-#include <sysman.h>
#include <vconf.h>
#include <pmapi.h>
#include <ITapiModem.h>
#include <mntent.h>
#include <sys/mount.h>
+#include "sysman.h"
#include "ss_log.h"
#include "ss_launch.h"
#include "ss_queue.h"
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",
#include <sys/types.h>
#include <device-node.h>
-#include <sysman.h>
#include "include/ss_data.h"
#include "ss_queue.h"
#include "ss_log.h"
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);
*/
-#include <sysman.h>
#include <dlfcn.h>
#include "include/ss_data.h"
#include "ss_core.h"
*/
-#include <sysman.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/socket.h>
#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
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",
#include <pmapi.h>
#include <vconf.h>
-#include <sysman.h>
#include "device-node.h"
#include "ss_log.h"
#include <pmapi.h>
#include <vconf.h>
-#include <sysman.h>
#include "include/ss_data.h"
#include "ss_queue.h"
#include "ss_log.h"
#include <pmapi.h>
#include <vconf.h>
-#include <sysman.h>
#include "ss_log.h"
#include "device-node.h"
--- /dev/null
+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)
+
--- /dev/null
+/*
+ * 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
+ * @{
+
+<h1 class="pg">Introduction</h1>
+
+<h2 class="pg">Purpose</h2>
+The purpose of the document is to describe how applications can use the System Manager APIs. This document gives programming guidelines to application engineers.
+
+<h2 class="pg">Scope</h2>
+The scope of this document is limited to System Manager API usage.
+
+<br>
+<h1 class="pg">System Manager Library Overview</h1>
+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.<br>
+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.
+
+<h1 class="pg">System Manager Funtions</h1>
+
+<h2 class="pg">System Manager APIs</h2>
+<i><b>API : sysman_get_pid</b></i>
+<br><b>Parameter In :</b> const char *execpath
+<br><b>Return :</b> int
+<br><b>Functionality :</b> This API is used to get the pid of the process which has the specified execpath.<br>
+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).
+<br><br>
+<i><b>API : sysman_get_cmdline_name</b></i>
+<br><b>Parameter In :</b> pid_t pid
+<br><b>Parameter Out :</b> char *cmdline
+<br><b>Parameter In :</b> size_t cmdline_size
+<br><b>Return :</b> int
+<br><b>Functionality :</b>This API is used to get the file name in the command line.<br>
+Caller process MUST allocate enough memory for the cmdline parameter. Its size should be assigned to cmdline_size.<br>
+Internally it reads the 1st argument of /proc/{pid}/cmdline and copies it to cmdline.<br>
+The function returns 0 on success and a negative value (-1) on failure.
+<br><br>
+<i><b>API : sysman_get_apppath</b></i>
+<br><b>Parameter In :</b> pid_t pid
+<br><b>Parameter Out :</b> char *app_path
+<br><b>Parameter In :</b> size_t app_path_size
+<br><b>Return :</b> int
+<br><b>Functionality :</b> This API is used to get the execution path of the process specified by the pid parameter.<br>
+Caller process MUST allocate enough memory for the app_path parameter. Its size should be assigned to app_path_size.<br>
+Internally it reads a link of /proc/{pid}/exe and copies the path to app_path. <br>
+The function returns 0 on success and a negative value (-1) on failure.
+<br><br>
+<i><b>API : sysconf_set_mempolicy</b></i>
+<br><b>Parameter In :</b> enum mem_policy mempol
+<br><b>Return :</b> int
+<br><b>Functionality :</b> This API is used to set the policy of the caller process for the situation of low available memory.<br>
+The function returns 0 on success and a negative value (-1) on failure.<br>
+If the caller process has no permission, it will be failed.
+
+<b>Enumerate values</b>
+@code
+enum mem_policy {
+ OOM_LIKELY , // For micelloneous applications
+ OOM_NORMAL , // For fundamental applications
+ OOM_IGNORE // For daemon
+};
+@endcode
+
+ @}
+**/
--- /dev/null
+#!/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
--- /dev/null
+#!/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
--- /dev/null
+# 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"
--- /dev/null
+all
+ ^TEST
+##### Scenarios for TEST #####
+
+# Test scenario
+TEST
+ :include:/unit/tslist
--- /dev/null
+TET_OUTPUT_CAPTURE=False
+TET_BUILD_TOOL=make
+TET_PASS_TC_NAME=True
--- /dev/null
+TET_OUTPUT_CAPTURE=False
+TET_CLEAN_TOOL=make clean
--- /dev/null
+TET_OUTPUT_CAPTURE=False
--- /dev/null
+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)
--- /dev/null
+#!/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"
--- /dev/null
+/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
+
--- /dev/null
+#include <tet_api.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}*/
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+#include <tet_api.h>
+#include <sysman.h>
+
+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);
+}
--- /dev/null
+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)
--- /dev/null
+#!/bin/sh
+
+# clean up vip process history
+rm -f /tmp/vip/*
+
--- /dev/null
+#!/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
+
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <sysman.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#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 <monitoring type> <process name>\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;
+}
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <limits.h>
+
+#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/<pid>/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);
+}
--- /dev/null
+/*
+ * 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 <sys/types.h>
+#include <sysman.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* This file will be removed */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* ___SYSMAN_INTERNAL___ */
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#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 <dlog.h>
+# 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___ */
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <poll.h>
+
+#include <vconf.h>
+#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;
+}
+
--- /dev/null
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#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.
+ * <br> Please use libslp-sysman-dev debian package and sysman.pc file for development.
+ * <br> 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 <br>
+ * 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 <br>
+ * 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___ */
--- /dev/null
+# 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}
+
+
--- /dev/null
+/*
+ * 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 <sys/time.h>
+
+/**
+ * @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___ */
--- /dev/null
+/*
+ * 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 <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+
+#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);
+}