summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-07-20 07:02:45 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-07-20 07:02:45 +0000
commit714abda3e749ae364806633b2ccc17c03a453bf4 (patch)
treee644130d48d1bfb833293601041849bf43638e06 /source3/lib
parent129b3966c04f4f1be33d35ca720e5946fbe76051 (diff)
downloadsamba-714abda3e749ae364806633b2ccc17c03a453bf4.tar.gz
samba-714abda3e749ae364806633b2ccc17c03a453bf4.tar.bz2
samba-714abda3e749ae364806633b2ccc17c03a453bf4.zip
Add support for duplicating stderr into our logfiles.
This is for two things: To allow panic actions etc to pump out backtraces to stderr and to allow vangrind to put its stuff in a logfile - making it possible to debug smbd when launched from inetd. I've also cleaned up some of the duplicate names in procedures between smbd and nmbd. Andrew Bartlett (This used to be commit 4bcb32731984b4aef1d4911a168a4e7a10d32fd4)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/debug.c6
-rw-r--r--source3/lib/util.c38
2 files changed, 27 insertions, 17 deletions
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index f41c3b6497..c43a98f4fa 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -602,6 +602,12 @@ BOOL reopen_logs( void )
force_check_log_size();
(void)umask(oldumask);
+ /* Take over stderr to catch ouput into logs */
+ if (sys_dup2(dbf->fd, 2) == -1) {
+ close_low_fds(True); /* Close stderr too, if dup2 can't point it
+ at the logfile */
+ }
+
return ret;
}
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 51c926dd0b..bcef3013f9 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -503,30 +503,33 @@ void make_dir_struct(char *buf,char *mask,char *fname,SMB_OFF_T size,int mode,ti
/*******************************************************************
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
}
/****************************************************************************
@@ -680,7 +683,8 @@ void become_daemon(void)
#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 */
}