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"
68 #define WANT_REQUEST_HANDLERS
71 /* Some versions of glibc don't define this */
76 /* path names for server master Unix socket */
77 static const char * const server_socket_name
= "socket"; /* name of the socket file */
78 static const char * const server_lock_name
= "lock"; /* name of the server lock file */
82 struct object obj
; /* object header */
83 struct fd
*fd
; /* file descriptor of the master socket */
86 static void master_socket_dump( struct object
*obj
, int verbose
);
87 static void master_socket_destroy( struct object
*obj
);
88 static void master_socket_poll_event( struct fd
*fd
, int event
);
90 static const struct object_ops master_socket_ops
=
92 sizeof(struct master_socket
), /* size */
93 master_socket_dump
, /* dump */
94 no_get_type
, /* get_type */
95 no_add_queue
, /* add_queue */
96 NULL
, /* remove_queue */
99 no_signal
, /* signal */
100 no_get_fd
, /* get_fd */
101 no_map_access
, /* map_access */
102 default_get_sd
, /* get_sd */
103 default_set_sd
, /* set_sd */
104 no_lookup_name
, /* lookup_name */
105 no_open_file
, /* open_file */
106 no_close_handle
, /* close_handle */
107 master_socket_destroy
/* destroy */
110 static const struct fd_ops master_socket_fd_ops
=
112 NULL
, /* get_poll_events */
113 master_socket_poll_event
, /* poll_event */
115 NULL
, /* get_fd_type */
117 NULL
, /* queue_async */
118 NULL
, /* reselect_async */
119 NULL
/* cancel_async */
123 struct thread
*current
= NULL
; /* thread handling the current request */
124 unsigned int global_error
= 0; /* global error code for when no thread is current */
125 timeout_t server_start_time
= 0; /* server startup time */
126 int server_dir_fd
= -1; /* file descriptor for the server dir */
127 int config_dir_fd
= -1; /* file descriptor for the config dir */
129 static struct master_socket
*master_socket
; /* the master socket object */
130 static struct timeout_user
*master_timeout
;
132 /* complain about a protocol error and terminate the client connection */
133 void fatal_protocol_error( struct thread
*thread
, const char *err
, ... )
137 va_start( args
, err
);
138 fprintf( stderr
, "Protocol error:%04x: ", thread
->id
);
139 vfprintf( stderr
, err
, args
);
141 thread
->exit_code
= 1;
142 kill_thread( thread
, 1 );
145 /* die on a fatal error */
146 void fatal_error( const char *err
, ... )
150 va_start( args
, err
);
151 fprintf( stderr
, "wineserver: " );
152 vfprintf( stderr
, err
, args
);
157 /* allocate the reply data */
158 void *set_reply_data_size( data_size_t size
)
160 assert( size
<= get_reply_max_size() );
161 if (size
&& !(current
->reply_data
= mem_alloc( size
))) size
= 0;
162 current
->reply_size
= size
;
163 return current
->reply_data
;
166 /* write the remaining part of the reply */
167 void write_reply( struct thread
*thread
)
171 if ((ret
= write( get_unix_fd( thread
->reply_fd
),
172 (char *)thread
->reply_data
+ thread
->reply_size
- thread
->reply_towrite
,
173 thread
->reply_towrite
)) >= 0)
175 if (!(thread
->reply_towrite
-= ret
))
177 free( thread
->reply_data
);
178 thread
->reply_data
= NULL
;
179 /* sent everything, can go back to waiting for requests */
180 set_fd_events( thread
->request_fd
, POLLIN
);
181 set_fd_events( thread
->reply_fd
, 0 );
186 kill_thread( thread
, 0 ); /* normal death */
187 else if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
188 fatal_protocol_error( thread
, "reply write: %s\n", strerror( errno
));
191 /* send a reply to the current thread */
192 static void send_reply( union generic_reply
*reply
)
196 if (!current
->reply_size
)
198 if ((ret
= write( get_unix_fd( current
->reply_fd
),
199 reply
, sizeof(*reply
) )) != sizeof(*reply
)) goto error
;
205 vec
[0].iov_base
= (void *)reply
;
206 vec
[0].iov_len
= sizeof(*reply
);
207 vec
[1].iov_base
= current
->reply_data
;
208 vec
[1].iov_len
= current
->reply_size
;
210 if ((ret
= writev( get_unix_fd( current
->reply_fd
), vec
, 2 )) < sizeof(*reply
)) goto error
;
212 if ((current
->reply_towrite
= current
->reply_size
- (ret
- sizeof(*reply
))))
214 /* couldn't write it all, wait for POLLOUT */
215 set_fd_events( current
->reply_fd
, POLLOUT
);
216 set_fd_events( current
->request_fd
, 0 );
220 free( current
->reply_data
);
221 current
->reply_data
= NULL
;
226 fatal_protocol_error( current
, "partial write %d\n", ret
);
227 else if (errno
== EPIPE
)
228 kill_thread( current
, 0 ); /* normal death */
230 fatal_protocol_error( current
, "reply write: %s\n", strerror( errno
));
233 /* call a request handler */
234 static void call_req_handler( struct thread
*thread
)
236 union generic_reply reply
;
237 enum request req
= thread
->req
.request_header
.req
;
240 current
->reply_size
= 0;
242 memset( &reply
, 0, sizeof(reply
) );
244 if (debug_level
) trace_request();
246 if (req
< REQ_NB_REQUESTS
)
247 req_handlers
[req
]( ¤t
->req
, &reply
);
249 set_error( STATUS_NOT_IMPLEMENTED
);
253 if (current
->reply_fd
)
255 reply
.reply_header
.error
= current
->error
;
256 reply
.reply_header
.reply_size
= current
->reply_size
;
257 if (debug_level
) trace_reply( req
, &reply
);
258 send_reply( &reply
);
262 current
->exit_code
= 1;
263 kill_thread( current
, 1 ); /* no way to continue without reply fd */
269 /* read a request from a thread */
270 void read_request( struct thread
*thread
)
274 if (!thread
->req_toread
) /* no pending request */
276 if ((ret
= read( get_unix_fd( thread
->request_fd
), &thread
->req
,
277 sizeof(thread
->req
) )) != sizeof(thread
->req
)) goto error
;
278 if (!(thread
->req_toread
= thread
->req
.request_header
.request_size
))
280 /* no data, handle request at once */
281 call_req_handler( thread
);
284 if (!(thread
->req_data
= malloc( thread
->req_toread
)))
286 fatal_protocol_error( thread
, "no memory for %u bytes request %d\n",
287 thread
->req_toread
, thread
->req
.request_header
.req
);
292 /* read the variable sized data */
295 ret
= read( get_unix_fd( thread
->request_fd
),
296 (char *)thread
->req_data
+ thread
->req
.request_header
.request_size
297 - thread
->req_toread
,
298 thread
->req_toread
);
300 if (!(thread
->req_toread
-= ret
))
302 call_req_handler( thread
);
303 free( thread
->req_data
);
304 thread
->req_data
= NULL
;
310 if (!ret
) /* closed pipe */
311 kill_thread( thread
, 0 );
313 fatal_protocol_error( thread
, "partial read %d\n", ret
);
314 else if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
315 fatal_protocol_error( thread
, "read: %s\n", strerror( errno
));
318 /* receive a file descriptor on the process socket */
319 int receive_fd( struct process
*process
)
323 struct msghdr msghdr
;
326 #ifdef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
327 msghdr
.msg_accrightslen
= sizeof(int);
328 msghdr
.msg_accrights
= (void *)&fd
;
329 #else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
330 char cmsg_buffer
[256];
331 msghdr
.msg_control
= cmsg_buffer
;
332 msghdr
.msg_controllen
= sizeof(cmsg_buffer
);
333 msghdr
.msg_flags
= 0;
334 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
336 msghdr
.msg_name
= NULL
;
337 msghdr
.msg_namelen
= 0;
338 msghdr
.msg_iov
= &vec
;
339 msghdr
.msg_iovlen
= 1;
340 vec
.iov_base
= (void *)&data
;
341 vec
.iov_len
= sizeof(data
);
343 ret
= recvmsg( get_unix_fd( process
->msg_fd
), &msghdr
, 0 );
345 #ifndef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
348 struct cmsghdr
*cmsg
;
349 for (cmsg
= CMSG_FIRSTHDR( &msghdr
); cmsg
; cmsg
= CMSG_NXTHDR( &msghdr
, cmsg
))
351 if (cmsg
->cmsg_level
!= SOL_SOCKET
) continue;
352 if (cmsg
->cmsg_type
== SCM_RIGHTS
) fd
= *(int *)CMSG_DATA(cmsg
);
355 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
357 if (ret
== sizeof(data
))
359 struct thread
*thread
;
361 if (data
.tid
) thread
= get_thread_from_id( data
.tid
);
362 else thread
= (struct thread
*)grab_object( get_process_first_thread( process
));
364 if (!thread
|| thread
->process
!= process
|| thread
->state
== TERMINATED
)
367 fprintf( stderr
, "%04x: *fd* %d <- %d bad thread id\n",
368 data
.tid
, data
.fd
, fd
);
374 fprintf( stderr
, "%04x: *fd* %d <- %d\n",
375 thread
->id
, data
.fd
, fd
);
376 thread_add_inflight_fd( thread
, data
.fd
, fd
);
378 if (thread
) release_object( thread
);
384 kill_process( process
, 0 );
388 fprintf( stderr
, "Protocol error: process %04x: partial recvmsg %d for fd\n",
390 if (fd
!= -1) close( fd
);
391 kill_process( process
, 1 );
395 if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
397 fprintf( stderr
, "Protocol error: process %04x: ", process
->id
);
399 kill_process( process
, 1 );
405 /* send an fd to a client */
406 int send_client_fd( struct process
*process
, int fd
, obj_handle_t handle
)
409 struct msghdr msghdr
;
412 #ifdef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
413 msghdr
.msg_accrightslen
= sizeof(fd
);
414 msghdr
.msg_accrights
= (void *)&fd
;
415 #else /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
416 char cmsg_buffer
[256];
417 struct cmsghdr
*cmsg
;
418 msghdr
.msg_control
= cmsg_buffer
;
419 msghdr
.msg_controllen
= sizeof(cmsg_buffer
);
420 msghdr
.msg_flags
= 0;
421 cmsg
= CMSG_FIRSTHDR( &msghdr
);
422 cmsg
->cmsg_len
= CMSG_LEN( sizeof(fd
) );
423 cmsg
->cmsg_level
= SOL_SOCKET
;
424 cmsg
->cmsg_type
= SCM_RIGHTS
;
425 *(int *)CMSG_DATA(cmsg
) = fd
;
426 msghdr
.msg_controllen
= cmsg
->cmsg_len
;
427 #endif /* HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS */
429 msghdr
.msg_name
= NULL
;
430 msghdr
.msg_namelen
= 0;
431 msghdr
.msg_iov
= &vec
;
432 msghdr
.msg_iovlen
= 1;
434 vec
.iov_base
= (void *)&handle
;
435 vec
.iov_len
= sizeof(handle
);
438 fprintf( stderr
, "%04x: *fd* %04x -> %d\n", current
? current
->id
: process
->id
, handle
, fd
);
440 ret
= sendmsg( get_unix_fd( process
->msg_fd
), &msghdr
, 0 );
442 if (ret
== sizeof(handle
)) return 0;
446 fprintf( stderr
, "Protocol error: process %04x: partial sendmsg %d\n", process
->id
, ret
);
447 kill_process( process
, 1 );
449 else if (errno
== EPIPE
)
451 kill_process( process
, 0 );
455 fprintf( stderr
, "Protocol error: process %04x: ", process
->id
);
457 kill_process( process
, 1 );
462 /* get current tick count to return to client */
463 unsigned int get_tick_count(void)
465 #ifdef HAVE_CLOCK_GETTIME
467 #ifdef CLOCK_MONOTONIC_RAW
468 if (!clock_gettime( CLOCK_MONOTONIC_RAW
, &ts
))
469 return ts
.tv_sec
* 1000 + ts
.tv_nsec
/ 1000000;
471 if (!clock_gettime( CLOCK_MONOTONIC
, &ts
))
472 return ts
.tv_sec
* 1000 + ts
.tv_nsec
/ 1000000;
473 #elif defined(__APPLE__)
474 static mach_timebase_info_data_t timebase
;
476 if (!timebase
.denom
) mach_timebase_info( &timebase
);
477 return mach_absolute_time() * timebase
.numer
/ timebase
.denom
/ 1000000;
479 return (current_time
- server_start_time
) / 10000;
482 static void master_socket_dump( struct object
*obj
, int verbose
)
484 struct master_socket
*sock
= (struct master_socket
*)obj
;
485 assert( obj
->ops
== &master_socket_ops
);
486 fprintf( stderr
, "Master socket fd=%p\n", sock
->fd
);
489 static void master_socket_destroy( struct object
*obj
)
491 struct master_socket
*sock
= (struct master_socket
*)obj
;
492 assert( obj
->ops
== &master_socket_ops
);
493 release_object( sock
->fd
);
496 /* handle a socket event */
497 static void master_socket_poll_event( struct fd
*fd
, int event
)
499 struct master_socket
*sock
= get_fd_user( fd
);
500 assert( master_socket
->obj
.ops
== &master_socket_ops
);
502 assert( sock
== master_socket
); /* there is only one master socket */
504 if (event
& (POLLERR
| POLLHUP
))
506 /* this is not supposed to happen */
507 fprintf( stderr
, "wineserver: Error on master socket\n" );
508 set_fd_events( sock
->fd
, -1 );
510 else if (event
& POLLIN
)
512 struct sockaddr_un dummy
;
513 socklen_t len
= sizeof(dummy
);
514 int client
= accept( get_unix_fd( master_socket
->fd
), (struct sockaddr
*) &dummy
, &len
);
515 if (client
== -1) return;
516 fcntl( client
, F_SETFL
, O_NONBLOCK
);
517 create_process( client
, NULL
, 0 );
521 /* remove the socket upon exit */
522 static void socket_cleanup(void)
524 static int do_it_once
;
525 if (!do_it_once
++) unlink( server_socket_name
);
528 /* create a directory and check its permissions */
529 static void create_dir( const char *name
, struct stat
*st
)
531 if (lstat( name
, st
) == -1)
534 fatal_error( "lstat %s: %s", name
, strerror( errno
));
535 if (mkdir( name
, 0700 ) == -1 && errno
!= EEXIST
)
536 fatal_error( "mkdir %s: %s\n", name
, strerror( errno
));
537 if (lstat( name
, st
) == -1)
538 fatal_error( "lstat %s: %s\n", name
, strerror( errno
));
540 if (!S_ISDIR(st
->st_mode
)) fatal_error( "%s is not a directory\n", name
);
541 if (st
->st_uid
!= getuid()) fatal_error( "%s is not owned by you\n", name
);
542 if (st
->st_mode
& 077) fatal_error( "%s must not be accessible by other users\n", name
);
545 /* create the server directory and chdir to it */
546 static void create_server_dir( const char *dir
)
548 char *p
, *server_dir
;
551 if (!(server_dir
= strdup( dir
))) fatal_error( "out of memory\n" );
553 /* first create the base directory if needed */
555 p
= strrchr( server_dir
, '/' );
557 create_dir( server_dir
, &st
);
559 /* now create the server directory */
562 create_dir( server_dir
, &st
);
564 if (chdir( server_dir
) == -1)
565 fatal_error( "chdir %s: %s\n", server_dir
, strerror( errno
));
566 if ((server_dir_fd
= open( ".", O_RDONLY
)) == -1)
567 fatal_error( "open %s: %s\n", server_dir
, strerror( errno
));
568 if (fstat( server_dir_fd
, &st2
) == -1)
569 fatal_error( "stat %s: %s\n", server_dir
, strerror( errno
));
570 if (st
.st_dev
!= st2
.st_dev
|| st
.st_ino
!= st2
.st_ino
)
571 fatal_error( "chdir did not end up in %s\n", server_dir
);
576 /* create the lock file and return its file descriptor */
577 static int create_server_lock(void)
582 if (lstat( server_lock_name
, &st
) == -1)
585 fatal_error( "lstat %s/%s: %s", wine_get_server_dir(), server_lock_name
, strerror( errno
));
589 if (!S_ISREG(st
.st_mode
))
590 fatal_error( "%s/%s is not a regular file\n", wine_get_server_dir(), server_lock_name
);
593 if ((fd
= open( server_lock_name
, O_CREAT
|O_TRUNC
|O_WRONLY
, 0600 )) == -1)
594 fatal_error( "error creating %s/%s: %s", wine_get_server_dir(), server_lock_name
, strerror( errno
));
598 /* wait for the server lock */
599 int wait_for_lock(void)
601 const char *server_dir
= wine_get_server_dir();
605 if (!server_dir
) return 0; /* no server dir, so no lock to wait on */
607 create_server_dir( server_dir
);
608 fd
= create_server_lock();
611 fl
.l_whence
= SEEK_SET
;
614 r
= fcntl( fd
, F_SETLKW
, &fl
);
620 /* kill the wine server holding the lock */
621 int kill_lock_owner( int sig
)
623 const char *server_dir
= wine_get_server_dir();
628 if (!server_dir
) return 0; /* no server dir, nothing to do */
630 create_server_dir( server_dir
);
631 fd
= create_server_lock();
633 for (i
= 1; i
<= 20; i
++)
636 fl
.l_whence
= SEEK_SET
;
639 if (fcntl( fd
, F_GETLK
, &fl
) == -1) goto done
;
640 if (fl
.l_type
!= F_WRLCK
) goto done
; /* the file is not locked */
641 if (!pid
) /* first time around */
643 if (!(pid
= fl
.l_pid
)) goto done
; /* shouldn't happen */
646 if (kill( pid
, SIGINT
) == -1) goto done
;
647 kill( pid
, SIGCONT
);
650 else /* just send the specified signal and return */
652 ret
= (kill( pid
, sig
) != -1);
656 else if (fl
.l_pid
!= pid
) goto done
; /* no longer the same process */
659 /* waited long enough, now kill it */
660 kill( pid
, SIGKILL
);
667 /* acquire the main server lock */
668 static void acquire_lock(void)
670 struct sockaddr_un addr
;
673 int fd
, slen
, got_lock
= 0;
675 fd
= create_server_lock();
678 fl
.l_whence
= SEEK_SET
;
681 if (fcntl( fd
, F_SETLK
, &fl
) != -1)
683 /* check for crashed server */
684 if (stat( server_socket_name
, &st
) != -1 && /* there is a leftover socket */
685 stat( "core", &st
) != -1 && st
.st_size
) /* and there is a non-empty core file */
688 "Warning: a previous instance of the wine server seems to have crashed.\n"
689 "Please run 'gdb %s %s/core',\n"
690 "type 'backtrace' at the gdb prompt and report the results. Thanks.\n\n",
691 server_argv0
, wine_get_server_dir() );
693 unlink( server_socket_name
); /* we got the lock, we can safely remove the socket */
695 /* in that case we reuse fd without closing it, this ensures
696 * that we hold the lock until the process exits */
705 /* check whether locks work at all on this file system */
706 if (fcntl( fd
, F_GETLK
, &fl
) == -1) break;
709 exit(2); /* we didn't get the lock, exit with special status */
711 fatal_error( "fcntl %s/%s: %s", wine_get_server_dir(), server_lock_name
, strerror( errno
));
713 /* it seems we can't use locks on this fs, so we will use the socket existence as lock */
717 if ((fd
= socket( AF_UNIX
, SOCK_STREAM
, 0 )) == -1) fatal_error( "socket: %s\n", strerror( errno
));
718 addr
.sun_family
= AF_UNIX
;
719 strcpy( addr
.sun_path
, server_socket_name
);
720 slen
= sizeof(addr
) - sizeof(addr
.sun_path
) + strlen(addr
.sun_path
) + 1;
721 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
724 if (bind( fd
, (struct sockaddr
*)&addr
, slen
) == -1)
726 if ((errno
== EEXIST
) || (errno
== EADDRINUSE
))
729 fatal_error( "couldn't bind to the socket even though we hold the lock\n" );
730 exit(2); /* we didn't get the lock, exit with special status */
732 fatal_error( "bind: %s\n", strerror( errno
));
734 atexit( socket_cleanup
);
735 chmod( server_socket_name
, 0600 ); /* make sure no other user can connect */
736 if (listen( fd
, 5 ) == -1) fatal_error( "listen: %s\n", strerror( errno
));
738 if (!(master_socket
= alloc_object( &master_socket_ops
)) ||
739 !(master_socket
->fd
= create_anonymous_fd( &master_socket_fd_ops
, fd
, &master_socket
->obj
, 0 )))
740 fatal_error( "out of memory\n" );
741 set_fd_events( master_socket
->fd
, POLLIN
);
742 make_object_static( &master_socket
->obj
);
745 /* open the master server socket and start waiting for new clients */
746 void open_master_socket(void)
748 const char *server_dir
= wine_get_server_dir();
749 const char *config_dir
= wine_get_config_dir();
750 int fd
, pid
, status
, sync_pipe
[2];
753 /* make sure no request is larger than the maximum size */
754 assert( sizeof(union generic_request
) == sizeof(struct request_max_size
) );
755 assert( sizeof(union generic_reply
) == sizeof(struct request_max_size
) );
757 /* make sure the stdio fds are open */
758 fd
= open( "/dev/null", O_RDWR
);
759 while (fd
>= 0 && fd
<= 2) fd
= dup( fd
);
762 fatal_error( "directory %s cannot be accessed\n", config_dir
);
763 if (chdir( config_dir
) == -1)
764 fatal_error( "chdir to %s: %s\n", config_dir
, strerror( errno
));
765 if ((config_dir_fd
= open( ".", O_RDONLY
)) == -1)
766 fatal_error( "open %s: %s\n", config_dir
, strerror( errno
));
768 create_server_dir( server_dir
);
772 if (pipe( sync_pipe
) == -1) fatal_error( "pipe: %s\n", strerror( errno
));
778 close( sync_pipe
[0] );
782 /* close stdin and stdout */
788 write( sync_pipe
[1], &dummy
, 1 );
789 close( sync_pipe
[1] );
793 fatal_error( "fork: %s\n", strerror( errno
));
796 default: /* parent */
797 close( sync_pipe
[1] );
799 /* wait for child to signal us and then exit */
800 if (read( sync_pipe
[0], &dummy
, 1 ) == 1) _exit(0);
802 /* child terminated, propagate exit status */
803 waitpid( pid
, &status
, 0 );
804 if (WIFEXITED(status
)) _exit( WEXITSTATUS(status
) );
808 else /* remain in the foreground */
813 /* init the process tracing mechanism */
814 init_tracing_mechanism();
818 /* master socket timer expiration handler */
819 static void close_socket_timeout( void *arg
)
821 master_timeout
= NULL
;
823 if (debug_level
) fprintf( stderr
, "wineserver: exiting (pid=%ld)\n", (long) getpid() );
826 close_objects(); /* shut down everything properly */
831 /* close the master socket and stop waiting for new clients */
832 void close_master_socket( timeout_t timeout
)
836 release_object( master_socket
);
837 master_socket
= NULL
;
839 if (master_timeout
) /* cancel previous timeout */
840 remove_timeout_user( master_timeout
);
842 master_timeout
= add_timeout_user( timeout
, close_socket_timeout
, NULL
);