/*******************************************************************
Close the low 3 fd's and open dev/null in their place.
********************************************************************/
-static void close_low_fds(bool stderr_too)
+
+_PUBLIC_ void close_low_fds(bool stderr_too)
{
#ifndef VALGRIND
int fd;
int i;
close(0);
- close(1);
+ close(1);
if (stderr_too)
close(2);
#endif
}
-/**
+/****************************************************************************
Become a daemon, discarding the controlling terminal.
-**/
+****************************************************************************/
-_PUBLIC_ void become_daemon(bool Fork)
+_PUBLIC_ void become_daemon(bool Fork, bool no_process_group)
{
if (Fork) {
if (fork()) {
}
}
- /* detach from the terminal */
+ /* detach from the terminal */
#ifdef HAVE_SETSID
- setsid();
+ if (!no_process_group) setsid();
#elif defined(TIOCNOTTY)
- {
- int i = open("/dev/tty", O_RDWR, 0);
+ if (!no_process_group) {
+ int i = sys_open("/dev/tty", O_RDWR, 0);
if (i != -1) {
- ioctl(i, (int) TIOCNOTTY, (char *)0);
+ ioctl(i, (int) TIOCNOTTY, (char *)0);
close(i);
}
}
close_low_fds(false); /* Don't close stderr, let the debug system
attach it to the logfile */
}
-
/* The following definitions come from lib/util/become_daemon.c */
-#if _SAMBA_BUILD_ == 4
+/**
+ Close the low 3 fd's and open dev/null in their place
+**/
+_PUBLIC_ void close_low_fds(bool stderr_too);
+
/**
Become a daemon, discarding the controlling terminal.
**/
-_PUBLIC_ void become_daemon(bool fork);
-#endif
+_PUBLIC_ void become_daemon(bool fork, bool no_process_group);
/**
* Load a ini-style file.
../lib/util/util_file.o ../lib/util/data_blob.o \
../lib/util/util.o ../lib/util/fsusage.o \
../lib/util/params.o ../lib/util/talloc_stack.o \
- ../lib/util/genrand.o ../lib/util/util_net.o
+ ../lib/util/genrand.o ../lib/util/util_net.o \
+ ../lib/util/become_daemon.o
CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
ssize_t message_push_blob(uint8 **outbuf, DATA_BLOB blob);
char *unix_clean_name(TALLOC_CTX *ctx, const char *s);
char *clean_name(TALLOC_CTX *ctx, const char *s);
-void close_low_fds(bool stderr_too);
ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, SMB_OFF_T pos);
int set_blocking(int fd, bool set);
void smb_msleep(unsigned int t);
-void become_daemon(bool Fork, bool no_process_group);
bool reinit_after_fork(struct messaging_context *msg_ctx,
struct event_context *ev_ctx,
bool parent_longlived);
return unix_clean_name(ctx, str);
}
-/*******************************************************************
- Close the low 3 fd's and open dev/null in their place.
-********************************************************************/
-
-void close_low_fds(bool stderr_too)
-{
-#ifndef VALGRIND
- int fd;
- int i;
-
- close(0);
- close(1);
-
- 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++) {
- 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
-}
-
/*******************************************************************
Write data into an fd at a given offset. Ignore seek errors.
********************************************************************/
#endif
}
-/****************************************************************************
- Become a daemon, discarding the controlling terminal.
-****************************************************************************/
-
-void become_daemon(bool Fork, bool no_process_group)
-{
- if (Fork) {
- if (sys_fork()) {
- _exit(0);
- }
- }
-
- /* detach from the terminal */
-#ifdef HAVE_SETSID
- if (!no_process_group) setsid();
-#elif defined(TIOCNOTTY)
- if (!no_process_group) {
- int i = sys_open("/dev/tty", O_RDWR, 0);
- if (i != -1) {
- ioctl(i, (int) TIOCNOTTY, (char *)0);
- close(i);
- }
- }
-#endif /* HAVE_SETSID */
-
- /* Close fd's 0,1,2. Needed if started by rsh */
- close_low_fds(False); /* Don't close stderr, let the debug system
- attach it to the logfile */
-}
-
bool reinit_after_fork(struct messaging_context *msg_ctx,
struct event_context *ev_ctx,
bool parent_longlived)
if (opt_daemon) {
DEBUG(3,("Becoming a daemon.\n"));
- become_daemon(true);
+ become_daemon(true, false);
}
cleanup_tmp_files(cmdline_lp_ctx);