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 <systemd/sd-daemon.h>
26 #include <libgdbus/dbus-system.h>
31 #define WATCHDOG_TIMEOUT 15 /* Seconds */
33 static GMainLoop *loop;
35 static void sig_quit(int signo)
37 _D("received SIGTERM signal %d", signo);
38 g_main_loop_quit(loop);
41 static void sig_usr1(int signo)
43 _D("received SIGUSR1 signal %d, storaged'll be finished!", signo);
45 g_main_loop_quit(loop);
48 void watchdog_notify(void)
50 int ret = aw_notify();
52 _E("aw_notify failed(%d)", ret);
55 static gboolean watchdog_cb(gpointer data)
58 return G_SOURCE_CONTINUE;
61 static gboolean storaged_notify(gpointer data)
63 _I("sd_notify(READY=1)");
64 sd_notify(0, "READY=1");
65 return G_SOURCE_REMOVE;
68 int main(int argc, char **argv)
73 loop = g_main_loop_new(NULL, TRUE);
75 _E("Failed to make main loop");
79 if (!dbus_handle_init(G_BUS_TYPE_SYSTEM, STORAGED_BUS_NAME, NULL, NULL)) {
80 _E("Failed to set dbus connection (%s)", STORAGED_BUS_NAME);
85 signal(SIGTERM, sig_quit);
86 signal(SIGUSR1, sig_usr1);
88 timer = g_timeout_add(WATCHDOG_TIMEOUT * 1000, watchdog_cb, NULL);
90 ret = aw_register(WATCHDOG_TIMEOUT * 2);
92 _E("aw_register failed");
95 g_idle_add(storaged_notify, NULL);
97 g_main_loop_run(loop);