Merge from vendor branch GCC:
[dragonfly.git] / sbin / rconfig / rconfig.c
1 /*
2  * rconfig - Remote configurator
3  *
4  *      rconfig [-W workingdir] [server_ip[:tag]]
5  *      rconfig [-f configfile] -s
6  *
7  * $DragonFly: src/sbin/rconfig/rconfig.c,v 1.2 2004/06/18 04:26:53 dillon Exp $
8  */
9
10 #include "defs.h"
11
12 const char *WorkDir = "/tmp";
13 const char *ConfigFiles = "/etc/defaults/rconfig.conf:/etc/rconfig.conf";
14 const char *TagDir = "/usr/local/etc/rconfig";
15 tag_t AddrBase;
16 tag_t VarBase;
17 int VerboseOpt;
18
19 static void usage(int code);
20 static void addTag(tag_t *basep, const char *tag, int flags);
21
22 int
23 main(int ac, char **av)
24 {
25     int ch;
26     int i;
27     int serverMode = 0;
28     
29     while ((ch = getopt(ac, av, "aD:W:irt:f:sv")) != -1) {
30         switch(ch) {
31         case 'a':       /* auto tag / standard broadcast */
32             addTag(&AddrBase, NULL, 0);
33             break;
34         case 'W':       /* specify working directory */
35             WorkDir = optarg;
36             break;
37         case 'T':
38             TagDir = optarg;
39             break;
40         case 'C':       /* specify server config file(s) (colon delimited) */
41             ConfigFiles = optarg;
42             break;
43         case 's':       /* run as server using config file */
44             serverMode = 1;
45             break;
46         case 'v':
47             VerboseOpt = 1;
48             break;
49         default:
50             usage(1);
51             /* not reached */
52         }
53     }
54     for (i = optind; i < ac; ++i) {
55         if (strchr(av[i], '='))
56             addTag(&VarBase, av[i], 0);
57         else
58             addTag(&AddrBase, av[i], 0);
59     }
60     if (AddrBase == NULL)
61         usage(1);
62     if (AddrBase && AddrBase->name == NULL && AddrBase->next) {
63         fprintf(stderr,
64                 "You cannot specify both -a AND a list of hosts.  If you want\n"
65                 "to use auto-broadcast mode with a tag other then 'auto',\n"
66                 "just specify the tag without a host, e.g. ':<tag>'\n");
67         exit(1);
68     }
69     if (serverMode)
70         doServer();
71     else
72         doClient();
73     return(0);
74 }
75
76 static
77 void
78 addTag(tag_t *basep, const char *name, int flags)
79 {
80     tag_t tag = calloc(sizeof(struct tag), 1);
81
82     while ((*basep) != NULL)
83         basep = &(*basep)->next;
84
85     tag->name = name;
86     tag->flags = flags;
87     *basep = tag;
88 }
89
90 static void
91 usage(int code)
92 {
93     fprintf(stderr, "rconfig [-W workdir] [-f servconfig] "
94                     "[-s] [var=data]* [server_ip[:tag]]* \n");
95     exit(code);
96 }
97