Adapted Winsock to Linux 2.4 TCP socket poll() behaviour
[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'. Your version of wine may be too old.\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     signal( SIGPIPE, SIG_IGN );
64     signal( SIGHUP, sigterm_handler );
65     signal( SIGINT, sigterm_handler );
66     signal( SIGQUIT, sigterm_handler );
67     signal( SIGTERM, sigterm_handler );
68     signal( SIGABRT, sigterm_handler );
69 }
70
71 int main( int argc, char *argv[] )
72 {
73     parse_args( argc, argv );
74     signal_init();
75     open_master_socket();
76     setvbuf( stderr, NULL, _IOLBF, 0 );
77
78     if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() );
79     init_registry();
80     select_loop();
81     close_registry();
82     if (debug_level) fprintf( stderr, "Server: exiting (pid=%ld)\n", (long) getpid() );
83
84 #ifdef DEBUG_OBJECTS
85     close_atom_table();
86     dump_objects();  /* dump any remaining objects */
87 #endif
88     exit(0);
89 }