From daac5c780296fbbf1005fedb45ae790d567b2dcd Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 6 Jul 2011 22:16:47 +0200 Subject: Initial commit --- .gitignore | 1 + Makefile | 14 ++++++++++++++ config.mk | 8 ++++++++ src/randsleep.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 config.mk create mode 100644 src/randsleep.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..216b572 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/src/randsleep diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..765a697 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +include config.mk + +src/randsleep: src/randsleep.c + ${CC} ${CFLAGS} ${LDFLAGS} -o $@ $< + +install: src/randsleep + +uninstall: + rm -f src/randsleep + +clean: + rm -f src/randsleep + +.PHONY: all install uninstall clean diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..31bec82 --- /dev/null +++ b/config.mk @@ -0,0 +1,8 @@ +CFLAGS ?= -Wall -Wextra -pedantic -O2 +LDFLAGS ?= -lrt +PREFIX ?= /usr/local + +main_dir = ${DESTDIR}${PREFIX} + +man_dir = ${main_dir}/share/man +bin_dir = ${main_dir}/bin diff --git a/src/randsleep.c b/src/randsleep.c new file mode 100644 index 0000000..d06fb0a --- /dev/null +++ b/src/randsleep.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +int main (int argc, char **argv) { + long maxsleep; + struct timespec ntime; + + if (argc < 2) { + fputs("Usage: randsleep ", stdout); + return 1; + } + + maxsleep = atol(argv[1]); + + if (clock_gettime(CLOCK_REALTIME, &ntime) == -1) + perror("clock_gettime"); + + srand(ntime.tv_nsec); + + sleep(rand() % maxsleep); + + execvp(argv[2], argv + 2); + perror("execvp"); +} -- cgit v1.2.3