/[packages]/cauldron/autofs/current/SOURCES/autofs-5.0.5-add-dump-maps-option.patch
ViewVC logotype

Contents of /cauldron/autofs/current/SOURCES/autofs-5.0.5-add-dump-maps-option.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49039 - (show annotations) (download)
Tue Feb 8 16:35:13 2011 UTC (13 years, 2 months ago) by ennael
File size: 9858 byte(s)
imported package autofs
1 autofs-5.0.5 - add dump maps option
2
3 From: Ondrej Valousek <webserv@s3group.cz>
4
5 Modified by Ian Kent <raven@themaw.net>
6 ---
7
8 CHANGELOG | 1
9 daemon/automount.c | 52 ++++++++++++++++-----
10 include/log.h | 1
11 include/master.h | 1
12 lib/log.c | 14 ++++--
13 lib/master.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++
14 man/automount.8 | 3 +
15 7 files changed, 180 insertions(+), 18 deletions(-)
16
17
18 diff --git a/CHANGELOG b/CHANGELOG
19 index 1975369..11054da 100644
20 --- a/CHANGELOG
21 +++ b/CHANGELOG
22 @@ -54,6 +54,7 @@
23 - fix direct map not updating on reread.
24 - add external bind method.
25 - fix add simple bind auth.
26 +- add option to dump configured automount maps.
27
28 03/09/2009 autofs-5.0.5
29 -----------------------
30 diff --git a/daemon/automount.c b/daemon/automount.c
31 index 9939a25..1b1007d 100644
32 --- a/daemon/automount.c
33 +++ b/daemon/automount.c
34 @@ -1664,6 +1664,7 @@ static void usage(void)
35 " -f --foreground do not fork into background\n"
36 " -r --random-multimount-selection\n"
37 " use ramdom replicated server selection\n"
38 + " -m --dumpmaps dump automounter maps and exit\n"
39 " -n --negative-timeout n\n"
40 " set the timeout for failed key lookups.\n"
41 " -O --global-options\n"
42 @@ -1813,7 +1814,7 @@ int main(int argc, char *argv[])
43 int res, opt, status;
44 int logpri = -1;
45 unsigned ghost, logging, daemon_check;
46 - unsigned foreground, have_global_options;
47 + unsigned dumpmaps, foreground, have_global_options;
48 time_t timeout;
49 time_t age = time(NULL);
50 struct rlimit rlim;
51 @@ -1827,6 +1828,7 @@ int main(int argc, char *argv[])
52 {"foreground", 0, 0, 'f'},
53 {"random-multimount-selection", 0, 0, 'r'},
54 {"negative-timeout", 1, 0, 'n'},
55 + {"dumpmaps", 0, 0, 'm'},
56 {"global-options", 1, 0, 'O'},
57 {"version", 0, 0, 'V'},
58 {"set-log-priority", 1, 0, 'l'},
59 @@ -1857,10 +1859,11 @@ int main(int argc, char *argv[])
60 global_options = NULL;
61 have_global_options = 0;
62 foreground = 0;
63 + dumpmaps = 0;
64 daemon_check = 1;
65
66 opterr = 0;
67 - while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:CF", long_options, NULL)) != EOF) {
68 + while ((opt = getopt_long(argc, argv, "+hp:t:vmdD:fVrO:l:n:CF", long_options, NULL)) != EOF) {
69 switch (opt) {
70 case 'h':
71 usage();
72 @@ -1902,6 +1905,10 @@ int main(int argc, char *argv[])
73 global_negative_timeout = getnumopt(optarg, opt);
74 break;
75
76 + case 'm':
77 + dumpmaps = 1;
78 + break;
79 +
80 case 'O':
81 if (!have_global_options) {
82 global_options = strdup(optarg);
83 @@ -1988,7 +1995,8 @@ int main(int argc, char *argv[])
84 }
85 #endif
86
87 - if (!query_kproto_ver() || get_kver_major() < 5) {
88 + /* Don't need the kernel module just to look at the configured maps */
89 + if (!dumpmaps && (!query_kproto_ver() || get_kver_major() < 5)) {
90 fprintf(stderr,
91 "%s: test mount forbidden or "
92 "incorrect kernel protocol version, "
93 @@ -2001,34 +2009,50 @@ int main(int argc, char *argv[])
94 rlim.rlim_max = MAX_OPEN_FILES;
95 res = setrlimit(RLIMIT_NOFILE, &rlim);
96 if (res)
97 - warn(logging,
98 - "can't increase open file limit - continuing");
99 + printf("%s: can't increase open file limit - continuing",
100 + argv[0]);
101
102 #if ENABLE_CORES
103 rlim.rlim_cur = RLIM_INFINITY;
104 rlim.rlim_max = RLIM_INFINITY;
105 res = setrlimit(RLIMIT_CORE, &rlim);
106 if (res)
107 - warn(logging,
108 - "can't increase core file limit - continuing");
109 + printf("%s: can't increase core file limit - continuing",
110 + argv[0]);
111 #endif
112
113 - become_daemon(foreground, daemon_check);
114 -
115 if (argc == 0)
116 master_list = master_new(NULL, timeout, ghost);
117 else
118 master_list = master_new(argv[0], timeout, ghost);
119
120 if (!master_list) {
121 - logerr("%s: can't create master map %s",
122 - program, argv[0]);
123 - res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
124 - close(start_pipefd[1]);
125 - release_flag_file();
126 + printf("%s: can't create master map %s", program, argv[0]);
127 exit(1);
128 }
129
130 + if (dumpmaps) {
131 + struct mapent_cache *nc;
132 +
133 + open_log();
134 +
135 + master_init_scan();
136 +
137 + nc = cache_init_null_cache(master_list);
138 + if (!nc) {
139 + printf("%s: failed to init null map cache for %s",
140 + master_list->name, argv[0]);
141 + exit(1);
142 + }
143 + master_list->nc = nc;
144 +
145 + lookup_nss_read_master(master_list, 0);
146 + master_show_mounts(master_list);
147 + exit(0);
148 + }
149 +
150 + become_daemon(foreground, daemon_check);
151 +
152 if (pthread_attr_init(&th_attr)) {
153 logerr("%s: failed to init thread attribute struct!",
154 program);
155 diff --git a/include/log.h b/include/log.h
156 index 6a4a942..7a394cb 100644
157 --- a/include/log.h
158 +++ b/include/log.h
159 @@ -35,6 +35,7 @@ extern void set_log_verbose_ap(struct autofs_point *ap);
160 extern void set_log_debug_ap(struct autofs_point *ap);
161 extern void set_mnt_logging(unsigned global_logopt);
162
163 +extern void open_log(void);
164 extern void log_to_syslog(void);
165 extern void log_to_stderr(void);
166
167 diff --git a/include/master.h b/include/master.h
168 index 0d6aa82..bef59d3 100644
169 --- a/include/master.h
170 +++ b/include/master.h
171 @@ -110,6 +110,7 @@ int master_submount_list_empty(struct autofs_point *ap);
172 int master_notify_submount(struct autofs_point *, const char *path, enum states);
173 void master_notify_state_change(struct master *, int);
174 int master_mount_mounts(struct master *, time_t, int);
175 +int master_show_mounts(struct master *);
176 extern inline unsigned int master_get_logopt(void);
177 int master_list_empty(struct master *);
178 int master_done(struct master *);
179 diff --git a/lib/log.c b/lib/log.c
180 index 46220fd..832add7 100644
181 --- a/lib/log.c
182 +++ b/lib/log.c
183 @@ -193,17 +193,23 @@ void logmsg(const char *msg, ...)
184 return;
185 }
186
187 -void log_to_syslog(void)
188 +void open_log(void)
189 {
190 - char buf[MAX_ERR_BUF];
191 - int nullfd;
192 -
193 if (!syslog_open) {
194 syslog_open = 1;
195 openlog("automount", LOG_PID, LOG_DAEMON);
196 }
197
198 logging_to_syslog = 1;
199 + return;
200 +}
201 +
202 +void log_to_syslog(void)
203 +{
204 + char buf[MAX_ERR_BUF];
205 + int nullfd;
206 +
207 + open_log();
208
209 /* Redirect all our file descriptors to /dev/null */
210 nullfd = open("/dev/null", O_RDWR);
211 diff --git a/lib/master.c b/lib/master.c
212 index ebeccce..ad3aa77 100644
213 --- a/lib/master.c
214 +++ b/lib/master.c
215 @@ -30,6 +30,7 @@
216 /* The root of the map entry tree */
217 struct master *master_list = NULL;
218
219 +extern const char *global_options;
220 extern long global_negative_timeout;
221
222 /* Attribute to create a joinable thread */
223 @@ -1189,6 +1190,131 @@ int master_mount_mounts(struct master *master, time_t age, int readall)
224 return 1;
225 }
226
227 +/* The nss source instances end up in reverse order. */
228 +static void list_source_instances(struct map_source *source, struct map_source *instance)
229 +{
230 + if (!source || !instance) {
231 + printf("none");
232 + return;
233 + }
234 +
235 + if (instance->next)
236 + list_source_instances(source, instance->next);
237 +
238 + /*
239 + * For convienience we map nss instance type "files" to "file".
240 + * Check for that and report corrected instance type.
241 + */
242 + if (strcmp(instance->type, "file"))
243 + printf("%s ", instance->type);
244 + else {
245 + if (source->argv && *(source->argv[0]) != '/')
246 + printf("files ");
247 + else
248 + printf("%s ", instance->type);
249 + }
250 +
251 + return;
252 +}
253 +
254 +int master_show_mounts(struct master *master)
255 +{
256 + struct list_head *p, *head;
257 +
258 + printf("\nautofs dump map information\n"
259 + "===========================\n\n");
260 +
261 + printf("global options: ");
262 + if (!global_options)
263 + printf("none configured\n");
264 + else {
265 + printf("%s\n", global_options);
266 + unsigned int append_options = defaults_get_append_options();
267 + const char *append = append_options ? "will" : "will not";
268 + printf("global options %s be appended to map entries\n", append);
269 + }
270 +
271 + if (list_empty(&master->mounts)) {
272 + printf("no master map entries found\n\n");
273 + return 1;
274 + }
275 +
276 + head = &master->mounts;
277 + p = head->next;
278 + while (p != head) {
279 + struct map_source *source;
280 + struct master_mapent *this;
281 + struct autofs_point *ap;
282 + time_t now = time(NULL);
283 + int i;
284 +
285 + this = list_entry(p, struct master_mapent, list);
286 + p = p->next;
287 +
288 + ap = this->ap;
289 +
290 + printf("\nMount point: %s\n", ap->path);
291 + printf("\nsource(s):\n");
292 +
293 + /* Read the map content into the cache */
294 + if (lookup_nss_read_map(ap, NULL, now))
295 + lookup_prune_cache(ap, now);
296 + else {
297 + printf(" failed to read map\n\n");
298 + continue;
299 + }
300 +
301 + if (!this->maps) {
302 + printf(" no map sources found\n\n");
303 + continue;
304 + }
305 +
306 + source = this->maps;
307 + while (source) {
308 + struct mapent *me;
309 +
310 + if (source->type)
311 + printf("\n type: %s\n", source->type);
312 + else {
313 + printf("\n instance type(s): ");
314 + list_source_instances(source, source->instance);
315 + printf("\n");
316 + }
317 +
318 + if (source->argc >= 1) {
319 + i = 0;
320 + if (source->argv[0] && *source->argv[0] != '-') {
321 + printf(" map: %s\n", source->argv[0]);
322 + i = 1;
323 + }
324 + if (source->argc > 1) {
325 + printf(" arguments: ");
326 + for (; i < source->argc; i++)
327 + printf("%s ", source->argv[i]);
328 + printf("\n");
329 + }
330 + }
331 +
332 + printf("\n");
333 +
334 + me = cache_lookup_first(source->mc);
335 + if (!me)
336 + printf(" no keys found in map\n");
337 + else {
338 + do {
339 + printf(" %s | %s\n", me->key, me->mapent);
340 + } while ((me = cache_lookup_next(source->mc, me)));
341 + }
342 +
343 + source = source->next;
344 + }
345 +
346 + printf("\n");
347 + }
348 +
349 + return 1;
350 +}
351 +
352 int master_list_empty(struct master *master)
353 {
354 int res = 0;
355 diff --git a/man/automount.8 b/man/automount.8
356 index 18f74bf..d57ecba 100644
357 --- a/man/automount.8
358 +++ b/man/automount.8
359 @@ -57,6 +57,9 @@ Run the daemon in the forground and log to stderr instead of syslog."
360 Enables the use of ramdom selection when choosing a host from a
361 list of replicated servers.
362 .TP
363 +.I "\-m, \-\-dumpmaps"
364 +Dump configured automounter maps, then exit.
365 +.TP
366 .I "\-O, \-\-global-options"
367 Allows the specification of global mount options used for all master
368 map entries. These options will either replace or be appened to options

  ViewVC Help
Powered by ViewVC 1.1.30