Author: metze
Date: 2006-03-21 15:38:27 +0000 (Tue, 21 Mar 2006)
New Revision: 14625

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14625

Log:
- add timelimit.c
- add configure tests --with-selftest-prefix=/tmp/samba-test
  this is needed because the path name of unix socket can only be 108 chars long
- add configure test 
--with-smbtorture4-path=/home/foo/prefix/samba4/bin/smbtorture
  this will be used to run samba4's smbtorture inside samba3's make test later

metze
Added:
   trunk/source/script/tests/timelimit.c
Modified:
   trunk/source/Makefile.in
   trunk/source/configure.in


Changeset:
Modified: trunk/source/Makefile.in
===================================================================
--- trunk/source/Makefile.in    2006-03-21 15:33:14 UTC (rev 14624)
+++ trunk/source/Makefile.in    2006-03-21 15:38:27 UTC (rev 14625)
@@ -11,6 +11,9 @@
 [EMAIL PROTECTED]@
 [EMAIL PROTECTED]@
 
[EMAIL PROTECTED]@
[EMAIL PROTECTED]@
+
 [EMAIL PROTECTED]@
 [EMAIL PROTECTED]@
 [EMAIL PROTECTED]@
@@ -1434,6 +1437,10 @@
 
 bin/[EMAIL PROTECTED]@: lib/snprintf.c
        $(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(DYNEXP) -DTEST_SNPRINTF 
lib/snprintf.c -lm
+
+bin/[EMAIL PROTECTED]@: script/tests/timelimit.c
+       $(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(DYNEXP) script/tests/timelimit.c
+
 install: installservers installbin @INSTALL_CIFSMOUNT@ installman 
installscripts installdat installswat installmodules @INSTALL_LIBSMBCLIENT@ 
@INSTALL_LIBMSRPC@
 
 install-everything: install installmodules

Modified: trunk/source/configure.in
===================================================================
--- trunk/source/configure.in   2006-03-21 15:33:14 UTC (rev 14624)
+++ trunk/source/configure.in   2006-03-21 15:38:27 UTC (rev 14625)
@@ -308,6 +308,41 @@
        SOCKWRAP="\$(SOCKET_WRAPPER_OBJ)"
     fi])
 
+#################################################
+# set prefix for 'make test'
+selftest_prefix="./"
+AC_SUBST(selftest_prefix)
+AC_ARG_WITH(selftest-prefix,
+[  --with-selftest-prefix=DIR    The prefix where make test will be runned 
($selftest_prefix)],
+[ case "$withval" in
+  yes|no)
+    AC_MSG_WARN([--with-selftest-prefix called without argument - will use 
default])
+  ;;
+  * )
+    selftest_prefix="$withval"
+    ;;
+  esac
+])
+
+#################################################
+# set path of samba4's smbtorture
+smbtorture4_path=""
+AC_SUBST(smbtorture4_path)
+AC_ARG_WITH(smbtorture4_path,
+[  --with-smbtorture4-path=PATH    The path to a samba4 smbtorture for make 
test (none)],
+[ case "$withval" in
+  yes|no)
+    AC_MSG_ERROR([--with-smbtorture4-path should take a path])
+  ;;
+  * )
+    smbtorture4_path="$withval"
+    if test -z "$smbtorture4_path" -a ! -f $smbtorture4_path; then
+       AC_MSG_ERROR(['$smbtorture_path' does not  exist!]) 
+    fi
+  ;;
+ esac
+])
+
 # compile with optimization and without debugging by default, but
 # allow people to set their own preference.
 # do this here since AC_CACHE_CHECK apparently sets the CFLAGS to "-g -O2"

Added: trunk/source/script/tests/timelimit.c
===================================================================
--- trunk/source/script/tests/timelimit.c       2006-03-21 15:33:14 UTC (rev 
14624)
+++ trunk/source/script/tests/timelimit.c       2006-03-21 15:38:27 UTC (rev 
14625)
@@ -0,0 +1,78 @@
+/* run a command with a limited timeout
+   [EMAIL PROTECTED], June 2005
+
+   attempt to be as portable as possible (fighting posix all the way)
+*/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+static void usage(void)
+{
+       printf("usage: timelimit <time> <command>\n");
+}
+
+static void sig_alrm(int sig)
+{
+       kill(0, SIGKILL);
+       exit(1);
+}
+
+static void sig_term_kill(int sig)
+{
+       static int c = 0;
+
+       if (c > 2) {
+               kill(0, SIGKILL);
+               exit(0);
+       }
+
+       c++;
+}
+
+static void sig_term(int sig)
+{
+       kill(0, SIGTERM);
+       signal(SIGTERM, sig_term_kill);
+}
+
+int main(int argc, char *argv[])
+{
+       int maxtime, ret=1;
+
+       if (argc < 3) {
+               usage();
+               exit(1);
+       }
+
+       if (setpgrp() == -1) {
+               perror("setpgrp");
+               exit(1);
+       }
+
+       maxtime = atoi(argv[1]);
+       signal(SIGALRM, sig_alrm);
+       alarm(maxtime);
+       signal(SIGTERM, sig_term);
+
+       if (fork() == 0) {
+               execvp(argv[2], argv+2);
+       }
+
+       do {
+               int status;
+               pid_t pid = wait(&status);
+               if (pid != -1) {
+                       ret = WEXITSTATUS(status);
+               } else if (errno == ECHILD) {
+                       break;
+               }
+       } while (1);
+
+       exit(ret);
+}

Reply via email to