msdaps: Add a stub marshaller object.
[wine.git] / server / main.c
bloba59350b552e7155fbf386d1f4d391b7f32ce0df5
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 #ifdef HAVE_GETOPT_H
32 # include <getopt.h>
33 #endif
35 #include "object.h"
36 #include "file.h"
37 #include "thread.h"
38 #include "request.h"
40 /* command-line options */
41 int debug_level = 0;
42 int foreground = 0;
43 timeout_t master_socket_timeout = 3 * -TICKS_PER_SEC; /* master socket timeout, default is 3 seconds */
44 const char *server_argv0;
46 /* parse-line args */
48 static void usage(void)
50 fprintf(stderr, "Usage: %s [options]\n\n", server_argv0);
51 fprintf(stderr, "Options:\n");
52 fprintf(stderr, " -d[n], --debug[=n] set debug level to n or +1 if n not specified\n");
53 fprintf(stderr, " -f, --foreground remain in the foreground for debugging\n");
54 fprintf(stderr, " -h, --help display this help message\n");
55 fprintf(stderr, " -k[n], --kill[=n] kill the current wineserver, optionally with signal n\n");
56 fprintf(stderr, " -p[n], --persistent[=n] make server persistent, optionally for n seconds\n");
57 fprintf(stderr, " -v, --version display version information and exit\n");
58 fprintf(stderr, " -w, --wait wait until the current wineserver terminates\n");
59 fprintf(stderr, "\n");
62 static void parse_args( int argc, char *argv[] )
64 int ret, optc;
66 static struct option long_options[] =
68 {"debug", 2, NULL, 'd'},
69 {"foreground", 0, NULL, 'f'},
70 {"help", 0, NULL, 'h'},
71 {"kill", 2, NULL, 'k'},
72 {"persistent", 2, NULL, 'p'},
73 {"version", 0, NULL, 'v'},
74 {"wait", 0, NULL, 'w'},
75 { NULL, 0, NULL, 0}
78 server_argv0 = argv[0];
80 while ((optc = getopt_long( argc, argv, "d::fhk::p::vw", long_options, NULL )) != -1)
82 switch(optc)
84 case 'd':
85 if (optarg && isdigit(*optarg))
86 debug_level = atoi( optarg );
87 else
88 debug_level++;
89 break;
90 case 'f':
91 foreground = 1;
92 break;
93 case 'h':
94 usage();
95 exit(0);
96 break;
97 case 'k':
98 if (optarg && isdigit(*optarg))
99 ret = kill_lock_owner( atoi( optarg ) );
100 else
101 ret = kill_lock_owner(-1);
102 exit( !ret );
103 case 'p':
104 if (optarg && isdigit(*optarg))
105 master_socket_timeout = (timeout_t)atoi( optarg ) * -TICKS_PER_SEC;
106 else
107 master_socket_timeout = TIMEOUT_INFINITE;
108 break;
109 case 'v':
110 fprintf( stderr, "%s\n", PACKAGE_STRING );
111 exit(0);
112 case 'w':
113 wait_for_lock();
114 exit(0);
115 default:
116 usage();
117 exit(1);
122 static void sigterm_handler( int signum )
124 exit(1); /* make sure atexit functions get called */
127 int main( int argc, char *argv[] )
129 setvbuf( stderr, NULL, _IOLBF, 0 );
130 parse_args( argc, argv );
132 /* setup temporary handlers before the real signal initialization is done */
133 signal( SIGPIPE, SIG_IGN );
134 signal( SIGHUP, sigterm_handler );
135 signal( SIGINT, sigterm_handler );
136 signal( SIGQUIT, sigterm_handler );
137 signal( SIGTERM, sigterm_handler );
138 signal( SIGABRT, sigterm_handler );
140 sock_init();
141 open_master_socket();
143 if (debug_level) fprintf( stderr, "wineserver: starting (pid=%ld)\n", (long) getpid() );
144 init_signals();
145 init_directories();
146 init_registry();
147 main_loop();
148 return 0;