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
32 #include <glib-unix.h>
38 #include "tlm-manager.h"
40 #include "tlm-config.h"
41 #include "tlm-config-general.h"
44 static GMainLoop *main_loop = NULL;
48 _on_manager_stopped_cb (TlmManager *manager, gpointer user_data)
50 DBG ("manager stopped - quit mainloop");
51 g_main_loop_quit (main_loop);
55 _on_sigterm_cb (gpointer data)
59 TlmManager *manager = TLM_MANAGER(data);
61 g_signal_connect (manager,
63 G_CALLBACK (_on_manager_stopped_cb),
65 tlm_manager_stop (manager);
71 _on_sighup_cb (gpointer data)
75 TlmManager *manager = TLM_MANAGER(data);
76 tlm_manager_sighup_received (manager);
82 _setup_unix_signal_handlers (TlmManager *manager)
84 if (signal (SIGINT, SIG_IGN) == SIG_ERR)
85 WARN ("failed ignore SIGINT: %s", strerror(errno));
87 g_unix_signal_add (SIGTERM, _on_sigterm_cb, (gpointer) manager);
88 g_unix_signal_add (SIGHUP, _on_sighup_cb, (gpointer) manager);
91 int main(int argc, char *argv[])
94 TlmManager *manager = 0;
96 gboolean show_version = FALSE;
97 gboolean fatal_warnings = FALSE;
98 gchar *username = NULL;
100 GOptionContext *opt_context = NULL;
101 GOptionEntry opt_entries[] = {
103 G_OPTION_ARG_NONE, &show_version,
104 "Login Manager Version", "Version" },
105 { "fatal-warnings", 0, 0,
106 G_OPTION_ARG_NONE, &fatal_warnings,
107 "Make all warnings fatal", NULL },
108 { "username", 'u', 0,
109 G_OPTION_ARG_STRING, &username,
110 "Username to use", NULL },
114 #if !GLIB_CHECK_VERSION(2,35,0)
118 opt_context = g_option_context_new ("Tizen Login Manager");
119 g_option_context_add_main_entries (opt_context, opt_entries, NULL);
120 g_option_context_parse (opt_context, &argc, &argv, &error);
121 g_option_context_free (opt_context);
123 ERR ("Error parsing options: %s", error->message);
124 g_error_free (error);
129 INFO("Version: "PACKAGE_VERSION"\n");
133 if (fatal_warnings) {
134 GLogLevelFlags log_level = g_log_set_always_fatal (G_LOG_FATAL_MASK);
135 log_level |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
136 g_log_set_always_fatal (log_level);
139 tlm_log_init (G_LOG_DOMAIN);
141 main_loop = g_main_loop_new (NULL, FALSE);
143 manager = tlm_manager_new (username);
144 _setup_unix_signal_handlers (manager);
145 tlm_manager_start (manager);
147 g_main_loop_run (main_loop);
149 g_object_unref (G_OBJECT(manager));
151 DBG ("clean shutdown");
153 tlm_log_close (NULL);