4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongGi Jang <dg0402.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <sys/types.h>
40 #include "sysman-priv.h"
42 API int sysman_get_pid(const char *execpath)
45 struct dirent *dentry;
50 dp = opendir("/proc");
56 while ((dentry = readdir(dp)) != NULL) {
57 if (!isdigit(dentry->d_name[0]))
60 pid = atoi(dentry->d_name);
62 snprintf(buf, BUFF_MAX, "/proc/%d/cmdline", pid);
63 fd = open(buf, O_RDONLY);
66 if (read(fd, buf2, BUFF_MAX) < 0) {
72 if (!strcmp(buf2, execpath)) {
83 API int sysman_get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size)
86 char buf[PATH_MAX + 1];
89 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
90 fd = open(buf, O_RDONLY);
96 ret = read(fd, buf, PATH_MAX);
100 filename = strrchr(buf, '/');
101 if (filename == NULL)
104 filename = filename + 1;
106 if (cmdline_size < strlen(filename) + 1) {
111 strncpy(cmdline, filename, cmdline_size - 1);
112 cmdline[cmdline_size - 1] = '\0';
116 API int sysman_get_apppath(pid_t pid, char *app_path, size_t app_path_size)
121 snprintf(buf, PATH_MAX, "/proc/%d/exe", pid);
123 || (ret = readlink(buf, app_path, app_path_size)) == -1)
125 if (app_path_size == ret) {
126 app_path[ret - 1] = '\0';
131 app_path[ret] = '\0';