4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/reboot.h>
24 #include "display/core.h"
27 #include "edbus-handler.h"
29 #include "shared/dbus.h"
30 #include "device-notifier.h"
32 #define PIDFILE_PATH "/var/run/.deviced.pid"
34 static void init_ad(struct main_data *ad)
36 memset(ad, 0x0, sizeof(struct main_data));
39 static void writepid(char *pidpath)
43 fp = fopen(pidpath, "w");
45 fprintf(fp, "%d", getpid());
50 static void sig_quit(int signo)
52 _D("received SIGTERM signal %d", signo);
55 static void sig_usr1(int signo)
57 _D("received SIGUSR1 signal %d, deviced'll be finished!", signo);
59 ecore_main_loop_quit();
62 static void check_systemd_active(void)
66 DBusMessageIter iter, sub;
70 pa[0] = "org.freedesktop.systemd1.Unit";
71 pa[1] = "ActiveState";
73 _I("%s %s", pa[0], pa[1]);
75 msg = dbus_method_sync_with_reply("org.freedesktop.systemd1",
76 "/org/freedesktop/systemd1/unit/default_2etarget",
77 "org.freedesktop.DBus.Properties",
82 dbus_error_init(&err);
84 if (!dbus_message_iter_init(msg, &iter) ||
85 dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
88 dbus_message_iter_recurse(&iter, &sub);
90 if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
93 dbus_message_iter_get_basic(&sub, &state);
95 if (strncmp(state, "active", 6) == 0) {
96 _I("notify relaunch");
97 device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)TRUE);
100 dbus_message_unref(msg);
101 dbus_error_free(&err);
104 static int system_main(int argc, char **argv)
111 check_systemd_active();
112 signal(SIGTERM, sig_quit);
113 signal(SIGUSR1, sig_usr1);
115 ecore_main_loop_begin();
123 int main(int argc, char **argv)
125 writepid(PIDFILE_PATH);
127 return system_main(argc, argv);