diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2011-04-25 13:29:40 -0700 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2011-04-26 20:22:06 -0700 |
commit | 0fdff42f786cf499d4103e4ed5d310f77ea3f1c3 (patch) | |
tree | 935ec37b25e786fe06197705acc7a261bf0b19ed | |
parent | d195dfe36b59707ab8800b951603fe8b5fa5b077 (diff) | |
download | memcached-0fdff42f786cf499d4103e4ed5d310f77ea3f1c3.tar.gz |
made stdin_check trigger shutdown on EOL
Erlang ports don't have API to close only output part. So it seems
that the only reasonable way to reliably control memcached from Erlang
is by signalling shutdown by something else than EOF. EOL seems good
enough. This allows sending shutdown 'message' and waiting for
shutdown termination by observing EOF on memcached's stdout.
Change-Id: I0bc994362e8f55a0956cb0ecb68305e495916ccb
-rw-r--r-- | extensions/daemon/stdin_check.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/extensions/daemon/stdin_check.c b/extensions/daemon/stdin_check.c index ea17c36..94cdc0f 100644 --- a/extensions/daemon/stdin_check.c +++ b/extensions/daemon/stdin_check.c @@ -12,15 +12,16 @@ union c99hack { static void* check_stdin_thread(void* arg) { + int ch; pthread_detach(pthread_self()); - while (!feof(stdin)) { - getc(stdin); - } + do { + ch = getc(stdin); + } while (ch != EOF && ch != '\n' && ch != '\r'); - fprintf(stderr, "EOF on stdin. Exiting\n"); - union c99hack ch = { .pointer = arg }; - ch.exit_function(); + fprintf(stderr, "%s on stdin. Exiting\n", (ch == EOF) ? "EOF" : "EOL"); + union c99hack chack = { .pointer = arg }; + chack.exit_function(); /* NOTREACHED */ return NULL; } |