ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/daemon.C
Revision: 1.10
Committed: Fri Apr 27 19:53:05 2007 UTC (17 years ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +0 -0 lines
State: FILE REMOVED
Log Message:
revamp loggin. have a new log flag logBacktrace that logs
the message and prepares a backtrace in the background, spewing
it into the log at a later time.

this is useful to shed some light on otherwise completely useless log
messages such as:

   2007-04-27 19:48:48.142 Calling random_roll with min=1 max=0

which could just as well not be there as we will never find out who is
doing this to puny poor random_roll.

File Contents

# User Rev Content
1 elmex 1.1 /*
2 pippijn 1.9 * CrossFire, A Multiplayer game for X-windows
3     *
4     * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5     * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (C) 1992 Frank Tore Johansen
7     *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21     *
22     * The author can be reached via e-mail to <crossfire@schmorp.de>
23     */
24 elmex 1.1
25     /*
26     * BecomeDaemon.c
27     * shamelessly swiped from xdm source code.
28     * Appropriate copyrights kept, and hereby follow
29     * ERic mehlhaff, 3/11/92
30     *
31     * xdm - display manager daemon
32     *
33     * $XConsortium: daemon.c,v 1.5 89/01/20 10:43:49 jim Exp $
34     *
35     * Copyright 1988 Massachusetts Institute of Technology
36     *
37     * Permission to use, copy, modify, and distribute this software and its
38     * documentation for any purpose and without fee is hereby granted, provided
39     * that the above copyright notice appear in all copies and that both that
40     * copyright notice and this permission notice appear in supporting
41     * documentation, and that the name of M.I.T. not be used in advertising or
42     * publicity pertaining to distribution of the software without specific,
43     * written prior permission. M.I.T. makes no representations about the
44     * suitability of this software for any purpose. It is provided "as is"
45     * without express or implied warranty.
46     *
47     * Author: Keith Packard, MIT X Consortium
48     */
49    
50    
51     #include <global.h>
52 root 1.7 #include <sproto.h>
53 elmex 1.1 #include <sys/ioctl.h>
54     #include <errno.h>
55     #include <stdio.h>
56     #include <sys/file.h>
57    
58 root 1.5 FILE * BecomeDaemon (const char *filename)
59 elmex 1.1 {
60     FILE *logfile;
61     int forkresult;
62    
63 root 1.5 if ((logfile = fopen (filename, "a")) == NULL)
64     {
65     fprintf (stderr, "Couldn't create logfile %s: %s\n", filename, strerror (errno));
66     exit (0);
67     }
68     fputs ("\n========================\n", logfile);
69     fputs ("Begin New Server Session\n", logfile);
70     fputs ("========================\n\n", logfile);
71     fflush (logfile);
72     /*
73     * fork so that the process goes into the background automatically. Also
74     * has a nice side effect of having the child process get inherited by
75     * init (pid 1).
76     */
77    
78     if ((forkresult = fork ()))
79     { /* if parent */
80     if (forkresult < 0)
81     {
82     perror ("Fork error!");
83     }
84     exit (0); /* then no more work to do */
85     }
86    
87     /*
88     * Close standard file descriptors and get rid of controlling tty
89     */
90    
91     close (0);
92     close (1);
93     close (2);
94    
95     /*
96     * Set up the standard file descriptors.
97     */
98     (void) open ("/", O_RDONLY); /* root inode already in core */
99     (void) dup2 (0, 1);
100     (void) dup2 (0, 2);
101    
102     setsid ();
103     return (logfile);
104 elmex 1.1 }