diff options
Diffstat (limited to 'source/smbd/server.c')
-rw-r--r-- | source/smbd/server.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/source/smbd/server.c b/source/smbd/server.c index f36df3d020c..58d5e27759f 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -39,16 +39,35 @@ int last_message = -1; extern int DEBUGLEVEL; extern pstring user_socket_options; +extern int ClientPort; #ifdef WITH_DFS extern int dcelogin_atmost_once; #endif /* WITH_DFS */ - extern fstring remote_machine; extern pstring OriginalDir; +/* really we should have a top level context structure that has the + client file descriptor as an element. That would require a major rewrite :( + + the following 2 functions are an alternative - they make the file + descriptor private to smbd + */ +static int server_fd; + +int smbd_server_fd(void) +{ + return server_fd; +} + +void smbd_set_server_fd(int fd) +{ + server_fd = fd; + client_setfd(fd); +} + /**************************************************************************** when exiting, take the whole family ****************************************************************************/ @@ -72,20 +91,18 @@ static void killkids(void) ****************************************************************************/ static BOOL open_sockets_inetd(void) { - extern int Client; - extern int ClientPort; /* Started from inetd. fd 0 is the socket. */ /* We will abort gracefully when the client or remote system goes away */ - Client = dup(0); + smbd_set_server_fd(dup(0)); ClientPort = SMB_PORT; /* close our standard file descriptors */ close_low_fds(); - set_socket_options(Client,"SO_KEEPALIVE"); - set_socket_options(Client,user_socket_options); + set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); + set_socket_options(smbd_server_fd(),user_socket_options); return True; } @@ -114,8 +131,6 @@ static int open_server_socket(int port, uint32 ipaddr) ****************************************************************************/ static BOOL open_sockets(BOOL is_daemon,int port, int port445) { - extern int Client; - extern int ClientPort; int num_interfaces = iface_count(); int fd_listenset[FD_SETSIZE]; fd_set listen_set; @@ -244,18 +259,18 @@ max can be %d\n", #endif } - Client = accept(s,&addr,&in_addrlen); + smbd_set_server_fd(accept(s,&addr,&in_addrlen)); - if (Client == -1 && errno == EINTR) + if (smbd_server_fd() == -1 && errno == EINTR) continue; - if (Client == -1) { + if (smbd_server_fd() == -1) { DEBUG(0,("open_sockets: accept: %s\n", strerror(errno))); continue; } - if (Client != -1 && fork()==0) { + if (smbd_server_fd() != -1 && fork()==0) { /* Child code ... */ /* close the listening socket(s) */ @@ -267,8 +282,8 @@ max can be %d\n", close_low_fds(); am_parent = 0; - set_socket_options(Client,"SO_KEEPALIVE"); - set_socket_options(Client,user_socket_options); + set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); + set_socket_options(smbd_server_fd(),user_socket_options); /* Reset global variables in util.c so that client substitutions will be @@ -285,7 +300,7 @@ max can be %d\n", return True; } /* The parent doesn't need this socket */ - close(Client); + close(smbd_server_fd()); /* Force parent to check log size after * spawning child. Fix from @@ -353,10 +368,9 @@ BOOL reload_services(BOOL test) load_interfaces(); { - extern int Client; - if (Client != -1) { - set_socket_options(Client,"SO_KEEPALIVE"); - set_socket_options(Client,user_socket_options); + if (smbd_server_fd() != -1) { + set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); + set_socket_options(smbd_server_fd(),user_socket_options); } } @@ -754,7 +768,7 @@ static void usage(char *pname) pidfile_create("smbd"); } - if (!open_sockets(is_daemon,port,port445)) + if (!open_sockets(is_daemon,port, port445)) exit(1); /* @@ -782,7 +796,6 @@ static void usage(char *pname) exit(1); smbd_process(); - close_sockets(); exit_server("normal exit"); return(0); |