[PATCH] trans/fakeroot: shutdown the translator if the last client is gone

2013-12-19 Thread Justus Winter
Previously, fakeroot would not exit if a process outlived the original
process started by settrans.  This caused bugs like this:

% fakeroot-hurd /bin/sh -c 'sleep 1' 21 | tee
hangs

Fix this by exiting if the last client of fakeroot goes away.

If noone has a right to any control or protid port, noone can ever
reacquire any such right. So it is safe to shutdown the fakeroot
translator in that case.

* trans/fakeroot.c (fakeroot_netfs_release_protid): Shutdown the
translator if the last protid object is destroyed and no control port
is around either.
---
 trans/fakeroot.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/trans/fakeroot.c b/trans/fakeroot.c
index 203f2c1..0e0b618 100644
--- a/trans/fakeroot.c
+++ b/trans/fakeroot.c
@@ -1,5 +1,5 @@
 /* fakeroot -- a translator for faking actions that aren't really permitted
-   Copyright (C) 2002, 2003, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2008, 2013 Free Software Foundation, Inc.
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -184,6 +184,24 @@ fakeroot_netfs_release_protid (void *cookie)
  out:
   pthread_mutex_unlock (np-lock);
   netfs_release_protid (cookie);
+
+  int cports = ports_count_class (netfs_control_class);
+  int nports = ports_count_class (netfs_protid_class);
+  ports_enable_class (netfs_control_class);
+  ports_enable_class (netfs_protid_class);
+  if (cports == 0  nports == 0)
+{
+  /* The last client is gone.  Our job is done.  */
+  error_t err = netfs_shutdown (0);
+  if (! err)
+exit (EXIT_SUCCESS);
+
+  /* If netfs_shutdown returns EBUSY, we lost a race against
+ fsys_goaway.  Hence we ignore this error.  */
+  if (err != EBUSY)
+error (1, err, netfs_shutdown);
+}
+
   pthread_mutex_unlock (idport_ihash_lock);
 }
 
-- 
1.8.5.1




Re: [PATCH] trans/fakeroot: shutdown the translator if the last client is gone

2013-12-19 Thread Samuel Thibault
Justus Winter, le Thu 19 Dec 2013 12:47:37 +0100, a écrit :
 Previously, fakeroot would not exit if a process outlived the original
 process started by settrans.  This caused bugs like this:
 
 % fakeroot-hurd /bin/sh -c 'sleep 1' 21 | tee
 hangs
 
 Fix this by exiting if the last client of fakeroot goes away.
 
 If noone has a right to any control or protid port, noone can ever
 reacquire any such right. So it is safe to shutdown the fakeroot
 translator in that case.

Ack.

 * trans/fakeroot.c (fakeroot_netfs_release_protid): Shutdown the
 translator if the last protid object is destroyed and no control port
 is around either.
 ---
  trans/fakeroot.c | 20 +++-
  1 file changed, 19 insertions(+), 1 deletion(-)
 
 diff --git a/trans/fakeroot.c b/trans/fakeroot.c
 index 203f2c1..0e0b618 100644
 --- a/trans/fakeroot.c
 +++ b/trans/fakeroot.c
 @@ -1,5 +1,5 @@
  /* fakeroot -- a translator for faking actions that aren't really permitted
 -   Copyright (C) 2002, 2003, 2008 Free Software Foundation, Inc.
 +   Copyright (C) 2002, 2003, 2008, 2013 Free Software Foundation, Inc.
  
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
 @@ -184,6 +184,24 @@ fakeroot_netfs_release_protid (void *cookie)
   out:
pthread_mutex_unlock (np-lock);
netfs_release_protid (cookie);
 +
 +  int cports = ports_count_class (netfs_control_class);
 +  int nports = ports_count_class (netfs_protid_class);
 +  ports_enable_class (netfs_control_class);
 +  ports_enable_class (netfs_protid_class);
 +  if (cports == 0  nports == 0)
 +{
 +  /* The last client is gone.  Our job is done.  */
 +  error_t err = netfs_shutdown (0);
 +  if (! err)
 +exit (EXIT_SUCCESS);
 +
 +  /* If netfs_shutdown returns EBUSY, we lost a race against
 + fsys_goaway.  Hence we ignore this error.  */
 +  if (err != EBUSY)
 +error (1, err, netfs_shutdown);
 +}
 +
pthread_mutex_unlock (idport_ihash_lock);
  }
  
 -- 
 1.8.5.1
 
 

-- 
Samuel
War doesn't prove who's right, just who's left.



[PATCH] trans/fakeroot: shutdown the translator if the last client is gone

2013-12-18 Thread Justus Winter
Previously, fakeroot would not exit if a process outlived the original
process started by settrans.  This caused bugs like this:

% fakeroot-hurd /bin/sh -c 'sleep 1' 21 | tee
hangs

Fix this by exiting if the last client of fakeroot goes away.

* trans/fakeroot.c (fakeroot_netfs_release_protid): Shutdown the
translator if the last protid object is destroyed.
---
 trans/fakeroot.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/trans/fakeroot.c b/trans/fakeroot.c
index 203f2c1..ca15c7e 100644
--- a/trans/fakeroot.c
+++ b/trans/fakeroot.c
@@ -1,5 +1,5 @@
 /* fakeroot -- a translator for faking actions that aren't really permitted
-   Copyright (C) 2002, 2003, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2008, 2013 Free Software Foundation, Inc.
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -184,6 +184,22 @@ fakeroot_netfs_release_protid (void *cookie)
  out:
   pthread_mutex_unlock (np-lock);
   netfs_release_protid (cookie);
+
+  int nports = ports_count_class (netfs_protid_class);
+  ports_enable_class (netfs_protid_class);
+  if (nports == 0)
+{
+  /* The last client is gone.  Our job is done.  */
+  error_t err = netfs_shutdown (0);
+  if (! err)
+exit (EXIT_SUCCESS);
+
+  /* If netfs_shutdown returns EBUSY, we lost a race against
+ fsys_goaway.  Hence we ignore this error.  */
+  if (err != EBUSY)
+error (1, err, netfs_shutdown);
+}
+
   pthread_mutex_unlock (idport_ihash_lock);
 }
 
-- 
1.8.5.1