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
39 #include "wine/library.h"
41 /* command-line options */
44 timeout_t master_socket_timeout
= 3 * -TICKS_PER_SEC
; /* master socket timeout, default is 3 seconds */
45 const char *server_argv0
;
49 static void usage(void)
51 fprintf(stderr
, "Usage: %s [options]\n\n", server_argv0
);
52 fprintf(stderr
, "Options:\n");
53 fprintf(stderr
, " -d[n], --debug[=n] set debug level to n or +1 if n not specified\n");
54 fprintf(stderr
, " -f, --foreground remain in the foreground for debugging\n");
55 fprintf(stderr
, " -h, --help display this help message\n");
56 fprintf(stderr
, " -k[n], --kill[=n] kill the current wineserver, optionally with signal n\n");
57 fprintf(stderr
, " -p[n], --persistent[=n] make server persistent, optionally for n seconds\n");
58 fprintf(stderr
, " -v, --version display version information and exit\n");
59 fprintf(stderr
, " -w, --wait wait until the current wineserver terminates\n");
60 fprintf(stderr
, "\n");
63 static void parse_args( int argc
, char *argv
[] )
67 static struct option long_options
[] =
69 {"debug", 2, NULL
, 'd'},
70 {"foreground", 0, NULL
, 'f'},
71 {"help", 0, NULL
, 'h'},
72 {"kill", 2, NULL
, 'k'},
73 {"persistent", 2, NULL
, 'p'},
74 {"version", 0, NULL
, 'v'},
75 {"wait", 0, NULL
, 'w'},
79 server_argv0
= argv
[0];
81 while ((optc
= getopt_long( argc
, argv
, "d::fhk::p::vw", long_options
, NULL
)) != -1)
86 if (optarg
&& isdigit(*optarg
))
87 debug_level
= atoi( optarg
);
99 if (optarg
&& isdigit(*optarg
))
100 ret
= kill_lock_owner( atoi( optarg
) );
102 ret
= kill_lock_owner(-1);
105 if (optarg
&& isdigit(*optarg
))
106 master_socket_timeout
= (timeout_t
)atoi( optarg
) * -TICKS_PER_SEC
;
108 master_socket_timeout
= TIMEOUT_INFINITE
;
111 fprintf( stderr
, "%s\n", wine_get_build_id());
123 static void sigterm_handler( int signum
)
125 exit(1); /* make sure atexit functions get called */
128 int main( int argc
, char *argv
[] )
130 setvbuf( stderr
, NULL
, _IOLBF
, 0 );
131 parse_args( argc
, argv
);
133 /* setup temporary handlers before the real signal initialization is done */
134 signal( SIGPIPE
, SIG_IGN
);
135 signal( SIGHUP
, sigterm_handler
);
136 signal( SIGINT
, sigterm_handler
);
137 signal( SIGQUIT
, sigterm_handler
);
138 signal( SIGTERM
, sigterm_handler
);
139 signal( SIGABRT
, sigterm_handler
);
142 open_master_socket();
144 if (debug_level
) fprintf( stderr
, "wineserver: starting (pid=%ld)\n", (long) getpid() );