Fixed WM_GETTEXTLENGTH handling.
[wine/multimedia.git] / server / main.c
blob2a4aade9cda3632e625c4fae063478e913595f7d
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 (more complete?) help option */
29 static void usage(const char *exeName)
31 fprintf(stderr, "\nusage: %s [options]\n\n", exeName);
32 fprintf(stderr, "options:\n");
33 fprintf(stderr, " -d<n> set debug level to <n>\n");
34 fprintf(stderr, " -p make server persistent\n");
35 fprintf(stderr, " -h display this help message\n");
36 fprintf(stderr, "\n");
39 static void parse_args( int argc, char *argv[] )
41 int i;
42 for (i = 1; i < argc; i++)
44 if (argv[i][0] == '-')
46 switch(argv[i][1])
48 case 'd':
49 if (isdigit(argv[i][2])) debug_level = atoi( argv[i] + 2 );
50 else debug_level++;
51 break;
52 case 'h':
53 usage( argv[0] );
54 exit(0);
55 break;
56 case 'p':
57 persistent_server = 1;
58 break;
59 default:
60 fprintf( stderr, "Unknown option '%s'\n", argv[i] );
61 usage( argv[0] );
62 exit(1);
65 else
67 fprintf( stderr, "Unknown argument '%s'. Your version of wine may be too old.\n", argv[i] );
68 usage(argv[0]);
69 exit(1);
74 static void sigterm_handler()
76 exit(1); /* make sure atexit functions get called */
79 /* initialize signal handling */
80 static void signal_init(void)
82 signal( SIGPIPE, SIG_IGN );
83 signal( SIGHUP, sigterm_handler );
84 signal( SIGINT, sigterm_handler );
85 signal( SIGQUIT, sigterm_handler );
86 signal( SIGTERM, sigterm_handler );
87 signal( SIGABRT, sigterm_handler );
90 /* get server start ticks used to calculate GetTickCount() in Wine clients */
91 static void get_start_ticks(void)
93 struct timeval t;
94 gettimeofday( &t, NULL );
95 server_start_ticks = (t.tv_sec * 1000) + (t.tv_usec / 1000);
98 int main( int argc, char *argv[] )
100 parse_args( argc, argv );
101 signal_init();
102 open_master_socket();
103 setvbuf( stderr, NULL, _IOLBF, 0 );
105 if (debug_level) fprintf( stderr, "Server: starting (pid=%ld)\n", (long) getpid() );
106 get_start_ticks();
107 init_registry();
108 select_loop();
109 close_registry();
110 if (debug_level) fprintf( stderr, "Server: exiting (pid=%ld)\n", (long) getpid() );
112 #ifdef DEBUG_OBJECTS
113 close_atom_table();
114 dump_objects(); /* dump any remaining objects */
115 #endif
116 exit(0);