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.
26 #include <Ecore_File.h>
29 #include "ss_launch.h"
31 #define BSNOTI_DIR "/opt/bs"
32 #define BSNOTI_FILE "curbs.log"
33 #define BSNOTI_FULL_PATH BSNOTI_DIR"/"BSNOTI_FILE
35 #define CRASH_WORKER_PATH "/usr/apps/org.tizen.crash-worker/bin/crash-worker"
38 static int add_noti(void);
40 static int make_noti_file(const char *path, const char *file)
42 PRT_TRACE("Make Noti File");
46 /* make a directory */
47 if (access(path, F_OK) == -1) {
48 snprintf(buf, sizeof(buf), "mkdir -p %s", path);
50 snprintf(buf, sizeof(buf), "chown root:app %s", path);
54 snprintf(buf, sizeof(buf), "%s/%s", path, file);
56 if (access(buf, F_OK) == 0)
59 fd = open(buf, O_CREAT, S_IRUSR | S_IWUSR);
61 snprintf(buf, sizeof(buf), "chmod 666 %s/%s", path, file);
63 snprintf(buf, sizeof(buf), "chown root:app %s/%s", path, file);
69 static void launch_crash_worker(void *data)
72 char bsfile_name[NAME_MAX], bs_color[MAX_INPUT];
73 char args[NAME_MAX + MAX_INPUT];
76 fp = fopen((char *)data, "r");
80 /* launch bs process */
81 while (fgets(args, NAME_MAX + MAX_INPUT, fp) != NULL) {
82 /* add rule for log */
83 if (args[strlen(args) - 1] != '\n') {
84 PRT_TRACE_ERR("bsfile log must be terminated with new line character\n");
87 /* change last caracter from \n to \0 */
88 args[strlen(args) - 1] = '\0';
89 for (i = 0; i < NAME_MAX + MAX_INPUT; i++) {
91 if (i >= NAME_MAX - 1) {
92 PRT_TRACE_ERR("bsfile name is over 254. 255(NAME_MAX) - 1(NULL Termination)\n");
95 strncpy(bsfile_name, args, i);
96 bsfile_name[i] = '\0';
97 strncpy(bs_color, args + i + 1, MAX_INPUT);
98 bs_color[MAX_INPUT - 1] = '\0';
99 snprintf(args, sizeof(args), "%s %s",
100 bsfile_name, bs_color);
101 PRT_TRACE("bsfile_name(size %d): %s\nargs: %s\n", i, bsfile_name, bs_color, args);
102 ret = ss_launch_evenif_exist (CRASH_WORKER_PATH, args);
112 fp = fopen((char *)data, "w");
122 static Ecore_File_Monitor *bs_file_monitor;
124 static Ecore_File_Monitor_Cb __bs_file_cb(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path)
127 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
128 case ECORE_FILE_EVENT_DELETED_SELF:
129 if (0 > make_noti_file(BSNOTI_DIR, BSNOTI_FILE)) {
130 launch_crash_worker((void *)path);
133 case ECORE_FILE_EVENT_MODIFIED:
135 launch_crash_worker((void *)path);
144 if (0 > make_noti_file(BSNOTI_DIR, BSNOTI_FILE)) {
145 PRT_TRACE_ERR("make_noti_file() failed");
146 launch_crash_worker((void *)BSNOTI_FULL_PATH);
149 if (0 == ecore_file_init()) {
150 PRT_TRACE_ERR("ecore_file_init() failed");
151 launch_crash_worker((void *)BSNOTI_FULL_PATH);
154 bs_file_monitor = ecore_file_monitor_add(BSNOTI_FULL_PATH,(void *) __bs_file_cb, NULL);
155 if (!bs_file_monitor) {
156 PRT_TRACE_ERR("ecore_file_monitor_add() failed");
157 launch_crash_worker((void *)BSNOTI_FULL_PATH);