WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH] Add some optional parameters to Stunnel.disconnect to

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH] Add some optional parameters to Stunnel.disconnect to cope with the stunnel zombie process issue and for future benefits
From: Zheng Li <dev@xxxxxxxx>
Date: Tue, 20 Apr 2010 18:21:45 -0000
Delivery-date: Tue, 20 Apr 2010 11:23:03 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.3.1
Signed-off-by: Zheng Li <dev@xxxxxxxx>


 stunnel/stunnel.ml  |  27 ++++++++++++++++++++++-----
 stunnel/stunnel.mli |   2 +-
 2 files changed, 23 insertions(+), 6 deletions(-)


diff -r 06f4d30cef5f -r 662381e03d34 stunnel/stunnel.ml
--- a/stunnel/stunnel.ml        Mon Apr 12 17:54:42 2010 +0100
+++ b/stunnel/stunnel.ml        Tue Apr 20 19:05:48 2010 +0100
@@ -130,12 +130,29 @@
 
 let ignore_exn f x = try f x with _ -> ()
 
-let disconnect x = 
+let rec disconnect ?(wait = true) ?(force = false) x = 
   List.iter (ignore_exn Unix.close) [ x.fd ];
-  match x.pid with
-  | FEFork pid -> ignore(Forkhelpers.waitpid pid)
-  | StdFork pid -> ignore(Unix.waitpid [] pid)
-  | Nopid -> ()
+  let waiter, pid = match x.pid with
+    | FEFork pid ->
+        (fun () -> 
+           (if wait then Forkhelpers.waitpid 
+            else Forkhelpers.waitpid_nohang) pid),
+        Forkhelpers.getpid pid
+    | StdFork pid -> 
+        (fun () -> 
+           (if wait then Unix.waitpid [] 
+            else Unix.waitpid [Unix.WNOHANG]) pid),
+        pid in
+  let res = 
+    try waiter ()
+    with Unix.Unix_error (Unix.ECHILD, _, _) -> pid, Unix.WEXITED 0 in
+  match res with
+  | 0, _ when force ->
+      (try Unix.kill pid Sys.sigkill 
+       with Unix.Unix_error (Unix.ESRCH, _, _) ->());
+      disconnect ~wait:wait ~force:force x
+  | _ -> ()
+
 
 (* With some probability, stunnel fails during its startup code before it reads
    the config data from us. Therefore we get a SIGPIPE writing the config data.
diff -r 06f4d30cef5f -r 662381e03d34 stunnel/stunnel.mli
--- a/stunnel/stunnel.mli       Mon Apr 12 17:54:42 2010 +0100
+++ b/stunnel/stunnel.mli       Tue Apr 20 19:05:48 2010 +0100
@@ -53,7 +53,7 @@
   string -> int -> t
 
 (** Disconnects from stunnel and cleans up *)
-val disconnect : t -> unit
+val disconnect : ?wait:bool -> ?force:bool -> t -> unit
 
 val diagnose_failure : t -> unit
 

Attachment: xen-api-lib.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-API] [PATCH] Add some optional parameters to Stunnel.disconnect to cope with the stunnel zombie process issue and for future benefits, Zheng Li <=