]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include: add timer.h
authorKarel Zak <kzak@redhat.com>
Wed, 13 Mar 2013 11:13:11 +0000 (12:13 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Mar 2013 11:13:11 +0000 (12:13 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/Makemodule.am
include/timer.h [new file with mode: 0644]

index 0c1656d2d043854d7c2dc5e9f369e77a67bf7338..7ba4593e4c65ef06924729cfed9f4496241f8213 100644 (file)
@@ -39,6 +39,7 @@ dist_noinst_HEADERS += \
        include/strutils.h \
        include/swapheader.h \
        include/sysfs.h \
+       include/timer.h \
        include/tt.h \
        include/ttyutils.h \
        include/wholedisk.h \
diff --git a/include/timer.h b/include/timer.h
new file mode 100644 (file)
index 0000000..b820453
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef UTIL_LINUX_TIMER_H
+#define UTIL_LINUX_TIMER_H
+
+#include <signal.h>
+#include <sys/time.h>
+
+static inline void setup_timer(
+                       struct itimerval *timer,
+                       struct itimerval *old_timer,
+                       struct sigaction *old_sa,
+                       void (*timeout_handler)(int))
+{
+       struct sigaction sa;
+
+       memset(&sa, 0, sizeof sa);
+       sa.sa_handler = timeout_handler;
+       sa.sa_flags = SA_RESETHAND;
+       sigaction(SIGALRM, &sa, old_sa);
+
+       setitimer(ITIMER_REAL, timer, old_timer);
+}
+
+static inline void cancel_timer(
+                       struct itimerval *old_timer,
+                       struct sigaction *old_sa)
+{
+       setitimer(ITIMER_REAL, old_timer, NULL);
+       sigaction(SIGALRM, old_sa, NULL);
+}
+
+#endif