provide daemon() if none exists. call it in bosserver and in afsd for afsdb handler
====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
add the file, too
AC_SIZEOF_TYPE(long)
AC_CHECK_FUNCS(timegm)
+AC_CHECK_FUNCS(daemon)
dnl Directory PATH handling
if test "x$enable_transarc_paths" = "xyes" ; then
printf("%s: Forking AFSDB lookup handler.\n", rn);
code = fork();
if (code == 0) {
+ /* Since the AFSDB lookup handler runs as a user process,
+ * need to drop the controlling TTY, etc.
+ */
+ if (daemon(0, 0) == -1) {
+ printf("Error starting AFSDB lookup handler: %s\n",
+ strerror(errno));
+ exit(1);
+ }
AfsdbLookupHandler();
exit(1);
}
}
#endif
+#if 0
/*
* This routine causes the calling process to go into the background and
* to lose its controlling tty.
}
}
#endif /* ! AFS_NT40_ENV */
+#endif
/* start a process and monitor it */
fflush(stdout);
#endif
- /* go into the background and remove our controlling tty */
+ /* go into the background and remove our controlling tty, close open
+ file desriptors
+ */
#ifndef AFS_NT40_ENV
if (!nofork)
- background();
+ daemon(0, 0);
#endif /* ! AFS_NT40_ENV */
if ((!DoSyslog)
objects = assert.o base64.o casestrcpy.o ktime.o volparse.o hostparse.o \
hputil.o kreltime.o isathing.o get_krbrlm.o uuid.o serverLog.o \
dirpath.o fileutil.o netutils.o flipbase64.o \
- afs_atomlist.o afs_lhash.o snprintf.o strlcat.o strlcpy.o ${REGEX_OBJ}
+ afs_atomlist.o afs_lhash.o snprintf.o strlcat.o strlcpy.o \
+ daemon.o ${REGEX_OBJ}
includes = \
${TOP_INCDIR}/afs/dirpath.h \
strlcpy.o: ${srcdir}/strlcpy.c ${includes}
${CCOBJ} ${CFLAGS} -c ${srcdir}/strlcpy.c
+daemon.o: ${srcdir}/daemon.c ${includes}
+ ${CCOBJ} ${CFLAGS} -c ${srcdir}/daemon.c
+
#
# Install targets
#
extern char *ucstring(char *d, char *s, int n);
extern char *strcompose(char *buf, size_t len, ...);
+/* daemon.c */
+#ifndef HAVE_DAEMON
+int daemon(int nochdir, int noclose);
+#endif
+
/* dirpath.c */
extern unsigned int initAFSDirPath(void);
extern const char *getDirPath(afsdir_id_t string_id);
--- /dev/null
+#include <afsconfig.h>
+#include <afs/param.h>
+
+#ifndef HAVE_DAEMON
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+
+int daemon(int nochdir, int noclose)
+{
+ int err = -1;
+ pid_t pid;
+
+ pid = fork();
+ if (pid == -1) {
+ goto out;
+ } else if (pid) {
+ exit(0);
+ }
+
+ err = setsid();
+ if (err == -1) {
+ goto out;
+ }
+
+ if (!nochdir) {
+ err = chdir("/");
+ if (err == -1) {
+ goto out;
+ }
+ }
+
+ err = -1;
+ if (!noclose) {
+ if (!freopen("/dev/null", "r", stdin)) {
+ goto out;
+ }
+
+ if (!freopen("/dev/null", "w", stdout)) {
+ goto out;
+ }
+
+ if (!freopen("/dev/null", "w", stderr)) {
+ goto out;
+ }
+ }
+
+ err = 0;
+
+out:
+ return(err);
+}
+#endif