NetworkManager/src/nm-logging.c
Tambet Ingo 326d1e8679 2007-09-12 Tambet Ingo <tambet@gmail.com>
* src/vpn-manager/nm-vpn-connection.[ch]: 
        * src/vpn-manager/nm-vpn-manager.[ch]:
        * src/vpn-manager/nm-vpn-service.[ch]: Rewrite the vpn handling
        * code. Using 
        dbus-glib, GObjects, signals etc.

        * libnm-glib/nm-vpn-manager.[ch]: 
        * libnm-glib/nm-vpn-connection.[ch]: Now that the NM
        * implementation changed
        so much, rewrite these too.

        * libnm-glib/Makefile.am: Add new files to build, build new
        * binding files for
        the new introspection files.

        * libnm-glib/nm-client.[ch]: Remove all VPN related stuff from
        * here.

        * libnm-glib/nm-dbus-utils.[ch]: Renamed from nm-utils.[ch] that
        * was shadowing
        the header with the same name from libnm-utils.

        * libnm-glib/nm-vpn-plugin.[ch]: Implement.

        * libnm-util/Makefile.am: Add nm-utils.[ch] to build.

        * introspection/nm-vpn-plugin.xml: Implement.

        * introspection/nm-vpn-connection.xml: Implement.

        * introspection/nm-vpn-manager.xml: Implement.

        * src/NetworkManagerSystem.c
        * (nm_system_vpn_device_set_from_ip4_config): Remove
        the named manager argument, it can just as easily get it as the
caller.
        (nm_system_vpn_device_unset_from_ip4_config): Ditto.

        * src/vpn-manager/nm-dbus-vpn.[ch]: Remove.

        * src/nm-dbus-manager.h: Fix up the name_owner signal signature.

        * src/dhcp-manager/nm-dhcp-manager.c (garray_to_string): Remove,
        * use one from
        libnm-utils.

        * libnm-util/nm-connection.c: Ditto.

        * src/NetworkManagerMain.h: Remove, it's finally empty.

        * configure.in: Remove utils/ from build.

        * include/NetworkManagerVPN.h: Add some more defines to reduce
        * the amount
        of hard-coded strings.

        * utils/: Move it over to libnm-util.

        * test/Makefile.am: Link against libnm-util now that util/ is
        * gone.

        * dispatcher-daemon/Makefile.am: Ditto.

        * src/Makefile.am: Ditto.



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2798 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-12 16:23:53 +00:00

164 lines
3.5 KiB
C

/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2006 Red Hat, Inc.
*/
#include <syslog.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include "nm-logging.h"
#include "nm-utils.h"
static void
fallback_get_backtrace (void)
{
void * frames[64];
size_t size;
char ** strings;
size_t i;
size = backtrace (frames, G_N_ELEMENTS (frames));
if ((strings = backtrace_symbols (frames, size)))
{
syslog (LOG_CRIT, "******************* START **********************************");
for (i = 0; i < size; i++)
syslog (LOG_CRIT, "Frame %zd: %s", i, strings[i]);
free (strings);
syslog (LOG_CRIT, "******************* END **********************************");
}
else
{
nm_warning ("NetworkManager crashed, but symbols "
"couldn't be retrieved.");
}
}
static gboolean
crashlogger_get_backtrace (void)
{
gboolean success = FALSE;
int pid;
pid = fork();
if (pid > 0)
{
/* Wait for the child to finish */
int estatus;
if (waitpid (pid, &estatus, 0) != -1)
{
/* Only succeed if the crashlogger succeeded */
if (WIFEXITED (estatus) && (WEXITSTATUS (estatus) == 0))
success = TRUE;
}
}
else if (pid == 0)
{
/* Child process */
execl (LIBEXECDIR"/nm-crash-logger",
LIBEXECDIR"/nm-crash-logger", NULL);
}
return success;
}
void
nm_logging_backtrace (void)
{
struct stat s;
gboolean fallback = TRUE;
/* Try to use gdb via nm-crash-logger if it exists, since
* we get much better information out of it. Otherwise
* fall back to execinfo.
*/
if (stat (LIBEXECDIR"/nm-crash-logger", &s) == 0)
fallback = crashlogger_get_backtrace () ? FALSE : TRUE;
if (fallback)
fallback_get_backtrace ();
}
static void
nm_log_handler (const gchar * log_domain,
GLogLevelFlags log_level,
const gchar * message,
gpointer ignored)
{
int syslog_priority;
switch (log_level)
{
case G_LOG_LEVEL_ERROR:
syslog_priority = LOG_CRIT;
break;
case G_LOG_LEVEL_CRITICAL:
syslog_priority = LOG_ERR;
break;
case G_LOG_LEVEL_WARNING:
syslog_priority = LOG_WARNING;
break;
case G_LOG_LEVEL_MESSAGE:
syslog_priority = LOG_NOTICE;
break;
case G_LOG_LEVEL_DEBUG:
syslog_priority = LOG_DEBUG;
break;
case G_LOG_LEVEL_INFO:
default:
syslog_priority = LOG_INFO;
break;
}
syslog (syslog_priority, "%s", message);
}
void
nm_logging_setup (gboolean become_daemon)
{
if (become_daemon)
openlog (G_LOG_DOMAIN, LOG_CONS, LOG_DAEMON);
else
openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR, LOG_USER);
g_log_set_handler (G_LOG_DOMAIN,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
nm_log_handler,
NULL);
}
void
nm_logging_shutdown (void)
{
closelog ();
}