aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <syzdek@bindlebinaries.com>2017-07-06 19:07:27 -0800
committerDavid M. Syzdek <syzdek@bindlebinaries.com>2017-07-06 19:07:27 -0800
commitba3e64f83c033f8122d6f67b06236b76e65000e2 (patch)
tree690fe69a31e7d353cf515ac304e66fb428285212 /src
parent012d70833ae03359c9cbbea15f8ee4e13d6e16b1 (diff)
downloadsecurecoreutils-ba3e64f83c033f8122d6f67b06236b76e65000e2.tar.gz
securecoreutils-ba3e64f83c033f8122d6f67b06236b76e65000e2.tar.bz2
securecoreutils-ba3e64f83c033f8122d6f67b06236b76e65000e2.tar.xz
securecoreutils-ba3e64f83c033f8122d6f67b06236b76e65000e2.zip
Adding ability to specify timeout for tail widget when following a file
Diffstat (limited to 'src')
-rw-r--r--src/securecoreutils.h5
-rw-r--r--src/widget-tail.c32
-rw-r--r--src/widget-tail.h1
3 files changed, 35 insertions, 3 deletions
diff --git a/src/securecoreutils.h b/src/securecoreutils.h
index b29a16c..ff1990f 100644
--- a/src/securecoreutils.h
+++ b/src/securecoreutils.h
@@ -85,6 +85,11 @@
85#endif 85#endif
86 86
87 87
88#ifndef SCU_TAIL_TIMEOUT
89#define SCU_TAIL_TIMEOUT 0
90#endif
91
92
88#ifdef LINE_MAX 93#ifdef LINE_MAX
89# define SCU_LINE_MAX LINE_MAX 94# define SCU_LINE_MAX LINE_MAX
90#elif defined _POSIX2_LINE_MAX 95#elif defined _POSIX2_LINE_MAX
diff --git a/src/widget-tail.c b/src/widget-tail.c
index 63ef5a4..69ed7c3 100644
--- a/src/widget-tail.c
+++ b/src/widget-tail.c
@@ -54,6 +54,7 @@
54#include <unistd.h> 54#include <unistd.h>
55#include <stdlib.h> 55#include <stdlib.h>
56#include <time.h> 56#include <time.h>
57#include <signal.h>
57 58
58 59
59/////////////////// 60///////////////////
@@ -80,6 +81,15 @@ int scu_widget_tail_lines(scu_config * cnf, int fd, struct stat * sb,
80 size_t opts, off_t optnum); 81 size_t opts, off_t optnum);
81 82
82 83
84////////////////
85// //
86// Variable //
87// //
88////////////////
89
90static int timeout_alarmed = 0;
91
92
83///////////////// 93/////////////////
84// // 94// //
85// Functions // 95// Functions //
@@ -332,10 +342,16 @@ int scu_widget_tail_follow(scu_config * cnf, int fd)
332 ssize_t len; 342 ssize_t len;
333 struct timespec ts; 343 struct timespec ts;
334 344
335 ts.tv_sec = 0; 345 ts.tv_sec = 0;
336 ts.tv_nsec = 10000000; 346 ts.tv_nsec = 10000000;
347 timeout_alarmed = 0;
348
349#if (SCU_TAIL_TIMEOUT > 0)
350 signal(SIGALRM, scu_widget_tail_follow_alarm);
351 alarm(SCU_TAIL_TIMEOUT);
352#endif
337 353
338 while (1) 354 while (!(timeout_alarmed))
339 { 355 {
340 switch (len = read(fd, buff, sizeof(buff))) 356 switch (len = read(fd, buff, sizeof(buff)))
341 { 357 {
@@ -361,6 +377,16 @@ int scu_widget_tail_follow(scu_config * cnf, int fd)
361} 377}
362 378
363 379
380void scu_widget_tail_follow_alarm(int sig)
381{
382 timeout_alarmed = 1;
383 signal (sig, scu_widget_tail_follow_alarm);
384 alarm(1);
385 fprintf(stderr, "\n\n*** TAIL WIDGET TIMEOUT EXPIRED ***\n\n\n");
386 return;
387}
388
389
364int scu_widget_tail_lines(scu_config * cnf, int fd, struct stat * sb, 390int scu_widget_tail_lines(scu_config * cnf, int fd, struct stat * sb,
365 size_t opts, off_t optnum) 391 size_t opts, off_t optnum)
366{ 392{
diff --git a/src/widget-tail.h b/src/widget-tail.h
index 62ab0cf..f4aedcd 100644
--- a/src/widget-tail.h
+++ b/src/widget-tail.h
@@ -63,5 +63,6 @@
63int scu_widget_tail(scu_config * cnf); 63int scu_widget_tail(scu_config * cnf);
64 64
65void scu_widget_tail_usage(scu_config * cnf); 65void scu_widget_tail_usage(scu_config * cnf);
66void scu_widget_tail_follow_alarm(int sig);
66 67
67#endif /* end of header */ 68#endif /* end of header */