[Fakeroot-commits] [SCM] fakeroot branch, upstream, updated. 08ed00124d8b6b445d3b91a9aa15eec638b02f05
Timo Savola
tsavola at movial.fi
Sun Nov 15 03:17:01 UTC 2009
The following commit has been merged in the upstream branch:
commit d7583168b40e4238252968be21d2e44b0fc42ea1
Author: Timo Savola <tsavola at movial.fi>
Date: Sat May 21 08:41:48 2005 +0000
Daemon support (TCP version)
faked goes into "detached" mode when it receives SIGHUP: it will terminate
as soon as all clients close their connections. The fakeroot script kills
faked with SIGHUP instead of SIGTERM when it exits. This is done in order
to provide a working (although isolated) fakeroot environment for daemon
processes that are launched from a fakeroot session.
git-archimport-id: fakeroot at packages.debian.org--fakeroot/fakeroot--main--0.0--patch-69
diff --git a/configure.ac b/configure.ac
index fd60c1b..ce5419c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,8 +44,13 @@ if test $ac_cv_use_ipc = "tcp"; then
AC_DEFINE_UNQUOTED(FAKEROOT_FAKENET, [TCP])
AC_CHECK_LIB(pthread, pthread_self)
AC_CHECK_LIB(socket, connect)
+signal=HUP
+else
+signal=TERM
fi
+AC_SUBST(signal)
+
dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
diff --git a/faked.c b/faked.c
index ab4e3b8..9d9093c 100644
--- a/faked.c
+++ b/faked.c
@@ -151,6 +151,7 @@ unsigned int highest_funcid = sizeof(func_arr)/sizeof(func_arr[0]);
key_t msg_key=0;
#else /* FAKEROOT_FAKENET */
static int comm_sd = -1;
+static volatile int detached = 0;
#endif /* FAKEROOT_FAKENET */
int debug = 0, unknown_is_real = 0;
@@ -765,6 +766,16 @@ void get_msg(const int listen_sd)
int count, maxfd;
unsigned int i;
+ if (debug)
+ fprintf(stderr, "fakeroot: detached=%i clients=%i\n", detached, sd_list_size());
+
+ if (detached && sd_list_size() == 0) {
+ if (debug)
+ fprintf(stderr, "fakeroot: exiting\n");
+
+ cleanup(0);
+ }
+
FD_ZERO(&readfds);
FD_SET(listen_sd, &readfds);
@@ -857,6 +868,20 @@ void save(int dummy){
fprintf(stderr, "fakeroot: database save FAILED\n");
}
+#ifdef FAKEROOT_FAKENET
+static void detach(int g)
+{
+ int saved_errno = errno;
+
+ if (debug)
+ fprintf(stderr, "fakeroot: detaching, signal=%i\n", g);
+
+ detached = 1;
+
+ errno = saved_errno;
+}
+#endif /* FAKEROOT_FAKENET */
+
#ifndef FAKEROOT_FAKENET
# define FAKEROOT_CLEANUPMSG "fakeroot: clearing up message queues and semaphores, signal=%i\n"
#else /* FAKEROOT_FAKENET */
@@ -948,6 +973,7 @@ int main(int argc, char **argv){
unsigned int port = 0;
struct sockaddr_in addr;
socklen_t addr_len;
+ struct sigaction sa_detach;
#endif /* FAKEROOT_FAKENET */
if(getenv(FAKEROOTKEY_ENV)) {
@@ -1074,6 +1100,10 @@ int main(int argc, char **argv){
port = ntohs(addr.sin_port);
+ sa_detach.sa_handler=detach;
+ sigemptyset(&sa_detach.sa_mask);
+ sa_detach.sa_flags=0;
+
#endif /* FAKEROOT_FAKENET */
sa.sa_handler=cleanup;
@@ -1104,6 +1134,11 @@ int main(int argc, char **argv){
case SIGUSR2:
sigaction(i,&sa_debug,NULL);
break;
+#ifdef FAKEROOT_FAKENET
+ case SIGHUP:
+ sigaction(i,&sa_detach,NULL);
+ break;
+#endif /* FAKEROOT_FAKENET */
default:
sigaction(i,&sa,NULL);
break;
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index cfdbed0..cd7be43 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -8,6 +8,7 @@ do_subst = sed -e 's,[@]prefix[@],$(prefix),g' \
-e 's,[@]libdir[@],$(libdir),g' \
-e 's,[@]fakeroot_transformed[@],'`echo fakeroot | sed -e '$(transform)'`',g' \
-e 's,[@]faked_transformed[@],'`echo faked | sed -e '$(transform)'`',g' \
+ -e 's,[@]signal[@],$(signal),g' \
-e 's,[@]VERSION[@],$(VERSION),g'
fakeroot: $(srcdir)/fakeroot.in Makefile
diff --git a/scripts/fakeroot.in b/scripts/fakeroot.in
index b613751..ce871fb 100755
--- a/scripts/fakeroot.in
+++ b/scripts/fakeroot.in
@@ -122,9 +122,9 @@ FAKEROOTKEY=`echo $KEY_PID|cut -d: -f1`
PID=`echo $KEY_PID|cut -d: -f2`
if [ "$WAITINTRAP" -eq 0 ]; then
- trap "kill -s TERM $PID" EXIT INT
+ trap "kill -s @signal@ $PID" EXIT INT
else
- trap "kill -s TERM $PID ; wait $PID >/dev/null 2>&1" EXIT INT
+ trap "kill -s @signal@ $PID ; wait $PID >/dev/null 2>&1" EXIT INT
fi
if test -z "$FAKEROOTKEY" || test -z "$PID"; then
--
fakeroot
More information about the Fakeroot-commits
mailing list