tizen 2.3 release
[framework/system/deviced.git] / src / core / main.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <sys/reboot.h>
23
24 #include "display/core.h"
25 #include "log.h"
26 #include "common.h"
27 #include "edbus-handler.h"
28 #include "devices.h"
29 #include "shared/dbus.h"
30 #include "device-notifier.h"
31
32 #define PIDFILE_PATH            "/var/run/.deviced.pid"
33
34 static void writepid(char *pidpath)
35 {
36         FILE *fp;
37
38         fp = fopen(pidpath, "w");
39         if (fp != NULL) {
40                 fprintf(fp, "%d", getpid());
41                 fclose(fp);
42         }
43 }
44
45 static void sig_quit(int signo)
46 {
47         _D("received SIGTERM signal %d", signo);
48 }
49
50 static void sig_usr1(int signo)
51 {
52         _D("received SIGUSR1 signal %d, deviced'll be finished!", signo);
53
54         ecore_main_loop_quit();
55 }
56
57 static int deviced_main(int argc, char **argv)
58 {
59         int ret;
60
61         edbus_init(NULL);
62         devices_init(NULL);
63         ret = check_systemd_active();
64         if (ret == TRUE) {
65                 _I("notify relaunch");
66                 device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)TRUE);
67         }
68         signal(SIGTERM, sig_quit);
69         signal(SIGUSR1, sig_usr1);
70
71         ecore_main_loop_begin();
72
73         devices_exit(NULL);
74         edbus_exit(NULL);
75         ecore_shutdown();
76         return 0;
77 }
78
79 int main(int argc, char **argv)
80 {
81         writepid(PIDFILE_PATH);
82         ecore_init();
83         return deviced_main(argc, argv);
84 }