No longer directly accessing debuggee memory.
[wine] / server / main.c
1 /*
2  * Server main function
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include <ctype.h>
9 #include <fcntl.h>
10 #include <signal.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <sys/time.h>
14 #include <unistd.h>
15
16 #include "object.h"
17 #include "thread.h"
18 #include "request.h"
19
20 /* command-line options */
21 int debug_level = 0;
22 int persistent_server = 0;
23
24 /* parse-line args */
25 /* FIXME: should probably use getopt, and add a help option */
26 static void parse_args( int argc, char *argv[] )
27 {
28     int i;
29     for (i = 1; i < argc; i++)
30     {
31         if (argv[i][0] == '-')
32         {
33             switch(argv[i][1])
34             {
35             case 'd':
36                 if (isdigit(argv[i][2])) debug_level = atoi( argv[i] + 2 );
37                 else debug_level++;
38                 break;
39             case 'p':
40                 persistent_server = 1;
41                 break;
42             default:
43                 fprintf( stderr, "Unknown option '%s'\n", argv[i] );
44                 exit(1);
45             }
46         }
47         else
48         {
49             fprintf( stderr, "Unknown argument '%s'\n", argv[i] );
50             exit(1);
51         }
52     }
53 }
54
55 static void sigterm_handler()
56 {
57     exit(1);  /* make sure atexit functions get called */
58 }
59
60 /* initialize signal handling */
61 static void signal_init(void)
62 {
63 #if 0
64     if (!debug_level)
65     {
66         switch(fork())
67         {
68         case -1:
69             break;
70         case 0:
71             setsid();
72             break;
73         default:
74             exit(0);
75         }
76     }
77 #endif
78     signal( SIGPIPE, SIG_IGN );
79     signal( SIGHUP, sigterm_handler );
80     signal( SIGINT, sigterm_handler );
81     signal( SIGQUIT, sigterm_handler );
82     signal( SIGTERM, sigterm_handler );
83     signal( SIGABRT, sigterm_handler );
84 }
85
86 int main( int argc, char *argv[] )
87 {
88     parse_args( argc, argv );
89     signal_init();
90     open_master_socket();
91
92     if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() );
93     select_loop();
94     if (debug_level) fprintf( stderr, "Server: exiting (pid=%ld)\n", (long) getpid() );
95
96 #ifdef DEBUG_OBJECTS
97     close_registry();
98     close_atom_table();
99     dump_objects();  /* dump any remaining objects */
100 #endif
101     exit(0);
102 }