ldconfig(8): clean up manual page
[dragonfly.git] / sbin / rconfig / rconfig.c
blobce3c1e40911e2dd7effc9e6b548715789878ce31
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.
41 #include "defs.h"
43 const char *WorkDir = "/tmp";
44 const char *ConfigFiles = "/etc/defaults/rconfig.conf:/etc/rconfig.conf";
45 const char *TagDir = "/usr/local/etc/rconfig";
46 tag_t AddrBase;
47 tag_t VarBase;
48 int VerboseOpt;
50 static void usage(int code);
51 static void addTag(tag_t *basep, const char *tag, int flags);
53 int
54 main(int ac, char **av)
56 int ch;
57 int i;
58 int serverMode = 0;
60 while ((ch = getopt(ac, av, "aW:T:C:sv")) != -1) {
61 switch(ch) {
62 case 'a': /* auto tag / standard broadcast */
63 addTag(&AddrBase, NULL, 0);
64 break;
65 case 'W': /* specify working directory */
66 WorkDir = optarg;
67 break;
68 case 'T':
69 TagDir = optarg;
70 break;
71 case 'C': /* specify server config file(s) (colon delimited) */
72 ConfigFiles = optarg;
73 break;
74 case 's': /* run as server using config file */
75 serverMode = 1;
76 break;
77 case 'v':
78 VerboseOpt = 1;
79 break;
80 default:
81 usage(1);
82 /* not reached */
85 for (i = optind; i < ac; ++i) {
86 if (strchr(av[i], '='))
87 addTag(&VarBase, av[i], 0);
88 else
89 addTag(&AddrBase, av[i], 0);
91 if (AddrBase == NULL)
92 usage(1);
93 if (AddrBase && AddrBase->name == NULL && AddrBase->next) {
94 fprintf(stderr,
95 "You cannot specify both -a AND a list of hosts. If you want\n"
96 "to use auto-broadcast mode with a tag other than 'auto',\n"
97 "just specify the tag without a host, e.g. ':<tag>'\n");
98 exit(1);
100 if (serverMode)
101 doServer();
102 else
103 doClient();
104 return(0);
107 static
108 void
109 addTag(tag_t *basep, const char *name, int flags)
111 tag_t tag = calloc(sizeof(struct tag), 1);
113 while ((*basep) != NULL)
114 basep = &(*basep)->next;
116 tag->name = name;
117 tag->flags = flags;
118 *basep = tag;
121 static void
122 usage(int code)
124 fprintf(stderr, "rconfig [-W workdir] [-f servconfig] "
125 "[-s] [var=data]* [server_ip[:tag]]* \n");
126 exit(code);