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 (Tiny 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)
86 gchar strerr_buf[MAX_STRERROR_LEN] = {0,};
87 WARN ("failed ignore SIGINT: %s", strerror_r(errno, strerr_buf, MAX_STRERROR_LEN));
90 g_unix_signal_add (SIGTERM, _on_sigterm_cb, (gpointer) manager);
91 g_unix_signal_add (SIGHUP, _on_sighup_cb, (gpointer) manager);
94 int main(int argc, char *argv[])
97 TlmManager *manager = 0;
99 gboolean show_version = FALSE;
100 gboolean fatal_warnings = FALSE;
101 gchar *username = NULL;
103 GOptionContext *opt_context = NULL;
104 GOptionEntry opt_entries[] = {
106 G_OPTION_ARG_NONE, &show_version,
107 "Login Manager Version", "Version" },
108 { "fatal-warnings", 0, 0,
109 G_OPTION_ARG_NONE, &fatal_warnings,
110 "Make all warnings fatal", NULL },
111 { "username", 'u', 0,
112 G_OPTION_ARG_STRING, &username,
113 "Username to use", NULL },
117 #if !GLIB_CHECK_VERSION(2,35,0)
121 opt_context = g_option_context_new ("Tiny Login Manager");
122 g_option_context_add_main_entries (opt_context, opt_entries, NULL);
123 g_option_context_parse (opt_context, &argc, &argv, &error);
124 g_option_context_free (opt_context);
126 ERR ("Error parsing options: %s", error->message);
127 g_error_free (error);
132 INFO("Version: "PACKAGE_VERSION"\n");
136 if (fatal_warnings) {
137 GLogLevelFlags log_level = g_log_set_always_fatal (G_LOG_FATAL_MASK);
138 log_level |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
139 g_log_set_always_fatal (log_level);
142 tlm_log_init (G_LOG_DOMAIN);
144 main_loop = g_main_loop_new (NULL, FALSE);
146 manager = tlm_manager_new (username);
148 GValue value = G_VALUE_INIT;
149 g_value_init (&value, G_TYPE_BOOLEAN);
150 g_object_get_property(G_OBJECT(manager),"dbus-connected", &value);
152 if (g_value_get_boolean(&value)) {
153 _setup_unix_signal_handlers (manager);
155 if (TRUE == tlm_manager_start (manager)) {
156 g_main_loop_run (main_loop);
159 CRITICAL("Fail to get system bus!!! Shut down the tlm");
162 g_object_unref (G_OBJECT(manager));
164 DBG ("clean shutdown");
166 ERR ("Cannot create tlm_manager object");
169 tlm_log_close (NULL);