summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWilliam Jon McCann <mccann@jhu.edu>2007-04-02 16:15:06 +0000
committerWilliam Jon McCann <mccann@src.gnome.org>2007-04-02 16:15:06 +0000
commit274890e38d22690afcd274caf790290f9463ef2d (patch)
tree709bd2c6fce468b1ecfa0cc1651b3fcb414dfdf6 /common
parent806c49cd95236147e6fbc5ab49d59730eb789145 (diff)
downloadgdm-274890e38d22690afcd274caf790290f9463ef2d.tar.gz
Use fewer global variables. Separate monolithic gdm.h into component
2007-04-02 William Jon McCann <mccann@jhu.edu> * common/Makefile.am: * common/gdm-common.c: (v4_v4_equal), (v6_v6_equal), (gdm_address_equal), (gdm_address_is_loopback), (gdm_address_get_info): * common/gdm-common.h: * common/gdm-config.c: (gdm_config_peek_value), (gdm_config_get_value), (gdm_config_peek_value_for_id), (gdm_config_peek_string_for_id), (gdm_config_get_string_for_id), (gdm_config_get_int_for_id), (gdm_config_set_int_for_id): * common/gdm-config.h: * common/gdm-log.c: (log_level_to_priority_and_prefix), (gdm_log_default_handler), (gdm_log_set_debug), (gdm_log_init), (gdm_log_shutdown): * common/gdm-log.h: * configure.ac: * daemon/Makefile.am: * daemon/auth.c: (add_auth_entry), (add_auth_entry_for_addr), (get_local_auths), (gdm_auth_user_add), (gdm_auth_set_local_auth), (gdm_auth_free_auth_list): * daemon/choose.c: (get_first_address_for_node), (gdm_choose_data), (gdm_choose_indirect_alloc), (gdm_choose_indirect_dispose_empty_id), (gdm_choose_indirect_lookup_by_chosen), (gdm_choose_indirect_lookup), (gdm_choose_indirect_dispose): * daemon/choose.h: * daemon/cookie.c: * daemon/cookie.h: * daemon/display.c: (gdm_display_manage), (count_session_limits), (gdm_display_dispose), (gdm_display_lookup): * daemon/display.h: * daemon/errorgui.c: (setup_dialog), (gdm_errorgui_error_box_full), (gdm_errorgui_error_box), (gdm_errorgui_failsafe_question), (gdm_errorgui_failsafe_yesno), (gdm_errorgui_failsafe_ask_buttons): * daemon/errorgui.h: * daemon/filecheck.c: (gdm_file_check), (gdm_auth_file_check): * daemon/gdm-daemon-config.c: (gdm_daemon_config_get_display_list), (gdm_daemon_config_display_list_append), (gdm_daemon_config_display_list_insert), (gdm_daemon_config_display_list_remove), (gdm_daemon_config_get_bool_for_id), (gdm_daemon_config_get_int_for_id), (gdm_daemon_config_get_string_for_id), (handle_no_displays), (gdm_daemon_config_parse): * daemon/gdm-daemon-config.h: * daemon/gdm-net.c: * daemon/gdm-net.h: * daemon/gdm.c: (mark_display_exists), (gdm_daemonify), (gdm_start_first_unborn_local), (gdm_final_cleanup), (deal_with_x_crashes), (gdm_safe_restart), (gdm_try_logout_action), (main), (order_exists), (get_new_order), (gdm_handle_message), (find_display), (handle_flexi_server), (handle_dynamic_server), (gdm_handle_user_message): * daemon/gdm.h: * daemon/gdmconsolekit.c: (get_path_array_from_iter): * daemon/gdmconsolekit.h: * daemon/md5.h: * daemon/misc.c: (gdm_clearenv_no_lang), (gdm_get_free_display), (gdm_exec_wait), (gdm_fork_extra), (gdm_wait_for_extra), (gdm_address_peek_local_list), (gdm_address_is_local), (fillout_addrinfo), (gdm_gethostbyname), (gdm_gethostbyaddr), (gdm_hostent_copy): * daemon/misc.h: * daemon/server.c: (gdm_exec_fbconsole), (gdm_server_spawn): * daemon/server.h: * daemon/slave.c: (get_runlevel), (gdm_slave_start), (focus_first_x_window), (run_config), (play_login_sound), (gdm_slave_greeter), (send_chosen_host), (gdm_slave_chooser), (session_child_run), (gdm_slave_session_start), (gdm_slave_session_stop), (check_for_interruption), (gdm_child_exit), (gdm_slave_exec_script), (gdm_parse_enriched_login), (gdm_is_user_valid): * daemon/slave.h: * daemon/verify-crypt.c: (gdm_verify_user), (gdm_verify_setup_user): * daemon/verify-pam.c: (gdm_verify_pam_conv), (gdm_verify_standalone_pam_conv), (gdm_verify_user), (gdm_verify_setup_user), (gdm_verify_cleanup), (gdm_verify_check): * daemon/verify-shadow.c: (gdm_verify_user), (gdm_verify_setup_user): * daemon/verify.h: * daemon/xdmcp.c: (gdm_xdmcp_displays_from_host), (gdm_xdmcp_display_lookup_by_host), (ai_family_str), (ai_type_str), (ai_protocol_str), (ai_flags_str), (debug_addrinfo), (gdm_xdmcp_create_socket), (gdm_xdmcp_bind), (gdm_xdmcp_init), (gdm_xdmcp_run), (gdm_xdmcp_close), (gdm_xdmcp_decode_packet), (gdm_xdmcp_handle_query), (set_port_for_request), (set_address_for_request), (gdm_xdmcp_send_forward_query), (gdm_forward_query_alloc), (gdm_forward_query_lookup), (gdm_forward_query_dispose), (create_sa_from_request), (gdm_xdmcp_handle_forward_query), (gdm_xdmcp_send_willing), (gdm_xdmcp_send_unwilling), (gdm_xdmcp_really_send_managed_forward), (managed_forward_handler), (gdm_xdmcp_send_managed_forward), (gdm_xdmcp_send_got_managed_forward), (gdm_xdmcp_handle_request), (gdm_xdmcp_send_accept), (gdm_xdmcp_send_decline), (gdm_xdmcp_handle_manage), (gdm_xdmcp_handle_managed_forward), (gdm_xdmcp_whack_queued_managed_forwards), (gdm_xdmcp_handle_got_managed_forward), (gdm_xdmcp_send_refuse), (gdm_xdmcp_send_failed), (gdm_xdmcp_handle_keepalive), (gdm_xdmcp_send_alive), (gdm_xdmcp_host_allow), (gdm_xdmcp_display_alloc), (gdm_xdmcp_display_lookup), (gdm_xdmcp_display_dispose_check), (gdm_xdmcp_displays_check), (gdm_xdmcp_recount_sessions): * daemon/xdmcp.h: * gui/Makefile.am: * gui/gdmXnestchooser.c: * gui/gdmchooser.c: (gdm_chooser_host_alloc), (gdm_chooser_cancel), (gdm_chooser_manage), (gdm_read_config), (gdm_reread_config), (main): * gui/gdmcomm.c: (do_command), (gdmcomm_call_gdm_real): * gui/gdmcommon.c: (gdm_common_log_init), (gdm_common_log_set_debug), (gdm_common_fail_exit), (gdm_common_fail_greeter), (gdm_common_info), (gdm_common_error), (gdm_common_warning), (gdm_common_debug), (gdm_common_expand_text): * gui/gdmcommon.h: * gui/gdmconfig.c: * gui/gdmdynamic.c: (main): * gui/gdmflexiserver.c: (main): * gui/gdmlanguages.c: * gui/gdmlogin.c: (gdm_login_restart_handler), (gdm_login_halt_handler), (gdm_login_use_chooser_handler), (gdm_read_config), (gdm_reread_config), (main): * gui/gdmsession.c: * gui/gdmsetup.c: * gui/gdmuser.c: * gui/gdmwm.c: * gui/greeter/greeter.c: (gdm_read_config), (greeter_reread_config), (main): * gui/greeter/greeter_item_customlist.c: * gui/greeter/greeter_item_pam.c: * gui/greeter/greeter_item_timed.c: * gui/greeter/greeter_item_ulist.c: * gui/greeter/greeter_parser.c: (parse_show): * gui/greeter/greeter_system.c: (query_greeter_restart_handler), (query_greeter_halt_handler), (greeter_restart_handler), (greeter_halt_handler), (greeter_chooser_handler): Use fewer global variables. Separate monolithic gdm.h into component parts. Use the Glib message logging API to write to syslog. Cleans up the ipv4/6 handling in the daemon to use a common code patch and be mostly AF- independent. Add a few convenience functions to gdm-config for get/set by ID. Patch from bug #376010 svn path=/trunk/; revision=4762
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am12
-rw-r--r--common/gdm-common.c87
-rw-r--r--common/gdm-common.h11
-rw-r--r--common/gdm-config.c127
-rw-r--r--common/gdm-config.h15
-rw-r--r--common/gdm-log.c185
-rw-r--r--common/gdm-log.h50
7 files changed, 469 insertions, 18 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index a67468c1..d55fff78 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -34,12 +34,15 @@ libgdmcommon_a_SOURCES = \
gdm-common-config.c \
gdm-config.h \
gdm-config.c \
+ gdm-log.h \
+ gdm-log.c \
ve-signal.h \
ve-signal.c \
$(NULL)
noinst_PROGRAMS = \
test-config \
+ test-log \
$(NULL)
test_config_SOURCES = \
@@ -51,3 +54,12 @@ test_config_LDADD = \
$(top_builddir)/common/libgdmcommon.a \
$(GLIB_LIBS) \
$(NULL)
+
+test_log_SOURCES = \
+ test-log.c \
+ $(NULL)
+
+test_log_LDADD = \
+ $(top_builddir)/common/libgdmcommon.a \
+ $(GLIB_LIBS) \
+ $(NULL)
diff --git a/common/gdm-common.c b/common/gdm-common.c
index 30c93ca7..dbb3ff31 100644
--- a/common/gdm-common.c
+++ b/common/gdm-common.c
@@ -32,6 +32,93 @@
#include "gdm-common.h"
+static gboolean
+v4_v4_equal (const struct sockaddr_in *a,
+ const struct sockaddr_in *b)
+{
+ return a->sin_addr.s_addr == b->sin_addr.s_addr;
+}
+
+#ifdef ENABLE_IPV6
+static gboolean
+v6_v6_equal (struct sockaddr_in6 *a,
+ struct sockaddr_in6 *b)
+{
+ return IN6_ARE_ADDR_EQUAL (&a->sin6_addr, &b->sin6_addr);
+}
+#endif
+
+#define SA(__s) ((struct sockaddr *) __s)
+#define SIN(__s) ((struct sockaddr_in *) __s)
+#define SIN6(__s) ((struct sockaddr_in6 *) __s)
+
+gboolean
+gdm_address_equal (struct sockaddr_storage *sa,
+ struct sockaddr_storage *sb)
+{
+ guint8 fam_a;
+ guint8 fam_b;
+
+ g_return_val_if_fail (sa != NULL, FALSE);
+ g_return_val_if_fail (sb != NULL, FALSE);
+
+ fam_a = sa->ss_family;
+ fam_b = sb->ss_family;
+
+ if (fam_a == AF_INET && fam_b == AF_INET) {
+ return v4_v4_equal (SIN (sa), SIN (sb));
+ }
+#ifdef ENABLE_IPV6
+ else if (fam_a == AF_INET6 && fam_b == AF_INET6) {
+ return v6_v6_equal (SIN6 (sa), SIN6 (sb));
+ }
+#endif
+ return FALSE;
+}
+
+gboolean
+gdm_address_is_loopback (struct sockaddr_storage *sa)
+{
+ switch(sa->ss_family){
+#ifdef AF_INET6
+ case AF_INET6:
+ return IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *)sa)->sin6_addr);
+ break;
+#endif
+ case AF_INET:
+ return (INADDR_LOOPBACK == (((struct sockaddr_in *)sa)->sin_addr.s_addr));
+ break;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+void
+gdm_address_get_info (struct sockaddr_storage *ss,
+ char **hostp,
+ char **servp)
+{
+ char host [NI_MAXHOST];
+ char serv [NI_MAXSERV];
+
+ host [0] = '\0';
+ serv [0] = '\0';
+ getnameinfo ((const struct sockaddr *)ss,
+ sizeof (struct sockaddr_storage),
+ host, sizeof (host),
+ serv, sizeof (serv),
+ NI_NUMERICHOST | NI_NUMERICSERV);
+
+ if (servp != NULL) {
+ *servp = g_strdup (serv);
+ }
+ if (hostp != NULL) {
+ *hostp = g_strdup (host);
+ }
+}
+
/**
* ve_clearenv:
*
diff --git a/common/gdm-common.h b/common/gdm-common.h
index 09c8960a..c189d41a 100644
--- a/common/gdm-common.h
+++ b/common/gdm-common.h
@@ -28,13 +28,24 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/socket.h>
#include <locale.h>
+#include <netdb.h>
#include "ve-signal.h"
#include "gdm-common-config.h"
#include "gdm-config.h"
G_BEGIN_DECLS
+
+
+gboolean gdm_address_equal (struct sockaddr_storage *sa,
+ struct sockaddr_storage *sb);
+gboolean gdm_address_is_loopback (struct sockaddr_storage *sa);
+void gdm_address_get_info (struct sockaddr_storage *sa,
+ char **host,
+ char **port);
+
void ve_clearenv (void);
char * ve_first_word (const char *s);
gboolean ve_first_word_executable (const char *s,
diff --git a/common/gdm-config.c b/common/gdm-config.c
index 38748655..52cfaf04 100644
--- a/common/gdm-config.c
+++ b/common/gdm-config.c
@@ -1107,14 +1107,14 @@ gdm_config_process_all (GdmConfig *config,
}
gboolean
-gdm_config_get_value (GdmConfig *config,
- const char *group,
- const char *key,
- GdmConfigValue **valuep)
+gdm_config_peek_value (GdmConfig *config,
+ const char *group,
+ const char *key,
+ const GdmConfigValue **valuep)
{
- gboolean ret;
- char *key_path;
- GdmConfigValue *value;
+ gboolean ret;
+ char *key_path;
+ const GdmConfigValue *value;
g_return_val_if_fail (config != NULL, FALSE);
@@ -1128,7 +1128,7 @@ gdm_config_get_value (GdmConfig *config,
if (valuep != NULL) {
if (ret) {
- *valuep = gdm_config_value_copy (value);
+ *valuep = value;
} else {
*valuep = NULL;
}
@@ -1138,6 +1138,23 @@ gdm_config_get_value (GdmConfig *config,
}
gboolean
+gdm_config_get_value (GdmConfig *config,
+ const char *group,
+ const char *key,
+ GdmConfigValue **valuep)
+{
+ gboolean res;
+ const GdmConfigValue *value;
+
+ res = gdm_config_peek_value (config, group, key, &value);
+ if (valuep != NULL) {
+ *valuep = (value == NULL) ? NULL : gdm_config_value_copy (value);
+ }
+
+ return res;
+}
+
+gboolean
gdm_config_set_value (GdmConfig *config,
const char *group,
const char *key,
@@ -1153,6 +1170,23 @@ gdm_config_set_value (GdmConfig *config,
return TRUE;
}
+static gboolean
+gdm_config_peek_value_for_id (GdmConfig *config,
+ int id,
+ const GdmConfigValue **valuep)
+{
+ const GdmConfigEntry *entry;
+
+ g_return_val_if_fail (config != NULL, FALSE);
+
+ entry = gdm_config_lookup_entry_for_id (config, id);
+ if (entry == NULL) {
+ return FALSE;
+ }
+
+ return gdm_config_peek_value (config, entry->group, entry->key, valuep);
+}
+
gboolean
gdm_config_get_value_for_id (GdmConfig *config,
int id,
@@ -1188,27 +1222,41 @@ gdm_config_set_value_for_id (GdmConfig *config,
}
gboolean
-gdm_config_get_string_for_id (GdmConfig *config,
- int id,
- char **strp)
+gdm_config_peek_string_for_id (GdmConfig *config,
+ int id,
+ const char **strp)
{
- GdmConfigValue *value;
- const char *str;
- gboolean res;
+ const GdmConfigValue *value;
+ const char *str;
+ gboolean res;
g_return_val_if_fail (config != NULL, FALSE);
- res = gdm_config_get_value_for_id (config, id, &value);
+ res = gdm_config_peek_value_for_id (config, id, &value);
if (! res) {
return FALSE;
}
str = gdm_config_value_get_string (value);
if (strp != NULL) {
- *strp = g_strdup (str);
+ *strp = str;
}
- gdm_config_value_free (value);
+ return res;
+}
+
+gboolean
+gdm_config_get_string_for_id (GdmConfig *config,
+ int id,
+ char **strp)
+{
+ gboolean res;
+ const char *str;
+
+ res = gdm_config_peek_string_for_id (config, id, &str);
+ if (strp != NULL) {
+ *strp = g_strdup (str);
+ }
return res;
}
@@ -1240,6 +1288,32 @@ gdm_config_get_bool_for_id (GdmConfig *config,
}
gboolean
+gdm_config_get_int_for_id (GdmConfig *config,
+ int id,
+ int *integerp)
+{
+ GdmConfigValue *value;
+ gboolean integer;
+ gboolean res;
+
+ g_return_val_if_fail (config != NULL, FALSE);
+
+ res = gdm_config_get_value_for_id (config, id, &value);
+ if (! res) {
+ return FALSE;
+ }
+
+ integer = gdm_config_value_get_int (value);
+ if (integerp != NULL) {
+ *integerp = integer;
+ }
+
+ gdm_config_value_free (value);
+
+ return res;
+}
+
+gboolean
gdm_config_set_string_for_id (GdmConfig *config,
int id,
char *str)
@@ -1276,3 +1350,22 @@ gdm_config_set_bool_for_id (GdmConfig *config,
return res;
}
+
+gboolean
+gdm_config_set_int_for_id (GdmConfig *config,
+ int id,
+ int integer)
+{
+ GdmConfigValue *value;
+ gboolean res;
+
+ g_return_val_if_fail (config != NULL, FALSE);
+
+ value = gdm_config_value_new (GDM_CONFIG_VALUE_INT);
+ gdm_config_value_set_int (value, integer);
+
+ res = gdm_config_set_value_for_id (config, id, value);
+ gdm_config_value_free (value);
+
+ return res;
+}
diff --git a/common/gdm-config.h b/common/gdm-config.h
index 554a96cb..eb3831ea 100644
--- a/common/gdm-config.h
+++ b/common/gdm-config.h
@@ -125,7 +125,10 @@ char ** gdm_config_get_keys_for_group (GdmConfig *confi
gsize *length,
GError **error);
-
+gboolean gdm_config_peek_value (GdmConfig *config,
+ const char *group,
+ const char *key,
+ const GdmConfigValue **value);
gboolean gdm_config_get_value (GdmConfig *config,
const char *group,
const char *key,
@@ -135,6 +138,7 @@ gboolean gdm_config_set_value (GdmConfig *confi
const char *key,
GdmConfigValue *value);
+/* convenience functions */
gboolean gdm_config_get_value_for_id (GdmConfig *config,
int id,
GdmConfigValue **value);
@@ -142,18 +146,27 @@ gboolean gdm_config_set_value_for_id (GdmConfig *confi
int id,
GdmConfigValue *value);
+gboolean gdm_config_peek_string_for_id (GdmConfig *config,
+ int id,
+ const char **str);
gboolean gdm_config_get_string_for_id (GdmConfig *config,
int id,
char **str);
gboolean gdm_config_get_bool_for_id (GdmConfig *config,
int id,
gboolean *bool);
+gboolean gdm_config_get_int_for_id (GdmConfig *config,
+ int id,
+ int *integer);
gboolean gdm_config_set_string_for_id (GdmConfig *config,
int id,
char *str);
gboolean gdm_config_set_bool_for_id (GdmConfig *config,
int id,
gboolean bool);
+gboolean gdm_config_set_int_for_id (GdmConfig *config,
+ int id,
+ int integer);
/* Config Values */
diff --git a/common/gdm-log.c b/common/gdm-log.c
new file mode 100644
index 00000000..9182359e
--- /dev/null
+++ b/common/gdm-log.c
@@ -0,0 +1,185 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors: William Jon McCann <mccann@jhu.edu>
+ *
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <signal.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <syslog.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#include "gdm-log.h"
+
+static gboolean initialized = FALSE;
+static int syslog_levels = (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
+
+static void
+log_level_to_priority_and_prefix (GLogLevelFlags log_level,
+ int *priorityp,
+ const char **prefixp)
+{
+ int priority;
+ const char *prefix;
+
+ /* Process the message prefix and priority */
+ switch (log_level & G_LOG_LEVEL_MASK) {
+ case G_LOG_FLAG_FATAL:
+ priority = LOG_EMERG;
+ prefix = "FATAL";
+ break;
+ case G_LOG_LEVEL_ERROR:
+ priority = LOG_ERR;
+ prefix = "ERROR";
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ priority = LOG_CRIT;
+ prefix = "CRITICAL";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ priority = LOG_WARNING;
+ prefix = "WARNING";
+ break;
+ case G_LOG_LEVEL_MESSAGE:
+ priority = LOG_NOTICE;
+ prefix = "MESSAGE";
+ break;
+ case G_LOG_LEVEL_INFO:
+ priority = LOG_INFO;
+ prefix = "INFO";
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ /* if debug was requested then bump this up to ERROR
+ * to ensure it is seen in a log */
+ if (syslog_levels & G_LOG_LEVEL_DEBUG) {
+ priority = LOG_WARNING;
+ } else {
+ priority = LOG_DEBUG;
+ }
+ prefix = "DEBUG";
+ break;
+ default:
+ priority = LOG_DEBUG;
+ prefix = "UNKNOWN";
+ break;
+ }
+
+ if (priorityp != NULL) {
+ *priorityp = priority;
+ }
+ if (prefixp != NULL) {
+ *prefixp = prefix;
+ }
+}
+
+void
+gdm_log_default_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer unused_data)
+{
+ GString *gstring;
+ int priority;
+ const char *level_prefix;
+ char *string;
+ gboolean do_log;
+ gboolean is_fatal;
+
+ is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
+
+ do_log = (log_level & syslog_levels);
+ if (! do_log) {
+ return;
+ }
+
+ if (! initialized) {
+ gdm_log_init ();
+ }
+
+ log_level_to_priority_and_prefix (log_level,
+ &priority,
+ &level_prefix);
+
+ gstring = g_string_new (NULL);
+
+ if (log_domain != NULL) {
+ g_string_append (gstring, log_domain);
+ g_string_append_c (gstring, '-');
+ }
+ g_string_append (gstring, level_prefix);
+
+ g_string_append (gstring, ": ");
+ if (message == NULL) {
+ g_string_append (gstring, "(NULL) message");
+ } else {
+ g_string_append (gstring, message);
+ }
+ if (is_fatal) {
+ g_string_append (gstring, "\naborting...\n");
+ } else {
+ g_string_append (gstring, "\n");
+ }
+
+ string = g_string_free (gstring, FALSE);
+
+ syslog (priority, "%s", string);
+
+ g_free (string);
+}
+
+void
+gdm_log_set_debug (gboolean debug)
+{
+ if (debug) {
+ syslog_levels |= G_LOG_LEVEL_DEBUG;
+ } else {
+ syslog_levels &= ~G_LOG_LEVEL_DEBUG;
+ }
+}
+
+void
+gdm_log_init (void)
+{
+ const char *prg_name;
+
+ g_log_set_default_handler (gdm_log_default_handler, NULL);
+
+ prg_name = g_get_prgname ();
+
+ openlog (prg_name, LOG_PERROR|LOG_PID, LOG_DAEMON);
+
+ initialized = TRUE;
+}
+
+void
+gdm_log_shutdown (void)
+{
+ closelog ();
+ initialized = FALSE;
+}
+
diff --git a/common/gdm-log.h b/common/gdm-log.h
new file mode 100644
index 00000000..3d6effbc
--- /dev/null
+++ b/common/gdm-log.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors: William Jon McCann <mccann@jhu.edu>
+ *
+ */
+
+#ifndef __GDM_LOG_H
+#define __GDM_LOG_H
+
+#include <stdarg.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void gdm_log_default_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer unused_data);
+void gdm_log_set_debug (gboolean debug);
+void gdm_log_init (void);
+void gdm_log_shutdown (void);
+
+/* compatibility */
+#define gdm_fail g_critical
+#define gdm_error g_warning
+#define gdm_info g_message
+#define gdm_debug g_debug
+
+#define gdm_assert g_assert
+#define gdm_assert_not_reached g_assert_not_reached
+
+G_END_DECLS
+
+#endif /* __GDM_LOG_H */