Adjust path for the upcoming 2.0 release
[dragonfly.git] / sbin / rconfig / rconfig.c
blobe4709ec5d9bcd3046fecd49a630eb212125bfbb4
1 /*
2 * rconfig - Remote configurator
4 * rconfig [-W workingdir] [server_ip[:tag]]
5 * rconfig [-f configfile] -s
6 *
7 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
8 *
9 * This code is derived from software contributed to The DragonFly Project
10 * by Matthew Dillon <dillon@backplane.com>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
21 * distribution.
22 * 3. Neither the name of The DragonFly Project nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific, prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
39 * $DragonFly: src/sbin/rconfig/rconfig.c,v 1.4 2007/02/20 15:52:43 swildner Exp $
42 #include "defs.h"
44 const char *WorkDir = "/tmp";
45 const char *ConfigFiles = "/etc/defaults/rconfig.conf:/etc/rconfig.conf";
46 const char *TagDir = "/usr/local/etc/rconfig";
47 tag_t AddrBase;
48 tag_t VarBase;
49 int VerboseOpt;
51 static void usage(int code);
52 static void addTag(tag_t *basep, const char *tag, int flags);
54 int
55 main(int ac, char **av)
57 int ch;
58 int i;
59 int serverMode = 0;
61 while ((ch = getopt(ac, av, "aD:W:irt:f:sv")) != -1) {
62 switch(ch) {
63 case 'a': /* auto tag / standard broadcast */
64 addTag(&AddrBase, NULL, 0);
65 break;
66 case 'W': /* specify working directory */
67 WorkDir = optarg;
68 break;
69 case 'T':
70 TagDir = optarg;
71 break;
72 case 'C': /* specify server config file(s) (colon delimited) */
73 ConfigFiles = optarg;
74 break;
75 case 's': /* run as server using config file */
76 serverMode = 1;
77 break;
78 case 'v':
79 VerboseOpt = 1;
80 break;
81 default:
82 usage(1);
83 /* not reached */
86 for (i = optind; i < ac; ++i) {
87 if (strchr(av[i], '='))
88 addTag(&VarBase, av[i], 0);
89 else
90 addTag(&AddrBase, av[i], 0);
92 if (AddrBase == NULL)
93 usage(1);
94 if (AddrBase && AddrBase->name == NULL && AddrBase->next) {
95 fprintf(stderr,
96 "You cannot specify both -a AND a list of hosts. If you want\n"
97 "to use auto-broadcast mode with a tag other than 'auto',\n"
98 "just specify the tag without a host, e.g. ':<tag>'\n");
99 exit(1);
101 if (serverMode)
102 doServer();
103 else
104 doClient();
105 return(0);
108 static
109 void
110 addTag(tag_t *basep, const char *name, int flags)
112 tag_t tag = calloc(sizeof(struct tag), 1);
114 while ((*basep) != NULL)
115 basep = &(*basep)->next;
117 tag->name = name;
118 tag->flags = flags;
119 *basep = tag;
122 static void
123 usage(int code)
125 fprintf(stderr, "rconfig [-W workdir] [-f servconfig] "
126 "[-s] [var=data]* [server_ip[:tag]]* \n");
127 exit(code);