1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of tlm (Tizen Login Manager)
6 * Copyright (C) 2013-2015 Intel Corporation.
8 * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
9 * Jussi Laako <jussi.laako@linux.intel.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 #include <glib-unix.h>
35 #include "tlm-manager.h"
37 #include "tlm-config.h"
38 #include "tlm-config-general.h"
41 static GMainLoop *main_loop = NULL;
45 _on_manager_stopped_cb (TlmManager *manager, gpointer user_data)
47 DBG ("manager stopped - quit mainloop");
48 g_main_loop_quit (main_loop);
52 _on_sigterm_cb (gpointer data)
54 DBG ("SIGTERM/SIGINT");
56 TlmManager *manager = TLM_MANAGER(data);
58 g_signal_connect (manager,
60 G_CALLBACK (_on_manager_stopped_cb),
62 tlm_manager_stop (manager);
68 _on_sighup_cb (gpointer data)
72 TlmManager *manager = TLM_MANAGER(data);
73 tlm_manager_sighup_received (manager);
79 _setup_unix_signal_handlers (TlmManager *manager)
81 g_unix_signal_add (SIGTERM, _on_sigterm_cb, (gpointer) manager);
82 g_unix_signal_add (SIGINT, _on_sigterm_cb, (gpointer) manager);
83 g_unix_signal_add (SIGHUP, _on_sighup_cb, (gpointer) manager);
86 int main(int argc, char *argv[])
89 TlmManager *manager = 0;
91 gboolean show_version = FALSE;
92 gboolean fatal_warnings = FALSE;
93 gchar *username = NULL;
95 GOptionContext *opt_context = NULL;
96 GOptionEntry opt_entries[] = {
98 G_OPTION_ARG_NONE, &show_version,
99 "Login Manager Version", "Version" },
100 { "fatal-warnings", 0, 0,
101 G_OPTION_ARG_NONE, &fatal_warnings,
102 "Make all warnings fatal", NULL },
103 { "username", 'u', 0,
104 G_OPTION_ARG_STRING, &username,
105 "Username to use", NULL },
109 #if !GLIB_CHECK_VERSION(2,35,0)
113 opt_context = g_option_context_new ("Tizen Login Manager");
114 g_option_context_add_main_entries (opt_context, opt_entries, NULL);
115 g_option_context_parse (opt_context, &argc, &argv, &error);
116 g_option_context_free (opt_context);
118 ERR ("Error parsing options: %s", error->message);
119 g_error_free (error);
124 INFO("Version: "PACKAGE_VERSION"\n");
128 if (fatal_warnings) {
129 GLogLevelFlags log_level = g_log_set_always_fatal (G_LOG_FATAL_MASK);
130 log_level |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
131 g_log_set_always_fatal (log_level);
134 tlm_log_init (G_LOG_DOMAIN);
136 main_loop = g_main_loop_new (NULL, FALSE);
138 manager = tlm_manager_new (username);
139 _setup_unix_signal_handlers (manager);
140 tlm_manager_start (manager);
142 g_main_loop_run (main_loop);
144 g_object_unref (G_OBJECT(manager));
146 DBG ("clean shutdown");
148 tlm_log_close (NULL);