bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] settrans -gl only kills the active translator


From: Neal H Walfield
Subject: [PATCH] settrans -gl only kills the active translator
Date: Sat, 31 Mar 2001 10:32:50 +0200
User-agent: Mutt/1.3.15i

This patch was inspired by the TODO item:

** settrans:
*** needs an option to make the active go away without using goaway. !

Note that I choose `-l' (i.e. leave passive translator) for lack of
a more fitting letter.

2001-03-29  Neal H Walfield  <neal@cs.uml.edu>

        * settrans.c: New argument -l, --leave.  Kill the active
        translator without touching the passive translator.


--- hurd-20010307-snapshot/utils/settrans.c     Wed Jan 31 00:45:32 2001
+++ hurd-20010313/utils/settrans.c      Fri Mar 30 18:23:28 2001
@@ -1,8 +1,8 @@
 /* Set a file's translator.
 
-   Copyright (C) 1995, 96, 97, 98 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,2001 Free Software Foundation, Inc.
 
-   Written by Miles Bader <miles@gnu.ai.mit.edu>
+   Written by Miles Bader <miles@gnu.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -30,6 +30,7 @@
 #include <argz.h>
 #include <hurd/fshelp.h>
 #include <hurd/process.h>
+#include <hurd/fsys.h>
 #include <version.h>
 
 const char *argp_program_version = STANDARD_HURD_VERSION (settrans);
@@ -59,6 +60,8 @@
   {"recursive",   'R', 0, 0, "Shutdown its children too"},
   {"force",       'f', 0, 0, "If it doesn't want to die, force it"},
   {"nosync",      'S', 0, 0, "Don't sync it before killing it"},
+  {"leave",       'l', 0, 0, "Shutdown the active translator, however, leave "
+                            "the passive translator if present"},
 
   {0, 0}
 };
@@ -91,7 +94,8 @@
   int goaway_flags = 0;
 
   /* Various option flags.  */
-  int passive = 0, active = 0, keep_active = 0, pause = 0, kill_active = 0;
+  int passive = 0, active = 0, keep_active = 0, pause = 0, kill_active = 0,
+      leave_passive = 0;
   int excl = 0;
   int timeout = DEFAULT_TIMEOUT * 1000; /* ms */
 
@@ -108,7 +112,7 @@
              error_t err =
                argz_create (state->argv + state->next - 1, &argz, &argz_len);
              if (err)
-               error(3, err, "Can't create options vector");
+               error(3, err, "Failed to create options vector");
              state->next = state->argc; /* stop parsing */
            }
          break;
@@ -121,6 +125,7 @@
        case 'p': passive = 1; break;
        case 'k': keep_active = 1; break;
        case 'g': kill_active = 1; break;
+       case 'l': leave_passive = 1; lookup_flags &= ~O_NOTRANS; break;
        case 'x': excl = 1; break;
        case 'P': pause = 1; break;
 
@@ -146,22 +151,6 @@
   if (!active && !passive)
     passive = 1;               /* By default, set the passive translator.  */
 
-  if (passive)
-    passive_flags = FS_TRANS_SET | (excl ? FS_TRANS_EXCL : 0);
-  if (active)
-    active_flags = FS_TRANS_SET | (excl ? FS_TRANS_EXCL : 0);
-
-  if (passive && !active)
-    {
-      /* When setting just the passive, decide what to do with any active.  */
-      if (kill_active)
-       /* Make it go away.  */
-       active_flags = FS_TRANS_SET;
-      else if (! keep_active)
-       /* Ensure that there isn't one.  */
-       active_flags = FS_TRANS_SET | FS_TRANS_EXCL;
-    }
-
   if (active && argz_len > 0)
     {
       /* Error during file lookup; we use this to avoid duplicating error
@@ -207,13 +196,58 @@
        error(1, errno, "%s", node_name);
     }
 
-  err =
-    file_set_translator(node,
-                       passive_flags, active_flags, goaway_flags,
-                       argz, argz_len,
-                       active_control, MACH_MSG_TYPE_COPY_SEND);
-  if (err)
-    error(5, err, "%s", node_name);
+  if (leave_passive && kill_active)
+    /* Kill the active translator, however, do not touch the passive
+       translator.  */
+    {
+      fsys_t control;
+
+      err = file_getcontrol (node, &control);
+      if (err)
+        error (5, err, "getting control port");
+
+      mach_port_deallocate (mach_task_self (), node);
+
+      err = fsys_goaway (control, goaway_flags);
+      if (err == EBUSY)
+        /* Hmm... Maybe our send right, NODE, has not been acknowledged
+          as dead yet.  */
+        {
+         sleep (1);
+         err = fsys_goaway (control, goaway_flags);
+       }
+
+      if (err)
+       error (1, err, "shutting down %s", node_name);
+    }
+  else
+    /* Set the passive translator.  */
+    {
+      if (passive)
+        passive_flags = FS_TRANS_SET | (excl ? FS_TRANS_EXCL : 0);
+      if (active)
+        active_flags = FS_TRANS_SET | (excl ? FS_TRANS_EXCL : 0);
+
+      if (passive && !active)
+        {
+          /* When setting just the passive, decide what to do with
+            any active.  */
+          if (kill_active)
+           /* Make it go away.  */
+           active_flags = FS_TRANS_SET;
+          else if (! keep_active)
+           /* Ensure that there isn't one.  */
+           active_flags = FS_TRANS_SET | FS_TRANS_EXCL;
+        }
+
+      err =
+       file_set_translator(node,
+                           passive_flags, active_flags, goaway_flags,
+                           argz, argz_len,
+                           active_control, MACH_MSG_TYPE_COPY_SEND);
+      if (err)
+       error(5, err, "%s", node_name);
+    }
 
   return 0;
 }

Attachment: pgpmFdkNh08Hs.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]