Define environment variable TMP as an alias for TEMP.
[wine.git] / server / main.c
blob49f181cd458b7e38324e02bd736c025b747df087
1 /*
2 * Server main function
4 * Copyright (C) 1998 Alexandre Julliard
5 */
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>
16 #include "object.h"
17 #include "thread.h"
18 #include "request.h"
20 /* command-line options */
21 int debug_level = 0;
22 int persistent_server = 0;
24 unsigned int server_start_ticks = 0;
26 /* parse-line args */
27 /* FIXME: should probably use getopt, and add a help option */
28 static void parse_args( int argc, char *argv[] )
30 int i;
31 for (i = 1; i < argc; i++)
33 if (argv[i][0] == '-')
35 switch(argv[i][1])
37 case 'd':
38 if (isdigit(argv[i][2])) debug_level = atoi( argv[i] + 2 );
39 else debug_level++;
40 break;
41 case 'p':
42 persistent_server = 1;
43 break;
44 default:
45 fprintf( stderr, "Unknown option '%s'\n", argv[i] );
46 exit(1);
49 else
51 fprintf( stderr, "Unknown argument '%s'. Your version of wine may be too old.\n", argv[i] );
52 exit(1);
57 static void sigterm_handler()
59 exit(1); /* make sure atexit functions get called */
62 /* initialize signal handling */
63 static void signal_init(void)
65 signal( SIGPIPE, SIG_IGN );
66 signal( SIGHUP, sigterm_handler );
67 signal( SIGINT, sigterm_handler );
68 signal( SIGQUIT, sigterm_handler );
69 signal( SIGTERM, sigterm_handler );
70 signal( SIGABRT, sigterm_handler );
73 /* get server start ticks used to calculate GetTickCount() in Wine clients */
74 static void get_start_ticks(void)
76 struct timeval t;
77 gettimeofday( &t, NULL );
78 server_start_ticks = (t.tv_sec * 1000) + (t.tv_usec / 1000);
81 int main( int argc, char *argv[] )
83 parse_args( argc, argv );
84 signal_init();
85 open_master_socket();
86 setvbuf( stderr, NULL, _IOLBF, 0 );
88 if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() );
89 get_start_ticks();
90 init_registry();
91 select_loop();
92 close_registry();
93 if (debug_level) fprintf( stderr, "Server: exiting (pid=%ld)\n", (long) getpid() );
95 #ifdef DEBUG_OBJECTS
96 close_atom_table();
97 dump_objects(); /* dump any remaining objects */
98 #endif
99 exit(0);