source: proiecte/PPPP/gdm/common/gdm-crash-logger.c @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

File size: 3.8 KB
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Dan Williams <dcbw@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * (C) Copyright 2006 Red Hat, Inc.
20 */
21
22#include "config.h"
23
24#include <stdio.h>
25#include <unistd.h>
26#include <errno.h>
27#include <sys/wait.h>
28#include <stdlib.h>
29#include <syslog.h>
30#include <glib.h>
31
32int main (int argc, char ** argv)
33{
34        GPid            gdb_pid;
35        int             out;
36        char            gdm_pid[16];
37        char            line[256];
38        int             gdb_stat;
39        int             bytes_read;
40        gboolean        res;
41        gboolean        done;
42        GError         *error;
43        int             options;
44        char *  args[] = { "gdb",
45                           "--batch",
46                           "--quiet",
47                           "--command=" DATADIR "/gdm/gdb-cmd",
48                           NULL,
49                           NULL };
50
51        snprintf (gdm_pid, sizeof (gdm_pid), "--pid=%d", getppid ());
52        args[4] = &gdm_pid[0];
53        error = NULL;
54        res = g_spawn_async_with_pipes (NULL,
55                                        args,
56                                        NULL,
57                                        G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
58                                        NULL,
59                                        NULL,
60                                        &gdb_pid,
61                                        NULL,
62                                        &out,
63                                        NULL,
64                                        &error);
65        if (! res) {
66                g_warning ("Unable to get backtrace: %s", error->message);
67                g_error_free (error);
68                exit (1);
69        }
70
71        options = LOG_PID | LOG_CONS;
72#ifdef LOG_PERROR
73        options |= LOG_PERROR;
74#endif
75
76        openlog ("gdm", options, LOG_DAEMON);
77        syslog (LOG_CRIT, "******************* START **********************************");
78        done = FALSE;
79        while (!done) {
80                bytes_read = read (out, line, sizeof (line) - 1);
81                if (bytes_read > 0) {
82                        char *end = &line[0];
83                        char *start = &line[0];
84
85                        /* Can't just funnel the output to syslog, have to do a separate
86                         * syslog () for each line in the output.
87                         */
88                        line[bytes_read] = '\0';
89                        while (*end != '\0') {
90                                if (*end == '\n') {
91                                        *end = '\0';
92                                        syslog (LOG_CRIT, "%s", start);
93                                        start = end + 1;
94                                }
95                                end++;
96                        }
97                } else if ((bytes_read <= 0) || ((errno != EINTR) && (errno != EAGAIN))) {
98                        done = TRUE;
99                }
100        }
101        syslog (LOG_CRIT, "******************* END **********************************");
102        close (out);
103        waitpid (gdb_pid, &gdb_stat, 0);
104        exit (0);
105}
Note: See TracBrowser for help on using the repository browser.