Fixed ANSI C related compile problems.
[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 (!debug_level)
64     {
65         switch(fork())
66         {
67         case -1:
68             break;
69         case 0:
70             setsid();
71             break;
72         default:
73             exit(0);
74         }
75     }
76     signal( SIGPIPE, SIG_IGN );
77     signal( SIGHUP, sigterm_handler );
78     signal( SIGINT, sigterm_handler );
79     signal( SIGQUIT, sigterm_handler );
80     signal( SIGTERM, sigterm_handler );
81     signal( SIGABRT, sigterm_handler );
82 }
83
84 int main( int argc, char *argv[] )
85 {
86     parse_args( argc, argv );
87     signal_init();
88     open_master_socket();
89
90     if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() );
91     select_loop();
92     if (debug_level) fprintf( stderr, "Server: exiting (pid=%ld)\n", (long) getpid() );
93
94 #ifdef DEBUG_OBJECTS
95     close_registry();
96     close_atom_table();
97     dump_objects();  /* dump any remaining objects */
98 #endif
99     exit(0);
100 }