2 * Server-side request handling
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
22 #include "wine/port.h"
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_WAIT_H
42 # include <sys/wait.h>
55 # include <mach/mach_time.h>
59 #define WIN32_NO_STATUS
64 #include "wine/library.h"
70 #define WANT_REQUEST_HANDLERS
73 /* Some versions of glibc don't define this */
78 /* path names for server master Unix socket */
79 static const char * const server_socket_name
= "socket"; /* name of the socket file */
80 static const char * const server_lock_name
= "lock"; /* name of the server lock file */
84 struct object obj
; /* object header */
85 struct fd
*fd
; /* file descriptor of the master socket */
88 static void master_socket_dump( struct object
*obj
, int verbose
);
89 static void master_socket_destroy( struct object
*obj
);
90 static void master_socket_poll_event( struct fd
*fd
, int event
);
92 static const struct object_ops master_socket_ops
=
94 sizeof(struct master_socket
), /* size */
95 master_socket_dump
, /* dump */
96 no_get_type
, /* get_type */
97 no_add_queue
, /* add_queue */
98 NULL
, /* remove_queue */
100 NULL
, /* satisfied */
101 no_signal
, /* signal */
102 no_get_fd
, /* get_fd */
103 no_map_access
, /* map_access */
104 default_get_sd
, /* get_sd */
105 default_set_sd
, /* set_sd */
106 no_lookup_name
, /* lookup_name */
107 no_open_file
, /* open_file */
108 no_close_handle
, /* close_handle */
109 master_socket_destroy
/* destroy */
112 static const struct fd_ops master_socket_fd_ops
=
114 NULL
, /* get_poll_events */
115 master_socket_poll_event
, /* poll_event */
117 NULL
, /* get_fd_type */
119 NULL
, /* queue_async */
120 NULL
, /* reselect_async */
121 NULL
/* cancel_async */
125 struct thread
*current
= NULL
; /* thread handling the current request */
126 unsigned int global_error
= 0; /* global error code for when no thread is current */
127 timeout_t server_start_time
= 0; /* server startup time */
128 int server_dir_fd
= -1; /* file descriptor for the server dir */
129 int config_dir_fd
= -1; /* file descriptor for the config dir */
131 static struct master_socket
*master_socket
; /* the master socket object */
132 static struct timeout_user
*master_timeout
;
134 /* complain about a protocol error and terminate the client connection */
135 void fatal_protocol_error( struct thread
*thread
, const char *err
, ... )
139 va_start( args
, err
);
140 fprintf( stderr
, "Protocol error:%04x: ", thread
->id
);
141 vfprintf( stderr
, err
, args
);
143 thread
->exit_code
= 1;
144 kill_thread( thread
, 1 );
147 /* die on a fatal error */
148 void fatal_error( const char *err
, ... )
152 va_start( args
, err
);
153 fprintf( stderr
, "wineserver: " );
154 vfprintf( stderr
, err
, args
);
159 /* allocate the reply data */
160 void *set_reply_data_size( data_size_t size
)
162 assert( size
<= get_reply_max_size() );
163 if (size
&& !(current
->reply_data
= mem_alloc( size
))) size
= 0;
164 current
->reply_size
= size
;
165 return current
->reply_data
;
168 /* return object attributes from the current request */
169 const struct object_attributes
*get_req_object_attributes( const struct security_descriptor
**sd
,
170 struct unicode_str
*name
)
172 static const struct object_attributes empty_attributes
;
173 const struct object_attributes
*attr
= get_req_data();
174 data_size_t size
= get_req_data_size();
180 return &empty_attributes
;
183 if ((size
< sizeof(*attr
)) || (size
- sizeof(*attr
) < attr
->sd_len
) ||
184 (size
- sizeof(*attr
) - attr
->sd_len
< attr
->name_len
))
186 set_error( STATUS_ACCESS_VIOLATION
);
189 if (attr
->sd_len
&& !sd_is_valid( (const struct security_descriptor
*)(attr
+ 1), attr
->sd_len
))
191 set_error( STATUS_INVALID_SECURITY_DESCR
);
195 *sd
= attr
->sd_len
? (const struct security_descriptor
*)(attr
+ 1) : NULL
;
196 name
->len
= (attr
->name_len
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
197 name
->str
= (const WCHAR
*)(attr
+ 1) + attr
->sd_len
/ sizeof(WCHAR
);
201 /* write the remaining part of the reply */
202 void write_reply( struct thread
*thread
)
206 if ((ret
= write( get_unix_fd( thread
->reply_fd
),
207 (char *)thread
->reply_data
+ thread
->reply_size
- thread
->reply_towrite
,
208 thread
->reply_towrite
)) >= 0)
210 if (!(thread
->reply_towrite
-= ret
))
212 free( thread
->reply_data
);
213 thread
->reply_data
= NULL
;
214 /* sent everything, can go back to waiting for requests */
215 set_fd_events( thread
->request_fd
, POLLIN
);
216 set_fd_events( thread
->reply_fd
, 0 );
221 kill_thread( thread
, 0 ); /* normal death */
222 else if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
223 fatal_protocol_error( thread
, "reply write: %s\n", strerror( errno
));
226 /* send a reply to the current thread */
227 static void send_reply( union generic_reply
*reply
)
231 if (!current
->reply_size
)
233 if ((ret
= write( get_unix_fd( current
->reply_fd
),
234 reply
, sizeof(*reply
) )) != sizeof(*reply
)) goto error
;
240 vec
[0].iov_base
= (void *)reply
;
241 vec
[0].iov_len
= sizeof(*reply
);
242 vec
[1].iov_base
= current
->reply_data
;
243 vec
[1].iov_len
= current
->reply_size
;
245 if ((ret
= writev( get_unix_fd( current
->reply_fd
), vec
, 2 )) < sizeof(*reply
)) goto error
;
247 if ((current
->reply_towrite
= current
->reply_size
- (ret
- sizeof(*reply
))))
249 /* couldn't write it all, wait for POLLOUT */
250 set_fd_events( current
->reply_fd
, POLLOUT
);
251 set_fd_events( current
->request_fd
, 0 );
255 free( current
->reply_data
);
256 current
->reply_data
= NULL
;
261 fatal_protocol_error( current
, "partial write %d\n", ret
);
262 else if (errno
== EPIPE
)
263 kill_thread( current
, 0 ); /* normal death */
265 fatal_protocol_error( current
, "reply write: %s\n", strerror( errno
));
268 /* call a request handler */
269 static void call_req_handler( struct thread
*thread
)
271 union generic_reply reply
;
272 enum request req
= thread
->req
.request_header
.req
;
275 current
->reply_size
= 0;
277 memset( &reply
, 0, sizeof(reply
) );
279 if (debug_level
) trace_request();
281 if (req
< REQ_NB_REQUESTS
)
282 req_handlers
[req
]( ¤t
->req
, &reply
);
284 set_error( STATUS_NOT_IMPLEMENTED
);
288 if (current
->reply_fd
)
290 reply
.reply_header
.error
= current
->error
;
291 reply
.reply_header
.reply_size
= current
->reply_size
;
292 if (debug_level
) trace_reply( req
, &reply
);
293 send_reply( &reply
);
297 current
->exit_code
= 1;
298 kill_thread( current
, 1 ); /* no way to continue without reply fd */
304 /* read a request from a thread */
305 void read_request( struct thread
*thread
)
309 if (!thread
->req_toread
) /* no pending request */
311 if ((ret
= read( get_unix_fd( thread
->request_fd
), &thread
->req
,
312 sizeof(thread
->req
) )) != sizeof(thread
->req
)) goto error
;
313 if (!(thread
->req_toread
= thread
->req
.request_header
.request_size
))
315 /* no data, handle request at once */
316 call_req_handler( thread
);
319 if (!(thread
->req_data
= malloc( thread
->req_toread
)))
321 fatal_protocol_error( thread
, "no memory for %u bytes request %d\n",
322 thread
->req_toread
, thread
->req
.request_header
.req
);
327 /* read the variable sized data */
330 ret
= read( get_unix_fd( thread
->request_fd
),
331 (char *)thread
->req_data
+ thread
->req
.request_header
.request_size
332 - thread
->req_toread
,
333 thread
->req_toread
);
335 if (!(thread
->req_toread
-= ret
))
337 call_req_handler( thread
);
338 free( thread
->req_data
);
339 thread
->req_data
= NULL
;
345 if (!ret
) /* closed pipe */
346 kill_thread( thread
, 0 );
348 fatal_protocol_error( thread
, "partial read %d\n", ret
);
349 else if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
350 fatal_protocol_error( thread
, "read: %s\n", strerror( errno
));
353 /* receive a file descriptor on the process socket */
354 int receive_fd( struct process
*process
)
358 struct msghdr msghdr
;
361 #ifdef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
362 msghdr
.msg_accrightslen
= sizeof(int);
363 msghdr
.msg_accrights
= (void *)&fd
;
364 #else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
365 char cmsg_buffer
[256];
366 msghdr
.msg_control
= cmsg_buffer
;
367 msghdr
.msg_controllen
= sizeof(cmsg_buffer
);
368 msghdr
.msg_flags
= 0;
369 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
371 msghdr
.msg_name
= NULL
;
372 msghdr
.msg_namelen
= 0;
373 msghdr
.msg_iov
= &vec
;
374 msghdr
.msg_iovlen
= 1;
375 vec
.iov_base
= (void *)&data
;
376 vec
.iov_len
= sizeof(data
);
378 ret
= recvmsg( get_unix_fd( process
->msg_fd
), &msghdr
, 0 );
380 #ifndef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
383 struct cmsghdr
*cmsg
;
384 for (cmsg
= CMSG_FIRSTHDR( &msghdr
); cmsg
; cmsg
= CMSG_NXTHDR( &msghdr
, cmsg
))
386 if (cmsg
->cmsg_level
!= SOL_SOCKET
) continue;
387 if (cmsg
->cmsg_type
== SCM_RIGHTS
) fd
= *(int *)CMSG_DATA(cmsg
);
390 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
392 if (ret
== sizeof(data
))
394 struct thread
*thread
;
396 if (data
.tid
) thread
= get_thread_from_id( data
.tid
);
397 else thread
= (struct thread
*)grab_object( get_process_first_thread( process
));
399 if (!thread
|| thread
->process
!= process
|| thread
->state
== TERMINATED
)
402 fprintf( stderr
, "%04x: *fd* %d <- %d bad thread id\n",
403 data
.tid
, data
.fd
, fd
);
409 fprintf( stderr
, "%04x: *fd* %d <- %d\n",
410 thread
->id
, data
.fd
, fd
);
411 thread_add_inflight_fd( thread
, data
.fd
, fd
);
413 if (thread
) release_object( thread
);
419 kill_process( process
, 0 );
423 fprintf( stderr
, "Protocol error: process %04x: partial recvmsg %d for fd\n",
425 if (fd
!= -1) close( fd
);
426 kill_process( process
, 1 );
430 if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
432 fprintf( stderr
, "Protocol error: process %04x: ", process
->id
);
434 kill_process( process
, 1 );
440 /* send an fd to a client */
441 int send_client_fd( struct process
*process
, int fd
, obj_handle_t handle
)
444 struct msghdr msghdr
;
447 #ifdef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
448 msghdr
.msg_accrightslen
= sizeof(fd
);
449 msghdr
.msg_accrights
= (void *)&fd
;
450 #else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
451 char cmsg_buffer
[256];
452 struct cmsghdr
*cmsg
;
453 msghdr
.msg_control
= cmsg_buffer
;
454 msghdr
.msg_controllen
= sizeof(cmsg_buffer
);
455 msghdr
.msg_flags
= 0;
456 cmsg
= CMSG_FIRSTHDR( &msghdr
);
457 cmsg
->cmsg_len
= CMSG_LEN( sizeof(fd
) );
458 cmsg
->cmsg_level
= SOL_SOCKET
;
459 cmsg
->cmsg_type
= SCM_RIGHTS
;
460 *(int *)CMSG_DATA(cmsg
) = fd
;
461 msghdr
.msg_controllen
= cmsg
->cmsg_len
;
462 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
464 msghdr
.msg_name
= NULL
;
465 msghdr
.msg_namelen
= 0;
466 msghdr
.msg_iov
= &vec
;
467 msghdr
.msg_iovlen
= 1;
469 vec
.iov_base
= (void *)&handle
;
470 vec
.iov_len
= sizeof(handle
);
473 fprintf( stderr
, "%04x: *fd* %04x -> %d\n", current
? current
->id
: process
->id
, handle
, fd
);
475 ret
= sendmsg( get_unix_fd( process
->msg_fd
), &msghdr
, 0 );
477 if (ret
== sizeof(handle
)) return 0;
481 fprintf( stderr
, "Protocol error: process %04x: partial sendmsg %d\n", process
->id
, ret
);
482 kill_process( process
, 1 );
484 else if (errno
== EPIPE
)
486 kill_process( process
, 0 );
490 fprintf( stderr
, "Protocol error: process %04x: ", process
->id
);
492 kill_process( process
, 1 );
497 /* get current tick count to return to client */
498 unsigned int get_tick_count(void)
500 #ifdef HAVE_CLOCK_GETTIME
502 #ifdef CLOCK_MONOTONIC_RAW
503 if (!clock_gettime( CLOCK_MONOTONIC_RAW
, &ts
))
504 return ts
.tv_sec
* 1000 + ts
.tv_nsec
/ 1000000;
506 if (!clock_gettime( CLOCK_MONOTONIC
, &ts
))
507 return ts
.tv_sec
* 1000 + ts
.tv_nsec
/ 1000000;
508 #elif defined(__APPLE__)
509 static mach_timebase_info_data_t timebase
;
511 if (!timebase
.denom
) mach_timebase_info( &timebase
);
512 return mach_absolute_time() * timebase
.numer
/ timebase
.denom
/ 1000000;
514 return (current_time
- server_start_time
) / 10000;
517 static void master_socket_dump( struct object
*obj
, int verbose
)
519 struct master_socket
*sock
= (struct master_socket
*)obj
;
520 assert( obj
->ops
== &master_socket_ops
);
521 fprintf( stderr
, "Master socket fd=%p\n", sock
->fd
);
524 static void master_socket_destroy( struct object
*obj
)
526 struct master_socket
*sock
= (struct master_socket
*)obj
;
527 assert( obj
->ops
== &master_socket_ops
);
528 release_object( sock
->fd
);
531 /* handle a socket event */
532 static void master_socket_poll_event( struct fd
*fd
, int event
)
534 struct master_socket
*sock
= get_fd_user( fd
);
535 assert( master_socket
->obj
.ops
== &master_socket_ops
);
537 assert( sock
== master_socket
); /* there is only one master socket */
539 if (event
& (POLLERR
| POLLHUP
))
541 /* this is not supposed to happen */
542 fprintf( stderr
, "wineserver: Error on master socket\n" );
543 set_fd_events( sock
->fd
, -1 );
545 else if (event
& POLLIN
)
547 struct sockaddr_un dummy
;
548 socklen_t len
= sizeof(dummy
);
549 int client
= accept( get_unix_fd( master_socket
->fd
), (struct sockaddr
*) &dummy
, &len
);
550 if (client
== -1) return;
551 fcntl( client
, F_SETFL
, O_NONBLOCK
);
552 create_process( client
, NULL
, 0 );
556 /* remove the socket upon exit */
557 static void socket_cleanup(void)
559 static int do_it_once
;
560 if (!do_it_once
++) unlink( server_socket_name
);
563 /* create a directory and check its permissions */
564 static void create_dir( const char *name
, struct stat
*st
)
566 if (lstat( name
, st
) == -1)
569 fatal_error( "lstat %s: %s", name
, strerror( errno
));
570 if (mkdir( name
, 0700 ) == -1 && errno
!= EEXIST
)
571 fatal_error( "mkdir %s: %s\n", name
, strerror( errno
));
572 if (lstat( name
, st
) == -1)
573 fatal_error( "lstat %s: %s\n", name
, strerror( errno
));
575 if (!S_ISDIR(st
->st_mode
)) fatal_error( "%s is not a directory\n", name
);
576 if (st
->st_uid
!= getuid()) fatal_error( "%s is not owned by you\n", name
);
577 if (st
->st_mode
& 077) fatal_error( "%s must not be accessible by other users\n", name
);
580 /* create the server directory and chdir to it */
581 static void create_server_dir( const char *dir
)
583 char *p
, *server_dir
;
586 if (!(server_dir
= strdup( dir
))) fatal_error( "out of memory\n" );
588 /* first create the base directory if needed */
590 p
= strrchr( server_dir
, '/' );
592 create_dir( server_dir
, &st
);
594 /* now create the server directory */
597 create_dir( server_dir
, &st
);
599 if (chdir( server_dir
) == -1)
600 fatal_error( "chdir %s: %s\n", server_dir
, strerror( errno
));
601 if ((server_dir_fd
= open( ".", O_RDONLY
)) == -1)
602 fatal_error( "open %s: %s\n", server_dir
, strerror( errno
));
603 if (fstat( server_dir_fd
, &st2
) == -1)
604 fatal_error( "stat %s: %s\n", server_dir
, strerror( errno
));
605 if (st
.st_dev
!= st2
.st_dev
|| st
.st_ino
!= st2
.st_ino
)
606 fatal_error( "chdir did not end up in %s\n", server_dir
);
611 /* create the lock file and return its file descriptor */
612 static int create_server_lock(void)
617 if (lstat( server_lock_name
, &st
) == -1)
620 fatal_error( "lstat %s/%s: %s", wine_get_server_dir(), server_lock_name
, strerror( errno
));
624 if (!S_ISREG(st
.st_mode
))
625 fatal_error( "%s/%s is not a regular file\n", wine_get_server_dir(), server_lock_name
);
628 if ((fd
= open( server_lock_name
, O_CREAT
|O_TRUNC
|O_WRONLY
, 0600 )) == -1)
629 fatal_error( "error creating %s/%s: %s", wine_get_server_dir(), server_lock_name
, strerror( errno
));
633 /* wait for the server lock */
634 int wait_for_lock(void)
636 const char *server_dir
= wine_get_server_dir();
640 if (!server_dir
) return 0; /* no server dir, so no lock to wait on */
642 create_server_dir( server_dir
);
643 fd
= create_server_lock();
646 fl
.l_whence
= SEEK_SET
;
649 r
= fcntl( fd
, F_SETLKW
, &fl
);
655 /* kill the wine server holding the lock */
656 int kill_lock_owner( int sig
)
658 const char *server_dir
= wine_get_server_dir();
663 if (!server_dir
) return 0; /* no server dir, nothing to do */
665 create_server_dir( server_dir
);
666 fd
= create_server_lock();
668 for (i
= 1; i
<= 20; i
++)
671 fl
.l_whence
= SEEK_SET
;
674 if (fcntl( fd
, F_GETLK
, &fl
) == -1) goto done
;
675 if (fl
.l_type
!= F_WRLCK
) goto done
; /* the file is not locked */
676 if (!pid
) /* first time around */
678 if (!(pid
= fl
.l_pid
)) goto done
; /* shouldn't happen */
681 if (kill( pid
, SIGINT
) == -1) goto done
;
682 kill( pid
, SIGCONT
);
685 else /* just send the specified signal and return */
687 ret
= (kill( pid
, sig
) != -1);
691 else if (fl
.l_pid
!= pid
) goto done
; /* no longer the same process */
694 /* waited long enough, now kill it */
695 kill( pid
, SIGKILL
);
702 /* acquire the main server lock */
703 static void acquire_lock(void)
705 struct sockaddr_un addr
;
708 int fd
, slen
, got_lock
= 0;
710 fd
= create_server_lock();
713 fl
.l_whence
= SEEK_SET
;
716 if (fcntl( fd
, F_SETLK
, &fl
) != -1)
718 /* check for crashed server */
719 if (stat( server_socket_name
, &st
) != -1 && /* there is a leftover socket */
720 stat( "core", &st
) != -1 && st
.st_size
) /* and there is a non-empty core file */
723 "Warning: a previous instance of the wine server seems to have crashed.\n"
724 "Please run 'gdb %s %s/core',\n"
725 "type 'backtrace' at the gdb prompt and report the results. Thanks.\n\n",
726 server_argv0
, wine_get_server_dir() );
728 unlink( server_socket_name
); /* we got the lock, we can safely remove the socket */
730 /* in that case we reuse fd without closing it, this ensures
731 * that we hold the lock until the process exits */
740 /* check whether locks work at all on this file system */
741 if (fcntl( fd
, F_GETLK
, &fl
) == -1) break;
744 exit(2); /* we didn't get the lock, exit with special status */
746 fatal_error( "fcntl %s/%s: %s", wine_get_server_dir(), server_lock_name
, strerror( errno
));
748 /* it seems we can't use locks on this fs, so we will use the socket existence as lock */
752 if ((fd
= socket( AF_UNIX
, SOCK_STREAM
, 0 )) == -1) fatal_error( "socket: %s\n", strerror( errno
));
753 addr
.sun_family
= AF_UNIX
;
754 strcpy( addr
.sun_path
, server_socket_name
);
755 slen
= sizeof(addr
) - sizeof(addr
.sun_path
) + strlen(addr
.sun_path
) + 1;
756 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
759 if (bind( fd
, (struct sockaddr
*)&addr
, slen
) == -1)
761 if ((errno
== EEXIST
) || (errno
== EADDRINUSE
))
764 fatal_error( "couldn't bind to the socket even though we hold the lock\n" );
765 exit(2); /* we didn't get the lock, exit with special status */
767 fatal_error( "bind: %s\n", strerror( errno
));
769 atexit( socket_cleanup
);
770 chmod( server_socket_name
, 0600 ); /* make sure no other user can connect */
771 if (listen( fd
, 5 ) == -1) fatal_error( "listen: %s\n", strerror( errno
));
773 if (!(master_socket
= alloc_object( &master_socket_ops
)) ||
774 !(master_socket
->fd
= create_anonymous_fd( &master_socket_fd_ops
, fd
, &master_socket
->obj
, 0 )))
775 fatal_error( "out of memory\n" );
776 set_fd_events( master_socket
->fd
, POLLIN
);
777 make_object_static( &master_socket
->obj
);
780 /* open the master server socket and start waiting for new clients */
781 void open_master_socket(void)
783 const char *server_dir
= wine_get_server_dir();
784 const char *config_dir
= wine_get_config_dir();
785 int fd
, pid
, status
, sync_pipe
[2];
788 /* make sure no request is larger than the maximum size */
789 assert( sizeof(union generic_request
) == sizeof(struct request_max_size
) );
790 assert( sizeof(union generic_reply
) == sizeof(struct request_max_size
) );
792 /* make sure the stdio fds are open */
793 fd
= open( "/dev/null", O_RDWR
);
794 while (fd
>= 0 && fd
<= 2) fd
= dup( fd
);
797 fatal_error( "directory %s cannot be accessed\n", config_dir
);
798 if (chdir( config_dir
) == -1)
799 fatal_error( "chdir to %s: %s\n", config_dir
, strerror( errno
));
800 if ((config_dir_fd
= open( ".", O_RDONLY
)) == -1)
801 fatal_error( "open %s: %s\n", config_dir
, strerror( errno
));
803 create_server_dir( server_dir
);
807 if (pipe( sync_pipe
) == -1) fatal_error( "pipe: %s\n", strerror( errno
));
813 close( sync_pipe
[0] );
817 /* close stdin and stdout */
823 write( sync_pipe
[1], &dummy
, 1 );
824 close( sync_pipe
[1] );
828 fatal_error( "fork: %s\n", strerror( errno
));
831 default: /* parent */
832 close( sync_pipe
[1] );
834 /* wait for child to signal us and then exit */
835 if (read( sync_pipe
[0], &dummy
, 1 ) == 1) _exit(0);
837 /* child terminated, propagate exit status */
838 waitpid( pid
, &status
, 0 );
839 if (WIFEXITED(status
)) _exit( WEXITSTATUS(status
) );
843 else /* remain in the foreground */
848 /* init the process tracing mechanism */
849 init_tracing_mechanism();
853 /* master socket timer expiration handler */
854 static void close_socket_timeout( void *arg
)
856 master_timeout
= NULL
;
858 if (debug_level
) fprintf( stderr
, "wineserver: exiting (pid=%ld)\n", (long) getpid() );
861 close_objects(); /* shut down everything properly */
866 /* close the master socket and stop waiting for new clients */
867 void close_master_socket( timeout_t timeout
)
871 release_object( master_socket
);
872 master_socket
= NULL
;
874 if (master_timeout
) /* cancel previous timeout */
875 remove_timeout_user( master_timeout
);
877 master_timeout
= add_timeout_user( timeout
, close_socket_timeout
, NULL
);