Skip to content

Commit

Permalink
Default to blocking even for slow tailers. Add -d option for old
Browse files Browse the repository at this point in the history
functionality.
  • Loading branch information
edgarsi committed May 8, 2014
1 parent 7b072ce commit 3e83621
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
.in-code todos
.package ("make dist" fixed)
.tailclient which doesn't use socat. Move arguments of the README.md examples to the end.
-why not make the strace wrapper public? - because some find it too funny
.default to blocking for clients ditching them optionally
2 changes: 1 addition & 1 deletion docs/tailclient.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.43.3.
.TH TAILCLIENT "1" "May 2014" "tailclient (tailserver) 2.0" "User Commands"
.TH TAILCLIENT "1" "May 2014" "tailclient (tailserver) 2.1" "User Commands"
.SH NAME
tailclient \- connect to tailserver and output tail
.SH SYNOPSIS
Expand Down
5 changes: 4 additions & 1 deletion docs/tailserver.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.43.3.
.TH TAILSERVER "1" "May 2014" "tailserver 2.0" "User Commands"
.TH TAILSERVER "1" "May 2014" "tailserver 2.1" "User Commands"
.SH NAME
tailserver \- serve stdin tail to connections
.SH SYNOPSIS
Expand All @@ -23,6 +23,9 @@ output the last K lines, instead of the last 1000
\fB\-w\fR, \fB\-\-wait\fR
postpone processing stdin until a client connects
.TP
\fB\-d\fR, \fB\-\-ditch\-slow\-tailers\fR
disconnect tailers who are slow at reading data
.TP
\fB\-i\fR, \fB\-\-ignore\-interrupts\fR
ignore interrupt signals
.TP
Expand Down
2 changes: 1 addition & 1 deletion src/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_MAJOR=2
VERSION_MINOR=0
VERSION_MINOR=1
13 changes: 12 additions & 1 deletion src/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ typedef struct tailer_t {

static tailer_t* first_tailer;

static bool tailer_block_forever;


static void tailer_final (tailer_t* tailer);

Expand All @@ -101,7 +103,11 @@ static ssize_t tailer_write_blocking (tailer_t* tailer, const char* buf, ssize_t
/* If this is eats too much CPU, try dynamically removing the O_NONBLOCK. It's still a weird solution though. */
/* Partial blocking: */
/* Use that safe_write being safe will not block forever. Get rid of blocking tailers for stdout must not be blocked. */
n = safe_write(tailer->socket, buf, size);
if (tailer_block_forever) {
n = safe_write_forever(tailer->socket, buf, size);
} else {
n = safe_write(tailer->socket, buf, size);
}

if (n < size) {
if (n < 0 && (errno == EPIPE /* Broken pipe */
Expand Down Expand Up @@ -335,6 +341,11 @@ void sockets_config_file (const char* file_path)
socket_file_path = file_path;
}

void sockets_config_tailer_block_forever (bool block)
{
tailer_block_forever = block;
}

bool sockets_init ()
{
struct sockaddr_un UNIXaddr;
Expand Down
1 change: 1 addition & 0 deletions src/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stddef.h>

void sockets_config_file (const char* file_path);
void sockets_config_tailer_block_forever (bool block);

void sockets_write_blocking (char* buf, ssize_t size);

Expand Down
12 changes: 11 additions & 1 deletion src/tailserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static struct option const long_options[] =
{"bytes", required_argument, NULL, 'c'},
{"lines", required_argument, NULL, 'n'},
{"wait", no_argument, NULL, 'w'},
{"ditch-slow-tailers", no_argument, NULL, 'd'},
{"ignore-interrupts", no_argument, NULL, 'i'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
Expand Down Expand Up @@ -87,6 +88,9 @@ Continue giving all new lines that arrive (just like 'tail -f' does).\n\
"), DEFAULT_N_LINES);
fputs(_("\
-w, --wait postpone processing stdin until a client connects\n\
"), stdout);
fputs(_("\
-d, --ditch-slow-tailers disconnect tailers who are slow at reading data\n\
"), stdout);
fputs(_("\
-i, --ignore-interrupts ignore interrupt signals\n\
Expand Down Expand Up @@ -200,8 +204,9 @@ int main (int argc, char** argv)
uintmax_t n_units = DEFAULT_N_LINES;
bool wait_for_client = false;
ignore_interrupts = false;
bool tailer_block_forever = true;

while ((optc = getopt_long(argc, argv, "c:n:wi", long_options, NULL)) != -1) {
while ((optc = getopt_long(argc, argv, "c:n:wdi", long_options, NULL)) != -1) {
switch (optc)
{
case 'c':
Expand All @@ -224,6 +229,10 @@ int main (int argc, char** argv)
wait_for_client = true;
break;

case 'd':
tailer_block_forever = false;
break;

case 'i':
ignore_interrupts = true;
break;
Expand Down Expand Up @@ -255,6 +264,7 @@ Call with --help for options.\n"), stderr);
buffer_config_n_units(n_units);
pipes_config_wait_for_client(wait_for_client);
sockets_config_file(file_path);
sockets_config_tailer_block_forever(tailer_block_forever);

/* Launch */

Expand Down

0 comments on commit 3e83621

Please sign in to comment.