Merge branch 'devel/tizen_3.0' into tizen
[platform/core/system/sensord.git] / src / server / main.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 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 <signal.h>
21 #include <sensor_logs.h>
22 #include <server.h>
23 #include <sensor_loader.h>
24 #include <string>
25
26 using std::string;
27
28 static void sig_term_handler(int signo, siginfo_t *info, void *data)
29 {
30         char proc_name[NAME_MAX];
31
32         get_proc_name(info->si_pid, proc_name);
33
34         _E("Received SIGTERM(%d) from %s(%d)\n", signo, proc_name, info->si_pid);
35         exit(EXIT_SUCCESS);
36 }
37
38 static void signal_init(void)
39 {
40         struct sigaction sig_act;
41         memset(&sig_act, 0, sizeof(struct sigaction));
42
43         sig_act.sa_handler = SIG_IGN;
44         sigaction(SIGCHLD, &sig_act, NULL);
45         sigaction(SIGPIPE, &sig_act, NULL);
46
47         sig_act.sa_handler = NULL;
48         sig_act.sa_sigaction = sig_term_handler;
49         sig_act.sa_flags = SA_SIGINFO;
50         sigaction(SIGTERM, &sig_act, NULL);
51 }
52
53 int main(int argc, char *argv[])
54 {
55         _I("Sensord started");
56
57         signal_init();
58
59         sensor_loader::get_instance().load();
60
61         server::get_instance().run();
62
63         server::get_instance().stop();
64
65         _I("Sensord terminated");
66         return 0;
67 }