X-Git-Url: http://sigaev.ru/git/gitweb.cgi?p=remotetop.git;a=blobdiff_plain;f=topd.c;fp=topd.c;h=1f1378cad071ae2cbd837300fb3fc36393eaa8cb;hp=56a7e037b83c7c9d8f50db98517773071986d761;hb=e3fdb3b9f9b62a71c2a11b5e27ee47214901a3e2;hpb=0db0da94f6e0d2809d5176cb408f40773d6073ca diff --git a/topd.c b/topd.c index 56a7e03..1f1378c 100644 --- a/topd.c +++ b/topd.c @@ -44,46 +44,65 @@ static int continueWork=1; static void inquireExit(int s) { - continueWork=0; + continueWork=0; } - + extern char *optarg; extern int optind; +void +usage() { + fputs( + "Copyright (c) 2004-2007 Teodor Sigaev . All rights reserved.\n" + "topd - daemon to collect load data from clients\n" + "Usage:\n" + "./top [-D] -h IP [-p PORT] [-n NUMCLIENTS]\n" + " -D - debug mode (do not daemonize, print to stderr instead of syslog)\n" + " -h HOST - listen IP\n" + " -p PORT - listen port\n" + " -n NUMCLIENTS - max number of clients\n", + stdout + ); + exit(1); +} int main( int argc, char *argv[] ) { int ch; int child=0, listenport = TOPD_SERVER_DEFAULT_PORT; - int n=1024; - char *host="127.0.0.1"; + int n=1024; + char *host=NULL; memset( &cfg, 0, sizeof(TCServer) ); - while( (ch=getopt(argc, argv, "h:p:c:s:D"))!=-1) { + while( (ch=getopt(argc, argv, "h:p:c:D"))!=-1) { switch(ch) { - case 'D': - cfg.debug=1; - break; - case 'h': - host=strdup(optarg); - break; - case 'p': - listenport=atoi(optarg); - break; - case 'n': - n=atoi(optarg); - break; + case 'D': + cfg.debug=1; + break; + case 'h': + host=strdup(optarg); + break; + case 'p': + listenport=atoi(optarg); + break; + case 'n': + n=atoi(optarg); + break; default: + usage(); return 1; } } + if (!host); + usage(); + signal(SIGCHLD, SIG_IGN); - if ( cfg.debug ) - opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL); - else - opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL); + if ( cfg.debug ) + opentlog( TL_OPEN_STDERR, TL_DEBUG, NULL); + else + opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL); if ( cfg.debug || (child = fork()) == 0 ) { /* child */