2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
50 HAPI int liveinfo_init(void)
55 HAPI int liveinfo_fini(void)
57 struct liveinfo *info;
59 EINA_LIST_FREE(s_info.info_list, info) {
61 unlink(info->fifo_name);
68 static inline int valid_requestor(pid_t pid)
70 char cmdline[60]; /* strlen("/proc/%d/cmdline") + 30 */
74 snprintf(cmdline, sizeof(cmdline), "/proc/%d/exe", pid);
76 DbgPrint("Open cmdline: %s (%d)\n", cmdline, pid);
78 if (stat(cmdline, &target) < 0) {
79 ErrPrint("Error: %s\n", strerror(errno));
83 if (stat("/usr/bin/liveinfo", &src) < 0) {
84 ErrPrint("Error: %s\n", strerror(errno));
88 return target.st_ino == src.st_ino;
91 HAPI struct liveinfo *liveinfo_create(pid_t pid, int handle)
93 struct liveinfo *info;
95 if (!valid_requestor(pid)) {
96 ErrPrint("Invalid requestor\n");
100 info = calloc(1, sizeof(*info));
102 ErrPrint("Heap: %s\n", strerror(errno));
106 snprintf(info->fifo_name, sizeof(info->fifo_name), "/tmp/.live_info.%lf", util_timestamp());
107 if (mkfifo(info->fifo_name, 0644) < 0) {
108 ErrPrint("mkfifo: %s\n", strerror(errno));
109 unlink(info->fifo_name);
116 info->handle = handle;
118 DbgPrint("Live info is successfully created\n");
119 s_info.info_list = eina_list_append(s_info.info_list, info);
123 HAPI int liveinfo_open_fifo(struct liveinfo *info)
125 DbgPrint("FIFO is created (%s)\n", info->fifo_name);
126 info->fp = fopen(info->fifo_name, "w");
128 ErrPrint("open: %s\n", strerror(errno));
135 HAPI int liveinfo_close_fifo(struct liveinfo *info)
145 HAPI int liveinfo_destroy(struct liveinfo *info)
147 s_info.info_list = eina_list_remove(s_info.info_list, info);
148 liveinfo_close_fifo(info);
149 unlink(info->fifo_name);
154 HAPI pid_t liveinfo_pid(struct liveinfo *info)
156 return info ? info->pid : (pid_t)-1;
159 HAPI const char *liveinfo_filename(struct liveinfo *info)
161 return info ? info->fifo_name : NULL;
164 HAPI FILE *liveinfo_fifo(struct liveinfo *info)
166 return info ? info->fp : NULL;
169 HAPI struct liveinfo *liveinfo_find_by_pid(pid_t pid)
172 struct liveinfo *info;
174 EINA_LIST_FOREACH(s_info.info_list, l, info) {
175 if (info->pid == pid)
182 HAPI struct liveinfo *liveinfo_find_by_handle(int handle)
185 struct liveinfo *info;
187 EINA_LIST_FOREACH(s_info.info_list, l, info) {
188 if (info->handle == handle)