aboutsummaryrefslogtreecommitdiffstatshomepage
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
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
-rw-r--r--acinclude.m446
-rw-r--r--configure.ac10
-rw-r--r--src/securecoreutils.h5
-rw-r--r--src/widget-tail.c32
-rw-r--r--src/widget-tail.h1
5 files changed, 88 insertions, 6 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 38b1afe..5131cd8 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -34,9 +34,44 @@
34# acinclude.m4 - custom m4 macros used by configure.ac 34# acinclude.m4 - custom m4 macros used by configure.ac
35# 35#
36 36
37# AC_OPENVPN_LDAPCMD_COMPONENTS 37# AC_SCU_WIDGET_TAIL
38# ______________________________________________________________________________ 38# ______________________________________________________________________________
39AC_DEFUN([AC_SCU_ZCAT_DEPS],[dnl 39AC_DEFUN([AC_SCU_WIDGET_TAIL],[dnl
40
41 withval=""
42 AC_ARG_WITH(
43 tail-timeout,
44 [AS_HELP_STRING([--with-tail-timeout=seconds], [terminate tail after seconds [0]])],
45 [ WTAIL_TIMEOUT=$withval ],
46 [ WTAIL_TIMEOUT=$withval ]
47 )
48
49 if test "x${WTAIL_TIMEOUT}" == "xyes";then
50 WTAIL_TIMEOUT=3600
51 elif test "x${WTAIL_TIMEOUT}" == "xno";then
52 WTAIL_TIMEOUT=0
53 elif test "x${WTAIL_TIMEOUT}" == "x";then
54 WTAIL_TIMEOUT=0
55 else
56 case $WTAIL_TIMEOUT in
57 ''|*[!0-9]*)
58 AC_MSG_ERROR([tail timeout must be a numeric value.])
59 ;;
60
61 *)
62 ;;
63 esac
64 fi
65 SCU_TAIL_TIMEOUT=${WTAIL_TIMEOUT}
66
67 AC_DEFINE_UNQUOTED(SCU_TAIL_TIMEOUT, ${SCU_TAIL_TIMEOUT}, [Timeout value for tail widget])
68
69])dnl
70
71
72# AC_SCU_WIDGET_ZCAT
73# ______________________________________________________________________________
74AC_DEFUN([AC_SCU_WIDGET_ZCAT],[dnl
40 75
41 enableval="" 76 enableval=""
42 AC_ARG_ENABLE( 77 AC_ARG_ENABLE(
@@ -59,6 +94,13 @@ AC_DEFUN([AC_SCU_ZCAT_DEPS],[dnl
59 [ EZLIB=$enableval ], 94 [ EZLIB=$enableval ],
60 [ EZLIB=$enableval ] 95 [ EZLIB=$enableval ]
61 ) 96 )
97 withval=""
98 AC_ARG_WITH(
99 tail-timeout,
100 [AS_HELP_STRING([--with-tail-timeout=seconds], [terminate tail after seconds [0]])],
101 [ WTAIL_TIMEOUT=$withval ],
102 [ WTAIL_TIMEOUT=$withval ]
103 )
62 104
63 # check zlib 105 # check zlib
64 USE_ZLIB=no; 106 USE_ZLIB=no;
diff --git a/configure.ac b/configure.ac
index 5a97403..541066e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -163,7 +163,8 @@ AC_BINDLE_GIT_PACKAGE_VERSION([contrib/bindletools/build-aux/git-package-version
163 163
164# custom configure options 164# custom configure options
165AC_BINDLE_ENABLE_WARNINGS 165AC_BINDLE_ENABLE_WARNINGS
166AC_SCU_ZCAT_DEPS 166AC_SCU_WIDGET_TAIL
167AC_SCU_WIDGET_ZCAT
167 168
168 169
169# enables getopt_long if header and functions were found 170# enables getopt_long if header and functions were found
@@ -180,6 +181,13 @@ AC_MSG_NOTICE([ ])
180AC_MSG_NOTICE([ Secure Core Utilities $GIT_PACKAGE_VERSION ($GIT_PACKAGE_BUILD)]) 181AC_MSG_NOTICE([ Secure Core Utilities $GIT_PACKAGE_VERSION ($GIT_PACKAGE_BUILD)])
181AC_MSG_NOTICE([ ]) 182AC_MSG_NOTICE([ ])
182AC_MSG_NOTICE([ Features:]) 183AC_MSG_NOTICE([ Features:])
184if test "x${SCU_TAIL_TIMEOUT}" = "x0";then
185 AC_MSG_NOTICE([ tail timeout: none)])
186else
187 AC_MSG_NOTICE([ tail timeout: $SCU_TAIL_TIMEOUT seconds])
188fi
189AC_MSG_NOTICE([ ])
190AC_MSG_NOTICE([ Support:])
183AC_MSG_NOTICE([ zlib support: $USE_ZLIB]) 191AC_MSG_NOTICE([ zlib support: $USE_ZLIB])
184AC_MSG_NOTICE([ bzip2 support: $USE_BZIP2]) 192AC_MSG_NOTICE([ bzip2 support: $USE_BZIP2])
185AC_MSG_NOTICE([ lzma support: $USE_LZMA]) 193AC_MSG_NOTICE([ lzma support: $USE_LZMA])
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 */