SET(STORAGED_APPS ${CMAKE_SOURCE_DIR}/apps)
SET(SRCS
- src/core/main.c
+ src/core/storaged.c
src/core/modules.c
src/shared/common.c
)
+++ /dev/null
-/*
- * storaged
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/reboot.h>
-#include <argos.h>
-#include <systemd/sd-daemon.h>
-#include <glib.h>
-#include <libsyscommon/libgdbus.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "log.h"
-#include "modules.h"
-#include "storaged_common.h"
-
-#define WATCHDOG_TIMEOUT 15 /* Seconds */
-#define STORAGED_DIR_PATH "/run/storaged"
-
-static GMainLoop *loop;
-static dbus_handle_h g_handle = NULL;
-
-static gboolean handle_signal(gpointer data)
-{
- long signo = (long) data;
-
- _D("Received signal(%ld), Storaged'll be finished.", signo);
-
- if (loop && g_main_loop_is_running(loop))
- g_main_loop_quit(loop);
-
- return G_SOURCE_REMOVE;
-}
-
-void watchdog_notify(void)
-{
- int ret = aw_notify();
- if (ret < 0)
- _E("Failed to aw_notify:%d", ret);
-}
-
-static gboolean watchdog_cb(gpointer data)
-{
- watchdog_notify();
- return G_SOURCE_CONTINUE;
-}
-
-static void dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
-{
- _I("sd_notify(READY=1)");
- sd_notify(0, "READY=1");
-}
-
-static void dir_init(void)
-{
- int ret;
-
- ret = remove_directory(STORAGED_DIR_PATH);
- if (ret < 0)
- _E("Failed to remove directory.");
- ret = mkdir(STORAGED_DIR_PATH, 0644);
- if (ret < 0)
- _E("Failed to make directory: %d", errno);
-
-}
-
-int main(int argc, char **argv)
-{
- guint timer;
- int ret;
-
- g_handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, TRUE);
- if (!g_handle)
- _E("Failed to get dbus connection.");
-
- loop = g_main_loop_new(NULL, TRUE);
- if (!loop) {
- _E("Failed to make main loop.");
- return -ENOMEM;
- }
-
- dir_init();
- modules_init((void *)&g_handle);
-
- ret = gdbus_request_name(g_handle, STORAGED_BUS_NAME, dbus_name_acquired, NULL);
- if (ret <= 0) {
- _E("Failed to request bus name.");
- gdbus_check_name_owner(NULL, STORAGED_BUS_NAME);
- }
-
- g_unix_signal_add(SIGTERM, handle_signal, (gpointer) SIGTERM);
- g_unix_signal_add(SIGUSR1, handle_signal, (gpointer) SIGUSR1);
-
- timer = g_timeout_add(WATCHDOG_TIMEOUT * 1000, watchdog_cb, NULL);
- if (timer > 0) {
- ret = aw_register(WATCHDOG_TIMEOUT * 6);
- if (ret < 0)
- _E("Failed to aw_register.");
- }
-
- g_main_loop_run(loop);
-
- modules_deinit(NULL);
-
- if (!g_handle)
- return 0;
-
- ret = gdbus_free_connection(g_handle);
- if (ret < 0) {
- _E("Failed to free dbus connection %d", ret);
- g_handle = NULL;
- return ret;
- }
-
- g_handle = NULL;
-
- return 0;
-}
--- /dev/null
+/*
+ * storaged
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/reboot.h>
+#include <argos.h>
+#include <systemd/sd-daemon.h>
+#include <glib.h>
+#include <libsyscommon/libgdbus.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "log.h"
+#include "storaged.h"
+#include "modules.h"
+#include "storaged_common.h"
+
+#define WATCHDOG_TIMEOUT 15 /* Seconds */
+#define STORAGED_DIR_PATH "/run/storaged"
+
+static GMainLoop *loop;
+static dbus_handle_h g_handle = NULL;
+
+static gboolean handle_signal(gpointer data)
+{
+ long signo = (long) data;
+
+ _D("Received signal(%ld), Storaged'll be finished.", signo);
+
+ if (loop && g_main_loop_is_running(loop))
+ g_main_loop_quit(loop);
+
+ return G_SOURCE_REMOVE;
+}
+
+void watchdog_notify(void)
+{
+ int ret = aw_notify();
+ if (ret < 0)
+ _E("Failed to aw_notify:%d", ret);
+}
+
+static gboolean watchdog_cb(gpointer data)
+{
+ watchdog_notify();
+ return G_SOURCE_CONTINUE;
+}
+
+static void dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+ _I("sd_notify(READY=1)");
+ sd_notify(0, "READY=1");
+}
+
+static void dir_init(void)
+{
+ int ret;
+
+ ret = remove_directory(STORAGED_DIR_PATH);
+ if (ret < 0)
+ _E("Failed to remove directory.");
+ ret = mkdir(STORAGED_DIR_PATH, 0644);
+ if (ret < 0)
+ _E("Failed to make directory: %d", errno);
+
+}
+
+int storaged_init(void *data)
+{
+ guint timer;
+ int ret;
+
+ g_handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, TRUE);
+ if (!g_handle)
+ _E("Failed to get dbus connection.");
+
+ dir_init();
+ modules_init((void *)&g_handle);
+
+ ret = gdbus_request_name(g_handle, STORAGED_BUS_NAME, dbus_name_acquired, NULL);
+ if (ret <= 0) {
+ _E("Failed to request bus name.");
+ gdbus_check_name_owner(NULL, STORAGED_BUS_NAME);
+ }
+
+ g_unix_signal_add(SIGTERM, handle_signal, (gpointer) SIGTERM);
+ g_unix_signal_add(SIGUSR1, handle_signal, (gpointer) SIGUSR1);
+
+ timer = g_timeout_add(WATCHDOG_TIMEOUT * 1000, watchdog_cb, NULL);
+ if (timer > 0) {
+ ret = aw_register(WATCHDOG_TIMEOUT * 6);
+ if (ret < 0)
+ _E("Failed to aw_register.");
+ }
+
+ return 0;
+}
+
+int storaged_exit(void *data)
+{
+ int ret = 0;
+
+ modules_deinit(NULL);
+
+ if (!g_handle)
+ return 0;
+
+ ret = gdbus_free_connection(g_handle);
+ if (ret < 0) {
+ _E("Failed to free dbus connection %d", ret);
+ g_handle = NULL;
+ return ret;
+ }
+
+ g_handle = NULL;
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ loop = g_main_loop_new(NULL, TRUE);
+ if (!loop) {
+ _E("Failed to make main loop.");
+ return -ENOMEM;
+ }
+
+ storaged_init(NULL);
+
+ g_main_loop_run(loop);
+
+ storaged_exit(NULL);
+
+ return 0;
+}
--- /dev/null
+/*
+ * storaged
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STORAGED_H__
+#define __STORAGED_H__
+
+int storaged_init(void *data);
+int storaged_exit(void *data);
+
+#endif /* __STORAGED_H__ */