diff options
author | Bertrand Marc <beberking@gmail.com> | 2012-06-06 20:47:48 +0200 |
---|---|---|
committer | Bertrand Marc <beberking@gmail.com> | 2012-06-06 20:47:48 +0200 |
commit | 740b30688bd745a527f96f9116c19acb3480971a (patch) | |
tree | 2709a3f4dba11c174aa9e1ba3612e30c578e76a9 /contrib | |
parent | 2b81464a43485fcc8ce079fafdee7b7a171835f4 (diff) |
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/Makefile.am | 42 | ||||
-rw-r--r-- | contrib/Makefile.in | 153 | ||||
-rwxr-xr-x | contrib/gnunet-gns-import.sh | 4 | ||||
-rw-r--r-- | contrib/gnunet_janitor.py.in | 12 | ||||
-rw-r--r-- | contrib/hellos/02UK | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/1G1M | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/7RAV | bin | 0 -> 292 bytes | |||
-rw-r--r-- | contrib/hellos/8B4T | bin | 0 -> 292 bytes | |||
-rw-r--r-- | contrib/hellos/94CH | bin | 0 -> 292 bytes | |||
-rw-r--r-- | contrib/hellos/ATF4 | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/F1GT | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/KD9V | bin | 0 -> 292 bytes | |||
-rw-r--r-- | contrib/hellos/KUPL | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/LJR8 | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/R69Q | bin | 0 -> 292 bytes | |||
-rw-r--r-- | contrib/hellos/R6OV | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/hellos/RL7P | bin | 0 -> 312 bytes | |||
-rw-r--r-- | contrib/timeout_watchdog_w32.c | 190 |
18 files changed, 356 insertions, 45 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am index df6bdc2..0d65393 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -1,29 +1,36 @@ INCLUDES = -I$(top_srcdir)/src/include -I$(top_builddir)/src/include -if !MINGW noinst_PROGRAMS = \ timeout_watchdog +if !MINGW timeout_watchdog_SOURCES = \ timeout_watchdog.c +else +timeout_watchdog_SOURCES = \ + timeout_watchdog_w32.c endif noinst_SCRIPTS = \ gnunet_pyexpect.py \ gnunet_janitor.py +bin_SCRIPTS = \ + gnunet-gns-import.sh + dist_pkgdata_DATA = \ - gnunet-logo-color.png + gnunet-logo-color.png \ + testing_hostkeys.dat EXTRA_DIST = \ coverage.sh \ hostlist.cgi \ hostlist.php \ report.sh \ - testing_hostkeys.dat \ gnunet_pyexpect.py.in \ - gnunet_janitor.py.in + gnunet_janitor.py.in \ + gnunet-gns-import.sh do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' @@ -45,3 +52,30 @@ check_PROGRAMS = \ test_gnunet_prefix_SOURCES = \ test_gnunet_prefix.c + +test_gnunet_prefix_LDADD = \ + $(GCLIBADD) $(WINLIB) \ + $(LTLIBICONV) \ + -lltdl -lunistring $(XLIB) + +pkghellodir= $(pkgdatadir)/hellos + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(pkghellodir) + @$(NORMAL_INSTALL) + for hello in $(srcdir)/hellos/*; do \ + if test -f $$hello; then \ + $(INSTALL_DATA) $$hello $(DESTDIR)$(pkghellodir)/ ; \ + fi \ + done + +dist-hook: + if test -d $(srcdir)/hellos; then \ + mkdir -p $(distdir)/hellos; \ + for hello in $(srcdir)/hellos/*; do \ + if test -f $$hello; then \ + cp -p $$hello $(distdir)/hellos; \ + fi \ + done \ + fi + diff --git a/contrib/Makefile.in b/contrib/Makefile.in index 04a23bf..80134e5 100644 --- a/contrib/Makefile.in +++ b/contrib/Makefile.in @@ -37,7 +37,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ -@MINGW_FALSE@noinst_PROGRAMS = timeout_watchdog$(EXEEXT) +noinst_PROGRAMS = timeout_watchdog$(EXEEXT) check_PROGRAMS = test_gnunet_prefix$(EXEEXT) subdir = contrib DIST_COMMON = $(dist_pkgdata_DATA) $(srcdir)/Makefile.am \ @@ -64,15 +64,41 @@ CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) am_test_gnunet_prefix_OBJECTS = test_gnunet_prefix.$(OBJEXT) test_gnunet_prefix_OBJECTS = $(am_test_gnunet_prefix_OBJECTS) -test_gnunet_prefix_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +test_gnunet_prefix_DEPENDENCIES = $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent -am__timeout_watchdog_SOURCES_DIST = timeout_watchdog.c +am__timeout_watchdog_SOURCES_DIST = timeout_watchdog.c \ + timeout_watchdog_w32.c @MINGW_FALSE@am_timeout_watchdog_OBJECTS = timeout_watchdog.$(OBJEXT) +@MINGW_TRUE@am_timeout_watchdog_OBJECTS = \ +@MINGW_TRUE@ timeout_watchdog_w32.$(OBJEXT) timeout_watchdog_OBJECTS = $(am_timeout_watchdog_OBJECTS) timeout_watchdog_LDADD = $(LDADD) -SCRIPTS = $(noinst_SCRIPTS) +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgdatadir)" +SCRIPTS = $(bin_SCRIPTS) $(noinst_SCRIPTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -102,28 +128,6 @@ am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(test_gnunet_prefix_SOURCES) $(timeout_watchdog_SOURCES) DIST_SOURCES = $(test_gnunet_prefix_SOURCES) \ $(am__timeout_watchdog_SOURCES_DIST) -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; -am__install_max = 40 -am__nobase_strip_setup = \ - srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` -am__nobase_strip = \ - for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" -am__nobase_list = $(am__nobase_strip_setup); \ - for p in $$list; do echo "$$p $$p"; done | \ - sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ - $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ - if (++n[$$2] == $(am__install_max)) \ - { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ - END { for (dir in files) print dir, files[dir] }' -am__base_list = \ - sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ - sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__installdirs = "$(DESTDIR)$(pkgdatadir)" DATA = $(dist_pkgdata_DATA) ETAGS = etags CTAGS = ctags @@ -183,6 +187,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INTLLIBS = @INTLLIBS@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +JAVAPORT = @JAVAPORT@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBADD_DL = @LIBADD_DL@ @@ -216,6 +221,7 @@ LT_DLLOADERS = @LT_DLLOADERS@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +MONKEYPREFIX = @MONKEYPREFIX@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ @@ -336,26 +342,39 @@ INCLUDES = -I$(top_srcdir)/src/include -I$(top_builddir)/src/include @MINGW_FALSE@timeout_watchdog_SOURCES = \ @MINGW_FALSE@ timeout_watchdog.c +@MINGW_TRUE@timeout_watchdog_SOURCES = \ +@MINGW_TRUE@ timeout_watchdog_w32.c + noinst_SCRIPTS = \ gnunet_pyexpect.py \ gnunet_janitor.py +bin_SCRIPTS = \ + gnunet-gns-import.sh + dist_pkgdata_DATA = \ - gnunet-logo-color.png + gnunet-logo-color.png \ + testing_hostkeys.dat EXTRA_DIST = \ coverage.sh \ hostlist.cgi \ hostlist.php \ report.sh \ - testing_hostkeys.dat \ gnunet_pyexpect.py.in \ - gnunet_janitor.py.in + gnunet_janitor.py.in \ + gnunet-gns-import.sh do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' test_gnunet_prefix_SOURCES = \ test_gnunet_prefix.c +test_gnunet_prefix_LDADD = \ + $(GCLIBADD) $(WINLIB) \ + $(LTLIBICONV) \ + -lltdl -lunistring $(XLIB) + +pkghellodir = $(pkgdatadir)/hellos all: all-am .SUFFIXES: @@ -414,6 +433,40 @@ test_gnunet_prefix$(EXEEXT): $(test_gnunet_prefix_OBJECTS) $(test_gnunet_prefix_ timeout_watchdog$(EXEEXT): $(timeout_watchdog_OBJECTS) $(timeout_watchdog_DEPENDENCIES) @rm -f timeout_watchdog$(EXEEXT) $(AM_V_CCLD)$(LINK) $(timeout_watchdog_OBJECTS) $(timeout_watchdog_LDADD) $(LIBS) +install-binSCRIPTS: $(bin_SCRIPTS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -423,6 +476,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_gnunet_prefix.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timeout_watchdog.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timeout_watchdog_w32.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -556,12 +610,15 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$(top_distdir)" distdir="$(distdir)" \ + dist-hook check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) check: check-am all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(DATA) installdirs: - for dir in "$(DESTDIR)$(pkgdatadir)"; do \ + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgdatadir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am @@ -612,13 +669,13 @@ info: info-am info-am: -install-data-am: install-dist_pkgdataDATA +install-data-am: install-data-local install-dist_pkgdataDATA install-dvi: install-dvi-am install-dvi-am: -install-exec-am: +install-exec-am: install-binSCRIPTS install-html: install-html-am @@ -658,16 +715,17 @@ ps: ps-am ps-am: -uninstall-am: uninstall-dist_pkgdataDATA +uninstall-am: uninstall-binSCRIPTS uninstall-dist_pkgdataDATA .MAKE: check-am install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean \ clean-checkPROGRAMS clean-generic clean-libtool \ - clean-noinstPROGRAMS ctags distclean distclean-compile \ - distclean-generic distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-dist_pkgdataDATA \ + clean-noinstPROGRAMS ctags dist-hook distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-binSCRIPTS install-data \ + install-data-am install-data-local install-dist_pkgdataDATA \ install-dvi install-dvi-am install-exec install-exec-am \ install-html install-html-am install-info install-info-am \ install-man install-pdf install-pdf-am install-ps \ @@ -675,13 +733,32 @@ uninstall-am: uninstall-dist_pkgdataDATA installdirs maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ - uninstall-am uninstall-dist_pkgdataDATA + uninstall-am uninstall-binSCRIPTS uninstall-dist_pkgdataDATA %.py: %.py.in Makefile $(do_subst) < $< > $@ chmod +x $@ +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(pkghellodir) + @$(NORMAL_INSTALL) + for hello in $(srcdir)/hellos/*; do \ + if test -f $$hello; then \ + $(INSTALL_DATA) $$hello $(DESTDIR)$(pkghellodir)/ ; \ + fi \ + done + +dist-hook: + if test -d $(srcdir)/hellos; then \ + mkdir -p $(distdir)/hellos; \ + for hello in $(srcdir)/hellos/*; do \ + if test -f $$hello; then \ + cp -p $$hello $(distdir)/hellos; \ + fi \ + done \ + fi + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/contrib/gnunet-gns-import.sh b/contrib/gnunet-gns-import.sh new file mode 100755 index 0000000..82d7cda --- /dev/null +++ b/contrib/gnunet-gns-import.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# This shell-script will import some GNS authorities into your GNS +# namestore. +gnunet-namestore -a -e never -n fcfs -p -t PKEY -V 72QC35CO20UJN1E91KPJFNT9TG4CLKAPB4VK9S3Q758S9MLBRKOG diff --git a/contrib/gnunet_janitor.py.in b/contrib/gnunet_janitor.py.in index c11ff4f..056ab9b 100644 --- a/contrib/gnunet_janitor.py.in +++ b/contrib/gnunet_janitor.py.in @@ -34,6 +34,9 @@ import signal if os.name == 'nt': from win32com.client import GetObject WMI = GetObject('winmgmts:') + killsignal = signal.SIGTERM # any valid value will result in TerminateProcess() +else: + killsignal = signal.SIGKILL def get_process_list (): result = [] @@ -44,7 +47,10 @@ def get_process_list (): else: pids = [pid for pid in os.listdir('/proc') if pid.isdigit ()] for pid in pids: - result.append ((pid, open (os.path.join ('/proc', pid, 'comm'), 'rb').read ())) + with open (os.path.join ('/proc', pid, 'cmdline'), 'rb') as p: + cmdline = p.read ().split ('\x00') + if len (cmdline) > 0: + result.append ((pid, cmdline[0])) return result def main (): @@ -57,7 +63,7 @@ def main (): if re.match (r'gnunet-service-arm', p[1]): print ("killing arm process {0:5} {1}".format (p[0], p[1])) try: - os.kill (p[0], signal.SIGTERM) + os.kill (int (p[0]), killsignal) except OSError as e: print ("failed: {0}".format (e)) pass @@ -65,7 +71,7 @@ def main (): if not re.match (r'gnunet-service-arm', p[1]): print ("killing non-arm process {0:5} {1}".format (p[0], p[1])) try: - os.kill (p[0], signal.SIGTERM) + os.kill (int (p[0]), killsignal) except OSError as e: print ("failed: {0}".format (e)) pass diff --git a/contrib/hellos/02UK b/contrib/hellos/02UK Binary files differnew file mode 100644 index 0000000..172a343 --- /dev/null +++ b/contrib/hellos/02UK diff --git a/contrib/hellos/1G1M b/contrib/hellos/1G1M Binary files differnew file mode 100644 index 0000000..6c13510 --- /dev/null +++ b/contrib/hellos/1G1M diff --git a/contrib/hellos/7RAV b/contrib/hellos/7RAV Binary files differnew file mode 100644 index 0000000..84128df --- /dev/null +++ b/contrib/hellos/7RAV diff --git a/contrib/hellos/8B4T b/contrib/hellos/8B4T Binary files differnew file mode 100644 index 0000000..23a319e --- /dev/null +++ b/contrib/hellos/8B4T diff --git a/contrib/hellos/94CH b/contrib/hellos/94CH Binary files differnew file mode 100644 index 0000000..9a93382 --- /dev/null +++ b/contrib/hellos/94CH diff --git a/contrib/hellos/ATF4 b/contrib/hellos/ATF4 Binary files differnew file mode 100644 index 0000000..cd6c83a --- /dev/null +++ b/contrib/hellos/ATF4 diff --git a/contrib/hellos/F1GT b/contrib/hellos/F1GT Binary files differnew file mode 100644 index 0000000..31ae9f7 --- /dev/null +++ b/contrib/hellos/F1GT diff --git a/contrib/hellos/KD9V b/contrib/hellos/KD9V Binary files differnew file mode 100644 index 0000000..ab6f76b --- /dev/null +++ b/contrib/hellos/KD9V diff --git a/contrib/hellos/KUPL b/contrib/hellos/KUPL Binary files differnew file mode 100644 index 0000000..a35a341 --- /dev/null +++ b/contrib/hellos/KUPL diff --git a/contrib/hellos/LJR8 b/contrib/hellos/LJR8 Binary files differnew file mode 100644 index 0000000..c573e06 --- /dev/null +++ b/contrib/hellos/LJR8 diff --git a/contrib/hellos/R69Q b/contrib/hellos/R69Q Binary files differnew file mode 100644 index 0000000..087a565 --- /dev/null +++ b/contrib/hellos/R69Q diff --git a/contrib/hellos/R6OV b/contrib/hellos/R6OV Binary files differnew file mode 100644 index 0000000..569a856 --- /dev/null +++ b/contrib/hellos/R6OV diff --git a/contrib/hellos/RL7P b/contrib/hellos/RL7P Binary files differnew file mode 100644 index 0000000..3076952 --- /dev/null +++ b/contrib/hellos/RL7P diff --git a/contrib/timeout_watchdog_w32.c b/contrib/timeout_watchdog_w32.c new file mode 100644 index 0000000..46a6157 --- /dev/null +++ b/contrib/timeout_watchdog_w32.c @@ -0,0 +1,190 @@ +/* + This file is part of GNUnet + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file contrib/timeout_watchdog_w32.c + * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period + * @author LRN + */ + +#include <windows.h> +#include <sys/types.h> +#include <stdio.h> + +int +main (int argc, char *argv[]) +{ + int i; + DWORD wait_result; + wchar_t *commandline; + wchar_t **wargv; + wchar_t *arg; + unsigned int cmdlen; + wchar_t *idx; + STARTUPINFOW start; + PROCESS_INFORMATION proc; + + wchar_t wpath[MAX_PATH + 1]; + + wchar_t *pathbuf; + DWORD pathbuf_len, alloc_len; + wchar_t *ptr; + wchar_t *non_const_filename; + wchar_t *wcmd; + int wargc; + int timeout = 0; + + HANDLE job; + + if (argc < 3) + { + printf + ("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n"); + exit (1); + } + + timeout = atoi (argv[1]); + + if (timeout == 0) + timeout = 600; + + commandline = GetCommandLineW (); + if (commandline == NULL) + { + printf ("Failed to get commandline: %lu\n", GetLastError ()); + exit (2); + } + + wargv = CommandLineToArgvW (commandline, &wargc); + if (wargv == NULL || wargc <= 1) + { + printf ("Failed to get parse commandline: %lu\n", GetLastError ()); + exit (3); + } + + job = CreateJobObject (NULL, NULL); + if (job == NULL) + { + printf ("Failed to create a job: %lu\n", GetLastError ()); + exit (4); + } + + pathbuf_len = GetEnvironmentVariableW (L"PATH", (wchar_t *) &pathbuf, 0); + + alloc_len = pathbuf_len + 1; + + pathbuf = malloc (alloc_len * sizeof (wchar_t)); + + ptr = pathbuf; + + alloc_len = GetEnvironmentVariableW (L"PATH", ptr, pathbuf_len); + + cmdlen = wcslen (wargv[2]); + if (cmdlen < 5 || wcscmp (&wargv[2][cmdlen - 4], L".exe") != 0) + { + non_const_filename = malloc (sizeof (wchar_t) * (cmdlen + 5)); + _snwprintf (non_const_filename, cmdlen + 5, L"%s.exe", wargv[2]); + } + else + { + non_const_filename = wcsdup (wargv[2]); + } + + /* Check that this is the full path. If it isn't, search. */ + if (non_const_filename[1] == L':') + _snwprintf (wpath, sizeof (wpath) / sizeof (wchar_t), L"%s", non_const_filename); + else if (!SearchPathW + (pathbuf, non_const_filename, NULL, sizeof (wpath) / sizeof (wchar_t), + wpath, NULL)) + { + printf ("Failed to get find executable: %lu\n", GetLastError ()); + exit (5); + } + free (pathbuf); + free (non_const_filename); + + cmdlen = wcslen (wpath) + 4; + i = 3; + while (NULL != (arg = wargv[i++])) + cmdlen += wcslen (arg) + 4; + + wcmd = idx = malloc (sizeof (wchar_t) * (cmdlen + 1)); + i = 2; + while (NULL != (arg = wargv[i++])) + { + /* This is to escape trailing slash */ + wchar_t arg_lastchar = arg[wcslen (arg) - 1]; + if (idx == wcmd) + idx += swprintf (idx, L"\"%s%s\" ", wpath, + arg_lastchar == L'\\' ? L"\\" : L""); + else + { + if (wcschr (arg, L' ') != NULL) + idx += swprintf (idx, L"\"%s%s\"%s", arg, + arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" "); + else + idx += swprintf (idx, L"%s%s%s", arg, + arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" "); + } + } + + LocalFree (wargv); + + memset (&start, 0, sizeof (start)); + start.cb = sizeof (start); + + if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, CREATE_SUSPENDED, + NULL, NULL, &start, &proc)) + { + wprintf (L"Failed to get spawn process `%s' with arguments `%s': %lu\n", wpath, wcmd, GetLastError ()); + exit (6); + } + + AssignProcessToJobObject (job, proc.hProcess); + + ResumeThread (proc.hThread); + CloseHandle (proc.hThread); + + free (wcmd); + + wait_result = WaitForSingleObject (proc.hProcess, timeout * 1000); + if (wait_result == WAIT_OBJECT_0) + { + DWORD status; + wait_result = GetExitCodeProcess (proc.hProcess, &status); + CloseHandle (proc.hProcess); + if (wait_result != 0) + { + printf ("Test process exited with result %lu\n", status); + TerminateJobObject (job, status); + exit (status); + } + printf ("Test process exited (failed to obtain exit status)\n"); + TerminateJobObject (job, 0); + exit (0); + } + printf ("Child processes were killed after timeout of %u seconds\n", + timeout); + TerminateJobObject (job, 1); + CloseHandle (proc.hProcess); + exit (1); +} + +/* end of timeout_watchdog_w32.c */ |