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
40 /* command-line options */
43 timeout_t master_socket_timeout = 3 * -TICKS_PER_SEC; /* master socket timeout, default is 3 seconds */
44 const char *server_argv0;
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[] )
66 static struct option long_options[] =
69 {"foreground", 0, 0, 'f'},
72 {"persistent", 2, 0, 'p'},
73 {"version", 0, 0, 'v'},
78 server_argv0 = argv[0];
80 while ((optc = getopt_long( argc, argv, "d::fhk::p::vw", long_options, NULL )) != -1)
85 if (optarg && isdigit(*optarg))
86 debug_level = atoi( optarg );
98 if (optarg && isdigit(*optarg))
99 ret = kill_lock_owner( atoi( optarg ) );
101 ret = kill_lock_owner(-1);
104 if (optarg && isdigit(*optarg))
105 master_socket_timeout = (timeout_t)atoi( optarg ) * -TICKS_PER_SEC;
107 master_socket_timeout = TIMEOUT_INFINITE;
110 fprintf( stderr, "%s\n", PACKAGE_STRING );
122 static void sigterm_handler( int signum )
124 exit(1); /* make sure atexit functions get called */
127 int main( int argc, char *argv[] )
129 parse_args( argc, argv );
131 /* setup temporary handlers before the real signal initialization is done */
132 signal( SIGPIPE, SIG_IGN );
133 signal( SIGHUP, sigterm_handler );
134 signal( SIGINT, sigterm_handler );
135 signal( SIGQUIT, sigterm_handler );
136 signal( SIGTERM, sigterm_handler );
137 signal( SIGABRT, sigterm_handler );
140 open_master_socket();
141 setvbuf( stderr, NULL, _IOLBF, 0 );
143 if (debug_level) fprintf( stderr, "wineserver: starting (pid=%ld)\n", (long) getpid() );