Package: timeout
Version: 1.11-6.3
Severity: wishlist
Tags: patch

I needed < 1 second timeouts for something so I wrote a patch that
adds support for non-integer timeouts like 0.5 seconds or 2.3 seconds.
Attached.

        Sami


--- ../../../tct-1.11.orig/src/misc/timeout.c   2001-09-10 00:46:10.000000000 
+0300
+++ timeout.c   2007-03-01 01:09:48.000000000 +0200
@@ -34,6 +34,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <time.h>
+#include <sys/wait.h>
 
 extern int optind;
 
@@ -64,10 +66,11 @@
 int     argc;
 char  **argv;
 {
-    int     time_to_run;
+    float   time_to_run;
     pid_t   pid;
     pid_t   child_pid;
     int     status;
+    struct  timespec ts;
 
     progname = argv[0];
 
@@ -78,7 +81,7 @@
        if ((kill_signal = atoi(*argv + 1)) <= 0)
            usage();
 
-    if (argc < 2 || (time_to_run = atoi(argv[0])) <= 0)
+    if (argc < 2 || (time_to_run = atof(argv[0])) <= 0)
        usage();
 
     commandname = argv[1];
@@ -100,7 +103,13 @@
        (void) signal(SIGQUIT, terminate);
        (void) signal(SIGTERM, terminate);
        (void) signal(SIGALRM, terminate);
-       alarm(time_to_run);
+       if (!fork()) {
+           ts.tv_sec = (int)time_to_run;
+           ts.tv_nsec = (time_to_run-ts.tv_sec)*1000000000;
+           nanosleep(&ts,NULL);
+           kill(getppid(),SIGALRM);
+           exit(0);
+       }
        while ((pid = wait(&status)) != -1 && pid != child_pid)
             /* void */ ;
        return (pid == child_pid ? status : -1);


-- System Information:
Debian Release: 4.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-4-amd64
Locale: LANG=C, [EMAIL PROTECTED] (charmap=ISO-8859-15)

Versions of packages timeout depends on:
ii  libc6                       2.3.6.ds1-13 GNU C Library: Shared libraries

timeout recommends no packages.

-- no debconf information

Attachment: signature.asc
Description: Digital signature

Reply via email to