Add usage(), minor code cleanups
[remotetop.git] / topd.c
diff --git a/topd.c b/topd.c
index 56a7e03..1f1378c 100644 (file)
--- 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 <teodor@sigaev.ru>. 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 */