2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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.
20 #include <sys/types.h>
23 #include <sys/signalfd.h>
28 #include <Ecore_Evas.h>
30 #include <glib-object.h>
37 #include "slave_life.h"
38 #include "slave_rpc.h"
39 #include "client_life.h"
41 #include "buffer_handler.h"
42 #include "script_handler.h"
45 #include "dead_monitor.h"
53 #include "critical_log.h"
55 #include "shortcut_service.h"
56 #include "notification_service.h"
57 #include "utility_service.h"
58 #include "badge_service.h"
64 static inline int app_create(void)
68 if (access(SLAVE_LOG_PATH, R_OK|W_OK) != 0) {
69 if (mkdir(SLAVE_LOG_PATH, 755) < 0)
70 ErrPrint("Failed to create %s (%s)\n", SLAVE_LOG_PATH, strerror(errno));
75 * Dead signal handler has to be initialized before
76 * initate package or client (slave and client).
78 * Because while creating slaves for packages.
79 * It could be crashed before complete the initation stage.
81 * Then the dead callback should be invoked to handle it properly.
83 * To enable the dead signal handler,
84 * dead_init should be done before other components are initiated.
87 DbgPrint("Setting initialized: %d\n", ret);
90 DbgPrint("Client initialized: %d\n", ret);
93 DbgPrint("Dead callback is registered: %d\n", ret);
96 DbgPrint("group init: %d\n", ret);
99 DbgPrint("Init I/O: %d\n", ret);
101 ret = package_init();
102 DbgPrint("pkgmgr initialized: %d\n", ret);
106 ret = xmonitor_init();
107 DbgPrint("XMonitor init is done: %d\n", ret);
109 ret = buffer_handler_init();
110 DbgPrint("Buffer handler init is done: %d\n", ret);
114 * After initiate all other sub-systtems,
115 * Enable the server socket.
118 DbgPrint("Server initialized: %d\n", ret);
122 shortcut_service_init();
123 notification_service_init();
124 badge_service_init();
125 utility_service_init();
131 static inline int app_terminate(void)
136 DbgPrint("Finalize server: %d\n", ret);
139 DbgPrint("dead signal handler finalized: %d\n", ret);
141 ret = utility_service_fini();
142 DbgPrint("utility: %d\n", ret);
144 ret = badge_service_fini();
145 DbgPrint("badge: %d\n", ret);
147 ret = notification_service_fini();
148 DbgPrint("noti: %d\n", ret);
150 ret = shortcut_service_fini();
151 DbgPrint("shortcut: %d\n", ret);
154 DbgPrint("event: %d\n", ret);
156 ret = setting_fini();
157 DbgPrint("Finalize setting : %d\n", ret);
159 ret = instance_fini();
160 DbgPrint("Finalizing instances: %d\n", ret);
162 ret = package_fini();
163 DbgPrint("Finalize package info: %d\n", ret);
166 DbgPrint("script: %d\n", ret);
168 ret = buffer_handler_fini();
169 DbgPrint("buffer handler: %d\n", ret);
176 DbgPrint("IO finalized: %d\n", ret);
179 DbgPrint("Group finalized: %d\n", ret);
181 DbgPrint("Terminated\n");
185 static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler)
187 struct signalfd_siginfo fdsi;
191 fd = ecore_main_fd_handler_fd_get(handler);
193 ErrPrint("Unable to get FD\n");
194 return ECORE_CALLBACK_CANCEL;
197 size = read(fd, &fdsi, sizeof(fdsi));
198 if (size != sizeof(fdsi)) {
199 ErrPrint("Unable to get siginfo: %s\n", strerror(errno));
200 return ECORE_CALLBACK_CANCEL;
203 if (fdsi.ssi_signo == SIGTERM) {
206 CRITICAL_LOG("Terminated(SIGTERM)\n");
208 cfd = creat("/tmp/.stop.provider", 0644);
209 if (cfd < 0 || close(cfd) < 0)
210 ErrPrint("stop.provider: %s\n", strerror(errno));
212 vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
214 ecore_main_loop_quit();
215 } else if (fdsi.ssi_signo == SIGUSR1) {
217 * Turn off auto-reactivation
218 * Terminate all slaves
220 CRITICAL_LOG("USRS1, Deactivate ALL\n");
221 slave_deactivate_all(0, 1);
222 } else if (fdsi.ssi_signo == SIGUSR2) {
224 * Turn on auto-reactivation
225 * Launch all slaves again
227 CRITICAL_LOG("USR2, Activate ALL\n");
228 slave_activate_all();
230 CRITICAL_LOG("Unknown SIG[%d] received\n", fdsi.ssi_signo);
233 return ECORE_CALLBACK_RENEW;
236 int main(int argc, char *argv[])
240 Ecore_Fd_Handler *signal_handler = NULL;
244 * Clear old contents files before start the master provider.
246 (void)util_unlink_files(ALWAYS_PATH);
247 (void)util_unlink_files(READER_PATH);
248 (void)util_unlink_files(IMAGE_PATH);
249 (void)util_unlink_files(SLAVE_LOG_PATH);
252 * How could we care this return values?
253 * Is there any way to print something on the screen?
255 ret = critical_log_init(util_basename(argv[0]));
257 ErrPrint("Failed to init the critical log\n");
260 __file_log_fp = fopen("/tmp/live.log", "w+t");
262 __file_log_fp = fdopen(1, "w+t");
264 /* appcore_agent_terminate */
265 if (ecore_init() <= 0) {
266 CRITICAL_LOG("Failed to initiate ecore\n");
273 ret = sigaddset(&mask, SIGTERM);
275 CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
277 ret = sigaddset(&mask, SIGUSR1);
279 CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
281 ret = sigaddset(&mask, SIGUSR2);
283 CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
285 ret = sigprocmask(SIG_BLOCK, &mask, NULL);
287 CRITICAL_LOG("Failed to mask the SIGTERM: %s\n", strerror(errno));
289 ret = signalfd(-1, &mask, 0);
291 CRITICAL_LOG("Failed to initiate the signalfd: %s\n", strerror(errno));
293 signal_handler = ecore_main_fd_handler_add(ret, ECORE_FD_READ, signal_cb, NULL, NULL, NULL);
294 CRITICAL_LOG("Signal handler initiated: %d\n", ret);
297 if (ecore_x_init(NULL) <= 0) {
298 CRITICAL_LOG("Failed to ecore x init\n");
304 ecore_app_args_set(argc, (const char **)argv);
306 if (evas_init() <= 0) {
307 CRITICAL_LOG("Failed to init evas return count is below than 0\n");
314 if (ecore_evas_init() <= 0) {
315 CRITICAL_LOG("Failed to init ecore_evas\n");
329 vconf_set_bool(VCONFKEY_MASTER_STARTED, 1);
330 ecore_main_loop_begin();
331 vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
336 ecore_evas_shutdown();
341 ecore_main_fd_handler_del(signal_handler);
348 fclose(__file_log_fp);