SOURCES: util-vserver-vwait-timeout-fix.patch (NEW) - vwait timeou...

romke romke at pld-linux.org
Thu Oct 13 16:10:55 CEST 2005


Author: romke                        Date: Thu Oct 13 14:10:55 2005 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- vwait timeout fix

---- Files affected:
SOURCES:
   util-vserver-vwait-timeout-fix.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/util-vserver-vwait-timeout-fix.patch
diff -u /dev/null SOURCES/util-vserver-vwait-timeout-fix.patch:1.1
--- /dev/null	Thu Oct 13 16:10:55 2005
+++ SOURCES/util-vserver-vwait-timeout-fix.patch	Thu Oct 13 16:10:50 2005
@@ -0,0 +1,71 @@
+diff -u -r1.1 -r1.2
+--- util-vserver/src/vwait.c	2005/05/05 09:22:03	1.1
++++ util-vserver/src/vwait.c	2005/07/25 15:50:48	1.2
+@@ -1,4 +1,4 @@
+-// $Id$    --*- c -*--
++// $Id$    --*- c -*--
+ 
+ // Copyright (C) 2005 Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
+ //  
+@@ -30,6 +30,7 @@
+ #include <time.h>
+ #include <errno.h>
+ #include <libgen.h>
++#include <assert.h>
+ 
+ #define ENSC_WRAPPERS_PREFIX	"vwait: "
+ #define ENSC_WRAPPERS_STDLIB	1
+@@ -105,11 +106,12 @@
+ static struct StatusType
+ doit(struct Arguments const *args)
+ {
+-  time_t			end_time = 0;
++  time_t			end_time = 0, now = 0;
+   struct StatusType		res;
+   
+   if (args->timeout>0) {
+     end_time = time(0) + args->timeout;
++    siginterrupt(SIGALRM, 1);
+     signal(SIGALRM, handler);
+     alarm(args->timeout);
+   }
+@@ -118,11 +120,14 @@
+     res.rc = vc_wait_exit(args->xid);
+     
+     if      (res.rc==-1 && errno!=EAGAIN && errno!=EINTR) {
++	// the error-case
+       res.rc     = errno;
+       res.status = stERROR;
+       perror(ENSC_WRAPPERS_PREFIX "vc_wait_exit()");
+     }
+-    else if (res.rc==-1 && args->timeout>0 && time(0)>=end_time) {
++    else if (res.rc==-1 && args->timeout>0 && (now=time(0))>=end_time) {
++	// an EINTR or EAGAIN signal was delivered, a timeout was set and
++	// reached
+       if (!args->do_terminate)
+ 	res.status = stTIMEOUT;
+       else {
+@@ -131,9 +136,21 @@
+ 	res.status = stKILLED;
+       }
+     }
+-    else if (res.rc==-1)
+-      continue;		// signal
++    else if (res.rc==-1) {
++	// an EINTR or EAGAIN signal was delivered but the timeout not set or
++	// not reached yet
++
++	// we are here, when args->timeout==0 or 'now' was initialized (and
++	// compared with 'end_time'). So, 'now' can be used below.
++      assert(args->timeout<=0 || (now < end_time));
++
++      if (args->timeout>0)	// (re)set the alarm-clock
++	alarm(end_time-now);
++
++      continue;
++    }
+     else
++	// vc_wait_exit(2) finished successfully
+       res.status = stFINISHED;
+ 
+     break;
================================================================



More information about the pld-cvs-commit mailing list