X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Famservice.c;h=8b8c50aaa86835ede40f05013f585cf8bdc5c724;hb=HEAD;hp=286a77059ad103b63cb82c33a57d682c7a993966;hpb=99080c663209a733fd597a2fcab96a45c9c41291;p=debian%2Famanda diff --git a/common-src/amservice.c b/common-src/amservice.c index 286a770..8b8c50a 100644 --- a/common-src/amservice.c +++ b/common-src/amservice.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-2000 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -35,6 +36,12 @@ #include "protocol.h" #include "amfeatures.h" #include "event.h" +#include "getopt.h" + +static struct option long_options[] = { + {"version" , 0, NULL, 1}, + {NULL, 0, NULL, 0} +}; static int copy_stream = 0; static time_t conf_ctimeout; @@ -58,7 +65,7 @@ static void read_server(void *cookie, void *buf, ssize_t size); void usage(void) { - error(_("Usage: amservice [-o configoption]* [-f input_file [-s]] host auth service")); + error(_("Usage: amservice [--version] [-o configoption]* [-f input_file [-s]] host auth service")); /*NOTREACHED*/ } @@ -110,8 +117,11 @@ main( cfg_ovr = new_config_overrides(argc/2); input_file = stdin; - while((opt = getopt(argc, argv, "o:f:s")) != EOF) { + while((opt = getopt_long(argc, argv, "o:f:s", long_options, NULL)) != EOF) { switch(opt) { + case 1: printf("amservice-%s\n", VERSION); + return(0); + break; case 'o': add_config_override_opt(cfg_ovr, optarg); break; case 'f': got_input_file = 1; @@ -312,18 +322,17 @@ read_in( void *cookie G_GNUC_UNUSED) { size_t nread; - char buf[1024]; + char buf[1025]; - event_release(event_in); nread = read(0, buf, 1024); - if (nread == 0) { + if (nread <= 0) { + event_release(event_in); security_stream_close(fd); return; } buf[nread] = '\0'; security_stream_write(fd, buf, nread); - event_in = event_register((event_id_t)0, EV_READFD, read_in, NULL); } static void @@ -342,7 +351,6 @@ read_server( if (errno > 0) { g_debug("failed to write to stdout: %s", strerror(errno)); } - security_stream_read(fd, read_server, NULL); break; } }