server: Bump priority on server to process messages faster
[wine/multimedia.git] / server / main.c
blob6c257b4676dc465b5b64bc8943d64f7371e45043
1 /*
2 * Server main function
4 * Copyright (C) 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <assert.h>
24 #include <ctype.h>
25 #include <fcntl.h>
26 #include <signal.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <sys/time.h>
30 #include <unistd.h>
31 #include <sys/syscall.h>
32 #ifdef HAVE_GETOPT_H
33 # include <getopt.h>
34 #endif
36 #include "object.h"
37 #include "file.h"
38 #include "thread.h"
39 #include "request.h"
40 #include "wine/library.h"
42 extern int rtkit_make_realtime(pid_t process, pid_t thread, int priority);
44 /* command-line options */
45 int debug_level = 0;
46 int foreground = 0;
47 timeout_t master_socket_timeout = 3 * -TICKS_PER_SEC; /* master socket timeout, default is 3 seconds */
48 const char *server_argv0;
50 /* parse-line args */
52 static void usage( FILE *fh )
54 fprintf(fh, "Usage: %s [options]\n\n", server_argv0);
55 fprintf(fh, "Options:\n");
56 fprintf(fh, " -d[n], --debug[=n] set debug level to n or +1 if n not specified\n");
57 fprintf(fh, " -f, --foreground remain in the foreground for debugging\n");
58 fprintf(fh, " -h, --help display this help message\n");
59 fprintf(fh, " -k[n], --kill[=n] kill the current wineserver, optionally with signal n\n");
60 fprintf(fh, " -p[n], --persistent[=n] make server persistent, optionally for n seconds\n");
61 fprintf(fh, " -v, --version display version information and exit\n");
62 fprintf(fh, " -w, --wait wait until the current wineserver terminates\n");
63 fprintf(fh, "\n");
66 static void parse_args( int argc, char *argv[] )
68 int ret, optc;
70 static struct option long_options[] =
72 {"debug", 2, NULL, 'd'},
73 {"foreground", 0, NULL, 'f'},
74 {"help", 0, NULL, 'h'},
75 {"kill", 2, NULL, 'k'},
76 {"persistent", 2, NULL, 'p'},
77 {"version", 0, NULL, 'v'},
78 {"wait", 0, NULL, 'w'},
79 { NULL, 0, NULL, 0}
82 server_argv0 = argv[0];
84 while ((optc = getopt_long( argc, argv, "d::fhk::p::vw", long_options, NULL )) != -1)
86 switch(optc)
88 case 'd':
89 if (optarg && isdigit(*optarg))
90 debug_level = atoi( optarg );
91 else
92 debug_level++;
93 break;
94 case 'f':
95 foreground = 1;
96 break;
97 case 'h':
98 usage(stdout);
99 exit(0);
100 break;
101 case 'k':
102 if (optarg && isdigit(*optarg))
103 ret = kill_lock_owner( atoi( optarg ) );
104 else
105 ret = kill_lock_owner(-1);
106 exit( !ret );
107 case 'p':
108 if (optarg && isdigit(*optarg))
109 master_socket_timeout = (timeout_t)atoi( optarg ) * -TICKS_PER_SEC;
110 else
111 master_socket_timeout = TIMEOUT_INFINITE;
112 break;
113 case 'v':
114 fprintf( stderr, "%s\n", wine_get_build_id());
115 exit(0);
116 case 'w':
117 wait_for_lock();
118 exit(0);
119 default:
120 usage(stderr);
121 exit(1);
126 static void sigterm_handler( int signum )
128 exit(1); /* make sure atexit functions get called */
131 int main( int argc, char *argv[] )
133 setvbuf( stderr, NULL, _IOLBF, 0 );
134 parse_args( argc, argv );
136 /* setup temporary handlers before the real signal initialization is done */
137 signal( SIGPIPE, SIG_IGN );
138 signal( SIGHUP, sigterm_handler );
139 signal( SIGINT, sigterm_handler );
140 signal( SIGQUIT, sigterm_handler );
141 signal( SIGTERM, sigterm_handler );
142 signal( SIGABRT, sigterm_handler );
144 sock_init();
145 open_master_socket();
147 if (debug_level) fprintf( stderr, "wineserver: starting (pid=%ld)\n", (long) getpid() );
148 init_signals();
149 init_directories();
150 init_registry();
151 rtkit_make_realtime(getpid(), syscall( SYS_gettid ), 2);
152 main_loop();
153 return 0;