Add usage(), minor code cleanups
[remotetop.git] / sendtop.c
index 8ab3269..297eabc 100644 (file)
--- a/sendtop.c
+++ b/sendtop.c
@@ -116,6 +116,21 @@ sendTop(Msg *msg) {
        return TC_sendMsg(msg);
 }
 
+void usage() {
+       fputs(
+               "Copyright (c) 2004-2007 Teodor Sigaev <teodor@sigaev.ru>. All rights reserved.\n"
+               "sendtop - small daemon to send load of box to server\n"
+               "Usage:\n"
+               "./sendtop [-D] -h HOST [-p PORT] [-s PERIOD]\n"
+               "  -D        - debug mode (do not daemonize, print to stderr instead of syslog)\n"
+               "  -h HOST   - server IP to send data\n"
+               "  -p PORT   - port number of server\n"
+               "  -s PERIOD - period of of send (in seconds)\n",
+               stdout
+       );
+
+       exit(1);
+}
 
 extern char *optarg;
 int
@@ -126,7 +141,7 @@ main( int argc, char *argv[] ) {
        int period=30;
 
        msg.port        = TOPD_SERVER_DEFAULT_PORT;
-       msg.host        = "127.0.0.1";
+       msg.host        = NULL;
        msg.msg = NULL;
        msg.sockfd =-1;
 
@@ -145,10 +160,14 @@ main( int argc, char *argv[] ) {
                                debug=1;
                                break;
                        default:
+                               usage();
                                return 1;
                }
        }
 
+       if (!msg.host)
+               usage();
+
        signal(SIGCHLD, SIG_IGN);
 
        if ( debug )