diff options
author | HyungKyu Song <hk76.song@samsung.com> | 2013-02-16 00:16:25 +0900 |
---|---|---|
committer | HyungKyu Song <hk76.song@samsung.com> | 2013-02-16 00:16:25 +0900 |
commit | ffc1b2e81b03a2ddc03edafef7abffc1be4454c0 (patch) | |
tree | 1c1a876954a650cfef753a9bb019e132ae9cc8bc /set_pmon | |
parent | 53096f6974850e1ac26414ff4bbfe5d632ab0c07 (diff) | |
download | libslp-sysman-ffc1b2e81b03a2ddc03edafef7abffc1be4454c0.tar.gz libslp-sysman-ffc1b2e81b03a2ddc03edafef7abffc1be4454c0.tar.bz2 libslp-sysman-ffc1b2e81b03a2ddc03edafef7abffc1be4454c0.zip |
Diffstat (limited to 'set_pmon')
-rw-r--r-- | set_pmon/CMakeLists.txt | 13 | ||||
-rwxr-xr-x | set_pmon/pmon | 5 | ||||
-rwxr-xr-x | set_pmon/regpmon.sh | 12 | ||||
-rwxr-xr-x | set_pmon/set_pmon.c | 126 |
4 files changed, 156 insertions, 0 deletions
diff --git a/set_pmon/CMakeLists.txt b/set_pmon/CMakeLists.txt new file mode 100644 index 0000000..72f3c70 --- /dev/null +++ b/set_pmon/CMakeLists.txt @@ -0,0 +1,13 @@ +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_BINARY_DIR}/set_pmon/regpmon.sh DESTINATION bin) + +# install rc script +INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/set_pmon/pmon DESTINATION /etc/rc.d/init.d) diff --git a/set_pmon/pmon b/set_pmon/pmon new file mode 100755 index 0000000..f389e5f --- /dev/null +++ b/set_pmon/pmon @@ -0,0 +1,5 @@ +#!/bin/sh + +# clean up vip process history +rm -f /tmp/vip/* + diff --git a/set_pmon/regpmon.sh b/set_pmon/regpmon.sh new file mode 100755 index 0000000..3aa71e8 --- /dev/null +++ b/set_pmon/regpmon.sh @@ -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/set_pmon/set_pmon.c b/set_pmon/set_pmon.c new file mode 100755 index 0000000..ce0725c --- /dev/null +++ b/set_pmon/set_pmon.c @@ -0,0 +1,126 @@ +/* + * 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'; + + if (type == 'v') + set_oomadj(pid, -17); + + 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]); + 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; +} |