/*******************************************************************
close the low 3 fd's and open dev/null in their place
********************************************************************/
-void close_low_fds(void)
+void close_low_fds(BOOL stderr_too)
{
-#ifndef VALGRIND
int fd;
int i;
close(0); close(1);
-#ifndef __INSURE__
- close(2);
-#endif
+
+ if (stderr_too) {
+ close(2);
+ }
+
/* try and use up these file descriptors, so silly
library routines writing to stdout etc won't cause havoc */
for (i=0;i<3;i++) {
- fd = sys_open("/dev/null",O_RDWR,0);
- if (fd < 0) fd = sys_open("/dev/null",O_WRONLY,0);
- if (fd < 0) {
- DEBUG(0,("Can't open /dev/null\n"));
- return;
- }
- if (fd != i) {
- DEBUG(0,("Didn't get file descriptor %d\n",i));
- return;
- }
+ if (i == 2 && !stderr_too)
+ continue;
+
+ fd = sys_open("/dev/null",O_RDWR,0);
+ if (fd < 0) fd = sys_open("/dev/null",O_WRONLY,0);
+ if (fd < 0) {
+ DEBUG(0,("Can't open /dev/null\n"));
+ return;
+ }
+ if (fd != i) {
+ DEBUG(0,("Didn't get file descriptor %d\n",i));
+ return;
+ }
}
-#endif
}
/****************************************************************************
#endif /* HAVE_SETSID */
/* Close fd's 0,1,2. Needed if started by rsh */
- close_low_fds();
+ close_low_fds(False); /* Don't close stderr, let the debug system
+ attach it to the logfile */
}
smbd_set_server_fd(dup(0));
/* close our standard file descriptors */
- close_low_fds();
+ close_low_fds(False); /* Don't close stderr */
set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
set_socket_options(smbd_server_fd(), user_socket_options);
Open the socket communication.
****************************************************************************/
-static BOOL open_sockets(BOOL is_daemon,int port)
+static BOOL open_sockets_smbd(BOOL is_daemon,int port)
{
int num_interfaces = iface_count();
int fd_listenset[FD_SETSIZE];
*/
if(num_interfaces > FD_SETSIZE) {
- DEBUG(0,("open_sockets: Too many interfaces specified to bind to. Number was %d \
+ DEBUG(0,("open_sockets_smbd: Too many interfaces specified to bind to. Number was %d \
max can be %d\n",
num_interfaces, FD_SETSIZE));
return False;
struct in_addr *ifip = iface_n_ip(i);
if(ifip == NULL) {
- DEBUG(0,("open_sockets: interface %d has NULL IP address !\n", i));
+ DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
continue;
}
s = fd_listenset[i] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
set_socket_options(s,user_socket_options);
if (listen(s, 5) == -1) {
- DEBUG(0,("open_sockets: listen: %s\n",
+ DEBUG(0,("open_sockets_smbd: listen: %s\n",
strerror(errno)));
close(s);
return False;
continue;
if (smbd_server_fd() == -1) {
- DEBUG(0,("open_sockets: accept: %s\n",
+ DEBUG(0,("open_sockets_smbd: accept: %s\n",
strerror(errno)));
continue;
}
/* close our standard file
descriptors */
- close_low_fds();
+ close_low_fds(False);
am_parent = 0;
set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
start_background_queue();
*/
- if (!open_sockets(is_daemon,port))
+ if (!open_sockets_smbd(is_daemon,port))
exit(1);
/*