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"
59 #include "file_service.h"
65 static inline int app_create(void)
69 if (access(SLAVE_LOG_PATH, R_OK|W_OK) != 0) {
70 if (mkdir(SLAVE_LOG_PATH, 755) < 0) {
71 ErrPrint("Failed to create %s (%s)\n", SLAVE_LOG_PATH, strerror(errno));
77 * Dead signal handler has to be initialized before
78 * initate package or client (slave and client).
80 * Because while creating slaves for packages.
81 * It could be crashed before complete the initation stage.
83 * Then the dead callback should be invoked to handle it properly.
85 * To enable the dead signal handler,
86 * dead_init should be done before other components are initiated.
89 DbgPrint("Setting initialized: %d\n", ret);
92 DbgPrint("Client initialized: %d\n", ret);
95 DbgPrint("Dead callback is registered: %d\n", ret);
98 DbgPrint("group init: %d\n", ret);
101 DbgPrint("Init I/O: %d\n", ret);
103 ret = package_init();
104 DbgPrint("pkgmgr initialized: %d\n", ret);
108 ret = xmonitor_init();
109 DbgPrint("XMonitor init is done: %d\n", ret);
111 ret = buffer_handler_init();
112 DbgPrint("Buffer handler init is done: %d\n", ret);
116 * After initiate all other sub-systtems,
117 * Enable the server socket.
120 DbgPrint("Server initialized: %d\n", ret);
124 shortcut_service_init();
125 notification_service_init();
126 badge_service_init();
127 utility_service_init();
135 static inline int app_terminate(void)
139 ret = file_service_fini();
140 DbgPrint("Finalize the file service: %d\n", ret);
143 DbgPrint("Finalize server: %d\n", ret);
146 DbgPrint("dead signal handler finalized: %d\n", ret);
148 ret = utility_service_fini();
149 DbgPrint("utility: %d\n", ret);
151 ret = badge_service_fini();
152 DbgPrint("badge: %d\n", ret);
154 ret = notification_service_fini();
155 DbgPrint("noti: %d\n", ret);
157 ret = shortcut_service_fini();
158 DbgPrint("shortcut: %d\n", ret);
161 DbgPrint("event: %d\n", ret);
163 ret = setting_fini();
164 DbgPrint("Finalize setting : %d\n", ret);
166 ret = instance_fini();
167 DbgPrint("Finalizing instances: %d\n", ret);
169 ret = package_fini();
170 DbgPrint("Finalize package info: %d\n", ret);
173 DbgPrint("script: %d\n", ret);
175 ret = buffer_handler_fini();
176 DbgPrint("buffer handler: %d\n", ret);
183 DbgPrint("IO finalized: %d\n", ret);
186 DbgPrint("Group finalized: %d\n", ret);
188 DbgPrint("Terminated\n");
192 static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler)
194 struct signalfd_siginfo fdsi;
198 fd = ecore_main_fd_handler_fd_get(handler);
200 ErrPrint("Unable to get FD\n");
201 return ECORE_CALLBACK_CANCEL;
204 size = read(fd, &fdsi, sizeof(fdsi));
205 if (size != sizeof(fdsi)) {
206 ErrPrint("Unable to get siginfo: %s\n", strerror(errno));
207 return ECORE_CALLBACK_CANCEL;
210 if (fdsi.ssi_signo == SIGTERM) {
213 CRITICAL_LOG("Terminated(SIGTERM)\n");
215 cfd = creat("/tmp/.stop.provider", 0644);
216 if (cfd < 0 || close(cfd) < 0) {
217 ErrPrint("stop.provider: %s\n", strerror(errno));
220 vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
222 ecore_main_loop_quit();
223 } else if (fdsi.ssi_signo == SIGUSR1) {
225 * Turn off auto-reactivation
226 * Terminate all slaves
228 CRITICAL_LOG("USRS1, Deactivate ALL\n");
229 slave_deactivate_all(0, 1);
230 } else if (fdsi.ssi_signo == SIGUSR2) {
232 * Turn on auto-reactivation
233 * Launch all slaves again
235 CRITICAL_LOG("USR2, Activate ALL\n");
236 slave_activate_all();
238 CRITICAL_LOG("Unknown SIG[%d] received\n", fdsi.ssi_signo);
241 return ECORE_CALLBACK_RENEW;
244 int main(int argc, char *argv[])
247 int restart_count = 0;
249 Ecore_Fd_Handler *signal_handler = NULL;
256 * Clear old contents files before start the master provider.
258 (void)util_unlink_files(ALWAYS_PATH);
259 (void)util_unlink_files(READER_PATH);
260 (void)util_unlink_files(IMAGE_PATH);
261 (void)util_unlink_files(SLAVE_LOG_PATH);
264 * How could we care this return values?
265 * Is there any way to print something on the screen?
267 ret = critical_log_init(util_basename(argv[0]));
269 ErrPrint("Failed to init the critical log\n");
273 __file_log_fp = fopen("/tmp/live.log", "w+t");
274 if (!__file_log_fp) {
275 __file_log_fp = fdopen(1, "w+t");
278 /* appcore_agent_terminate */
279 if (ecore_init() <= 0) {
280 CRITICAL_LOG("Failed to initiate ecore\n");
287 ret = sigaddset(&mask, SIGTERM);
289 CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
292 ret = sigaddset(&mask, SIGUSR1);
294 CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
297 ret = sigaddset(&mask, SIGUSR2);
299 CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
302 ret = sigprocmask(SIG_BLOCK, &mask, NULL);
304 CRITICAL_LOG("Failed to mask the SIGTERM: %s\n", strerror(errno));
307 ret = signalfd(-1, &mask, 0);
309 CRITICAL_LOG("Failed to initiate the signalfd: %s\n", strerror(errno));
311 signal_handler = ecore_main_fd_handler_add(ret, ECORE_FD_READ, signal_cb, NULL, NULL, NULL);
312 CRITICAL_LOG("Signal handler initiated: %d\n", ret);
315 if (ecore_x_init(NULL) <= 0) {
316 CRITICAL_LOG("Failed to ecore x init\n");
322 ecore_app_args_set(argc, (const char **)argv);
324 if (evas_init() <= 0) {
325 CRITICAL_LOG("Failed to init evas return count is below than 0\n");
332 if (ecore_evas_init() <= 0) {
333 CRITICAL_LOG("Failed to init ecore_evas\n");
341 #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
347 * conf_update_size requires ecore_x_init.
353 vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count);
355 vconf_set_int(VCONFKEY_MASTER_RESTART_COUNT, restart_count);
357 vconf_set_bool(VCONFKEY_MASTER_STARTED, 1);
358 ecore_main_loop_begin();
359 vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
364 ecore_evas_shutdown();
368 if (signal_handler) {
369 ecore_main_fd_handler_del(signal_handler);
377 fclose(__file_log_fp);