1 /* cvm/module.c - CVM generic server module main routine
2  * Copyright (C) 2010  Bruce Guenter <bruce@untroubled.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include <bglibs/msg.h>
22 
23 #include "module.h"
24 
25 const int msg_show_pid = 0;
26 
usage(void)27 void usage(void)
28 {
29   die5(1, "Incorrect usage.\n"
30        "usage: ", program, " cvm-local:/path/to/socket\n"
31        "or:    ", program, " cvm-udp:hostname:port");
32 }
33 
34 extern int command_main(void);
35 extern int local_main(const char*);
36 extern int udp_main(const char*, const char*);
37 
main(int argc,char ** argv)38 int main(int argc, char** argv)
39 {
40   cvm_module_init_request();
41   if (argc == 1)
42     return command_main();
43   if (argc == 2) {
44     if (memcmp(argv[1], "cvm-local:", 10) == 0)
45       return local_main(argv[1] + 10);
46     if (memcmp(argv[1], "cvm-udp:", 8) == 0) {
47       char* hostname = argv[1] + 8;
48       char* port = strchr(hostname, ':');
49       if (port == 0) usage();
50       *port++ = 0;
51       return udp_main(hostname, port);
52     }
53   }
54   usage();
55   return 0;
56 }
57