]> git.pld-linux.org Git - packages/autofs.git/blob - autofs-5.0.2-dynamic-logging.patch
- rel.1, lets try
[packages/autofs.git] / autofs-5.0.2-dynamic-logging.patch
1 diff --git a/CHANGELOG b/CHANGELOG
2 index ca171a4..a7ac9fb 100644
3 --- a/CHANGELOG
4 +++ b/CHANGELOG
5 @@ -35,6 +35,7 @@
6  - fix typo in autofs(5) man page.
7  - fix map entry expansion when undefined macro is present.
8  - remove unused export validation code.
9 +- add dynamic logging (adapted from v4 patch from Jeff Moyer).
10  
11  18/06/2007 autofs-5.0.2
12  -----------------------
13 diff --git a/daemon/automount.c b/daemon/automount.c
14 index 70a3b9d..9ec6923 100644
15 --- a/daemon/automount.c
16 +++ b/daemon/automount.c
17 @@ -173,7 +173,7 @@ int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev)
18                  */
19                 memset(&st, 0, sizeof(st));
20                 if (lstat(buf, &st) != 0) {
21 -                       crit(ap->logopt, "lstat of %s failed.", buf);
22 +                       crit(ap->logopt, "lstat of %s failed", buf);
23                         return -1;
24                 }
25  
26 @@ -234,14 +234,15 @@ int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev)
27  /* Like ftw, except fn gets called twice: before a directory is
28     entered, and after.  If the before call returns 0, the directory
29     isn't entered. */
30 -static int walk_tree(const char *base, int (*fn) (const char *file,
31 +static int walk_tree(const char *base, int (*fn) (unsigned logopt,
32 +                                                 const char *file,
33                                                   const struct stat * st,
34 -                                                 int, void *), int incl, void *arg)
35 +                                                 int, void *), int incl, unsigned logopt, void *arg)
36  {
37         char buf[PATH_MAX + 1];
38         struct stat st;
39  
40 -       if (lstat(base, &st) != -1 && (fn) (base, &st, 0, arg)) {
41 +       if (lstat(base, &st) != -1 && (fn) (logopt, base, &st, 0, arg)) {
42                 if (S_ISDIR(st.st_mode)) {
43                         struct dirent **de;
44                         int n;
45 @@ -269,18 +270,18 @@ static int walk_tree(const char *base, int (*fn) (const char *file,
46                                         return -1;
47                                 }
48  
49 -                               walk_tree(buf, fn, 1, arg);
50 +                               walk_tree(buf, fn, 1, logopt, arg);
51                                 free(de[n]);
52                         }
53                         free(de);
54                 }
55                 if (incl)
56 -                       (fn) (base, &st, 1, arg);
57 +                       (fn) (logopt, base, &st, 1, arg);
58         }
59         return 0;
60  }
61  
62 -static int rm_unwanted_fn(const char *file, const struct stat *st, int when, void *arg)
63 +static int rm_unwanted_fn(unsigned logopt, const char *file, const struct stat *st, int when, void *arg)
64  {
65         dev_t dev = *(dev_t *) arg;
66         char buf[MAX_ERR_BUF];
67 @@ -293,41 +294,38 @@ static int rm_unwanted_fn(const char *file, const struct stat *st, int when, voi
68         }
69  
70         if (lstat(file, &newst)) {
71 -               crit(LOGOPT_ANY,
72 -                    "unable to stat file, possible race condition");
73 +               crit(logopt, "unable to stat file, possible race condition");
74                 return 0;
75         }
76  
77         if (newst.st_dev != dev) {
78 -               crit(LOGOPT_ANY,
79 -                    "file %s has the wrong device, possible race condition",
80 +               crit(logopt, "file %s has the wrong device, possible race condition",
81                      file);
82                 return 0;
83         }
84  
85         if (S_ISDIR(newst.st_mode)) {
86 -               debug(LOGOPT_ANY, "removing directory %s", file);
87 +               debug(logopt, "removing directory %s", file);
88                 if (rmdir(file)) {
89                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
90 -                       warn(LOGOPT_ANY,
91 +                       warn(logopt,
92                               "unable to remove directory %s: %s", file, estr);
93                         return 0;
94                 }
95         } else if (S_ISREG(newst.st_mode)) {
96 -               crit(LOGOPT_ANY,
97 -                    "attempting to remove files from a mounted "
98 +               crit(logopt, "attempting to remove files from a mounted "
99                      "directory. file %s", file);
100                 return 0;
101         } else if (S_ISLNK(newst.st_mode)) {
102 -               debug(LOGOPT_ANY, "removing symlink %s", file);
103 +               debug(logopt, "removing symlink %s", file);
104                 unlink(file);
105         }
106         return 1;
107  }
108  
109 -void rm_unwanted(const char *path, int incl, dev_t dev)
110 +void rm_unwanted(unsigned logopt, const char *path, int incl, dev_t dev)
111  {
112 -       walk_tree(path, rm_unwanted_fn, incl, &dev);
113 +       walk_tree(path, rm_unwanted_fn, incl, logopt, &dev);
114  }
115  
116  struct counter_args {
117 @@ -335,7 +333,7 @@ struct counter_args {
118         dev_t dev;
119  };
120  
121 -static int counter_fn(const char *file, const struct stat *st, int when, void *arg)
122 +static int counter_fn(unsigned logopt, const char *file, const struct stat *st, int when, void *arg)
123  {
124         struct counter_args *counter = (struct counter_args *) arg;
125  
126 @@ -349,14 +347,14 @@ static int counter_fn(const char *file, const struct stat *st, int when, void *a
127  }
128  
129  /* Count mounted filesystems and symlinks */
130 -int count_mounts(const char *path, dev_t dev)
131 +int count_mounts(unsigned logopt, const char *path, dev_t dev)
132  {
133         struct counter_args counter;
134  
135         counter.count = 0;
136         counter.dev = dev;
137         
138 -       if (walk_tree(path, counter_fn, 0, &counter) == -1)
139 +       if (walk_tree(path, counter_fn, 0, logopt, &counter) == -1)
140                 return -1;
141  
142         return counter.count;
143 @@ -368,9 +366,9 @@ static void check_rm_dirs(struct autofs_point *ap, const char *path, int incl)
144             (ap->state == ST_SHUTDOWN_PENDING ||
145              ap->state == ST_SHUTDOWN_FORCE ||
146              ap->state == ST_SHUTDOWN))
147 -               rm_unwanted(path, incl, ap->dev);
148 +               rm_unwanted(ap->logopt, path, incl, ap->dev);
149         else if (ap->ghost && (ap->type == LKP_INDIRECT))
150 -               rm_unwanted(path, 0, ap->dev);
151 +               rm_unwanted(ap->logopt, path, 0, ap->dev);
152  }
153  
154  /* Try to purge cache entries kept around due to existing mounts */
155 @@ -466,7 +464,7 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
156                 cache_multi_lock(me->parent);
157                 if (umount_multi_triggers(ap, root, me, base)) {
158                         warn(ap->logopt,
159 -                            "could not umount some offsets under %s", path);
160 +                            "some offset mounts still present under %s", path);
161                         left++;
162                 }
163                 cache_multi_unlock(me->parent);
164 @@ -483,7 +481,7 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
165          * it already to ensure it's ok to remove any offset triggers.
166          */
167         if (!is_mm_root && is_mounted(_PATH_MOUNTED, path, MNTS_REAL)) {
168 -               msg("unmounting dir = %s", path);
169 +               info(ap->logopt, "unmounting dir = %s", path);
170                 if (umount_ent(ap, path)) {
171                         warn(ap->logopt, "could not umount dir %s", path);
172                         left++;
173 @@ -576,35 +574,35 @@ int umount_autofs(struct autofs_point *ap, int force)
174         return ret;
175  }
176  
177 -int send_ready(int ioctlfd, unsigned int wait_queue_token)
178 +int send_ready(unsigned logopt, int ioctlfd, unsigned int wait_queue_token)
179  {
180         char buf[MAX_ERR_BUF];
181  
182         if (wait_queue_token == 0)
183                 return 0;
184  
185 -       debug(LOGOPT_NONE, "token = %d", wait_queue_token);
186 +       debug(logopt, "token = %d", wait_queue_token);
187  
188         if (ioctl(ioctlfd, AUTOFS_IOC_READY, wait_queue_token) < 0) {
189                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
190 -               error(LOGOPT_ANY, "AUTOFS_IOC_READY: error %s", estr);
191 +               logerr("AUTOFS_IOC_READY: error %s", estr);
192                 return 1;
193         }
194         return 0;
195  }
196  
197 -int send_fail(int ioctlfd, unsigned int wait_queue_token)
198 +int send_fail(unsigned logopt, int ioctlfd, unsigned int wait_queue_token)
199  {
200         char buf[MAX_ERR_BUF];
201  
202         if (wait_queue_token == 0)
203                 return 0;
204  
205 -       debug(LOGOPT_NONE, "token = %d", wait_queue_token);
206 +       debug(logopt, "token = %d", wait_queue_token);
207  
208         if (ioctl(ioctlfd, AUTOFS_IOC_FAIL, wait_queue_token) < 0) {
209                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
210 -               error(LOGOPT_ANY, "AUTOFS_IOC_FAIL: error %s", estr);
211 +               logerr("AUTOFS_IOC_FAIL: error %s", estr);
212                 return 1;
213         }
214         return 0;
215 @@ -649,23 +647,245 @@ static int fullread(int fd, void *ptr, size_t len)
216         return len;
217  }
218  
219 +static char *automount_path_to_fifo(unsigned logopt, const char *path)
220 +{
221 +       char *fifo_name, *p;
222 +       int  name_len = strlen(path) + strlen(AUTOFS_LOGPRI_FIFO) + 1;
223 +       int ret;
224 +
225 +       fifo_name = malloc(name_len);
226 +       if (!fifo_name)
227 +               return NULL;
228 +       ret = snprintf(fifo_name, name_len, "%s%s",
229 +                      AUTOFS_LOGPRI_FIFO, path);
230 +       if (ret >= name_len) {
231 +               info(logopt,
232 +                    "fifo path for \"%s\" truncated to \"%s\".  This may "
233 +                    "lead to --set-log-priority commands being sent to the "
234 +                    "wrong automount daemon.", path, fifo_name);
235 +       }
236 +
237 +       /*
238 +        *  An automount path can be made up of subdirectories.  So, to
239 +        *  create the fifo name, we will just replace instances of '/' with
240 +        *  '-'. 
241 +        */
242 +       p = fifo_name + strlen(AUTOFS_LOGPRI_FIFO);
243 +       while (*p != '\0') {
244 +               if (*p == '/')
245 +                       *p = '-';
246 +               p++;
247 +       }
248 +
249 +       debug(logopt, "fifo name %s",fifo_name);
250 +
251 +       return fifo_name;
252 +}
253 +
254 +static int create_logpri_fifo(struct autofs_point *ap)
255 +{
256 +       int ret = -1;
257 +       int fd;
258 +       char *fifo_name;
259 +
260 +       fifo_name = automount_path_to_fifo(ap->logopt, ap->path);
261 +       if (!fifo_name) {
262 +               crit(ap->logopt, "Failed to allocate memory!");
263 +               goto out_free; /* free(NULL) is okay */
264 +       }
265 +
266 +       ret = unlink(fifo_name);
267 +       if (ret != 0 && errno != ENOENT) {
268 +               crit(ap->logopt,
269 +                    "Failed to unlink FIFO. Is the automount daemon "
270 +                    "already running?");
271 +               goto out_free;
272 +       }
273 +
274 +       ret = mkfifo(fifo_name, S_IRUSR|S_IWUSR);
275 +       if (ret != 0) {
276 +               crit(ap->logopt,
277 +                    "mkfifo for %s returned %d", fifo_name, errno);
278 +               goto out_free;
279 +       }
280 +
281 +       fd = open(fifo_name, O_RDWR|O_NONBLOCK);
282 +       if (fd < 0) {
283 +               crit(ap->logopt,
284 +                    "Failed to open %s, errno %d", fifo_name, errno);
285 +               goto out_free;
286 +       }
287 +
288 +       ap->logpri_fifo = fd;
289 +
290 +out_free:
291 +       free(fifo_name);
292 +       return ret;
293 +}
294 +
295 +static int destroy_logpri_fifo(struct autofs_point *ap)
296 +{
297 +       int ret = -1;
298 +       int fd = ap->logpri_fifo;
299 +       char *fifo_name;
300 +
301 +       fifo_name = automount_path_to_fifo(ap->logopt, ap->path);
302 +       if (!fifo_name) {
303 +               crit(ap->logopt, "Failed to allocate memory!");
304 +               goto out_free; /* free(NULL) is okay */
305 +       }
306 +
307 +       ap->logpri_fifo = -1;
308 +
309 +       ret = close(fd);
310 +       if (ret != 0) {
311 +               warn(ap->logopt,
312 +                    "close for fifo %s returned %d", fifo_name, errno);
313 +       }
314 +
315 +       ret = unlink(fifo_name);
316 +       if (ret != 0) {
317 +               warn(ap->logopt,
318 +                    "Failed to unlink FIFO. Was the fifo created OK?");
319 +       }
320 +
321 +out_free:
322 +       free(fifo_name);
323 +       return ret;
324 +}
325 +
326 +static void handle_fifo_message(struct autofs_point *ap, int fd)
327 +{
328 +       int ret;
329 +       char buffer[PIPE_BUF];
330 +       char *end;
331 +       long pri;
332 +
333 +       memset(buffer, 0, sizeof(buffer));
334 +       ret = read(fd, &buffer, sizeof(buffer));
335 +       if (ret < 0) {
336 +               warn(ap->logopt, "read on fifo returned error %d", errno);
337 +               return;
338 +       }
339 +
340 +       if (ret != 2) {
341 +               debug(ap->logopt, "expected 2 bytes, received %d.", ret);
342 +               return;
343 +       }
344 +
345 +       errno = 0;
346 +       pri = strtol(buffer, &end, 10);
347 +       if ((pri == LONG_MIN || pri == LONG_MAX) && errno == ERANGE) {
348 +               debug(ap->logopt, "strtol reported an %s.  Failed to set "
349 +                     "log priority.", pri == LONG_MIN ? "underflow" : "overflow");
350 +               return;
351 +       }
352 +       if ((pri == 0 && errno == EINVAL) || end == buffer) {
353 +               debug(ap->logopt, "priority is expected to be an integer "
354 +                     "in the range 0-7 inclusive.");
355 +               return;
356 +       }
357 +
358 +       if (pri > LOG_DEBUG || pri < LOG_EMERG) {
359 +               debug(ap->logopt, "invalid log priority (%ld) received "
360 +                     "on fifo", pri);
361 +               return;
362 +       }
363 +
364 +       /*
365 +        * OK, the message passed all of the sanity checks.  The
366 +        * automounter actually only supports three log priorities.
367 +        * Everything is logged at log level debug, deamon messages
368 +        * and everything except debug messages are logged with the
369 +        * verbose setting and only error and critical messages are
370 +        * logged when debugging isn't enabled.
371 +        */
372 +       if (pri >= LOG_WARNING) {
373 +               if (pri == LOG_DEBUG) {
374 +                       set_log_debug_ap(ap);
375 +                       info(ap->logopt, "Debug logging set for %s", ap->path);
376 +               } else {
377 +                       set_log_verbose_ap(ap);
378 +                       info(ap->logopt, "Verbose logging set for %s", ap->path);
379 +               }
380 +       } else {
381 +               if (ap->logopt & LOGOPT_ANY)
382 +                       info(ap->logopt, "Basic logging set for %s", ap->path);
383 +               set_log_norm_ap(ap);
384 +       }
385 +}
386 +
387 +static int set_log_priority(const char *path, int priority)
388 +{
389 +       int fd;
390 +       char *fifo_name;
391 +       char buf[2];
392 +
393 +       if (priority > LOG_DEBUG || priority < LOG_EMERG) {
394 +               fprintf(stderr, "Log priority %d is invalid.\n", priority);
395 +               fprintf(stderr, "Please spcify a number in the range 0-7.\n");
396 +               return -1;
397 +       }
398 +
399 +       /*
400 +        * This is an ascii based protocol, so we want the string
401 +        * representation of the integer log priority.
402 +        */
403 +       snprintf(buf, sizeof(buf), "%d", priority);
404 +
405 +       fifo_name = automount_path_to_fifo(LOGOPT_NONE, path);
406 +       if (!fifo_name) {
407 +               fprintf(stderr, "%s: Failed to allocate memory!\n",
408 +                       __FUNCTION__);
409 +               return -1;
410 +       }
411 +
412 +       /*
413 +        * Specify O_NONBLOCK so that the open will fail if there is no
414 +        * daemon reading from the other side of the FIFO.
415 +        */
416 +       fd = open(fifo_name, O_WRONLY|O_NONBLOCK);
417 +       if (fd < 0) {
418 +               fprintf(stderr, "%s: open of %s failed with %d\n",
419 +                       __FUNCTION__, fifo_name, errno);
420 +               free(fifo_name);
421 +               return -1;
422 +       }
423 +
424 +       if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
425 +               fprintf(stderr, "Failed to change logging priority.  ");
426 +               fprintf(stderr, "write to fifo failed with errno %d.\n",
427 +                       errno);
428 +               close(fd);
429 +               free(fifo_name);
430 +               return -1;
431 +       }
432 +       close(fd);
433 +       free(fifo_name);
434 +       fprintf(stdout, "Successfully set log priority for %s.\n", path);
435 +
436 +       return 0;
437 +}
438 +
439  static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
440  {
441 -       struct pollfd fds[2];
442 +       struct pollfd fds[3];
443         char buf[MAX_ERR_BUF];
444  
445         fds[0].fd = ap->pipefd;
446         fds[0].events = POLLIN;
447         fds[1].fd = ap->state_pipe[0];
448         fds[1].events = POLLIN;
449 +       fds[2].fd = ap->logpri_fifo;
450 +       fds[2].events = POLLIN;
451  
452         for (;;) {
453 -               if (poll(fds, 2, -1) == -1) {
454 +               if (poll(fds, 3, -1) == -1) {
455                         char *estr;
456                         if (errno == EINTR)
457                                 continue;
458                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
459 -                       error(ap->logopt, "poll failed: %s", estr);
460 +                       logerr("poll failed: %s", estr);
461                         return -1;
462                 }
463  
464 @@ -709,6 +929,11 @@ static int get_pkt(struct autofs_point *ap, union autofs_packet_union *pkt)
465  
466                 if (fds[0].revents & POLLIN)
467                         return fullread(ap->pipefd, pkt, kpkt_len);
468 +
469 +               if (fds[2].revents & POLLIN) {
470 +                       debug(ap->logopt, "message pending on control fifo.");
471 +                       handle_fifo_message(ap, fds[2].fd);
472 +               }
473         }
474  }
475  
476 @@ -730,21 +955,93 @@ int do_expire(struct autofs_point *ap, const char *name, int namelen)
477                 return 1;
478         }
479  
480 -       msg("expiring path %s", buf);
481 +       info(ap->logopt, "expiring path %s", buf);
482  
483         ret = umount_multi(ap, buf, 1);
484         if (ret == 0)
485 -               msg("expired %s", buf);
486 +               info(ap->logopt, "expired %s", buf);
487         else
488                 warn(ap->logopt, "couldn't complete expire of %s", buf);
489  
490         return ret;
491  }
492  
493 +static int autofs_init_ap(struct autofs_point *ap)
494 +{
495 +       int pipefd[2], cl_flags;
496 +
497 +       if ((ap->state != ST_INIT)) {
498 +               /* This can happen if an autofs process is already running*/
499 +               error(ap->logopt, "bad state %d", ap->state);
500 +               return -1;
501 +       }
502 +
503 +       ap->pipefd = ap->kpipefd = ap->ioctlfd = -1;
504 +
505 +       /* Pipe for kernel communications */
506 +       if (pipe(pipefd) < 0) {
507 +               crit(ap->logopt,
508 +                    "failed to create commumication pipe for autofs path %s",
509 +                    ap->path);
510 +               free(ap->path);
511 +               return -1;
512 +       }
513 +
514 +       ap->pipefd = pipefd[0];
515 +       ap->kpipefd = pipefd[1];
516 +
517 +       if ((cl_flags = fcntl(ap->pipefd, F_GETFD, 0)) != -1) {
518 +               cl_flags |= FD_CLOEXEC;
519 +               fcntl(ap->pipefd, F_SETFD, cl_flags);
520 +       }
521 +
522 +       if ((cl_flags = fcntl(ap->kpipefd, F_GETFD, 0)) != -1) {
523 +               cl_flags |= FD_CLOEXEC;
524 +               fcntl(ap->kpipefd, F_SETFD, cl_flags);
525 +       }
526 +
527 +       /* Pipe state changes from signal handler to main loop */
528 +       if (pipe(ap->state_pipe) < 0) {
529 +               crit(ap->logopt,
530 +                    "failed create state pipe for autofs path %s", ap->path);
531 +               close(ap->pipefd);
532 +               close(ap->kpipefd);     /* Close kernel pipe end */
533 +               free(ap->path);
534 +               return -1;
535 +       }
536 +
537 +       if ((cl_flags = fcntl(ap->state_pipe[0], F_GETFD, 0)) != -1) {
538 +               cl_flags |= FD_CLOEXEC;
539 +               fcntl(ap->state_pipe[0], F_SETFD, cl_flags);
540 +       }
541 +
542 +       if ((cl_flags = fcntl(ap->state_pipe[1], F_GETFD, 0)) != -1) {
543 +               cl_flags |= FD_CLOEXEC;
544 +               fcntl(ap->state_pipe[1], F_SETFD, cl_flags);
545 +       }
546 +
547 +       if (create_logpri_fifo(ap) < 0) {
548 +               crit(ap->logopt,
549 +                    "failed to create FIFO for path %s\n", ap->path);
550 +               destroy_logpri_fifo(ap);
551 +               close(ap->pipefd);
552 +               close(ap->kpipefd);
553 +               free(ap->path);
554 +               close(ap->state_pipe[0]);
555 +               close(ap->state_pipe[1]);
556 +               return -1;
557 +       }
558 +
559 +       return 0;
560 +}
561 +
562  static int mount_autofs(struct autofs_point *ap)
563  {
564         int status = 0;
565  
566 +       if (autofs_init_ap(ap) != 0)
567 +               return -1;
568 +
569         if (ap->type == LKP_DIRECT)
570                 status = mount_autofs_direct(ap);
571         else
572 @@ -841,9 +1138,8 @@ static void become_daemon(unsigned foreground)
573                         fclose(pidfp);
574                 } else {
575                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
576 -                       warn(LOGOPT_ANY,
577 -                            "failed to write pid file %s: %s",
578 -                            pid_file, estr);
579 +                       logerr("failed to write pid file %s: %s",
580 +                              pid_file, estr);
581                         pid_file = NULL;
582                 }
583         }
584 @@ -889,12 +1185,12 @@ static void *do_notify_state(void *arg)
585  
586         master = mrc.master;
587  
588 -       debug(master->default_logging, "signal %d", sig);
589 +       debug(master->logopt, "signal %d", sig);
590  
591         mrc.signaled = 1;
592         status = pthread_cond_signal(&mrc.cond);
593         if (status) {
594 -               error(master->default_logging,
595 +               error(master->logopt,
596                       "failed to signal state notify condition");
597                 status = pthread_mutex_unlock(&mrc.mutex);
598                 if (status)
599 @@ -923,7 +1219,7 @@ static pthread_t do_signals(struct master *master, int sig)
600  
601         status = pthread_create(&thid, &thread_attr, do_notify_state, &r_sig);
602         if (status) {
603 -               error(master->default_logging,
604 +               error(master->logopt,
605                       "mount state notify thread create failed");
606                 status = pthread_mutex_unlock(&mrc.mutex);
607                 if (status)
608 @@ -951,6 +1247,7 @@ static pthread_t do_signals(struct master *master, int sig)
609  static void *do_read_master(void *arg)
610  {
611         struct master *master;
612 +       unsigned int logopt;
613         time_t age;
614         int readall = 1;
615         int status;
616 @@ -961,11 +1258,12 @@ static void *do_read_master(void *arg)
617  
618         master = mrc.master;
619         age = mrc.age;
620 +       logopt = master->logopt;
621  
622         mrc.signaled = 1;
623         status = pthread_cond_signal(&mrc.cond);
624         if (status) {
625 -               error(master->default_logging,
626 +               error(logopt,
627                       "failed to signal master read map condition");
628                 master->reading = 0;
629                 status = pthread_mutex_unlock(&mrc.mutex);
630 @@ -989,6 +1287,7 @@ static void *do_read_master(void *arg)
631  
632  static int do_hup_signal(struct master *master, time_t age)
633  {
634 +       unsigned int logopt = master->logopt;
635         pthread_t thid;
636         int status;
637  
638 @@ -1007,7 +1306,7 @@ static int do_hup_signal(struct master *master, time_t age)
639  
640         status = pthread_create(&thid, &thread_attr, do_read_master, NULL);
641         if (status) {
642 -               error(master->default_logging,
643 +               error(logopt,
644                       "master read map thread create failed");
645                 master->reading = 0;
646                 status = pthread_mutex_unlock(&mrc.mutex);
647 @@ -1062,8 +1361,7 @@ static void *statemachine(void *arg)
648                         break;
649  
650                 default:
651 -                       error(master_list->default_logging,
652 -                             "got unexpected signal %d!", sig);
653 +                       logerr("got unexpected signal %d!", sig);
654                         continue;
655                 }
656         }
657 @@ -1134,10 +1432,11 @@ static void handle_mounts_cleanup(void *arg)
658         struct autofs_point *ap;
659         char path[PATH_MAX + 1];
660         char buf[MAX_ERR_BUF];
661 -       unsigned int clean = 0, submount;
662 +       unsigned int clean = 0, submount, logopt;
663  
664         ap = (struct autofs_point *) arg;
665  
666 +       logopt = ap->logopt;
667         submount = ap->submount;
668  
669         strcpy(path, ap->path);
670 @@ -1152,6 +1451,7 @@ static void handle_mounts_cleanup(void *arg)
671  
672         umount_autofs(ap, 1);
673  
674 +       destroy_logpri_fifo(ap);
675         master_signal_submount(ap, MASTER_SUBMNT_JOIN);
676         master_remove_mapent(ap->entry);
677         master_free_mapent_sources(ap->entry, 1);
678 @@ -1162,12 +1462,12 @@ static void handle_mounts_cleanup(void *arg)
679         if (clean) {
680                 if (rmdir(path) == -1) {
681                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
682 -                       warn(LOGOPT_NONE, "failed to remove dir %s: %s",
683 +                       warn(logopt, "failed to remove dir %s: %s",
684                              path, estr);
685                 }
686         }
687  
688 -       msg("shut down path %s", path);
689 +       info(logopt, "shut down path %s", path);
690  
691         /* If we are the last tell the state machine to shutdown */
692         if (!submount && master_list_empty(master_list))
693 @@ -1190,7 +1490,7 @@ void *handle_mounts(void *arg)
694  
695         status = pthread_mutex_lock(&suc.mutex);
696         if (status) {
697 -               crit(ap->logopt, "failed to lock startup condition mutex!");
698 +               logerr("failed to lock startup condition mutex!");
699                 fatal(status);
700         }
701  
702 @@ -1204,7 +1504,7 @@ void *handle_mounts(void *arg)
703         }
704  
705         if (ap->ghost && ap->type != LKP_DIRECT)
706 -               msg("ghosting enabled");
707 +               info(ap->logopt, "ghosting enabled");
708  
709         suc.status = 0;
710         pthread_cleanup_pop(1);
711 @@ -1356,6 +1656,8 @@ static void usage(void)
712                 "                       use ramdom replicated server selection\n"
713                 "       -O --global-options\n"
714                 "                       specify global mount options\n"
715 +               "       -l --set-log-priority priority path [path,...]\n"
716 +               "                       set daemon log verbosity\n"
717                 "       -V --version    print version, build config and exit\n"
718                 , program);
719  }
720 @@ -1437,9 +1739,45 @@ static void show_build_info(void)
721         return;
722  }
723  
724 +typedef struct _code {
725 +       char    *c_name;
726 +       int     c_val;
727 +} CODE;
728 +
729 +CODE prioritynames[] = {
730 +       { "alert",      LOG_ALERT },
731 +       { "crit",       LOG_CRIT },
732 +       { "debug",      LOG_DEBUG },
733 +       { "emerg",      LOG_EMERG },
734 +       { "err",        LOG_ERR },
735 +       { "error",      LOG_ERR },              /* DEPRECATED */
736 +       { "info",       LOG_INFO },
737 +       { "notice",     LOG_NOTICE },
738 +       { "panic",      LOG_EMERG },            /* DEPRECATED */
739 +       { "warn",       LOG_WARNING },          /* DEPRECATED */
740 +       { "warning",    LOG_WARNING },
741 +       { NULL,         -1 },
742 +};
743 +
744 +static int convert_log_priority(char *priority_name)
745 +{
746 +       CODE *priority_mapping;
747 +
748 +       for (priority_mapping = prioritynames;
749 +            priority_mapping->c_name != NULL;
750 +            priority_mapping++) {
751 +
752 +               if (!strcasecmp(priority_name, priority_mapping->c_name))
753 +                       return priority_mapping->c_val;
754 +       }
755 +
756 +       return -1;
757 +}
758 +
759  int main(int argc, char *argv[])
760  {
761         int res, opt, status;
762 +       int logpri = -1;
763         unsigned ghost, logging;
764         unsigned foreground, have_global_options;
765         time_t timeout;
766 @@ -1457,6 +1795,7 @@ int main(int argc, char *argv[])
767                 {"random-multimount-selection", 0, 0, 'r'},
768                 {"global-options", 1, 0, 'O'},
769                 {"version", 0, 0, 'V'},
770 +               {"set-log-priority", 1, 0, 'l'},
771                 {0, 0, 0, 0}
772         };
773  
774 @@ -1477,7 +1816,7 @@ int main(int argc, char *argv[])
775         foreground = 0;
776  
777         opterr = 0;
778 -       while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:", long_options, NULL)) != EOF) {
779 +       while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:", long_options, NULL)) != EOF) {
780                 switch (opt) {
781                 case 'h':
782                         usage();
783 @@ -1525,6 +1864,23 @@ int main(int argc, char *argv[])
784                                 program);
785                         break;
786  
787 +               case 'l':
788 +                       if (isalpha(*optarg)) {
789 +                               logpri = convert_log_priority(optarg);
790 +                               if (logpri < 0) {
791 +                                       fprintf(stderr, "Invalid log priority:"
792 +                                               " %s\n", optarg);
793 +                                       exit(1);
794 +                               }
795 +                       } else if (isdigit(*optarg)) {
796 +                               logpri = getnumopt(optarg, opt);
797 +                       } else {
798 +                               fprintf(stderr, "non-alphanumeric character "
799 +                                       "found in log priority.  Aborting.\n");
800 +                               exit(1);
801 +                       }
802 +                       break;
803 +
804                 case '?':
805                 case ':':
806                         printf("%s: Ambiguous or unknown options\n", program);
807 @@ -1548,6 +1904,26 @@ int main(int argc, char *argv[])
808         argv += optind;
809         argc -= optind;
810  
811 +       if (logpri >= 0) {
812 +               int exit_code = 0;
813 +               int i;
814 +
815 +               /*
816 +                * The remaining argv elements are the paths for which
817 +                * log priorities must be changed.
818 +                */
819 +               for (i = 0; i < argc; i++) {
820 +                       if (set_log_priority(argv[i], logpri) < 0)
821 +                               exit_code = 1;
822 +               }
823 +               if (argc < 1) {
824 +                       fprintf(stderr,
825 +                               "--set-log-priority requires a path.\n");
826 +                       exit_code = 1;
827 +               }
828 +               exit(exit_code);
829 +       }
830 +
831         if (is_automount_running() > 0) {
832                 fprintf(stderr, "%s: program is already running.\n",
833                         program);
834 @@ -1572,7 +1948,7 @@ int main(int argc, char *argv[])
835         rlim.rlim_max = MAX_OPEN_FILES;
836         res = setrlimit(RLIMIT_NOFILE, &rlim);
837         if (res)
838 -               warn(LOGOPT_NONE,
839 +               warn(logging,
840                      "can't increase open file limit - continuing");
841  
842  #if ENABLE_CORES
843 @@ -1580,7 +1956,7 @@ int main(int argc, char *argv[])
844         rlim.rlim_max = RLIM_INFINITY;
845         res = setrlimit(RLIMIT_CORE, &rlim);
846         if (res)
847 -               warn(LOGOPT_NONE,
848 +               warn(logging,
849                      "can't increase core file limit - continuing");
850  #endif
851  
852 @@ -1592,15 +1968,14 @@ int main(int argc, char *argv[])
853                 master_list = master_new(argv[0], timeout, ghost);
854  
855         if (!master_list) {
856 -               crit(LOGOPT_ANY, "%s: can't create master map %s",
857 +               logerr("%s: can't create master map %s",
858                         program, argv[0]);
859                 close(start_pipefd[1]);
860                 exit(1);
861         }
862  
863         if (pthread_attr_init(&thread_attr)) {
864 -               crit(LOGOPT_ANY,
865 -                    "%s: failed to init thread attribute struct!",
866 +               logerr("%s: failed to init thread attribute struct!",
867                      program);
868                 close(start_pipefd[1]);
869                 exit(1);
870 @@ -1608,8 +1983,7 @@ int main(int argc, char *argv[])
871  
872         if (pthread_attr_setdetachstate(
873                         &thread_attr, PTHREAD_CREATE_DETACHED)) {
874 -               crit(LOGOPT_ANY,
875 -                    "%s: failed to set detached thread attribute!",
876 +               logerr("%s: failed to set detached thread attribute!",
877                      program);
878                 close(start_pipefd[1]);
879                 exit(1);
880 @@ -1618,38 +1992,37 @@ int main(int argc, char *argv[])
881  #ifdef _POSIX_THREAD_ATTR_STACKSIZE
882         if (pthread_attr_setstacksize(
883                         &thread_attr, PTHREAD_STACK_MIN*64)) {
884 -               crit(LOGOPT_ANY,
885 -                    "%s: failed to set stack size thread attribute!",
886 -                    program);
887 +               logerr("%s: failed to set stack size thread attribute!",
888 +                      program);
889                 close(start_pipefd[1]);
890                 exit(1);
891         }
892  #endif
893  
894 -       msg("Starting automounter version %s, master map %s",
895 +       info(logging, "Starting automounter version %s, master map %s",
896                 version, master_list->name);
897 -       msg("using kernel protocol version %d.%02d",
898 +       info(logging, "using kernel protocol version %d.%02d",
899                 get_kver_major(), get_kver_minor());
900  
901         status = pthread_key_create(&key_thread_stdenv_vars,
902                                 key_thread_stdenv_vars_destroy);
903         if (status) {
904 -               crit(LOGOPT_ANY,
905 -                    "failed to create thread data key for std env vars!");
906 +               logerr("%s: failed to create thread data key for std env vars!",
907 +                      program);
908                 master_kill(master_list);
909                 close(start_pipefd[1]);
910                 exit(1);
911         }
912  
913         if (!alarm_start_handler()) {
914 -               crit(LOGOPT_ANY, "failed to create alarm handler thread!");
915 +               logerr("%s: failed to create alarm handler thread!", program);
916                 master_kill(master_list);
917                 close(start_pipefd[1]);
918                 exit(1);
919         }
920  
921         if (!st_start_handler()) {
922 -               crit(LOGOPT_ANY, "failed to create FSM handler thread!");
923 +               logerr("%s: failed to create FSM handler thread!", program);
924                 master_kill(master_list);
925                 close(start_pipefd[1]);
926                 exit(1);
927 @@ -1685,5 +2058,7 @@ int main(int argc, char *argv[])
928         if (dh)
929                 dlclose(dh);
930  #endif
931 +       info(logging, "autofs stopped");
932 +
933         exit(0);
934  }
935 diff --git a/daemon/direct.c b/daemon/direct.c
936 index 9a39a6f..4ab4204 100644
937 --- a/daemon/direct.c
938 +++ b/daemon/direct.c
939 @@ -86,61 +86,6 @@ static void mnts_cleanup(void *arg)
940         return;
941  }
942  
943 -static int autofs_init_direct(struct autofs_point *ap)
944 -{
945 -       int pipefd[2], cl_flags;
946 -
947 -       if ((ap->state != ST_INIT)) {
948 -               /* This can happen if an autofs process is already running*/
949 -               error(ap->logopt, "bad state %d", ap->state);
950 -               return -1;
951 -       }
952 -
953 -       ap->pipefd = ap->kpipefd = ap->ioctlfd = -1;
954 -
955 -       /* Pipe for kernel communications */
956 -       if (pipe(pipefd) < 0) {
957 -               crit(ap->logopt,
958 -                    "failed to create commumication pipe for autofs path %s",
959 -                    ap->path);
960 -               return -1;
961 -       }
962 -
963 -       ap->pipefd = pipefd[0];
964 -       ap->kpipefd = pipefd[1];
965 -
966 -       if ((cl_flags = fcntl(ap->pipefd, F_GETFD, 0)) != -1) {
967 -               cl_flags |= FD_CLOEXEC;
968 -               fcntl(ap->pipefd, F_SETFD, cl_flags);
969 -       }
970 -
971 -       if ((cl_flags = fcntl(ap->kpipefd, F_GETFD, 0)) != -1) {
972 -               cl_flags |= FD_CLOEXEC;
973 -               fcntl(ap->kpipefd, F_SETFD, cl_flags);
974 -       }
975 -
976 -       /* Pipe state changes from signal handler to main loop */
977 -       if (pipe(ap->state_pipe) < 0) {
978 -               crit(ap->logopt, "failed create state pipe for autofs path %s",
979 -                    ap->path);
980 -               close(ap->pipefd);
981 -               close(ap->kpipefd);
982 -               return -1;
983 -       }
984 -
985 -       if ((cl_flags = fcntl(ap->state_pipe[0], F_GETFD, 0)) != -1) {
986 -               cl_flags |= FD_CLOEXEC;
987 -               fcntl(ap->state_pipe[0], F_SETFD, cl_flags);
988 -       }
989 -
990 -       if ((cl_flags = fcntl(ap->state_pipe[1], F_GETFD, 0)) != -1) {
991 -               cl_flags |= FD_CLOEXEC;
992 -               fcntl(ap->state_pipe[1], F_SETFD, cl_flags);
993 -       }
994 -
995 -       return 0;
996 -}
997 -
998  int do_umount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me)
999  {
1000         char buf[MAX_ERR_BUF];
1001 @@ -241,10 +186,10 @@ int do_umount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, stru
1002  
1003  force_umount:
1004         if (rv != 0) {
1005 -               msg("forcing umount of direct mount %s", me->key);
1006 +               info(ap->logopt, "forcing umount of direct mount %s", me->key);
1007                 rv = umount2(me->key, MNT_DETACH);
1008         } else
1009 -               msg("umounted direct mount %s", me->key);
1010 +               info(ap->logopt, "umounted direct mount %s", me->key);
1011  
1012         if (!rv && me->dir_created) {
1013                 if  (rmdir(me->key) == -1) {
1014 @@ -326,7 +271,7 @@ static int unlink_mount_tree(struct autofs_point *ap, struct list_head *list)
1015                         continue;
1016  
1017                 if (strcmp(mnt->fs_type, "autofs"))
1018 -                       rv = spawn_umount(log_debug, "-l", mnt->path, NULL);
1019 +                       rv = spawn_umount(ap->logopt, "-l", mnt->path, NULL);
1020                 else
1021                         rv = umount2(mnt->path, MNT_DETACH);
1022                 if (rv == -1) {
1023 @@ -475,13 +420,15 @@ int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struc
1024         ioctl(ioctlfd, AUTOFS_IOC_SETTIMEOUT, &timeout);
1025  
1026         if (ap->exp_timeout)
1027 -               msg("mounted direct mount on %s "
1028 +               info(ap->logopt,
1029 +                   "mounted direct mount on %s "
1030                     "with timeout %u, freq %u seconds", me->key,
1031                     (unsigned int) ap->exp_timeout,
1032                     (unsigned int) ap->exp_runfreq);
1033         else
1034 -               msg("mounted direct mount on %s with timeouts disabled",
1035 -                   me->key);
1036 +               info(ap->logopt,
1037 +                    "mounted direct mount on %s with timeouts disabled",
1038 +                    me->key);
1039  
1040         ret = fstat(ioctlfd, &st);
1041         if (ret == -1) {
1042 @@ -522,9 +469,6 @@ int mount_autofs_direct(struct autofs_point *ap)
1043                 return -1;
1044         }
1045  
1046 -       if (autofs_init_direct(ap))
1047 -               return -1;
1048 -
1049         /* TODO: check map type */
1050         if (lookup_nss_read_map(ap, NULL, now))
1051                 lookup_prune_cache(ap, now);
1052 @@ -607,7 +551,7 @@ int umount_autofs_offset(struct autofs_point *ap, struct mapent *me)
1053                 /* offset isn't mounted, return success and try to recover */
1054                 if (!is_mounted(_PROC_MOUNTS, me->key, MNTS_AUTOFS)) {
1055                         debug(ap->logopt,
1056 -                             "offset %s unexpectedly not mounted",
1057 +                             "offset %s not mounted",
1058                               me->key);
1059                         return 0;
1060                 }
1061 @@ -627,7 +571,7 @@ int umount_autofs_offset(struct autofs_point *ap, struct mapent *me)
1062                 rv = ioctl(ioctlfd, AUTOFS_IOC_ASKUMOUNT, &status);
1063                 if (rv) {
1064                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1065 -                       error(ap->logopt, "ioctl failed: %s", estr);
1066 +                       logerr("ioctl failed: %s", estr);
1067                         return 1;
1068                 } else if (!status) {
1069                         if (ap->state != ST_SHUTDOWN_FORCE) {
1070 @@ -692,10 +636,10 @@ int umount_autofs_offset(struct autofs_point *ap, struct mapent *me)
1071  
1072  force_umount:
1073         if (rv != 0) {
1074 -               msg("forcing umount of offset mount %s", me->key);
1075 +               info(ap->logopt, "forcing umount of offset mount %s", me->key);
1076                 rv = umount2(me->key, MNT_DETACH);
1077         } else
1078 -               msg("umounted offset mount %s", me->key);
1079 +               info(ap->logopt, "umounted offset mount %s", me->key);
1080  
1081         if (!rv && me->dir_created) {
1082                 if  (rmdir(me->key) == -1) {
1083 @@ -868,7 +812,7 @@ static int expire_direct(int ioctlfd, const char *path, unsigned int when, unsig
1084                 return 0;
1085         }
1086  
1087 -       retries = (count_mounts(path, st.st_dev) + 1) * EXPIRE_RETRIES;
1088 +       retries = (count_mounts(logopt, path, st.st_dev) + 1) * EXPIRE_RETRIES;
1089  
1090         while (retries--) {
1091                 struct timespec tm = {0, 100000000};
1092 @@ -1018,7 +962,7 @@ void *expire_proc_direct(void *arg)
1093  
1094                         if (me->ioctlfd != -1 && 
1095                             fstat(ioctlfd, &st) != -1 &&
1096 -                           !count_mounts(next->path, st.st_dev)) {
1097 +                           !count_mounts(ap->logopt, next->path, st.st_dev)) {
1098                                 close(ioctlfd);
1099                                 me->ioctlfd = -1;
1100                         }
1101 @@ -1049,6 +993,9 @@ void *expire_proc_direct(void *arg)
1102         }
1103         pthread_cleanup_pop(1);
1104  
1105 +       if (left)
1106 +               info(ap->logopt, "%d remaining in %s", left, ap->path);
1107 +
1108         ec.status = left;
1109  
1110         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
1111 @@ -1072,7 +1019,7 @@ static void pending_cond_destroy(void *arg)
1112  static void expire_send_fail(void *arg)
1113  {
1114         struct pending_args *mt = arg;
1115 -       send_fail(mt->ioctlfd, mt->wait_queue_token);
1116 +       send_fail(mt->ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1117  }
1118  
1119  static void free_pending_args(void *arg)
1120 @@ -1124,14 +1071,14 @@ static void *do_expire_direct(void *arg)
1121         status = do_expire(ap, mt->name, len);
1122         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1123         if (status)
1124 -               send_fail(mt->ioctlfd, mt->wait_queue_token);
1125 +               send_fail(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1126         else {
1127                 struct mapent *me;
1128                 cache_readlock(mt->mc);
1129                 me = cache_lookup_distinct(mt->mc, mt->name);
1130                 me->ioctlfd = -1;
1131                 cache_unlock(mt->mc);
1132 -               send_ready(mt->ioctlfd, mt->wait_queue_token);
1133 +               send_ready(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1134                 close(mt->ioctlfd);
1135         }
1136         pthread_setcancelstate(state, NULL);
1137 @@ -1194,7 +1141,7 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_di
1138         if (!mt) {
1139                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1140                 error(ap->logopt, "malloc: %s", estr);
1141 -               send_fail(me->ioctlfd, pkt->wait_queue_token);
1142 +               send_fail(ap->logopt, me->ioctlfd, pkt->wait_queue_token);
1143                 cache_unlock(mc);
1144                 pthread_setcancelstate(state, NULL);
1145                 return 1;
1146 @@ -1223,7 +1170,7 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_di
1147         status = pthread_create(&thid, &thread_attr, do_expire_direct, mt);
1148         if (status) {
1149                 error(ap->logopt, "expire thread create failed");
1150 -               send_fail(mt->ioctlfd, pkt->wait_queue_token);
1151 +               send_fail(ap->logopt, mt->ioctlfd, pkt->wait_queue_token);
1152                 cache_unlock(mc);
1153                 expire_mutex_unlock(NULL);
1154                 pending_cond_destroy(mt);
1155 @@ -1252,7 +1199,7 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_di
1156  static void mount_send_fail(void *arg)
1157  {
1158         struct pending_args *mt = arg;
1159 -       send_fail(mt->ioctlfd, mt->wait_queue_token);
1160 +       send_fail(mt->ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1161         close(mt->ioctlfd);
1162  }
1163  
1164 @@ -1319,7 +1266,7 @@ static void *do_mount_direct(void *arg)
1165  
1166         pthread_setcancelstate(state, NULL);
1167  
1168 -       msg("attempting to mount entry %s", mt->name);
1169 +       info(ap->logopt, "attempting to mount entry %s", mt->name);
1170  
1171         /*
1172          * Setup thread specific data values for macro
1173 @@ -1445,16 +1392,16 @@ cont:
1174                 cache_unlock(mt->mc);
1175                 if (set_fd) {
1176                         me->ioctlfd = mt->ioctlfd;
1177 -                       send_ready(mt->ioctlfd, mt->wait_queue_token);
1178 +                       send_ready(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1179                 } else {
1180 -                       send_ready(mt->ioctlfd, mt->wait_queue_token);
1181 +                       send_ready(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1182                         close(mt->ioctlfd);
1183                 }
1184 -               msg("mounted %s", mt->name);
1185 +               info(ap->logopt, "mounted %s", mt->name);
1186         } else {
1187 -               send_fail(mt->ioctlfd, mt->wait_queue_token);
1188 +               send_fail(mt->ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1189                 close(mt->ioctlfd);
1190 -               msg("failed to mount %s", mt->name);
1191 +               info(ap->logopt, "failed to mount %s", mt->name);
1192         }
1193         pthread_setcancelstate(state, NULL);
1194  
1195 @@ -1505,7 +1452,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
1196                  * Shouldn't happen as the kernel is telling us
1197                  * someone has walked on our mount point.
1198                  */
1199 -               crit(ap->logopt, "can't find map entry for (%lu,%lu)",
1200 +               logerr("can't find map entry for (%lu,%lu)",
1201                     (unsigned long) pkt->dev, (unsigned long) pkt->ino);
1202                 pthread_setcancelstate(state, NULL);
1203                 return 1;
1204 @@ -1538,7 +1485,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
1205         if (ap->state == ST_SHUTDOWN_PENDING ||
1206             ap->state == ST_SHUTDOWN_FORCE ||
1207             ap->state == ST_SHUTDOWN) {
1208 -               send_fail(ioctlfd, pkt->wait_queue_token);
1209 +               send_fail(ap->logopt, ioctlfd, pkt->wait_queue_token);
1210                 close(ioctlfd);
1211                 cache_unlock(mc);
1212                 pthread_setcancelstate(state, NULL);
1213 @@ -1549,7 +1496,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
1214         if (!mt) {
1215                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1216                 error(ap->logopt, "malloc: %s", estr);
1217 -               send_fail(ioctlfd, pkt->wait_queue_token);
1218 +               send_fail(ap->logopt, ioctlfd, pkt->wait_queue_token);
1219                 close(ioctlfd);
1220                 cache_unlock(mc);
1221                 pthread_setcancelstate(state, NULL);
1222 @@ -1578,7 +1525,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
1223         status = pthread_create(&thid, &thread_attr, do_mount_direct, mt);
1224         if (status) {
1225                 error(ap->logopt, "missing mount thread create failed");
1226 -               send_fail(ioctlfd, pkt->wait_queue_token);
1227 +               send_fail(ap->logopt, ioctlfd, pkt->wait_queue_token);
1228                 close(ioctlfd);
1229                 cache_unlock(mc);
1230                 mount_mutex_unlock(NULL);
1231 diff --git a/daemon/indirect.c b/daemon/indirect.c
1232 index 02e7045..5c422c8 100644
1233 --- a/daemon/indirect.c
1234 +++ b/daemon/indirect.c
1235 @@ -43,63 +43,6 @@ extern pthread_attr_t thread_attr;
1236  static pthread_mutex_t ma_mutex = PTHREAD_MUTEX_INITIALIZER;
1237  static pthread_mutex_t ea_mutex = PTHREAD_MUTEX_INITIALIZER;
1238  
1239 -static int autofs_init_indirect(struct autofs_point *ap)
1240 -{
1241 -       int pipefd[2], cl_flags;
1242 -
1243 -       if ((ap->state != ST_INIT)) {
1244 -               /* This can happen if an autofs process is already running*/
1245 -               error(ap->logopt, "bad state %d", ap->state);
1246 -               return -1;
1247 -       }
1248 -
1249 -       ap->pipefd = ap->kpipefd = ap->ioctlfd = -1;
1250 -
1251 -       /* Pipe for kernel communications */
1252 -       if (pipe(pipefd) < 0) {
1253 -               crit(ap->logopt,
1254 -                    "failed to create commumication pipe for autofs path %s",
1255 -                    ap->path);
1256 -               free(ap->path);
1257 -               return -1;
1258 -       }
1259 -
1260 -       ap->pipefd = pipefd[0];
1261 -       ap->kpipefd = pipefd[1];
1262 -
1263 -       if ((cl_flags = fcntl(ap->pipefd, F_GETFD, 0)) != -1) {
1264 -               cl_flags |= FD_CLOEXEC;
1265 -               fcntl(ap->pipefd, F_SETFD, cl_flags);
1266 -       }
1267 -
1268 -       if ((cl_flags = fcntl(ap->kpipefd, F_GETFD, 0)) != -1) {
1269 -               cl_flags |= FD_CLOEXEC;
1270 -               fcntl(ap->kpipefd, F_SETFD, cl_flags);
1271 -       }
1272 -
1273 -       /* Pipe state changes from signal handler to main loop */
1274 -       if (pipe(ap->state_pipe) < 0) {
1275 -               crit(ap->logopt,
1276 -                    "failed create state pipe for autofs path %s", ap->path);
1277 -               close(ap->pipefd);
1278 -               close(ap->kpipefd);     /* Close kernel pipe end */
1279 -               free(ap->path);
1280 -               return -1;
1281 -       }
1282 -
1283 -       if ((cl_flags = fcntl(ap->state_pipe[0], F_GETFD, 0)) != -1) {
1284 -               cl_flags |= FD_CLOEXEC;
1285 -               fcntl(ap->state_pipe[0], F_SETFD, cl_flags);
1286 -       }
1287 -
1288 -       if ((cl_flags = fcntl(ap->state_pipe[1], F_GETFD, 0)) != -1) {
1289 -               cl_flags |= FD_CLOEXEC;
1290 -               fcntl(ap->state_pipe[1], F_SETFD, cl_flags);
1291 -       }
1292 -
1293 -       return 0;
1294 -}
1295 -
1296  static int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
1297  {
1298         struct mnt_list *this;
1299 @@ -118,7 +61,7 @@ static int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
1300                 }
1301  
1302                 if (strcmp(this->fs_type, "autofs"))
1303 -                       rv = spawn_umount(log_debug, "-l", this->path, NULL);
1304 +                       rv = spawn_umount(ap->logopt, "-l", this->path, NULL);
1305                 else
1306                         rv = umount2(this->path, MNT_DETACH);
1307                 if (rv == -1) {
1308 @@ -222,12 +165,14 @@ static int do_mount_autofs_indirect(struct autofs_point *ap)
1309         ioctl(ap->ioctlfd, AUTOFS_IOC_SETTIMEOUT, &timeout);
1310  
1311         if (ap->exp_timeout)
1312 -               msg("mounted indirect mount on %s "
1313 +               info(ap->logopt,
1314 +                   "mounted indirect mount on %s "
1315                     "with timeout %u, freq %u seconds", ap->path,
1316 -                  (unsigned int) ap->exp_timeout,
1317 -                  (unsigned int) ap->exp_runfreq);
1318 +                   (unsigned int) ap->exp_timeout,
1319 +                   (unsigned int) ap->exp_runfreq);
1320         else
1321 -               msg("mounted indirect mount on %s with timeouts disabled",
1322 +               info(ap->logopt,
1323 +                   "mounted indirect mount on %s with timeouts disabled",
1324                     ap->path);
1325  
1326         fstat(ap->ioctlfd, &st);
1327 @@ -257,9 +202,6 @@ int mount_autofs_indirect(struct autofs_point *ap)
1328         int status;
1329         int map;
1330  
1331 -        if (autofs_init_indirect(ap))
1332 -               return -1;
1333 -
1334         /* TODO: read map, determine map type is OK */
1335         if (lookup_nss_read_map(ap, NULL, now))
1336                 lookup_prune_cache(ap, now);
1337 @@ -309,7 +251,7 @@ int umount_autofs_indirect(struct autofs_point *ap)
1338         rv = ioctl(ap->ioctlfd, AUTOFS_IOC_ASKUMOUNT, &ret);
1339         if (rv == -1) {
1340                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1341 -               error(ap->logopt, "ioctl failed: %s", estr);
1342 +               logerr("ioctl failed: %s", estr);
1343                 return 1;
1344         } else if (!ret) {
1345                 error(ap->logopt, "ask umount returned busy %s", ap->path);
1346 @@ -370,9 +312,9 @@ force_umount:
1347                      "forcing umount of indirect mount %s", ap->path);
1348                 rv = umount2(ap->path, MNT_DETACH);
1349         } else {
1350 -               msg("umounted indirect mount %s", ap->path);
1351 +               info(ap->logopt, "umounted indirect mount %s", ap->path);
1352                 if (ap->submount)
1353 -                       rm_unwanted(ap->path, 1, ap->dev);
1354 +                       rm_unwanted(ap->logopt, ap->path, 1, ap->dev);
1355         }
1356  
1357         return rv;
1358 @@ -390,7 +332,7 @@ static int expire_indirect(struct autofs_point *ap, int ioctlfd, const char *pat
1359                 return 0;
1360         }
1361  
1362 -       retries = (count_mounts(path, st.st_dev) + 1) * EXPIRE_RETRIES;
1363 +       retries = (count_mounts(ap->logopt, path, st.st_dev) + 1) * EXPIRE_RETRIES;
1364  
1365         while (retries--) {
1366                 struct timespec tm = {0, 100000000};
1367 @@ -559,13 +501,7 @@ void *expire_proc_indirect(void *arg)
1368          * words) the umounts are done by the time we reach here
1369          */
1370         if (count)
1371 -               debug(ap->logopt, "%d remaining in %s", count, ap->path);
1372 -
1373 -       /* If we are trying to shutdown make sure we can umount */
1374 -       if (!ioctl(ap->ioctlfd, AUTOFS_IOC_ASKUMOUNT, &ret)) {
1375 -               if (!ret)
1376 -                       msg("mount still busy %s", ap->path);
1377 -       }
1378 +               info(ap->logopt, "%d remaining in %s", count, ap->path);
1379  
1380         ec.status = left;
1381  
1382 @@ -590,7 +526,7 @@ static void pending_cond_destroy(void *arg)
1383  static void expire_send_fail(void *arg)
1384  {
1385         struct pending_args *mt = arg;
1386 -       send_fail(mt->ap->ioctlfd, mt->wait_queue_token);
1387 +       send_fail(mt->ap->logopt, mt->ap->ioctlfd, mt->wait_queue_token);
1388  }
1389  
1390  static void free_pending_args(void *arg)
1391 @@ -634,9 +570,9 @@ static void *do_expire_indirect(void *arg)
1392         status = do_expire(mt->ap, mt->name, mt->len);
1393         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1394         if (status)
1395 -               send_fail(ap->ioctlfd, mt->wait_queue_token);
1396 +               send_fail(ap->logopt, ap->ioctlfd, mt->wait_queue_token);
1397         else
1398 -               send_ready(ap->ioctlfd, mt->wait_queue_token);
1399 +               send_ready(ap->logopt, ap->ioctlfd, mt->wait_queue_token);
1400         pthread_setcancelstate(state, NULL);
1401  
1402         pthread_cleanup_pop(0);
1403 @@ -661,8 +597,8 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
1404         mt = malloc(sizeof(struct pending_args));
1405         if (!mt) {
1406                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1407 -               error(ap->logopt, "malloc: %s", estr);
1408 -               send_fail(ap->ioctlfd, pkt->wait_queue_token);
1409 +               logerr("malloc: %s", estr);
1410 +               send_fail(ap->logopt, ap->ioctlfd, pkt->wait_queue_token);
1411                 pthread_setcancelstate(state, NULL);
1412                 return 1;
1413         }
1414 @@ -684,7 +620,7 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
1415         status = pthread_create(&thid, &thread_attr, do_expire_indirect, mt);
1416         if (status) {
1417                 error(ap->logopt, "expire thread create failed");
1418 -               send_fail(ap->ioctlfd, pkt->wait_queue_token);
1419 +               send_fail(ap->logopt, ap->ioctlfd, pkt->wait_queue_token);
1420                 expire_mutex_unlock(NULL);
1421                 pending_cond_destroy(mt);
1422                 free_pending_args(mt);
1423 @@ -710,7 +646,7 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
1424  static void mount_send_fail(void *arg)
1425  {
1426         struct pending_args *mt = arg;
1427 -       send_fail(mt->ap->ioctlfd, mt->wait_queue_token);
1428 +       send_fail(mt->ap->logopt, mt->ap->ioctlfd, mt->wait_queue_token);
1429  }
1430  
1431  static void mount_mutex_unlock(void *arg)
1432 @@ -775,7 +711,7 @@ static void *do_mount_indirect(void *arg)
1433  
1434         pthread_setcancelstate(state, NULL);
1435  
1436 -       msg("attempting to mount entry %s", buf);
1437 +       info(ap->logopt, "attempting to mount entry %s", buf);
1438  
1439         /*
1440          * Setup thread specific data values for macro
1441 @@ -887,11 +823,11 @@ cont:
1442         status = lookup_nss_mount(ap, NULL, mt->name, mt->len);
1443         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1444         if (status) {
1445 -               send_ready(ap->ioctlfd, mt->wait_queue_token);
1446 -               msg("mounted %s", buf);
1447 +               send_ready(ap->logopt, ap->ioctlfd, mt->wait_queue_token);
1448 +               info(ap->logopt, "mounted %s", buf);
1449         } else {
1450 -               send_fail(ap->ioctlfd, mt->wait_queue_token);
1451 -               msg("failed to mount %s", buf);
1452 +               send_fail(ap->logopt, ap->ioctlfd, mt->wait_queue_token);
1453 +               info(ap->logopt, "failed to mount %s", buf);
1454         }
1455         pthread_setcancelstate(state, NULL);
1456  
1457 @@ -918,7 +854,7 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
1458         if (ap->state == ST_SHUTDOWN_PENDING ||
1459             ap->state == ST_SHUTDOWN_FORCE ||
1460             ap->state == ST_SHUTDOWN) {
1461 -               send_fail(ap->ioctlfd, pkt->wait_queue_token);
1462 +               send_fail(ap->logopt, ap->ioctlfd, pkt->wait_queue_token);
1463                 pthread_setcancelstate(state, NULL);
1464                 return 0;
1465         }
1466 @@ -926,8 +862,8 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
1467         mt = malloc(sizeof(struct pending_args));
1468         if (!mt) {
1469                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1470 -               error(ap->logopt, "malloc: %s", estr);
1471 -               send_fail(ap->ioctlfd, pkt->wait_queue_token);
1472 +               logerr("malloc: %s", estr);
1473 +               send_fail(ap->logopt, ap->ioctlfd, pkt->wait_queue_token);
1474                 pthread_setcancelstate(state, NULL);
1475                 return 1;
1476         }
1477 @@ -953,7 +889,7 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
1478         status = pthread_create(&thid, &thread_attr, do_mount_indirect, mt);
1479         if (status) {
1480                 error(ap->logopt, "expire thread create failed");
1481 -               send_fail(ap->ioctlfd, pkt->wait_queue_token);
1482 +               send_fail(ap->logopt, ap->ioctlfd, pkt->wait_queue_token);
1483                 mount_mutex_unlock(NULL);
1484                 pending_cond_destroy(mt);
1485                 free_pending_args(mt);
1486 diff --git a/daemon/lookup.c b/daemon/lookup.c
1487 index 4f2b318..fd99cf2 100644
1488 --- a/daemon/lookup.c
1489 +++ b/daemon/lookup.c
1490 @@ -103,6 +103,7 @@ static int do_read_master(struct master *master, char *type, time_t age)
1491  
1492  static int read_master_map(struct master *master, char *type, time_t age)
1493  {
1494 +       unsigned int logopt = master->logopt;
1495         char *path, *save_name;
1496         int result;
1497  
1498 @@ -117,7 +118,7 @@ static int read_master_map(struct master *master, char *type, time_t age)
1499          */
1500  
1501         if (strchr(master->name, '/')) {
1502 -               error(LOGOPT_ANY, "relative path invalid in files map name");
1503 +               error(logopt, "relative path invalid in files map name");
1504                 return NSS_STATUS_NOTFOUND;
1505         }
1506  
1507 @@ -142,6 +143,7 @@ static int read_master_map(struct master *master, char *type, time_t age)
1508  
1509  int lookup_nss_read_master(struct master *master, time_t age)
1510  {
1511 +       unsigned int logopt = master->logopt;
1512         struct list_head nsslist;
1513         struct list_head *head, *p;
1514         int result = NSS_STATUS_UNKNOWN;
1515 @@ -149,12 +151,10 @@ int lookup_nss_read_master(struct master *master, time_t age)
1516         /* If it starts with a '/' it has to be a file or LDAP map */
1517         if (*master->name == '/') {
1518                 if (*(master->name + 1) == '/') {
1519 -                       debug(LOGOPT_NONE,
1520 -                             "reading master ldap %s", master->name);
1521 +                       debug(logopt, "reading master ldap %s", master->name);
1522                         result = do_read_master(master, "ldap", age);
1523                 } else {
1524 -                       debug(LOGOPT_NONE,
1525 -                             "reading master file %s", master->name);
1526 +                       debug(logopt, "reading master file %s", master->name);
1527                         result = do_read_master(master, "file", age);
1528                 }
1529  
1530 @@ -184,13 +184,11 @@ int lookup_nss_read_master(struct master *master, time_t age)
1531                                  */
1532                                 if (strncmp(name, "ldap", 4)) {
1533                                         master->name = tmp + 1;
1534 -                                       debug(LOGOPT_NONE,
1535 -                                             "reading master %s %s",
1536 +                                       debug(logopt, "reading master %s %s",
1537                                               source, master->name);
1538                                 } else {
1539                                         master->name = name;
1540 -                                       debug(LOGOPT_NONE,
1541 -                                             "reading master %s %s",
1542 +                                       debug(logopt, "reading master %s %s",
1543                                               source, tmp + 1);
1544                                 }
1545  
1546 @@ -208,7 +206,7 @@ int lookup_nss_read_master(struct master *master, time_t age)
1547         if (result) {
1548                 if (!list_empty(&nsslist))
1549                         free_sources(&nsslist);
1550 -               error(LOGOPT_ANY, "can't to read name service switch config.");
1551 +               error(logopt, "can't to read name service switch config.");
1552                 return 0;
1553         }
1554  
1555 @@ -220,13 +218,12 @@ int lookup_nss_read_master(struct master *master, time_t age)
1556  
1557                 this = list_entry(p, struct nss_source, list);
1558  
1559 -               debug(LOGOPT_NONE,
1560 +               debug(logopt,
1561                       "reading master %s %s", this->source, master->name);
1562  
1563                 result = read_master_map(master, this->source, age);
1564                 if (result == NSS_STATUS_UNKNOWN) {
1565 -                       debug(LOGOPT_NONE,
1566 -                             "no map - continuing to next source");
1567 +                       debug(logopt, "no map - continuing to next source");
1568                         continue;
1569                 }
1570  
1571 @@ -1008,9 +1005,10 @@ int lookup_prune_cache(struct autofs_point *ap, time_t age)
1572                                 if (this->ioctlfd == -1)
1573                                         status = cache_delete(mc, key);
1574                                 if (status != CHE_FAIL) {
1575 -                                       if (ap->type == LKP_INDIRECT)
1576 -                                               rmdir_path(ap, path, ap->dev);
1577 -                                       else
1578 +                                       if (ap->type == LKP_INDIRECT) {
1579 +                                               if (ap->ghost)
1580 +                                                       rmdir_path(ap, path, ap->dev);
1581 +                                       } else
1582                                                 rmdir_path(ap, path, this->dev);
1583                                 }
1584                         }
1585 diff --git a/daemon/module.c b/daemon/module.c
1586 index e83c929..36eca00 100644
1587 --- a/daemon/module.c
1588 +++ b/daemon/module.c
1589 @@ -33,7 +33,7 @@ int load_autofs4_module(void)
1590          */
1591         fp = fopen("/proc/filesystems", "r");
1592         if (!fp) {
1593 -               error(LOGOPT_ANY, "cannot open /proc/filesystems\n");
1594 +               logerr("cannot open /proc/filesystems\n");
1595                 return 0;
1596         }
1597  
1598 @@ -45,7 +45,7 @@ int load_autofs4_module(void)
1599         }
1600         fclose(fp);
1601  
1602 -       ret = spawnl(log_debug, PATH_MODPROBE, PATH_MODPROBE,
1603 +       ret = spawnl(LOGOPT_NONE, PATH_MODPROBE, PATH_MODPROBE,
1604                                 "-q", FS_MODULE_NAME, NULL);
1605         if (ret)
1606                 return 0;
1607 @@ -72,7 +72,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
1608         if (!mod) {
1609                 if (err_prefix) {
1610                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1611 -                       crit(LOGOPT_ANY, "%s%s", err_prefix, estr);
1612 +                       logerr("%s%s", err_prefix, estr);
1613                 }
1614                 return NULL;
1615         }
1616 @@ -83,7 +83,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
1617                 free(mod);
1618                 if (err_prefix) {
1619                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1620 -                       crit(LOGOPT_ANY, "%s%s", err_prefix, estr);
1621 +                       logerr("%s%s", err_prefix, estr);
1622                 }
1623                 return NULL;
1624         }
1625 @@ -91,7 +91,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
1626  
1627         if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
1628                 if (err_prefix)
1629 -                       crit(LOGOPT_ANY, "%scannot open lookup module %s (%s)",
1630 +                       logerr("%scannot open lookup module %s (%s)",
1631                                err_prefix, name, dlerror());
1632                 free(mod);
1633                 return NULL;
1634 @@ -100,8 +100,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
1635         if (!(ver = (int *) dlsym(dh, "lookup_version"))
1636             || *ver != AUTOFS_LOOKUP_VERSION) {
1637                 if (err_prefix)
1638 -                       crit(LOGOPT_ANY,
1639 -                            "%slookup module %s version mismatch",
1640 +                       logerr("%slookup module %s version mismatch",
1641                              err_prefix, name);
1642                 dlclose(dh);
1643                 free(mod);
1644 @@ -114,7 +113,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
1645             !(mod->lookup_mount = (lookup_mount_t) dlsym(dh, "lookup_mount")) ||
1646             !(mod->lookup_done = (lookup_done_t) dlsym(dh, "lookup_done"))) {
1647                 if (err_prefix)
1648 -                       crit(LOGOPT_ANY, "%slookup module %s corrupt", err_prefix, name);
1649 +                       logerr("%slookup module %s corrupt", err_prefix, name);
1650                 dlclose(dh);
1651                 free(mod);
1652                 return NULL;
1653 @@ -156,7 +155,7 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
1654         if (!mod) {
1655                 if (err_prefix) {
1656                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1657 -                       crit(LOGOPT_ANY, "%s%s", err_prefix, estr);
1658 +                       logerr("%s%s", err_prefix, estr);
1659                 }
1660                 return NULL;
1661         }
1662 @@ -167,7 +166,7 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
1663                 free(mod);
1664                 if (err_prefix) {
1665                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1666 -                       crit(LOGOPT_ANY, "%s%s", err_prefix, estr);
1667 +                       logerr("%s%s", err_prefix, estr);
1668                 }
1669                 return NULL;
1670         }
1671 @@ -175,8 +174,7 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
1672  
1673         if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
1674                 if (err_prefix)
1675 -                       crit(LOGOPT_ANY,
1676 -                            "%scannot open parse module %s (%s)",
1677 +                       logerr("%scannot open parse module %s (%s)",
1678                              err_prefix, name, dlerror());
1679                 free(mod);
1680                 return NULL;
1681 @@ -185,8 +183,7 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
1682         if (!(ver = (int *) dlsym(dh, "parse_version"))
1683             || *ver != AUTOFS_PARSE_VERSION) {
1684                 if (err_prefix)
1685 -                       crit(LOGOPT_ANY,
1686 -                            "%sparse module %s version mismatch",
1687 +                       logerr("%sparse module %s version mismatch",
1688                              err_prefix, name);
1689                 dlclose(dh);
1690                 free(mod);
1691 @@ -197,8 +194,7 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
1692             !(mod->parse_mount = (parse_mount_t) dlsym(dh, "parse_mount")) ||
1693             !(mod->parse_done = (parse_done_t) dlsym(dh, "parse_done"))) {
1694                 if (err_prefix)
1695 -                       crit(LOGOPT_ANY,
1696 -                            "%sparse module %s corrupt",
1697 +                       logerr("%sparse module %s corrupt",
1698                              err_prefix, name);
1699                 dlclose(dh);
1700                 free(mod);
1701 @@ -240,7 +236,7 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
1702         if (!mod) {
1703                 if (err_prefix) {
1704                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1705 -                       crit(LOGOPT_ANY, "%s%s", err_prefix, estr);
1706 +                       logerr("%s%s", err_prefix, estr);
1707                 }
1708                 return NULL;
1709         }
1710 @@ -251,7 +247,7 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
1711                 free(mod);
1712                 if (err_prefix) {
1713                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1714 -                       crit(LOGOPT_ANY, "%s%s", err_prefix, estr);
1715 +                       logerr("%s%s", err_prefix, estr);
1716                 }
1717                 return NULL;
1718         }
1719 @@ -259,8 +255,7 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
1720  
1721         if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
1722                 if (err_prefix)
1723 -                       crit(LOGOPT_ANY,
1724 -                            "%scannot open mount module %s (%s)",
1725 +                       logerr("%scannot open mount module %s (%s)",
1726                              err_prefix, name, dlerror());
1727                 free(mod);
1728                 return NULL;
1729 @@ -269,8 +264,7 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
1730         if (!(ver = (int *) dlsym(dh, "mount_version"))
1731             || *ver != AUTOFS_MOUNT_VERSION) {
1732                 if (err_prefix)
1733 -                       crit(LOGOPT_ANY,
1734 -                            "%smount module %s version mismatch",
1735 +                       logerr("%smount module %s version mismatch",
1736                              err_prefix, name);
1737                 dlclose(dh);
1738                 free(mod);
1739 @@ -281,8 +275,7 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
1740             !(mod->mount_mount = (mount_mount_t) dlsym(dh, "mount_mount")) ||
1741             !(mod->mount_done = (mount_done_t) dlsym(dh, "mount_done"))) {
1742                 if (err_prefix)
1743 -                       crit(LOGOPT_ANY,
1744 -                            "%smount module %s corrupt",
1745 +                       logerr("%smount module %s corrupt",
1746                              err_prefix, name);
1747                 dlclose(dh);
1748                 free(mod);
1749 diff --git a/daemon/spawn.c b/daemon/spawn.c
1750 index 271d37e..3d5ea56 100644
1751 --- a/daemon/spawn.c
1752 +++ b/daemon/spawn.c
1753 @@ -88,7 +88,7 @@ void reset_signals(void)
1754  
1755  #define ERRBUFSIZ 2047         /* Max length of error string excl \0 */
1756  
1757 -static int do_spawn(logger *log, unsigned int options, const char *prog, const char *const *argv)
1758 +static int do_spawn(unsigned logopt, unsigned int options, const char *prog, const char *const *argv)
1759  {
1760         pid_t f;
1761         int ret, status, pipefd[2];
1762 @@ -195,7 +195,7 @@ static int do_spawn(logger *log, unsigned int options, const char *prog, const c
1763                                 while (errp && (p = memchr(sp, '\n', errp))) {
1764                                         *p++ = '\0';
1765                                         if (sp[0])      /* Don't output empty lines */
1766 -                                               log(LOGOPT_ANY, ">> %s", sp);
1767 +                                               warn(logopt, ">> %s", sp);
1768                                         errp -= (p - sp);
1769                                         sp = p;
1770                                 }
1771 @@ -206,7 +206,7 @@ static int do_spawn(logger *log, unsigned int options, const char *prog, const c
1772                                 if (errp >= ERRBUFSIZ) {
1773                                         /* Line too long, split */
1774                                         errbuf[errp] = '\0';
1775 -                                       log(LOGOPT_ANY, ">> %s", errbuf);
1776 +                                       warn(logopt, ">> %s", errbuf);
1777                                         errp = 0;
1778                                 }
1779                         }
1780 @@ -217,7 +217,7 @@ static int do_spawn(logger *log, unsigned int options, const char *prog, const c
1781                 if (errp > 0) {
1782                         /* End of file without \n */
1783                         errbuf[errp] = '\0';
1784 -                       log(LOGOPT_ANY, ">> %s", errbuf);
1785 +                       warn(logopt, ">> %s", errbuf);
1786                 }
1787  
1788                 if (waitpid(f, &ret, 0) != f)
1789 @@ -235,12 +235,12 @@ static int do_spawn(logger *log, unsigned int options, const char *prog, const c
1790         }
1791  }
1792  
1793 -int spawnv(logger *log, const char *prog, const char *const *argv)
1794 +int spawnv(unsigned logopt, const char *prog, const char *const *argv)
1795  {
1796 -       return do_spawn(log, SPAWN_OPT_NONE, prog, argv);
1797 +       return do_spawn(logopt, SPAWN_OPT_NONE, prog, argv);
1798  }
1799  
1800 -int spawnl(logger *log, const char *prog, ...)
1801 +int spawnl(unsigned logopt, const char *prog, ...)
1802  {
1803         va_list arg;
1804         int argc;
1805 @@ -258,10 +258,10 @@ int spawnl(logger *log, const char *prog, ...)
1806         while ((*p++ = va_arg(arg, char *)));
1807         va_end(arg);
1808  
1809 -       return do_spawn(log, SPAWN_OPT_NONE, prog, (const char **) argv);
1810 +       return do_spawn(logopt, SPAWN_OPT_NONE, prog, (const char **) argv);
1811  }
1812  
1813 -int spawn_mount(logger *log, ...)
1814 +int spawn_mount(unsigned logopt, ...)
1815  {
1816         va_list arg;
1817         int argc;
1818 @@ -279,7 +279,7 @@ int spawn_mount(logger *log, ...)
1819         options = SPAWN_OPT_NONE;
1820  #endif
1821  
1822 -       va_start(arg, log);
1823 +       va_start(arg, logopt);
1824         for (argc = 1; va_arg(arg, char *); argc++);
1825         va_end(arg);
1826  
1827 @@ -288,13 +288,13 @@ int spawn_mount(logger *log, ...)
1828  
1829         argv[0] = arg0;
1830  
1831 -       va_start(arg, log);
1832 +       va_start(arg, logopt);
1833         p = argv + 1;
1834         while ((*p++ = va_arg(arg, char *)));
1835         va_end(arg);
1836  
1837         while (retries--) {
1838 -               ret = do_spawn(log, options, prog, (const char **) argv);
1839 +               ret = do_spawn(logopt, options, prog, (const char **) argv);
1840                 if (ret & MTAB_NOTUPDATED)
1841                         continue;
1842                 break;
1843 @@ -311,7 +311,7 @@ int spawn_mount(logger *log, ...)
1844   * NOTE: If mount locking is enabled this type of recursive mount cannot
1845   *      work.
1846   */
1847 -int spawn_bind_mount(logger *log, ...)
1848 +int spawn_bind_mount(unsigned logopt, ...)
1849  {
1850         va_list arg;
1851         int argc;
1852 @@ -330,7 +330,7 @@ int spawn_bind_mount(logger *log, ...)
1853         options = SPAWN_OPT_ACCESS;
1854  #endif
1855  
1856 -       va_start(arg, log);
1857 +       va_start(arg, logopt);
1858         for (argc = 1; va_arg(arg, char *); argc++);
1859         va_end(arg);
1860  
1861 @@ -340,13 +340,13 @@ int spawn_bind_mount(logger *log, ...)
1862         argv[0] = arg0;
1863         argv[1] = bind;
1864  
1865 -       va_start(arg, log);
1866 +       va_start(arg, logopt);
1867         p = argv + 2;
1868         while ((*p++ = va_arg(arg, char *)));
1869         va_end(arg);
1870  
1871         while (retries--) {
1872 -               ret = do_spawn(log, options, prog, (const char **) argv);
1873 +               ret = do_spawn(logopt, options, prog, (const char **) argv);
1874                 if (ret & MTAB_NOTUPDATED)
1875                         continue;
1876                 break;
1877 @@ -355,7 +355,7 @@ int spawn_bind_mount(logger *log, ...)
1878         return ret;
1879  }
1880  
1881 -int spawn_umount(logger *log, ...)
1882 +int spawn_umount(unsigned logopt, ...)
1883  {
1884         va_list arg;
1885         int argc;
1886 @@ -372,7 +372,7 @@ int spawn_umount(logger *log, ...)
1887         options = SPAWN_OPT_NONE;
1888  #endif
1889  
1890 -       va_start(arg, log);
1891 +       va_start(arg, logopt);
1892         for (argc = 1; va_arg(arg, char *); argc++);
1893         va_end(arg);
1894  
1895 @@ -381,13 +381,13 @@ int spawn_umount(logger *log, ...)
1896  
1897         argv[0] = arg0;
1898  
1899 -       va_start(arg, log);
1900 +       va_start(arg, logopt);
1901         p = argv + 1;
1902         while ((*p++ = va_arg(arg, char *)));
1903         va_end(arg);
1904  
1905         while (retries--) {
1906 -               ret = do_spawn(log, options, prog, (const char **) argv);
1907 +               ret = do_spawn(logopt, options, prog, (const char **) argv);
1908                 if (ret & MTAB_NOTUPDATED)
1909                         continue;
1910                 break;
1911 diff --git a/daemon/state.c b/daemon/state.c
1912 index 39f4497..a2da762 100644
1913 --- a/daemon/state.c
1914 +++ b/daemon/state.c
1915 @@ -58,22 +58,20 @@ void dump_state_queue(void)
1916         struct list_head *head = &state_queue;
1917         struct list_head *p, *q;
1918  
1919 -       debug(LOGOPT_ANY, "dumping queue");
1920 +       logmsg("dumping queue");
1921  
1922         list_for_each(p, head) {
1923                 struct state_queue *entry;
1924  
1925                 entry = list_entry(p, struct state_queue, list);
1926 -               debug(LOGOPT_ANY,
1927 -                     "queue list head path %s state %d busy %d",
1928 +               logmsg("queue list head path %s state %d busy %d",
1929                       entry->ap->path, entry->state, entry->busy);
1930  
1931                 list_for_each(q, &entry->pending) {
1932                         struct state_queue *this;
1933  
1934                         this = list_entry(q, struct state_queue, pending);
1935 -                       debug(LOGOPT_ANY,
1936 -                             "queue list entry path %s state %d busy %d",
1937 +                       logmsg("queue list entry path %s state %d busy %d",
1938                               this->ap->path, this->state, this->busy);
1939                 }
1940         }
1941 @@ -85,7 +83,7 @@ void nextstate(int statefd, enum states next)
1942  
1943         if (write(statefd, &next, sizeof(next)) != sizeof(next)) {
1944                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1945 -               error(LOGOPT_ANY, "write failed %s", estr);
1946 +               logerr("write failed %s", estr);
1947         }
1948  }
1949  
1950 diff --git a/include/automount.h b/include/automount.h
1951 index d55ba5c..37a3c0a 100644
1952 --- a/include/automount.h
1953 +++ b/include/automount.h
1954 @@ -131,6 +131,7 @@ struct mapent_cache {
1955         unsigned int size;
1956         pthread_mutex_t ino_index_mutex;
1957         struct list_head *ino_index;
1958 +       struct autofs_point *ap;
1959         struct map_source *map;
1960         struct mapent **hash;
1961  };
1962 @@ -164,7 +165,7 @@ void cache_readlock(struct mapent_cache *mc);
1963  void cache_writelock(struct mapent_cache *mc);
1964  int cache_try_writelock(struct mapent_cache *mc);
1965  void cache_unlock(struct mapent_cache *mc);
1966 -struct mapent_cache *cache_init(struct map_source *map);
1967 +struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map);
1968  struct mapent_cache *cache_init_null_cache(struct master *master);
1969  int cache_set_ino_index(struct mapent_cache *mc, const char *key, dev_t dev, ino_t ino);
1970  /* void cache_set_ino(struct mapent *me, dev_t dev, ino_t ino); */
1971 @@ -200,11 +201,11 @@ int free_argv(int argc, const char **argv);
1972  inline void dump_core(void);
1973  int aquire_lock(void);
1974  void release_lock(void);
1975 -int spawnl(logger *log, const char *prog, ...);
1976 -int spawnv(logger *log, const char *prog, const char *const *argv);
1977 -int spawn_mount(logger *log, ...);
1978 -int spawn_bind_mount(logger *log, ...);
1979 -int spawn_umount(logger *log, ...);
1980 +int spawnl(unsigned logopt, const char *prog, ...);
1981 +int spawnv(unsigned logopt, const char *prog, const char *const *argv);
1982 +int spawn_mount(unsigned logopt, ...);
1983 +int spawn_bind_mount(unsigned logopt, ...);
1984 +int spawn_umount(unsigned logopt, ...);
1985  void reset_signals(void);
1986  int do_mount(struct autofs_point *ap, const char *root, const char *name,
1987              int name_len, const char *what, const char *fstype,
1988 @@ -222,6 +223,8 @@ int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev);
1989  #define MAPENT_MAX_LEN 4095
1990  #define PARSE_MAX_BUF  KEY_MAX_LEN + MAPENT_MAX_LEN + 2
1991  
1992 +#define AUTOFS_LOGPRI_FIFO "/tmp/autofs.fifo"
1993 +
1994  int lookup_nss_read_master(struct master *master, time_t age);
1995  int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age);
1996  int lookup_enumerate(struct autofs_point *ap,
1997 @@ -435,6 +438,7 @@ struct autofs_point {
1998         int pipefd;                     /* File descriptor for pipe */
1999         int kpipefd;                    /* Kernel end descriptor for pipe */
2000         int ioctlfd;                    /* File descriptor for ioctls */
2001 +       int logpri_fifo;                /* FIFO used for changing log levels */
2002         dev_t dev;                      /* "Device" number assigned by kernel */
2003         struct master_mapent *entry;    /* Master map entry for this mount */
2004         unsigned int type;              /* Type of map direct or indirect */
2005 @@ -464,8 +468,8 @@ struct autofs_point {
2006  
2007  void *handle_mounts(void *arg);
2008  int umount_multi(struct autofs_point *ap, const char *path, int incl);
2009 -int send_ready(int ioctlfd, unsigned int wait_queue_token);
2010 -int send_fail(int ioctlfd, unsigned int wait_queue_token);
2011 +int send_ready(unsigned logopt, int ioctlfd, unsigned int wait_queue_token);
2012 +int send_fail(unsigned logopt, int ioctlfd, unsigned int wait_queue_token);
2013  int do_expire(struct autofs_point *ap, const char *name, int namelen);
2014  void *expire_proc_indirect(void *);
2015  void *expire_proc_direct(void *);
2016 @@ -483,8 +487,8 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
2017  int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_direct_t *pkt);
2018  int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missing_indirect_t *pkt);
2019  int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_direct_t *pkt);
2020 -void rm_unwanted(const char *path, int incl, dev_t dev);
2021 -int count_mounts(const char *path, dev_t dev);
2022 +void rm_unwanted(unsigned logopt, const char *path, int incl, dev_t dev);
2023 +int count_mounts(unsigned logopt, const char *path, dev_t dev);
2024  
2025  #define state_mutex_lock(ap) \
2026  do { \
2027 diff --git a/include/log.h b/include/log.h
2028 index 3276cca..6a4a942 100644
2029 --- a/include/log.h
2030 +++ b/include/log.h
2031 @@ -20,6 +20,7 @@
2032  /* Define logging functions */
2033  
2034  #define LOGOPT_NONE    0x0000
2035 +#define LOGOPT_ERROR   0x0000
2036  #define LOGOPT_DEBUG   0x0001
2037  #define LOGOPT_VERBOSE 0x0002
2038  #define LOGOPT_ANY     (LOGOPT_DEBUG | LOGOPT_VERBOSE)
2039 @@ -29,34 +30,33 @@ struct autofs_point;
2040  extern void set_log_norm(void);
2041  extern void set_log_verbose(void);
2042  extern void set_log_debug(void);
2043 -extern void set_mnt_logging(struct autofs_point *);
2044 +extern void set_log_norm_ap(struct autofs_point *ap);
2045 +extern void set_log_verbose_ap(struct autofs_point *ap);
2046 +extern void set_log_debug_ap(struct autofs_point *ap);
2047 +extern void set_mnt_logging(unsigned global_logopt);
2048  
2049  extern void log_to_syslog(void);
2050  extern void log_to_stderr(void);
2051   
2052 -typedef void logger(unsigned int logopt, const char* msg, ...);
2053 -
2054 -extern void (*log_info)(unsigned int, const char* msg, ...);
2055 -extern void (*log_notice)(unsigned int, const char* msg, ...);
2056 -extern void (*log_warn)(unsigned int, const char* msg, ...);
2057 -extern void (*log_error)(unsigned int, const char* msg, ...);
2058 -extern void (*log_crit)(unsigned int, const char* msg, ...);
2059 -extern void (*log_debug)(unsigned int, const char* msg, ...);
2060 -
2061 -#define msg(msg, args...)      \
2062 -       do { log_info(LOGOPT_NONE, msg, ##args); } while (0)
2063 +extern void log_info(unsigned int, const char* msg, ...);
2064 +extern void log_notice(unsigned int, const char* msg, ...);
2065 +extern void log_warn(unsigned int, const char* msg, ...);
2066 +extern void log_error(unsigned, const char* msg, ...);
2067 +extern void log_crit(unsigned, const char* msg, ...);
2068 +extern void log_debug(unsigned int, const char* msg, ...);
2069 +extern void logmsg(const char* msg, ...);
2070  
2071  #define debug(opt, msg, args...)       \
2072         do { log_debug(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
2073  
2074 -#define info(opt, msg, args...)        \
2075 -       do { log_info(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
2076 +#define info(opt, msg, args...)                \
2077 +       do { log_info(opt, msg,  ##args); } while (0)
2078  
2079  #define notice(opt, msg, args...)      \
2080 -       do { log_notice(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
2081 +       do { log_notice(opt, msg, ##args); } while (0)
2082  
2083 -#define warn(opt, msg, args...)        \
2084 -       do { log_warn(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
2085 +#define warn(opt, msg, args...)                \
2086 +       do { log_warn(opt, msg, ##args); } while (0)
2087  
2088  #define error(opt, msg, args...)       \
2089         do { log_error(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
2090 @@ -64,17 +64,18 @@ extern void (*log_debug)(unsigned int, const char* msg, ...);
2091  #define crit(opt, msg, args...)        \
2092         do { log_crit(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
2093  
2094 +#define logerr(msg, args...)   \
2095 +       do { logmsg("%s:%d: " msg, __FUNCTION__, __LINE__, ##args); } while (0)
2096 +
2097  #define fatal(status)                                              \
2098         do {                                                        \
2099                 if (status == EDEADLK) {                            \
2100 -                       log_crit(LOGOPT_ANY,                        \
2101 -                                "%s: deadlock detected "           \
2102 +                       logmsg("deadlock detected "                 \
2103                                  "at line %d in %s, dumping core.", \
2104 -                                __FUNCTION__, __LINE__, __FILE__); \
2105 +                                 __LINE__, __FILE__);              \
2106                         dump_core();                                \
2107                 }                                                   \
2108 -               log_crit(LOGOPT_ANY,                                \
2109 -                        "unexpected pthreads error: %d at %d "     \
2110 +               logmsg("unexpected pthreads error: %d at %d "       \
2111                          "in %s", status, __LINE__, __FILE__);      \
2112                 abort();                                            \
2113         } while(0)
2114 @@ -83,7 +84,7 @@ extern void (*log_debug)(unsigned int, const char* msg, ...);
2115  #define assert(x)                                                      \
2116  do {                                                                   \
2117         if (!(x)) {                                                     \
2118 -               log_crit(LOGOPT_ANY, __FILE__                           \
2119 +               logmsg(__FILE__                                 \
2120                          ":%d: assertion failed: " #x, __LINE__);       \
2121         }                                                               \
2122  } while(0)
2123 diff --git a/include/lookup_ldap.h b/include/lookup_ldap.h
2124 index ca8d658..5b5c475 100644
2125 --- a/include/lookup_ldap.h
2126 +++ b/include/lookup_ldap.h
2127 @@ -94,13 +94,13 @@ struct lookup_context {
2128  #define LDAP_AUTH_AUTODETECT   0x0004
2129  
2130  /* lookup_ldap.c */
2131 -LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt);
2132 -int unbind_ldap_connection(LDAP *ldap, struct lookup_context *ctxt);
2133 +LDAP *init_ldap_connection(unsigned logopt, const char *uri, struct lookup_context *ctxt);
2134 +int unbind_ldap_connection(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt);
2135  int authtype_requires_creds(const char *authtype);
2136  
2137  /* cyrus-sasl.c */
2138 -int autofs_sasl_init(LDAP *ldap, struct lookup_context *ctxt);
2139 -int autofs_sasl_bind(LDAP *ldap, struct lookup_context *ctxt);
2140 +int autofs_sasl_init(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt);
2141 +int autofs_sasl_bind(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt);
2142  void autofs_sasl_unbind(struct lookup_context *ctxt);
2143  void autofs_sasl_done(struct lookup_context *ctxt);
2144  #endif
2145 diff --git a/include/master.h b/include/master.h
2146 index 8470bb1..5f10d1f 100644
2147 --- a/include/master.h
2148 +++ b/include/master.h
2149 @@ -62,6 +62,7 @@ struct master {
2150         unsigned int default_ghost;
2151         unsigned int default_logging;
2152         unsigned int default_timeout;
2153 +       unsigned int logopt;
2154         struct mapent_cache *nc;
2155         struct list_head mounts;
2156  };
2157 @@ -106,6 +107,7 @@ int master_notify_submount(struct autofs_point *, const char *path, enum states)
2158  void master_signal_submount(struct autofs_point *, unsigned int);
2159  void master_notify_state_change(struct master *, int);
2160  int master_mount_mounts(struct master *, time_t, int);
2161 +extern inline unsigned int master_get_logopt(void);
2162  int master_list_empty(struct master *);
2163  int master_kill(struct master *);
2164  
2165 diff --git a/include/replicated.h b/include/replicated.h
2166 index 3afe9f7..672f853 100644
2167 --- a/include/replicated.h
2168 +++ b/include/replicated.h
2169 @@ -62,8 +62,8 @@ struct host {
2170  
2171  void seed_random(void);
2172  void free_host_list(struct host **);
2173 -int parse_location(struct host **, const char *);
2174 -int prune_host_list(struct host **, unsigned int, const char *, unsigned int);
2175 +int parse_location(unsigned, struct host **, const char *);
2176 +int prune_host_list(unsigned, struct host **, unsigned int, const char *, unsigned int);
2177  void dump_host_list(struct host *);
2178  
2179  #endif
2180 diff --git a/lib/alarm.c b/lib/alarm.c
2181 index 90bf7aa..6a70ed1 100755
2182 --- a/lib/alarm.c
2183 +++ b/lib/alarm.c
2184 @@ -51,7 +51,7 @@ void dump_alarms(void)
2185                 struct alarm *this;
2186  
2187                 this = list_entry(p, struct alarm, list);
2188 -               msg("alarm time = %d", this->time);
2189 +               logmsg("alarm time = %d", this->time);
2190         }
2191         pthread_mutex_unlock(&mutex);
2192  }
2193 diff --git a/lib/args.c b/lib/args.c
2194 index fbfb004..9616598 100644
2195 --- a/lib/args.c
2196 +++ b/lib/args.c
2197 @@ -37,7 +37,7 @@ char **add_argv(int argc, char **argv, char *str)
2198                 if (argv[i]) {
2199                         vector[i] = strdup(argv[i]);
2200                         if (!vector[i]) {
2201 -                               error(LOGOPT_ANY, "failed to strdup arg");
2202 +                               logerr("failed to strdup arg");
2203                                 break;
2204                         }
2205                 } else
2206 @@ -81,7 +81,7 @@ char **append_argv(int argc1, char **argv1, int argc2, char **argv2)
2207                 if (argv2[j]) {
2208                         vector[i] = strdup(argv2[j]);
2209                         if (!vector[i]) {
2210 -                               error(LOGOPT_ANY, "failed to strdup arg");
2211 +                               logerr("failed to strdup arg");
2212                                 break;
2213                         }
2214                 } else
2215 @@ -116,7 +116,7 @@ const char **copy_argv(int argc, const char **argv)
2216                 if (argv[i]) {
2217                         vector[i] = strdup(argv[i]);
2218                         if (!vector[i]) {
2219 -                               error(LOGOPT_ANY, "failed to strdup arg");
2220 +                               logerr("failed to strdup arg");
2221                                 break;
2222                         }
2223                 } else
2224 diff --git a/lib/cache.c b/lib/cache.c
2225 index 06bb461..55586a3 100644
2226 --- a/lib/cache.c
2227 +++ b/lib/cache.c
2228 @@ -34,7 +34,7 @@ void cache_dump_multi(struct list_head *list)
2229  
2230         list_for_each(p, list) {
2231                 me = list_entry(p, struct mapent, multi_list);
2232 -               msg("key=%s", me->key);
2233 +               logmsg("key=%s", me->key);
2234         }
2235  }
2236  
2237 @@ -48,7 +48,7 @@ void cache_dump_cache(struct mapent_cache *mc)
2238                 if (me == NULL)
2239                         continue;
2240                 while (me) {
2241 -                       msg("me->key=%s me->multi=%p dev=%ld ino=%ld",
2242 +                       logmsg("me->key=%s me->multi=%p dev=%ld ino=%ld",
2243                                 me->key, me->multi, me->dev, me->ino);
2244                         me = me->next;
2245                 }
2246 @@ -61,7 +61,7 @@ void cache_readlock(struct mapent_cache *mc)
2247  
2248         status = pthread_rwlock_rdlock(&mc->rwlock);
2249         if (status) {
2250 -               error(LOGOPT_ANY, "mapent cache rwlock lock failed");
2251 +               logmsg("mapent cache rwlock lock failed");
2252                 fatal(status);
2253         }
2254         return;
2255 @@ -73,7 +73,7 @@ void cache_writelock(struct mapent_cache *mc)
2256  
2257         status = pthread_rwlock_wrlock(&mc->rwlock);
2258         if (status) {
2259 -               error(LOGOPT_ANY, "mapent cache rwlock lock failed");
2260 +               logmsg("mapent cache rwlock lock failed");
2261                 fatal(status);
2262         }
2263         return;
2264 @@ -85,7 +85,7 @@ int cache_try_writelock(struct mapent_cache *mc)
2265  
2266         status = pthread_rwlock_trywrlock(&mc->rwlock);
2267         if (status) {
2268 -               debug(LOGOPT_ANY, "mapent cache rwlock busy");
2269 +               logmsg("mapent cache rwlock busy");
2270                 return 0;
2271         }
2272         return 1;
2273 @@ -97,7 +97,7 @@ void cache_unlock(struct mapent_cache *mc)
2274  
2275         status = pthread_rwlock_unlock(&mc->rwlock);
2276         if (status) {
2277 -               error(LOGOPT_ANY, "mapent cache rwlock unlock failed");
2278 +               logmsg("mapent cache rwlock unlock failed");
2279                 fatal(status);
2280         }
2281         return;
2282 @@ -120,7 +120,7 @@ void cache_multi_lock(struct mapent *me)
2283  
2284         status = pthread_mutex_lock(&me->multi_mutex);
2285         if (status) {
2286 -               error(LOGOPT_ANY, "mapent cache multi mutex lock failed");
2287 +               logmsg("mapent cache multi mutex lock failed");
2288                 fatal(status);
2289         }
2290         return;
2291 @@ -135,7 +135,7 @@ void cache_multi_unlock(struct mapent *me)
2292  
2293         status = pthread_mutex_unlock(&me->multi_mutex);
2294         if (status) {
2295 -               error(LOGOPT_ANY, "mapent cache multi mutex unlock failed");
2296 +               logmsg("mapent cache multi mutex unlock failed");
2297                 fatal(status);
2298         }
2299         return;
2300 @@ -164,7 +164,7 @@ static inline void ino_index_unlock(struct mapent_cache *mc)
2301         return;
2302  }
2303  
2304 -struct mapent_cache *cache_init(struct map_source *map)
2305 +struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map)
2306  {
2307         struct mapent_cache *mc;
2308         unsigned int i;
2309 @@ -207,6 +207,7 @@ struct mapent_cache *cache_init(struct map_source *map)
2310                 INIT_LIST_HEAD(&mc->ino_index[i]);
2311         }
2312  
2313 +       mc->ap = ap;
2314         mc->map = map;
2315  
2316         cache_unlock(mc);
2317 @@ -257,6 +258,9 @@ struct mapent_cache *cache_init_null_cache(struct master *master)
2318                 INIT_LIST_HEAD(&mc->ino_index[i]);
2319         }
2320  
2321 +       mc->ap = NULL;
2322 +       mc->map = NULL;
2323 +
2324         cache_unlock(mc);
2325  
2326         return mc;
2327 @@ -608,6 +612,7 @@ static void cache_add_ordered_offset(struct mapent *me, struct list_head *head)
2328  /* cache must be write locked by caller */
2329  int cache_add_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age)
2330  {
2331 +       unsigned logopt = mc->ap ? mc->ap->logopt : master_get_logopt();
2332         struct mapent *me, *owner;
2333         int ret = CHE_OK;
2334  
2335 @@ -621,7 +626,7 @@ int cache_add_offset(struct mapent_cache *mc, const char *mkey, const char *key,
2336  
2337         ret = cache_add(mc, owner->source, key, mapent, age);
2338         if (ret == CHE_FAIL) {
2339 -               warn(LOGOPT_ANY, "failed to add key %s to cache", key);
2340 +               warn(logopt, "failed to add key %s to cache", key);
2341                 return CHE_FAIL;
2342         }
2343  
2344 @@ -689,6 +694,7 @@ int cache_set_parents(struct mapent *mm)
2345  /* cache must be write locked by caller */
2346  int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age)
2347  {
2348 +       unsigned logopt = mc->ap ? mc->ap->logopt : master_get_logopt();
2349         struct mapent *me = NULL;
2350         char *pent;
2351         int ret = CHE_OK;
2352 @@ -697,7 +703,7 @@ int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key
2353         if (!me || (*me->key == '*' && *key != '*')) {
2354                 ret = cache_add(mc, ms, key, mapent, age);
2355                 if (!ret) {
2356 -                       debug(LOGOPT_NONE, "failed for %s", key);
2357 +                       debug(logopt, "failed for %s", key);
2358                         return CHE_FAIL;
2359                 }
2360                 ret = CHE_UPDATED;
2361 @@ -796,6 +802,7 @@ done:
2362  /* cache must be write locked by caller */
2363  int cache_delete_offset_list(struct mapent_cache *mc, const char *key)
2364  {
2365 +       unsigned logopt = mc->ap ? mc->ap->logopt : master_get_logopt();
2366         struct mapent *me;
2367         struct mapent *this;
2368         struct list_head *head, *next;
2369 @@ -816,7 +823,7 @@ int cache_delete_offset_list(struct mapent_cache *mc, const char *key)
2370                 this = list_entry(next, struct mapent, multi_list);
2371                 next = next->next;
2372                 if (this->ioctlfd != -1) {
2373 -                       error(LOGOPT_ANY,
2374 +                       error(logopt,
2375                               "active offset mount key %s", this->key);
2376                         return CHE_FAIL;
2377                 }
2378 @@ -829,10 +836,10 @@ int cache_delete_offset_list(struct mapent_cache *mc, const char *key)
2379                 next = next->next;
2380                 list_del_init(&this->multi_list);
2381                 this->multi = NULL;
2382 -               debug(LOGOPT_NONE, "deleting offset key %s", this->key);
2383 +               debug(logopt, "deleting offset key %s", this->key);
2384                 status = cache_delete(mc, this->key);
2385                 if (status == CHE_FAIL) {
2386 -                       warn(LOGOPT_ANY,
2387 +                       warn(logopt,
2388                              "failed to delete offset %s", this->key);
2389                         this->multi = me;
2390                         /* TODO: add list back in */
2391 diff --git a/lib/defaults.c b/lib/defaults.c
2392 index 2cccf20..94885e8 100644
2393 --- a/lib/defaults.c
2394 +++ b/lib/defaults.c
2395 @@ -105,17 +105,22 @@ static int get_env_yesno(const char *name)
2396   * We've changed the key names so we need to check for the
2397   * config key and it's old name for backward conpatibility.
2398  */
2399 -static int check_set_config_value(const char *res, const char *name, const char *value)
2400 +static int check_set_config_value(const char *res, const char *name, const char *value, unsigned to_syslog)
2401  {
2402         char *old_name;
2403         int ret;
2404  
2405         if (!strcasecmp(res, name)) {
2406                 ret = setenv(name, value, 0);
2407 -               if (ret)
2408 -                       fprintf(stderr,
2409 -                               "can't set config value for %s, "
2410 -                               "error %d", name, ret);
2411 +               if (ret) {
2412 +                       if (!to_syslog)
2413 +                               fprintf(stderr,
2414 +                                       "can't set config value for %s, "
2415 +                                       "error %d\n", name, ret);
2416 +                       else
2417 +                               logmsg("can't set config value for %s, "
2418 +                                     "error %d", name, ret);
2419 +               }
2420                 return 1;
2421         }
2422  
2423 @@ -125,10 +130,15 @@ static int check_set_config_value(const char *res, const char *name, const char
2424  
2425         if (!strcasecmp(res, old_name)) {
2426                 ret = setenv(name, value, 0);
2427 -               if (ret)
2428 -                       fprintf(stderr,
2429 -                               "can't set config value for %s, "
2430 -                               "error %d", name, ret);
2431 +               if (ret) {
2432 +                       if (!to_syslog)
2433 +                               fprintf(stderr,
2434 +                                       "can't set config value for %s, "
2435 +                                       "error %d\n", name, ret);
2436 +                       else
2437 +                               logmsg("can't set config value for %s, "
2438 +                                     "error %d\n", name, ret);
2439 +               }
2440                 return 1;
2441         }
2442         return 0;
2443 @@ -296,19 +306,19 @@ unsigned int defaults_read_config(unsigned int to_syslog)
2444                 if (!parse_line(res, &key, &value))
2445                         continue;
2446  
2447 -               if (check_set_config_value(key, ENV_NAME_MASTER_MAP, value) ||
2448 -                   check_set_config_value(key, ENV_NAME_TIMEOUT, value) ||
2449 -                   check_set_config_value(key, ENV_NAME_BROWSE_MODE, value) ||
2450 -                   check_set_config_value(key, ENV_NAME_LOGGING, value) ||
2451 -                   check_set_config_value(key, ENV_LDAP_TIMEOUT, value) ||
2452 -                   check_set_config_value(key, ENV_LDAP_NETWORK_TIMEOUT, value) ||
2453 -                   check_set_config_value(key, ENV_NAME_MAP_OBJ_CLASS, value) ||
2454 -                   check_set_config_value(key, ENV_NAME_ENTRY_OBJ_CLASS, value) ||
2455 -                   check_set_config_value(key, ENV_NAME_MAP_ATTR, value) ||
2456 -                   check_set_config_value(key, ENV_NAME_ENTRY_ATTR, value) ||
2457 -                   check_set_config_value(key, ENV_NAME_VALUE_ATTR, value) ||
2458 -                   check_set_config_value(key, ENV_APPEND_OPTIONS, value) ||
2459 -                   check_set_config_value(key, ENV_AUTH_CONF_FILE, value))
2460 +               if (check_set_config_value(key, ENV_NAME_MASTER_MAP, value, to_syslog) ||
2461 +                   check_set_config_value(key, ENV_NAME_TIMEOUT, value, to_syslog) ||
2462 +                   check_set_config_value(key, ENV_NAME_BROWSE_MODE, value, to_syslog) ||
2463 +                   check_set_config_value(key, ENV_NAME_LOGGING, value, to_syslog) ||
2464 +                   check_set_config_value(key, ENV_LDAP_TIMEOUT, value, to_syslog) ||
2465 +                   check_set_config_value(key, ENV_LDAP_NETWORK_TIMEOUT, value, to_syslog) ||
2466 +                   check_set_config_value(key, ENV_NAME_MAP_OBJ_CLASS, value, to_syslog) ||
2467 +                   check_set_config_value(key, ENV_NAME_ENTRY_OBJ_CLASS, value, to_syslog) ||
2468 +                   check_set_config_value(key, ENV_NAME_MAP_ATTR, value, to_syslog) ||
2469 +                   check_set_config_value(key, ENV_NAME_ENTRY_ATTR, value, to_syslog) ||
2470 +                   check_set_config_value(key, ENV_NAME_VALUE_ATTR, value, to_syslog) ||
2471 +                   check_set_config_value(key, ENV_APPEND_OPTIONS, value, to_syslog) ||
2472 +                   check_set_config_value(key, ENV_AUTH_CONF_FILE, value, to_syslog))
2473                         ;
2474         }
2475  
2476 @@ -318,8 +328,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
2477                                 "fgets returned error %d while reading %s\n",
2478                                 ferror(f), DEFAULTS_CONFIG_FILE);
2479                 } else {
2480 -                       error(LOGOPT_ANY,
2481 -                             "fgets returned error %d while reading %s",
2482 +                       logmsg("fgets returned error %d while reading %s",
2483                               ferror(f), DEFAULTS_CONFIG_FILE);
2484                 }
2485                 fclose(f);
2486 diff --git a/lib/log.c b/lib/log.c
2487 index b747e12..65e8ad2 100644
2488 --- a/lib/log.c
2489 +++ b/lib/log.c
2490 @@ -27,11 +27,6 @@
2491  
2492  #include "automount.h"
2493  
2494 -/*
2495 -struct syslog_data syslog_context = AUTOFS_SYSLOG_CONTEXT;
2496 -struct syslog_data *slc = &syslog_context;
2497 -*/
2498 -
2499  static unsigned int syslog_open = 0;
2500  static unsigned int logging_to_syslog = 0;
2501  
2502 @@ -39,32 +34,44 @@ static unsigned int logging_to_syslog = 0;
2503  static unsigned int do_verbose = 0;            /* Verbose feedback option */
2504  static unsigned int do_debug = 0;              /* Full debug output */
2505  
2506 -static void null(unsigned int logopt, const char *msg, ...) { }
2507 -
2508 -void (*log_info)(unsigned int logopt, const char* msg, ...) = null;
2509 -void (*log_notice)(unsigned int logopt, const char* msg, ...) = null;
2510 -void (*log_warn)(unsigned int logopt, const char* msg, ...) = null;
2511 -void (*log_error)(unsigned int logopt, const char* msg, ...) = null;
2512 -void (*log_crit)(unsigned int logopt, const char* msg, ...) = null;
2513 -void (*log_debug)(unsigned int logopt, const char* msg, ...) = null;
2514 -
2515  void set_log_norm(void)
2516  {
2517         do_verbose = 0;
2518         do_debug = 0;
2519 +       return;
2520  }
2521  
2522  void set_log_verbose(void)
2523  {
2524         do_verbose = 1;
2525 +       return;
2526  }
2527  
2528  void set_log_debug(void)
2529  {
2530         do_debug = 1;
2531 +       return;
2532 +}
2533 +
2534 +void set_log_norm_ap(struct autofs_point *ap)
2535 +{
2536 +       ap->logopt = LOGOPT_ERROR;
2537 +       return;
2538 +}
2539 +
2540 +void set_log_verbose_ap(struct autofs_point *ap)
2541 +{
2542 +       ap->logopt = LOGOPT_VERBOSE;
2543 +       return;
2544 +}
2545 +
2546 +void set_log_debug_ap(struct autofs_point *ap)
2547 +{
2548 +       ap->logopt = LOGOPT_DEBUG;
2549 +       return;
2550  }
2551  
2552 -static void syslog_info(unsigned int logopt, const char *msg, ...)
2553 +void log_info(unsigned int logopt, const char *msg, ...)
2554  {
2555         unsigned int opt_log = logopt & (LOGOPT_DEBUG | LOGOPT_VERBOSE);
2556         va_list ap;
2557 @@ -73,11 +80,18 @@ static void syslog_info(unsigned int logopt, const char *msg, ...)
2558                 return;
2559  
2560         va_start(ap, msg);
2561 -       vsyslog(LOG_INFO, msg, ap);
2562 +       if (logging_to_syslog)
2563 +               vsyslog(LOG_INFO, msg, ap);
2564 +       else {
2565 +               vfprintf(stderr, msg, ap);
2566 +               fputc('\n', stderr);
2567 +       }
2568         va_end(ap);
2569 +
2570 +       return;
2571  }
2572  
2573 -static void syslog_notice(unsigned int logopt, const char *msg, ...)
2574 +void log_notice(unsigned int logopt, const char *msg, ...)
2575  {
2576         unsigned int opt_log = logopt & (LOGOPT_DEBUG | LOGOPT_VERBOSE);
2577         va_list ap;
2578 @@ -86,11 +100,18 @@ static void syslog_notice(unsigned int logopt, const char *msg, ...)
2579                 return;
2580  
2581         va_start(ap, msg);
2582 -       vsyslog(LOG_NOTICE, msg, ap);
2583 +       if (logging_to_syslog)
2584 +               vsyslog(LOG_NOTICE, msg, ap);
2585 +       else {
2586 +               vfprintf(stderr, msg, ap);
2587 +               fputc('\n', stderr);
2588 +       }
2589         va_end(ap);
2590 +
2591 +       return;
2592  }
2593  
2594 -static void syslog_warn(unsigned int logopt, const char *msg, ...)
2595 +void log_warn(unsigned int logopt, const char *msg, ...)
2596  {
2597         unsigned int opt_log = logopt & (LOGOPT_DEBUG | LOGOPT_VERBOSE);
2598         va_list ap;
2599 @@ -99,70 +120,79 @@ static void syslog_warn(unsigned int logopt, const char *msg, ...)
2600                 return;
2601  
2602         va_start(ap, msg);
2603 -       vsyslog(LOG_WARNING, msg, ap);
2604 +       if (logging_to_syslog)
2605 +               vsyslog(LOG_WARNING, msg, ap);
2606 +       else {
2607 +               vfprintf(stderr, msg, ap);
2608 +               fputc('\n', stderr);
2609 +       }
2610         va_end(ap);
2611 +
2612 +       return;
2613  }
2614  
2615 -static void syslog_err(unsigned int logopt, const char *msg, ...)
2616 +void log_error(unsigned logopt, const char *msg, ...)
2617  {
2618         va_list ap;
2619 +
2620         va_start(ap, msg);
2621 -       vsyslog(LOG_ERR, msg, ap);
2622 +       if (logging_to_syslog)
2623 +               vsyslog(LOG_ERR, msg, ap);
2624 +       else {
2625 +               vfprintf(stderr, msg, ap);
2626 +               fputc('\n', stderr);
2627 +       }
2628         va_end(ap);
2629 +       return;
2630  }
2631  
2632 -static void syslog_crit(unsigned int logopt, const char *msg, ...)
2633 +void log_crit(unsigned logopt, const char *msg, ...)
2634  {
2635         va_list ap;
2636 +
2637         va_start(ap, msg);
2638 -       vsyslog(LOG_CRIT, msg, ap);
2639 +       if (logging_to_syslog)
2640 +               vsyslog(LOG_CRIT, msg, ap);
2641 +       else {
2642 +               vfprintf(stderr, msg, ap);
2643 +               fputc('\n', stderr);
2644 +       }
2645         va_end(ap);
2646 +       return;
2647  }
2648  
2649 -static void syslog_debug(unsigned int logopt, const char *msg, ...)
2650 +void log_debug(unsigned int logopt, const char *msg, ...)
2651  {
2652 +       unsigned int opt_log = logopt & LOGOPT_DEBUG;
2653         va_list ap;
2654  
2655 -       if (!do_debug && !(logopt & LOGOPT_DEBUG))
2656 +       if (!do_debug && !opt_log)
2657                 return;
2658  
2659         va_start(ap, msg);
2660 -       vsyslog(LOG_DEBUG, msg, ap);
2661 +       if (logging_to_syslog)
2662 +               vsyslog(LOG_WARNING, msg, ap);
2663 +       else {
2664 +               vfprintf(stderr, msg, ap);
2665 +               fputc('\n', stderr);
2666 +       }
2667         va_end(ap);
2668 +
2669 +       return;
2670  }
2671  
2672 -static void to_stderr(unsigned int logopt, const char *msg, ...)
2673 +void logmsg(const char *msg, ...)
2674  {
2675         va_list ap;
2676         va_start(ap, msg);
2677 -       vfprintf(stderr, msg, ap);
2678 -       fputc('\n',stderr);
2679 -       va_end(ap);
2680 -}
2681 -
2682 -void set_mnt_logging(struct autofs_point *ap)
2683 -{
2684 -       unsigned int opt_verbose = ap->logopt & LOGOPT_VERBOSE;
2685 -       unsigned int opt_debug = ap->logopt & LOGOPT_DEBUG;
2686 -
2687 -       if (opt_debug) {
2688 -               if (logging_to_syslog)
2689 -                       log_debug = syslog_debug;
2690 -               else
2691 -                       log_debug = to_stderr;
2692 -       }
2693 -
2694 -       if (opt_verbose || opt_debug) {
2695 -               if (logging_to_syslog) {
2696 -                       log_info = syslog_info;
2697 -                       log_notice = syslog_notice;
2698 -                       log_warn = syslog_warn;
2699 -               } else {
2700 -                       log_info = to_stderr;
2701 -                       log_notice = to_stderr;
2702 -                       log_warn = to_stderr;
2703 -               }
2704 +       if (logging_to_syslog)
2705 +               vsyslog(LOG_CRIT, msg, ap);
2706 +       else {
2707 +               vfprintf(stderr, msg, ap);
2708 +               fputc('\n', stderr);
2709         }
2710 +       va_end(ap);
2711 +       return;
2712  }
2713  
2714  void log_to_syslog(void)
2715 @@ -175,31 +205,13 @@ void log_to_syslog(void)
2716                 openlog("automount", LOG_PID, LOG_DAEMON);
2717         }
2718  
2719 -       if (do_debug)
2720 -               log_debug = syslog_debug;
2721 -       else
2722 -               log_debug = null;
2723 -
2724 -       if (do_verbose || do_debug) {
2725 -               log_info = syslog_info;
2726 -               log_notice = syslog_notice;
2727 -               log_warn = syslog_warn;
2728 -       } else {
2729 -               log_info = null;
2730 -               log_notice = null;
2731 -               log_warn = null;
2732 -       }
2733 -
2734 -       log_error = syslog_err;
2735 -       log_crit = syslog_crit;
2736 -
2737         logging_to_syslog = 1;
2738  
2739         /* Redirect all our file descriptors to /dev/null */
2740         nullfd = open("/dev/null", O_RDWR);
2741         if (nullfd < 0) {
2742                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
2743 -               syslog_crit(LOGOPT_ANY, "cannot open /dev/null: %s", estr);
2744 +               fprintf(stderr, "cannot open /dev/null: %s", estr);
2745                 exit(1);
2746         }
2747  
2748 @@ -207,13 +219,15 @@ void log_to_syslog(void)
2749             dup2(nullfd, STDOUT_FILENO) < 0 ||
2750             dup2(nullfd, STDERR_FILENO) < 0) {
2751                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
2752 -               syslog_crit(LOGOPT_ANY,
2753 -                           "redirecting file descriptors failed: %s", estr);
2754 +               fprintf(stderr,
2755 +                       "redirecting file descriptors failed: %s", estr);
2756                 exit(1);
2757         }
2758  
2759         if (nullfd > 2)
2760                 close(nullfd);
2761 +
2762 +       return;
2763  }
2764  
2765  void log_to_stderr(void)
2766 @@ -223,23 +237,7 @@ void log_to_stderr(void)
2767                 closelog();
2768         }
2769  
2770 -       if (do_debug)
2771 -               log_debug = to_stderr;
2772 -       else
2773 -               log_debug = null;
2774 -
2775 -       if (do_verbose || do_debug) {
2776 -               log_info = to_stderr;
2777 -               log_notice = to_stderr;
2778 -               log_warn = to_stderr;
2779 -       } else {
2780 -               log_info = null;
2781 -               log_notice = null;
2782 -               log_warn = null;
2783 -       }
2784 -
2785 -       log_error = to_stderr;
2786 -       log_crit = to_stderr;
2787 -
2788         logging_to_syslog = 0;
2789 +
2790 +       return;
2791  }
2792 diff --git a/lib/macros.c b/lib/macros.c
2793 index 936ae06..fa6db8e 100644
2794 --- a/lib/macros.c
2795 +++ b/lib/macros.c
2796 @@ -50,8 +50,7 @@ void dump_table(struct substvar *table)
2797                 fatal(status);
2798  
2799         while (lv) {
2800 -               debug(LOGOPT_NONE,
2801 -                     "lv->def %s lv->val %s lv->next %p",
2802 +               logmsg("lv->def %s lv->val %s lv->next %p",
2803                       lv->def, lv->val, lv->next);
2804                 lv = lv->next;
2805         }
2806 diff --git a/lib/master.c b/lib/master.c
2807 index abc3bc2..2e24ad0 100644
2808 --- a/lib/master.c
2809 +++ b/lib/master.c
2810 @@ -524,8 +524,7 @@ void master_source_writelock(struct master_mapent *entry)
2811  
2812         status = pthread_rwlock_wrlock(&entry->source_lock);
2813         if (status) {
2814 -               error(LOGOPT_ANY,
2815 -                     "master_mapent source write lock failed");
2816 +               logmsg("master_mapent source write lock failed");
2817                 fatal(status);
2818         }
2819         return;
2820 @@ -537,8 +536,7 @@ void master_source_readlock(struct master_mapent *entry)
2821  
2822         status = pthread_rwlock_rdlock(&entry->source_lock);
2823         if (status) {
2824 -               error(LOGOPT_ANY,
2825 -                     "master_mapent source read lock failed");
2826 +               logmsg("master_mapent source read lock failed");
2827                 fatal(status);
2828         }
2829         return;
2830 @@ -550,8 +548,7 @@ void master_source_unlock(struct master_mapent *entry)
2831  
2832         status = pthread_rwlock_unlock(&entry->source_lock);
2833         if (status) {
2834 -               error(LOGOPT_ANY,
2835 -                     "master_mapent source unlock failed");
2836 +               logmsg("master_mapent source unlock failed");
2837                 fatal(status);
2838         }
2839         return;
2840 @@ -572,7 +569,7 @@ void master_source_current_wait(struct master_mapent *entry)
2841  
2842         status = pthread_mutex_lock(&entry->current_mutex);
2843         if (status) {
2844 -               error(LOGOPT_ANY, "entry current source lock failed");
2845 +               logmsg("entry current source lock failed");
2846                 fatal(status);
2847         }
2848  
2849 @@ -580,8 +577,7 @@ void master_source_current_wait(struct master_mapent *entry)
2850                 status = pthread_cond_wait(
2851                                 &entry->current_cond, &entry->current_mutex);
2852                 if (status) {
2853 -                       error(LOGOPT_ANY,
2854 -                             "entry current source condition wait failed");
2855 +                       logmsg("entry current source condition wait failed");
2856                         fatal(status);
2857                 }
2858         }
2859 @@ -595,14 +591,13 @@ void master_source_current_signal(struct master_mapent *entry)
2860  
2861         status = pthread_cond_signal(&entry->current_cond);
2862         if (status) {
2863 -               error(LOGOPT_ANY,
2864 -                     "entry current source condition signal failed");
2865 +               logmsg("entry current source condition signal failed");
2866                 fatal(status);
2867         }
2868  
2869         status = pthread_mutex_unlock(&entry->current_mutex);
2870         if (status) {
2871 -               error(LOGOPT_ANY, "entry current source unlock failed");
2872 +               logmsg("entry current source unlock failed");
2873                 fatal(status);
2874         }
2875  
2876 @@ -770,6 +765,7 @@ struct master *master_new(const char *name, unsigned int timeout, unsigned int g
2877         master->default_ghost = ghost;
2878         master->default_timeout = timeout;
2879         master->default_logging = defaults_get_logging();
2880 +       master->logopt = master->default_logging;
2881  
2882         INIT_LIST_HEAD(&master->mounts);
2883  
2884 @@ -778,11 +774,12 @@ struct master *master_new(const char *name, unsigned int timeout, unsigned int g
2885  
2886  int master_read_master(struct master *master, time_t age, int readall)
2887  {
2888 +       unsigned int logopt = master->logopt;
2889         struct mapent_cache *nc;
2890  
2891         nc = cache_init_null_cache(master);
2892         if (!nc) {
2893 -               error(LOGOPT_ANY,
2894 +               error(logopt,
2895                       "failed to init null map cache for %s", master->name);
2896                 return 0;
2897         }
2898 @@ -791,7 +788,7 @@ int master_read_master(struct master *master, time_t age, int readall)
2899         master_init_scan();
2900  
2901         if (!lookup_nss_read_master(master, age)) {
2902 -               error(LOGOPT_ANY,
2903 +               error(logopt,
2904                       "can't read master map %s", master->name);
2905                 return 0;
2906         }
2907 @@ -802,7 +799,7 @@ int master_read_master(struct master *master, time_t age, int readall)
2908  
2909         if (list_empty(&master->mounts)) {
2910                 master_mutex_unlock();
2911 -               warn(LOGOPT_ANY, "no mounts in table");
2912 +               warn(logopt, "no mounts in table");
2913                 return 1;
2914         }
2915  
2916 @@ -934,6 +931,7 @@ void master_notify_state_change(struct master *master, int sig)
2917         struct autofs_point *ap;
2918         struct list_head *p;
2919         int state_pipe, cur_state;
2920 +       unsigned int logopt;
2921  
2922         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
2923         master_mutex_lock();
2924 @@ -944,6 +942,7 @@ void master_notify_state_change(struct master *master, int sig)
2925                 entry = list_entry(p, struct master_mapent, list);
2926  
2927                 ap = entry->ap;
2928 +               logopt = ap->logopt;
2929  
2930                 state_mutex_lock(ap);
2931  
2932 @@ -978,7 +977,7 @@ void master_notify_state_change(struct master *master, int sig)
2933                 }
2934  next:
2935                 if (next != ST_INVAL)
2936 -                       debug(ap->logopt,
2937 +                       debug(logopt,
2938                               "sig %d switching %s from %d to %d",
2939                               sig, ap->path, ap->state, next);
2940  
2941 @@ -1230,6 +1229,11 @@ int master_list_empty(struct master *master)
2942         return res;
2943  }
2944  
2945 +inline unsigned int master_get_logopt(void)
2946 +{
2947 +       return master_list ? master_list->logopt : LOGOPT_NONE;
2948 +}
2949 +
2950  int master_kill(struct master *master)
2951  {
2952         if (!list_empty(&master->mounts))
2953 @@ -1251,6 +1255,6 @@ void dump_master(struct master *master)
2954         head = &master->mounts;
2955         list_for_each(p, head) {
2956                 struct master_mapent *this = list_entry(p, struct master_mapent, list);
2957 -               debug(LOGOPT_ANY, "path %s", this->path);
2958 +               logmsg("path %s", this->path);
2959         }
2960  }
2961 diff --git a/lib/master_parse.y b/lib/master_parse.y
2962 index 70b48be..a767f9e 100644
2963 --- a/lib/master_parse.y
2964 +++ b/lib/master_parse.y
2965 @@ -585,13 +585,13 @@ static char *master_strdup(char *str)
2966  
2967  static int master_error(const char *s)
2968  {
2969 -       error(LOGOPT_ANY, "%s while parsing map.", s);
2970 +       logmsg("%s while parsing map.", s);
2971         return 0;
2972  }
2973  
2974  static int master_notify(const char *s)
2975  {
2976 -       warn(LOGOPT_ANY, "syntax error in map near [ %s ]", s);
2977 +       logmsg("syntax error in map near [ %s ]", s);
2978         return(0);
2979  }
2980  
2981 @@ -704,6 +704,7 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
2982         struct master_mapent *entry, *new;
2983         struct map_source *source;
2984         unsigned int logopt = logging;
2985 +       unsigned int m_logopt = master->logopt;
2986         int ret;
2987  
2988         local_init_vars();
2989 @@ -758,8 +759,8 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
2990         } else {
2991                 if (entry->age && entry->age == age) {
2992                         if (strcmp(path, "/-")) {
2993 -                               warn(LOGOPT_VERBOSE,
2994 -                                    "ignoring duplicate indirect mount %s",
2995 +                               info(m_logopt,
2996 +                                   "ignoring duplicate indirect mount %s",
2997                                      path);
2998                                 local_free_vars();
2999                                 return 0;
3000 @@ -770,13 +771,12 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
3001         if (!entry->ap) {
3002                 ret = master_add_autofs_point(entry, timeout, logopt, ghost, 0);
3003                 if (!ret) {
3004 -                       error(LOGOPT_ANY, "failed to add autofs_point");
3005 +                       error(m_logopt, "failed to add autofs_point");
3006                         if (new)
3007                                 master_free_mapent(new);
3008                         local_free_vars();
3009                         return 0;
3010                 }
3011 -               set_mnt_logging(entry->ap);
3012         } else {
3013                 struct autofs_point *ap = entry->ap;
3014                 time_t tout = timeout;
3015 @@ -786,14 +786,11 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
3016                  * use the ghost, log and timeout of the first
3017                  */
3018                 if (entry->age < age) {
3019 -                       ap->ghost = ghost;
3020 -                       ap->logopt = logopt;
3021                         ap->exp_timeout = timeout;
3022                         ap->exp_runfreq = (ap->exp_timeout + CHECK_RATIO - 1) / CHECK_RATIO;
3023                         if (ap->ioctlfd != -1 && ap->type == LKP_INDIRECT)
3024                                 ioctl(ap->ioctlfd, AUTOFS_IOC_SETTIMEOUT, &tout);
3025                 }
3026 -               set_mnt_logging(ap);
3027         }
3028         entry->ap->random_selection = random_selection;
3029  
3030 @@ -809,7 +806,7 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
3031         source = master_add_map_source(entry, type, format, age, 
3032                                         local_argc, (const char **) local_argv);
3033         if (!source) {
3034 -               error(LOGOPT_ANY, "failed to add source");
3035 +               error(m_logopt, "failed to add source");
3036                 if (new)
3037                         master_free_mapent(new);
3038                 local_free_vars();
3039 @@ -817,9 +814,9 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
3040         }
3041  
3042         if (!source->mc) {
3043 -               source->mc = cache_init(source);
3044 +               source->mc = cache_init(entry->ap, source);
3045                 if (!source->mc) {
3046 -                       error(LOGOPT_ANY, "failed to init source cache");
3047 +                       error(m_logopt, "failed to init source cache");
3048                         if (new)
3049                                 master_free_mapent(new);
3050                         local_free_vars();
3051 diff --git a/lib/master_tok.l b/lib/master_tok.l
3052 index 2735223..00cd223 100644
3053 --- a/lib/master_tok.l
3054 +++ b/lib/master_tok.l
3055 @@ -368,7 +368,7 @@ int master_wrap(void)
3056  
3057  static void master_echo(void)
3058  {
3059 -       debug(LOGOPT_NONE, "%s", master_text);
3060 +       logmsg("%s", master_text);
3061         return;
3062  }
3063  
3064 diff --git a/lib/mounts.c b/lib/mounts.c
3065 index 0e428e8..425a65a 100644
3066 --- a/lib/mounts.c
3067 +++ b/lib/mounts.c
3068 @@ -126,7 +126,7 @@ char *make_options_string(char *path, int pipefd, char *extra)
3069  
3070         options = malloc(MAX_OPTIONS_LEN + 1);
3071         if (!options) {
3072 -               crit(LOGOPT_ANY, "can't malloc options string");
3073 +               logerr("can't malloc options string");
3074                 return NULL;
3075         }
3076  
3077 @@ -141,13 +141,12 @@ char *make_options_string(char *path, int pipefd, char *extra)
3078                         AUTOFS_MAX_PROTO_VERSION);
3079  
3080         if (len >= MAX_OPTIONS_LEN) {
3081 -               crit(LOGOPT_ANY, "buffer to small for options - truncated");
3082 +               logerr("buffer to small for options - truncated");
3083                 len = MAX_OPTIONS_LEN - 1;
3084         }
3085  
3086         if (len < 0) {
3087 -               crit(LOGOPT_ANY,
3088 -                    "failed to malloc autofs mount options for %s", path);
3089 +               logerr("failed to malloc autofs mount options for %s", path);
3090                 free(options);
3091                 return NULL;
3092         }
3093 @@ -163,7 +162,7 @@ char *make_mnt_name_string(char *path)
3094  
3095         mnt_name = malloc(MAX_MNT_NAME_LEN + 1);
3096         if (!mnt_name) {
3097 -               crit(LOGOPT_ANY, "can't malloc mnt_name string");
3098 +               logerr("can't malloc mnt_name string");
3099                 return NULL;
3100         }
3101  
3102 @@ -171,13 +170,12 @@ char *make_mnt_name_string(char *path)
3103                         mnt_name_template, (unsigned) getpid());
3104  
3105         if (len >= MAX_MNT_NAME_LEN) {
3106 -               crit(LOGOPT_ANY, "buffer to small for mnt_name - truncated");
3107 +               logerr("buffer to small for mnt_name - truncated");
3108                 len = MAX_MNT_NAME_LEN - 1;
3109         }
3110  
3111         if (len < 0) {
3112 -               crit(LOGOPT_ANY,
3113 -                    "failed setting up mnt_name for autofs path %s", path);
3114 +               logerr("failed setting up mnt_name for autofs path %s", path);
3115                 free(mnt_name);
3116                 return NULL;
3117         }
3118 @@ -207,7 +205,7 @@ struct mnt_list *get_mnt_list(const char *table, const char *path, int include)
3119         tab = setmntent(table, "r");
3120         if (!tab) {
3121                 char *estr = strerror_r(errno, buf, PATH_MAX - 1);
3122 -               error(LOGOPT_ANY, "setmntent: %s", estr);
3123 +               logerr("setmntent: %s", estr);
3124                 return NULL;
3125         }
3126  
3127 @@ -398,7 +396,7 @@ int is_mounted(const char *table, const char *path, unsigned int type)
3128         tab = setmntent(table, "r");
3129         if (!tab) {
3130                 char *estr = strerror_r(errno, buf, PATH_MAX - 1);
3131 -               error(LOGOPT_ANY, "setmntent: %s", estr);
3132 +               logerr("setmntent: %s", estr);
3133                 return 0;
3134         }
3135  
3136 @@ -443,7 +441,7 @@ int has_fstab_option(const char *opt)
3137         tab = setmntent(_PATH_MNTTAB, "r");
3138         if (!tab) {
3139                 char *estr = strerror_r(errno, buf, PATH_MAX - 1);
3140 -               error(LOGOPT_ANY, "setmntent: %s", estr);
3141 +               logerr("setmntent: %s", estr);
3142                 return 0;
3143         }
3144  
3145 @@ -471,7 +469,7 @@ char *find_mnt_ino(const char *table, dev_t dev, ino_t ino)
3146         tab = setmntent(table, "r");
3147         if (!tab) {
3148                 char *estr = strerror_r(errno, buf, (size_t) PATH_MAX - 1);
3149 -               error(LOGOPT_ANY, "setmntent: %s", estr);
3150 +               logerr("setmntent: %s", estr);
3151                 return 0;
3152         }
3153  
3154 @@ -667,7 +665,7 @@ struct mnt_list *tree_make_mnt_tree(const char *table, const char *path)
3155         tab = setmntent(table, "r");
3156         if (!tab) {
3157                 char *estr = strerror_r(errno, buf, PATH_MAX - 1);
3158 -               error(LOGOPT_ANY, "setmntent: %s", estr);
3159 +               logerr("setmntent: %s", estr);
3160                 return NULL;
3161         }
3162  
3163 diff --git a/lib/nss_parse.y b/lib/nss_parse.y
3164 index e559696..90b7d25 100644
3165 --- a/lib/nss_parse.y
3166 +++ b/lib/nss_parse.y
3167 @@ -127,13 +127,13 @@ status_exp: STATUS EQUAL ACTION
3168  
3169  static int nss_ignore(const char *s)
3170  {
3171 -       msg("ignored invalid nsswitch config near [ %s ]", s);
3172 +       logmsg("ignored invalid nsswitch config near [ %s ]", s);
3173         return(0);
3174  }
3175  
3176  static int nss_error(const char *s)
3177  {
3178 -       msg("syntax error in nsswitch config near [ %s ]\n", s);
3179 +       logmsg("syntax error in nsswitch config near [ %s ]\n", s);
3180         return(0);
3181  }
3182  
3183 @@ -167,7 +167,7 @@ int nsswitch_parse(struct list_head *list)
3184  
3185         nsswitch = fopen(NSSWITCH_FILE, "r");
3186         if (!nsswitch) {
3187 -               error(LOGOPT_ANY, "couldn't open %s\n", NSSWITCH_FILE);
3188 +               logerr("couldn't open %s\n", NSSWITCH_FILE);
3189                 return 1;
3190         }
3191  
3192 diff --git a/lib/nss_tok.l b/lib/nss_tok.l
3193 index f96b47f..c435b63 100644
3194 --- a/lib/nss_tok.l
3195 +++ b/lib/nss_tok.l
3196 @@ -135,6 +135,6 @@ int nss_wrap(void)
3197  
3198  static void nss_echo(void)
3199  {
3200 -       msg("%s", nss_text);
3201 +       logmsg("%s", nss_text);
3202         return;
3203  }
3204 diff --git a/lib/parse_subs.c b/lib/parse_subs.c
3205 index 3627f44..5422fef 100644
3206 --- a/lib/parse_subs.c
3207 +++ b/lib/parse_subs.c
3208 @@ -337,9 +337,9 @@ int umount_ent(struct autofs_point *ap, const char *path)
3209          * and EBADSLT relates to CD changer not responding.
3210          */
3211         if (!status && (S_ISDIR(st.st_mode) && st.st_dev != ap->dev)) {
3212 -               rv = spawn_umount(log_debug, path, NULL);
3213 +               rv = spawn_umount(ap->logopt, path, NULL);
3214         } else if (is_smbfs && (sav_errno == EIO || sav_errno == EBADSLT)) {
3215 -               rv = spawn_umount(log_debug, path, NULL);
3216 +               rv = spawn_umount(ap->logopt, path, NULL);
3217         }
3218  
3219         /* We are doing a forced shutcwdown down so unlink busy mounts */
3220 @@ -356,8 +356,8 @@ int umount_ent(struct autofs_point *ap, const char *path)
3221                 }
3222  
3223                 if (ap->state == ST_SHUTDOWN_FORCE) {
3224 -                       msg("forcing umount of %s", path);
3225 -                       rv = spawn_umount(log_debug, "-l", path, NULL);
3226 +                       info(ap->logopt, "forcing umount of %s", path);
3227 +                       rv = spawn_umount(ap->logopt, "-l", path, NULL);
3228                 }
3229  
3230                 /*
3231 @@ -503,7 +503,7 @@ int umount_multi_triggers(struct autofs_point *ap, char *root, struct mapent *me
3232                  * the offset triggers back.
3233                  */
3234                 if (is_mounted(_PATH_MOUNTED, root, MNTS_REAL)) {
3235 -                       msg("unmounting dir = %s", root);
3236 +                       info(ap->logopt, "unmounting dir = %s", root);
3237                         if (umount_ent(ap, root)) {
3238                                 if (!mount_multi_triggers(ap, root, me, "/"))
3239                                         warn(ap->logopt,
3240 diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
3241 index d79a94f..5797639 100644
3242 --- a/lib/rpc_subs.c
3243 +++ b/lib/rpc_subs.c
3244 @@ -96,7 +96,7 @@ static CLIENT *create_udp_client(struct conn_info *info)
3245         if (ret || !result) {
3246                 int err = ghn_errno == -1 ? errno : ghn_errno;
3247                 char *estr = strerror_r(err, buf, HOST_ENT_BUF_SIZE);
3248 -               error(LOGOPT_ANY, "hostname lookup failed: %s", estr);
3249 +               logerr("hostname lookup failed: %s", estr);
3250                 goto out_close;
3251         }
3252         memcpy(&raddr.sin_addr.s_addr, php->h_addr, php->h_length);
3253 @@ -305,7 +305,7 @@ static CLIENT *create_tcp_client(struct conn_info *info)
3254         if (ret || !result) {
3255                 int err = ghn_errno == -1 ? errno : ghn_errno;
3256                 char *estr =  strerror_r(err, buf, HOST_ENT_BUF_SIZE);
3257 -               error(LOGOPT_ANY, "hostname lookup failed: %s", estr);
3258 +               logerr("hostname lookup failed: %s", estr);
3259                 goto out_close;
3260         }
3261         memcpy(&addr.sin_addr.s_addr, php->h_addr, php->h_length);
3262 diff --git a/man/automount.8 b/man/automount.8
3263 index e203a3e..5cd63c7 100644
3264 --- a/man/automount.8
3265 +++ b/man/automount.8
3266 @@ -62,6 +62,22 @@ setting.
3267  .TP
3268  .I "\-V, \-\-version"
3269  Display the version number, then exit.
3270 +.TP
3271 +.I "\-l, \-\-set-log-priority priority path [path,...]"
3272 +Set the daemon log priority to the specified value.  Valid values include
3273 +the numbers 0-7, or the strings emerg, alert, crit, err, warning, notice,
3274 +info, or debug. Log level debug will log everything, log levels info, warn
3275 +(or warning), or notice with enable the daemon verbose logging. Any other
3276 +level will set basic logging. Note that enabling debug or verbose
3277 +logging in the autofs global configuration will override dynamic log level
3278 +changes. For example, if verbose logging is set in the configuration then
3279 +attempting to set logging to basic logging, by using alert, crit, err
3280 +or emerg won't stop the verbose logging. However, setting logging to debug
3281 +will lead to everything (debug logging) being logged witch can then also
3282 +be disabled, returning the daemon to verbose logging.
3283 +.P
3284 +The \fIpath\fP argument corresponds to the automounted
3285 +path name as specified in the master map.
3286  .SH ARGUMENTS
3287  \fBautomount\fP takes one optional argument, the name of the master map to
3288  use.
3289 diff --git a/modules/cyrus-sasl.c b/modules/cyrus-sasl.c
3290 index 68e5dd7..18733f3 100644
3291 --- a/modules/cyrus-sasl.c
3292 +++ b/modules/cyrus-sasl.c
3293 @@ -96,18 +96,18 @@ sasl_log_func(void *context, int level, const char *message)
3294         switch (level) {
3295         case SASL_LOG_ERR:
3296         case SASL_LOG_FAIL:
3297 -               error(LOGOPT_ANY, "%s", message);
3298 +               logerr("%s", message);
3299                 break;
3300         case SASL_LOG_WARN:
3301 -               warn(LOGOPT_ANY, "%s", message);
3302 +               logmsg("%s", message);
3303                 break;
3304         case SASL_LOG_NOTE:
3305 -               info(LOGOPT_ANY, "%s", message);
3306 +               logmsg("%s", message);
3307                 break;
3308         case SASL_LOG_DEBUG:
3309         case SASL_LOG_TRACE:
3310         case SASL_LOG_PASS:
3311 -               debug(LOGOPT_NONE, "%s", message);
3312 +               debug(LOGOPT_DEBUG, "%s", message);
3313                 break;
3314         default:
3315                 break;
3316 @@ -129,7 +129,7 @@ getuser_func(void *context, int id, const char **result, unsigned *len)
3317                         *len = strlen(sasl_auth_id);
3318                 break;
3319         default:
3320 -               error(LOGOPT_ANY, "unknown id in request: %d", id);
3321 +               error(LOGOPT_VERBOSE, "unknown id in request: %d", id);
3322                 return SASL_FAIL;
3323         }
3324  
3325 @@ -166,7 +166,7 @@ getpass_func(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
3326   *                the returned data.
3327   */
3328  char **
3329 -get_server_SASL_mechanisms(LDAP *ld)
3330 +get_server_SASL_mechanisms(unsigned logopt, LDAP *ld)
3331  {
3332         int ret;
3333         const char *saslattrlist[] = {"supportedSASLmechanisms", NULL};
3334 @@ -178,7 +178,7 @@ get_server_SASL_mechanisms(LDAP *ld)
3335                                 NULL, NULL,
3336                                 NULL, LDAP_NO_LIMIT, &results);
3337         if (ret != LDAP_SUCCESS) {
3338 -               error(LOGOPT_ANY, "%s", ldap_err2string(ret));
3339 +               error(logopt, "%s", ldap_err2string(ret));
3340                 return NULL;
3341         }
3342  
3343 @@ -186,7 +186,7 @@ get_server_SASL_mechanisms(LDAP *ld)
3344         if (entry == NULL) {
3345                 /* No root DSE. (!) */
3346                 ldap_msgfree(results);
3347 -               debug(LOGOPT_NONE,
3348 +               debug(logopt,
3349                       "a lookup of \"supportedSASLmechanisms\" returned "
3350                       "no results.");
3351                 return NULL;
3352 @@ -196,7 +196,7 @@ get_server_SASL_mechanisms(LDAP *ld)
3353         ldap_msgfree(results);
3354         if (mechanisms == NULL) {
3355                 /* Well, that was a waste of time. */
3356 -               msg("No SASL authentication mechanisms are supported"
3357 +               info(logopt, "No SASL authentication mechanisms are supported"
3358                     " by the LDAP server.");
3359                 return NULL;
3360         }
3361 @@ -208,7 +208,7 @@ get_server_SASL_mechanisms(LDAP *ld)
3362   *  Returns 0 upon successful connect, -1 on failure.
3363   */
3364  int
3365 -do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3366 +do_sasl_bind(unsigned logopt, LDAP *ld, sasl_conn_t *conn, const char **clientout,
3367              unsigned int *clientoutlen, const char *auth_mech, int sasl_result)
3368  {
3369         int ret, msgid, bind_result;
3370 @@ -226,7 +226,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3371                                      &client_cred : NULL,
3372                                      NULL, NULL, &msgid);
3373                 if (ret != LDAP_SUCCESS) {
3374 -                       crit(LOGOPT_ANY,
3375 +                       crit(logopt,
3376                              "Error sending sasl_bind request to "
3377                              "the server: %s", ldap_err2string(ret));
3378                         return -1;
3379 @@ -236,7 +236,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3380                 results = NULL;
3381                 ret = ldap_result(ld, msgid, LDAP_MSG_ALL, NULL, &results);
3382                 if (ret != LDAP_RES_BIND) {
3383 -                       crit(LOGOPT_ANY,
3384 +                       crit(logopt,
3385                              "Error while waiting for response to "
3386                              "sasl_bind request: %s", ldap_err2string(ret));
3387                         return -1;
3388 @@ -264,7 +264,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3389                         ret = ldap_get_option(ld, LDAP_OPT_RESULT_CODE,
3390                                               &bind_result);
3391                         if (ret != LDAP_SUCCESS) {
3392 -                               crit(LOGOPT_ANY,
3393 +                               crit(logopt,
3394                                      "Error retrieving response to sasl_bind "
3395                                      "request: %s", ldap_err2string(ret));
3396                                 ret = -1;
3397 @@ -277,7 +277,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3398                                 bind_result = ret;
3399                                 break;
3400                         default:
3401 -                               warn(LOGOPT_ANY,
3402 +                               warn(logopt,
3403                                      "Error parsing response to sasl_bind "
3404                                      "request: %s.", ldap_err2string(ret));
3405                                 break;
3406 @@ -299,7 +299,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3407                 expected_data = sasl_result == SASL_CONTINUE;
3408  
3409                 if (have_data && !expected_data) {
3410 -                       warn(LOGOPT_ANY,
3411 +                       warn(logopt,
3412                              "The LDAP server sent data in response to our "
3413                              "bind request, but indicated that the bind was "
3414                              "complete. LDAP SASL bind with mechansim %s "
3415 @@ -308,7 +308,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3416                         break;
3417                 }
3418                 if (expected_data && !have_data) {
3419 -                       warn(LOGOPT_ANY,
3420 +                       warn(logopt,
3421                              "The LDAP server indicated that the LDAP SASL "
3422                              "bind was incomplete, but did not provide the "
3423                              "required data to proceed. LDAP SASL bind with "
3424 @@ -340,7 +340,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3425                          */
3426                         if ((*clientoutlen > 0) &&
3427                             (bind_result != LDAP_SASL_BIND_IN_PROGRESS)) {
3428 -                               warn(LOGOPT_ANY,
3429 +                               warn(logopt,
3430                                      "We have data for the server, "
3431                                      "but it thinks we are done!");
3432                                 /* XXX should print out debug data here */
3433 @@ -372,7 +372,7 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn, const char **clientout,
3434   *  Upon failure, -1 is returned.
3435   */
3436  int
3437 -sasl_do_kinit(struct lookup_context *ctxt)
3438 +sasl_do_kinit(unsigned logopt, struct lookup_context *ctxt)
3439  {
3440         krb5_error_code ret;
3441         krb5_principal tgs_princ, krb5_client_princ = ctxt->krb5_client_princ;
3442 @@ -384,33 +384,33 @@ sasl_do_kinit(struct lookup_context *ctxt)
3443                 return 0;
3444         ctxt->kinit_done = 1;
3445  
3446 -       debug(LOGOPT_NONE,
3447 +       debug(logopt,
3448               "initializing kerberos ticket: client principal %s ",
3449               ctxt->client_princ ? "" : "autofsclient");
3450  
3451         ret = krb5_init_context(&ctxt->krb5ctxt);
3452         if (ret) {
3453 -               error(LOGOPT_ANY, "krb5_init_context failed with %d", ret);
3454 +               error(logopt, "krb5_init_context failed with %d", ret);
3455                 return -1;
3456         }
3457  
3458         ret = krb5_cc_resolve(ctxt->krb5ctxt, krb5ccval, &ctxt->krb5_ccache);
3459         if (ret) {
3460 -               error(LOGOPT_ANY, "krb5_cc_resolve failed with error %d",
3461 +               error(logopt, "krb5_cc_resolve failed with error %d",
3462                       ret);
3463                 krb5_free_context(ctxt->krb5ctxt);
3464                 return -1;
3465         }
3466  
3467         if (ctxt->client_princ) {
3468 -               debug(LOGOPT_NONE,
3469 +               debug(logopt,
3470                       "calling krb5_parse_name on client principal %s",
3471                       ctxt->client_princ);
3472  
3473                 ret = krb5_parse_name(ctxt->krb5ctxt, ctxt->client_princ,
3474                                       &krb5_client_princ);
3475                 if (ret) {
3476 -                       error(LOGOPT_ANY,
3477 +                       error(logopt,
3478                               "krb5_parse_name failed for "
3479                               "specified client principal %s",
3480                               ctxt->client_princ);
3481 @@ -419,14 +419,14 @@ sasl_do_kinit(struct lookup_context *ctxt)
3482         } else {
3483                 char *tmp_name = NULL;
3484  
3485 -               debug(LOGOPT_NONE,
3486 +               debug(logopt,
3487                       "calling krb5_sname_to_principal using defaults");
3488  
3489                 ret = krb5_sname_to_principal(ctxt->krb5ctxt, NULL,
3490                                         "autofsclient", KRB5_NT_SRV_HST, 
3491                                         &krb5_client_princ);
3492                 if (ret) {
3493 -                       error(LOGOPT_ANY,
3494 +                       error(logopt,
3495                               "krb5_sname_to_principal failed for "
3496                               "%s with error %d",
3497                               ctxt->client_princ ? "" : "autofsclient", ret);
3498 @@ -437,13 +437,13 @@ sasl_do_kinit(struct lookup_context *ctxt)
3499                 ret = krb5_unparse_name(ctxt->krb5ctxt,
3500                                         krb5_client_princ, &tmp_name);
3501                 if (ret) {
3502 -                       debug(LOGOPT_NONE,
3503 +                       debug(logopt,
3504                               "krb5_unparse_name failed with error %d",
3505                               ret);
3506                         goto out_cleanup_cc;
3507                 }
3508  
3509 -               debug(LOGOPT_NONE,
3510 +               debug(logopt,
3511                       "principal used for authentication: \"%s\"", tmp_name);
3512  
3513                 krb5_free_unparsed_name(ctxt->krb5ctxt, tmp_name);
3514 @@ -458,19 +458,19 @@ sasl_do_kinit(struct lookup_context *ctxt)
3515                 krb5_princ_realm(ctxt->krb5ctxt, krb5_client_princ)->data,
3516                 0);
3517         if (ret) {
3518 -               error(LOGOPT_ANY,
3519 +               error(logopt,
3520                       "krb5_build_principal failed with error %d", ret);
3521                 goto out_cleanup_cc;
3522         }
3523  
3524         ret = krb5_unparse_name(ctxt->krb5ctxt, tgs_princ, &tgs_name);
3525         if (ret) {
3526 -               error(LOGOPT_ANY, "krb5_unparse_name failed with error %d",
3527 +               error(logopt, "krb5_unparse_name failed with error %d",
3528                       ret);
3529                 goto out_cleanup_cc;
3530         }
3531  
3532 -       debug(LOGOPT_NONE, "Using tgs name %s", tgs_name);
3533 +       debug(logopt, "Using tgs name %s", tgs_name);
3534  
3535         memset(&my_creds, 0, sizeof(my_creds));
3536         ret = krb5_get_init_creds_keytab(ctxt->krb5ctxt, &my_creds,
3537 @@ -479,7 +479,7 @@ sasl_do_kinit(struct lookup_context *ctxt)
3538                                          0 /* relative start time */,
3539                                          tgs_name, NULL);
3540         if (ret) {
3541 -               error(LOGOPT_ANY,
3542 +               error(logopt,
3543                       "krb5_get_init_creds_keytab failed with error %d",
3544                       ret);
3545                 goto out_cleanup_unparse;
3546 @@ -500,7 +500,7 @@ sasl_do_kinit(struct lookup_context *ctxt)
3547                 fatal(status);
3548  
3549         if (ret) {
3550 -               error(LOGOPT_ANY,
3551 +               error(logopt,
3552                       "krb5_cc_initialize failed with error %d", ret);
3553                 goto out_cleanup_unparse;
3554         }
3555 @@ -508,7 +508,7 @@ sasl_do_kinit(struct lookup_context *ctxt)
3556         /* and store credentials for that principal */
3557         ret = krb5_cc_store_cred(ctxt->krb5ctxt, ctxt->krb5_ccache, &my_creds);
3558         if (ret) {
3559 -               error(LOGOPT_ANY,
3560 +               error(logopt,
3561                       "krb5_cc_store_cred failed with error %d", ret);
3562                 goto out_cleanup_unparse;
3563         }
3564 @@ -516,12 +516,12 @@ sasl_do_kinit(struct lookup_context *ctxt)
3565         /* finally, set the environment variable to point to our
3566          * credentials cache */
3567         if (setenv(krb5ccenv, krb5ccval, 1) != 0) {
3568 -               error(LOGOPT_ANY, "setenv failed with %d", errno);
3569 +               error(logopt, "setenv failed with %d", errno);
3570                 goto out_cleanup_unparse;
3571         }
3572         ctxt->kinit_successful = 1;
3573  
3574 -       debug(LOGOPT_NONE, "Kerberos authentication was successful!");
3575 +       debug(logopt, "Kerberos authentication was successful!");
3576  
3577         krb5_free_unparsed_name(ctxt->krb5ctxt, tgs_name);
3578  
3579 @@ -540,7 +540,7 @@ out_cleanup_cc:
3580         else
3581                 ret = krb5_cc_destroy(ctxt->krb5ctxt, ctxt->krb5_ccache);
3582         if (ret)
3583 -               warn(LOGOPT_ANY,
3584 +               warn(logopt,
3585                      "krb5_cc_destroy failed with non-fatal error %d", ret);
3586  
3587         status = pthread_mutex_unlock(&krb5cc_mutex);
3588 @@ -559,7 +559,7 @@ out_cleanup_cc:
3589   *  Returns a valid sasl_conn_t pointer upon success, NULL on failure.
3590   */
3591  sasl_conn_t *
3592 -sasl_bind_mech(LDAP *ldap, struct lookup_context *ctxt, const char *mech)
3593 +sasl_bind_mech(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt, const char *mech)
3594  {
3595         sasl_conn_t *conn;
3596         char *tmp, *host = NULL;
3597 @@ -569,15 +569,15 @@ sasl_bind_mech(LDAP *ldap, struct lookup_context *ctxt, const char *mech)
3598         int result;
3599  
3600         if (!strncmp(mech, "GSSAPI", 6)) {
3601 -               if (sasl_do_kinit(ctxt) != 0)
3602 +               if (sasl_do_kinit(logopt, ctxt) != 0)
3603                         return NULL;
3604         }
3605  
3606 -       debug(LOGOPT_NONE, "Attempting sasl bind with mechanism %s", mech);
3607 +       debug(logopt, "Attempting sasl bind with mechanism %s", mech);
3608  
3609         result = ldap_get_option(ldap, LDAP_OPT_HOST_NAME, &host);
3610         if (result != LDAP_SUCCESS || !host) {
3611 -               debug(LOGOPT_NONE, "failed to get hostname for connection");
3612 +               debug(logopt, "failed to get hostname for connection");
3613                 return NULL;
3614         }
3615  
3616 @@ -587,7 +587,7 @@ sasl_bind_mech(LDAP *ldap, struct lookup_context *ctxt, const char *mech)
3617         /* Create a new authentication context for the service. */
3618         result = sasl_client_new("ldap", host, NULL, NULL, NULL, 0, &conn);
3619         if (result != SASL_OK) {
3620 -               error(LOGOPT_ANY, "sasl_client_new failed with error %d",
3621 +               error(logopt, "sasl_client_new failed with error %d",
3622                       result);
3623                 ldap_memfree(host);
3624                 return NULL;
3625 @@ -599,23 +599,23 @@ sasl_bind_mech(LDAP *ldap, struct lookup_context *ctxt, const char *mech)
3626  
3627         /* OK and CONTINUE are the only non-fatal return codes here. */
3628         if ((result != SASL_OK) && (result != SASL_CONTINUE)) {
3629 -               error(LOGOPT_ANY, "sasl_client start failed with error: %s",
3630 +               error(logopt, "sasl_client start failed with error: %s",
3631                       sasl_errdetail(conn));
3632                 ldap_memfree(host);
3633                 sasl_dispose(&conn);
3634                 return NULL;
3635         }
3636  
3637 -       result = do_sasl_bind(ldap, conn,
3638 +       result = do_sasl_bind(logopt, ldap, conn,
3639                          &clientout, &clientoutlen, chosen_mech, result);
3640         if (result == 0) {
3641                 ldap_memfree(host);
3642 -               debug(LOGOPT_NONE, "sasl bind with mechanism %s succeeded",
3643 +               debug(logopt, "sasl bind with mechanism %s succeeded",
3644                       chosen_mech);
3645                 return conn;
3646         }
3647  
3648 -       info(LOGOPT_ANY, "sasl bind with mechanism %s failed", mech);
3649 +       info(logopt, "sasl bind with mechanism %s failed", mech);
3650  
3651         /* sasl bind failed */
3652         ldap_memfree(host);
3653 @@ -629,14 +629,14 @@ sasl_bind_mech(LDAP *ldap, struct lookup_context *ctxt, const char *mech)
3654   *  -1 on error or if no mechanism is supported by both client and server.
3655   */
3656  sasl_conn_t *
3657 -sasl_choose_mech(LDAP *ldap, struct lookup_context *ctxt)
3658 +sasl_choose_mech(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
3659  {
3660         sasl_conn_t *conn;
3661         int authenticated;
3662         int i;
3663         char **mechanisms;
3664  
3665 -       mechanisms = get_server_SASL_mechanisms(ldap);
3666 +       mechanisms = get_server_SASL_mechanisms(logopt, ldap);
3667         if (!mechanisms)
3668                 return NULL;
3669  
3670 @@ -652,12 +652,11 @@ sasl_choose_mech(LDAP *ldap, struct lookup_context *ctxt)
3671                 if (authtype_requires_creds(mechanisms[i]))
3672                         continue;
3673  
3674 -               conn = sasl_bind_mech(ldap, ctxt, mechanisms[i]);
3675 +               conn = sasl_bind_mech(logopt, ldap, ctxt, mechanisms[i]);
3676                 if (conn) {
3677                         ctxt->sasl_mech = strdup(mechanisms[i]);
3678                         if (!ctxt->sasl_mech) {
3679 -                               crit(LOGOPT_ANY,
3680 -                                    "Successfully authenticated with "
3681 +                               crit(logopt, "Successfully authenticated with "
3682                                      "mechanism %s, but failed to allocate "
3683                                      "memory to hold the mechanism type.",
3684                                      mechanisms[i]);
3685 @@ -668,11 +667,11 @@ sasl_choose_mech(LDAP *ldap, struct lookup_context *ctxt)
3686                         authenticated = 1;
3687                         break;
3688                 }
3689 -               debug(LOGOPT_NONE, "Failed to authenticate with mech %s",
3690 +               debug(logopt, "Failed to authenticate with mech %s",
3691                       mechanisms[i]);
3692         }
3693  
3694 -       debug(LOGOPT_NONE, "authenticated: %d, sasl_mech: %s",
3695 +       debug(logopt, "authenticated: %d, sasl_mech: %s",
3696               authenticated, ctxt->sasl_mech);
3697  
3698         ldap_value_free(mechanisms);
3699 @@ -680,14 +679,14 @@ sasl_choose_mech(LDAP *ldap, struct lookup_context *ctxt)
3700  }
3701  
3702  int
3703 -autofs_sasl_bind(LDAP *ldap, struct lookup_context *ctxt)
3704 +autofs_sasl_bind(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
3705  {
3706         sasl_conn_t *conn;
3707  
3708         if (!ctxt->sasl_mech)
3709                 return -1;
3710  
3711 -       conn = sasl_bind_mech(ldap, ctxt, ctxt->sasl_mech);
3712 +       conn = sasl_bind_mech(logopt, ldap, ctxt, ctxt->sasl_mech);
3713         if (!conn)
3714                 return -1;
3715  
3716 @@ -717,13 +716,13 @@ autofs_sasl_unbind(struct lookup_context *ctxt)
3717   * -1  -  Failure
3718   */
3719  int
3720 -autofs_sasl_init(LDAP *ldap, struct lookup_context *ctxt)
3721 +autofs_sasl_init(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
3722  {
3723         sasl_conn_t *conn;
3724  
3725         /* Start up Cyrus SASL--only needs to be done once. */
3726         if (sasl_client_init(callbacks) != SASL_OK) {
3727 -               error(LOGOPT_ANY, "sasl_client_init failed");
3728 +               error(logopt, "sasl_client_init failed");
3729                 return -1;
3730         }
3731  
3732 @@ -736,9 +735,9 @@ autofs_sasl_init(LDAP *ldap, struct lookup_context *ctxt)
3733          *  select one.
3734          */
3735         if (ctxt->sasl_mech)
3736 -               conn = sasl_bind_mech(ldap, ctxt, ctxt->sasl_mech);
3737 +               conn = sasl_bind_mech(logopt, ldap, ctxt, ctxt->sasl_mech);
3738         else
3739 -               conn = sasl_choose_mech(ldap, ctxt);
3740 +               conn = sasl_choose_mech(logopt, ldap, ctxt);
3741  
3742         if (conn) {
3743                 sasl_dispose(&conn);
3744 @@ -772,8 +771,7 @@ autofs_sasl_done(struct lookup_context *ctxt)
3745                 else 
3746                         ret = krb5_cc_destroy(ctxt->krb5ctxt, ctxt->krb5_ccache);
3747                 if (ret)
3748 -                       warn(LOGOPT_ANY,
3749 -                            "krb5_cc_destroy failed with non-fatal error %d",
3750 +                       logmsg("krb5_cc_destroy failed with non-fatal error %d",
3751                              ret);
3752  
3753                 status = pthread_mutex_unlock(&krb5cc_mutex);
3754 @@ -782,8 +780,7 @@ autofs_sasl_done(struct lookup_context *ctxt)
3755  
3756                 krb5_free_context(ctxt->krb5ctxt);
3757                 if (unsetenv(krb5ccenv) != 0)
3758 -                       warn(LOGOPT_ANY,
3759 -                            "unsetenv failed with error %d", errno);
3760 +                       logerr("unsetenv failed with error %d", errno);
3761  
3762                 ctxt->krb5ctxt = NULL;
3763                 ctxt->krb5_ccache = NULL;
3764 diff --git a/modules/lookup_file.c b/modules/lookup_file.c
3765 index 31ee0fb..921b32b 100644
3766 --- a/modules/lookup_file.c
3767 +++ b/modules/lookup_file.c
3768 @@ -63,13 +63,13 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
3769         ctxt = malloc(sizeof(struct lookup_context));
3770         if (!ctxt) {
3771                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
3772 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
3773 +               logerr(MODPREFIX "malloc: %s", estr);
3774                 return 1;
3775         }
3776  
3777         if (argc < 1) {
3778                 free(ctxt);
3779 -               crit(LOGOPT_ANY, MODPREFIX "No map name");
3780 +               logerr(MODPREFIX "No map name");
3781                 return 1;
3782         }
3783  
3784 @@ -77,21 +77,21 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
3785  
3786         if (ctxt->mapname[0] != '/') {
3787                 free(ctxt);
3788 -               msg(MODPREFIX "file map %s is not an absolute pathname",
3789 -                   argv[0]);
3790 +               logmsg(MODPREFIX
3791 +                    "file map %s is not an absolute pathname", argv[0]);
3792                 return 1;
3793         }
3794  
3795         if (access(ctxt->mapname, R_OK)) {
3796                 free(ctxt);
3797 -               msg(MODPREFIX "file map %s missing or not readable",
3798 -                   argv[0]);
3799 +               warn(LOGOPT_NONE, MODPREFIX
3800 +                   "file map %s missing or not readable", argv[0]);
3801                 return 1;
3802         }
3803  
3804         if (stat(ctxt->mapname, &st)) {
3805                 free(ctxt);
3806 -               crit(LOGOPT_ANY, MODPREFIX "file map %s, could not stat",
3807 +               logmsg(MODPREFIX "file map %s, could not stat",
3808                      argv[0]);
3809                 return 1;
3810         }
3811 @@ -104,7 +104,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
3812         ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
3813         if (!ctxt->parse) {
3814                 free(ctxt);
3815 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
3816 +               logmsg(MODPREFIX "failed to open parse context");
3817                 return 1;
3818         }
3819         *context = ctxt;
3820 @@ -112,7 +112,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
3821         return 0;
3822  }
3823  
3824 -static int read_one(FILE *f, char *key, unsigned int *k_len, char *mapent, unsigned int *m_len)
3825 +static int read_one(unsigned logopt, FILE *f, char *key, unsigned int *k_len, char *mapent, unsigned int *m_len)
3826  {
3827         char *kptr, *p;
3828         int mapent_len, key_len;
3829 @@ -193,7 +193,7 @@ static int read_one(FILE *f, char *key, unsigned int *k_len, char *mapent, unsig
3830                                 if (gotten == got_plus)
3831                                         goto got_it;
3832                                 else if (escape == esc_all) {
3833 -                                       warn(LOGOPT_ANY, MODPREFIX
3834 +                                       warn(logopt, MODPREFIX
3835                                             "unmatched \" in map key %s", key);
3836                                         goto next;
3837                                 } else if (escape != esc_val)
3838 @@ -208,7 +208,7 @@ static int read_one(FILE *f, char *key, unsigned int *k_len, char *mapent, unsig
3839                                 if (key_len == KEY_MAX_LEN) {
3840                                         state = st_badent;
3841                                         gotten = got_nothing;
3842 -                                       warn(LOGOPT_ANY,
3843 +                                       warn(logopt,
3844                                               MODPREFIX "map key \"%s...\" "
3845                                               "is too long.  The maximum key "
3846                                               "length is %d", key,
3847 @@ -245,7 +245,7 @@ static int read_one(FILE *f, char *key, unsigned int *k_len, char *mapent, unsig
3848                                 state = st_begin;
3849                                 if (gotten == got_real || gotten == getting)
3850                                         goto got_it;
3851 -                               warn(LOGOPT_ANY, MODPREFIX 
3852 +                               warn(logopt, MODPREFIX 
3853                                       "bad map entry \"%s...\" for key "
3854                                       "\"%s\"", mapent, key);
3855                                 goto next;
3856 @@ -286,7 +286,7 @@ static int read_one(FILE *f, char *key, unsigned int *k_len, char *mapent, unsig
3857                         if (ch == '\n') {
3858                                 if (escape == esc_all) {
3859                                         state = st_begin;
3860 -                                       warn(LOGOPT_ANY, MODPREFIX
3861 +                                       warn(logopt, MODPREFIX
3862                                              "unmatched \" in %s for key %s",
3863                                              mapent, key);
3864                                         goto next;
3865 @@ -310,7 +310,7 @@ static int read_one(FILE *f, char *key, unsigned int *k_len, char *mapent, unsig
3866                                         goto got_it;
3867                                 ungetc(nch, f);
3868                         } else {
3869 -                               warn(LOGOPT_ANY,
3870 +                               warn(logopt,
3871                                       MODPREFIX "map entry \"%s...\" for key "
3872                                       "\"%s\" is too long.  The maximum entry"
3873                                       " size is %d", mapent, key,
3874 @@ -388,6 +388,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
3875         struct lookup_context *ctxt = (struct lookup_context *) context;
3876         unsigned int timeout = master->default_timeout;
3877         unsigned int logging = master->default_logging;
3878 +       unsigned int logopt = master->logopt;
3879         char *buffer;
3880         int blen;
3881         char *path;
3882 @@ -402,29 +403,28 @@ int lookup_read_master(struct master *master, time_t age, void *context)
3883                 return NSS_STATUS_UNAVAIL;
3884  
3885         if (master->depth > MAX_INCLUDE_DEPTH) {
3886 -               error(LOGOPT_ANY,
3887 -                     MODPREFIX
3888 +               error(logopt, MODPREFIX
3889                       "maximum include depth exceeded %s", master->name);
3890                 return NSS_STATUS_UNAVAIL;
3891         }
3892  
3893         path = alloca(KEY_MAX_LEN + 1);
3894         if (!path) {
3895 -               error(LOGOPT_ANY,
3896 +               error(logopt,
3897                       MODPREFIX "could not malloc storage for path");
3898                 return NSS_STATUS_UNAVAIL;
3899         }
3900  
3901         ent = alloca(MAPENT_MAX_LEN + 1);
3902         if (!ent) {
3903 -               error(LOGOPT_ANY,
3904 +               error(logopt,
3905                       MODPREFIX "could not malloc storage for mapent");
3906                 return NSS_STATUS_UNAVAIL;
3907         }
3908  
3909         f = fopen(ctxt->mapname, "r");
3910         if (!f) {
3911 -               error(LOGOPT_ANY,
3912 +               error(logopt,
3913                       MODPREFIX "could not open master map file %s",
3914                       ctxt->mapname);
3915                 return NSS_STATUS_UNAVAIL;
3916 @@ -438,19 +438,19 @@ int lookup_read_master(struct master *master, time_t age, void *context)
3917         }
3918  
3919         while(1) {
3920 -               entry = read_one(f, path, &path_len, ent, &ent_len);
3921 +               entry = read_one(logopt, f, path, &path_len, ent, &ent_len);
3922                 if (!entry) {
3923                         if (feof(f))
3924                                 break;
3925                         if (ferror(f)) {
3926 -                               warn(LOGOPT_ANY, MODPREFIX
3927 +                               warn(logopt, MODPREFIX
3928                                      "error reading map %s", ctxt->mapname);
3929                                 break;
3930                         }
3931                         continue;
3932                 }
3933  
3934 -               debug(LOGOPT_NONE, MODPREFIX "read entry %s", path);
3935 +               debug(logopt, MODPREFIX "read entry %s", path);
3936  
3937                 /*
3938                  * If key starts with '+' it has to be an
3939 @@ -470,7 +470,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
3940                         master->depth++;
3941                         status = lookup_nss_read_master(master, age);
3942                         if (!status)
3943 -                               warn(LOGOPT_ANY,
3944 +                               warn(logopt,
3945                                      MODPREFIX
3946                                      "failed to read included master map %s",
3947                                      master->name);
3948 @@ -482,7 +482,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
3949                         blen = path_len + 1 + ent_len + 1;
3950                         buffer = malloc(blen);
3951                         if (!buffer) {
3952 -                               error(LOGOPT_ANY,
3953 +                               error(logopt,
3954                                       MODPREFIX "could not malloc parse buffer");
3955                                 return NSS_STATUS_UNAVAIL;
3956                         }
3957 @@ -503,7 +503,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
3958         }
3959  
3960         if (fstat(fd, &st)) {
3961 -               crit(LOGOPT_ANY, MODPREFIX "file map %s, could not stat",
3962 +               crit(logopt, MODPREFIX "file map %s, could not stat",
3963                        ctxt->mapname);
3964                 return NSS_STATUS_UNAVAIL;
3965         }
3966 @@ -684,12 +684,12 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
3967         }
3968  
3969         while(1) {
3970 -               entry = read_one(f, key, &k_len, mapent, &m_len);
3971 +               entry = read_one(ap->logopt, f, key, &k_len, mapent, &m_len);
3972                 if (!entry) {
3973                         if (feof(f))
3974                                 break;
3975                         if (ferror(f)) {
3976 -                               warn(LOGOPT_ANY, MODPREFIX
3977 +                               warn(ap->logopt, MODPREFIX
3978                                       "error reading map %s", ctxt->mapname);
3979                                 break;
3980                         }
3981 @@ -791,7 +791,7 @@ static int lookup_one(struct autofs_point *ap,
3982         }
3983  
3984         while(1) {
3985 -               entry = read_one(f, mkey, &k_len, mapent, &m_len);
3986 +               entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
3987                 if (entry) {
3988                         /*
3989                          * If key starts with '+' it has to be an
3990 @@ -860,7 +860,7 @@ static int lookup_one(struct autofs_point *ap,
3991                         break;
3992  
3993                 if (ferror(f)) {
3994 -                       warn(LOGOPT_ANY, MODPREFIX
3995 +                       warn(ap->logopt, MODPREFIX
3996                               "error reading map %s", ctxt->mapname);
3997                         break;
3998                 }               
3999 @@ -904,7 +904,7 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
4000         }
4001  
4002         while(1) {
4003 -               entry = read_one(f, mkey, &k_len, mapent, &m_len);
4004 +               entry = read_one(ap->logopt, f, mkey, &k_len, mapent, &m_len);
4005                 if (entry) {
4006                         int eq;
4007  
4008 @@ -925,7 +925,7 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
4009                         break;
4010  
4011                 if (ferror(f)) {
4012 -                       warn(LOGOPT_ANY, MODPREFIX
4013 +                       warn(ap->logopt, MODPREFIX
4014                               "error reading map %s", ctxt->mapname);
4015                         break;
4016                 }               
4017 diff --git a/modules/lookup_hesiod.c b/modules/lookup_hesiod.c
4018 index f30e9b2..649e24c 100644
4019 --- a/modules/lookup_hesiod.c
4020 +++ b/modules/lookup_hesiod.c
4021 @@ -48,7 +48,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4022         ctxt = malloc(sizeof(struct lookup_context));
4023         if (!ctxt) {
4024                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4025 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4026 +               logerr(MODPREFIX "malloc: %s", estr);
4027                 return 1;
4028         }
4029  
4030 @@ -58,7 +58,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4031         /* Initialize the hesiod context. */
4032         if (hesiod_init(&(ctxt->hesiod_context)) != 0) {
4033                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4034 -               crit(LOGOPT_ANY, MODPREFIX "hesiod_init(): %s", estr);
4035 +               logerr(MODPREFIX "hesiod_init(): %s", estr);
4036                 free(ctxt);
4037                 return 1;
4038         }
4039 @@ -70,7 +70,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4040         /* Open the parser, if we can. */
4041         ctxt->parser = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
4042         if (!ctxt->parser) {
4043 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
4044 +               logerr(MODPREFIX "failed to open parse context");
4045                 free(ctxt);
4046                 return 1;
4047         }
4048 diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
4049 index d711611..d746e42 100644
4050 --- a/modules/lookup_hosts.c
4051 +++ b/modules/lookup_hosts.c
4052 @@ -57,7 +57,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4053         ctxt = malloc(sizeof(struct lookup_context));
4054         if (!ctxt) {
4055                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4056 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4057 +               logerr(MODPREFIX "malloc: %s", estr);
4058                 return 1;
4059         }
4060  
4061 @@ -65,7 +65,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4062  
4063         ctxt->parse = open_parse(mapfmt, MODPREFIX, argc, argv);
4064         if (!ctxt->parse) {
4065 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
4066 +               logerr(MODPREFIX "failed to open parse context");
4067                 free(ctxt);
4068                 return 1;
4069         }
4070 @@ -94,7 +94,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
4071  
4072         status = pthread_mutex_lock(&hostent_mutex);
4073         if (status) {
4074 -               error(LOGOPT_ANY, MODPREFIX "failed to lock hostent mutex");
4075 +               error(ap->logopt, MODPREFIX "failed to lock hostent mutex");
4076                 return NSS_STATUS_UNAVAIL;
4077         }
4078  
4079 @@ -110,7 +110,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
4080  
4081         status = pthread_mutex_unlock(&hostent_mutex);
4082         if (status)
4083 -               error(LOGOPT_ANY, MODPREFIX "failed to unlock hostent mutex");
4084 +               error(ap->logopt, MODPREFIX "failed to unlock hostent mutex");
4085  
4086         source->age = age;
4087  
4088 @@ -157,10 +157,10 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
4089                 }
4090  
4091                 if (*name == '/')
4092 -                       msg(MODPREFIX
4093 +                       info(ap->logopt, MODPREFIX
4094                               "can't find path in hosts map %s", name);
4095                 else
4096 -                       msg(MODPREFIX
4097 +                       info(ap->logopt, MODPREFIX
4098                               "can't find path in hosts map %s/%s",
4099                               ap->path, name);
4100  
4101 @@ -216,7 +216,7 @@ done:
4102                         if (!mapent) {
4103                                 char *estr;
4104                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
4105 -                               crit(ap->logopt, MODPREFIX "malloc: %s", estr);
4106 +                               logerr(MODPREFIX "malloc: %s", estr);
4107                                 rpc_exports_free(exp);
4108                                 return NSS_STATUS_UNAVAIL;
4109                         }
4110 @@ -230,7 +230,7 @@ done:
4111                         if (!mapent) {
4112                                 char *estr;
4113                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
4114 -                               crit(ap->logopt, MODPREFIX "malloc: %s", estr);
4115 +                               logerr(MODPREFIX "malloc: %s", estr);
4116                                 rpc_exports_free(exp);
4117                                 return NSS_STATUS_UNAVAIL;
4118                         }
4119 diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
4120 index c0f228b..00215af 100644
4121 --- a/modules/lookup_ldap.c
4122 +++ b/modules/lookup_ldap.c
4123 @@ -49,9 +49,9 @@ static struct ldap_schema common_schema[] = {
4124  };
4125  static unsigned int common_schema_count = sizeof(common_schema)/sizeof(struct ldap_schema);
4126  
4127 -static LDAP *auth_init(const char *, struct lookup_context *);
4128 +static LDAP *auth_init(unsigned logopt, const char *, struct lookup_context *);
4129  
4130 -int bind_ldap_anonymous(LDAP *ldap, struct lookup_context *ctxt)
4131 +int bind_ldap_anonymous(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
4132  {
4133         int rv;
4134  
4135 @@ -62,15 +62,14 @@ int bind_ldap_anonymous(LDAP *ldap, struct lookup_context *ctxt)
4136  
4137         if (rv != LDAP_SUCCESS) {
4138                 if (!ctxt->uri) {
4139 -                       crit(LOGOPT_ANY,
4140 -                            MODPREFIX "Unable to bind to the LDAP server: "
4141 +                       crit(logopt, MODPREFIX
4142 +                            "Unable to bind to the LDAP server: "
4143                              "%s, error %s", ctxt->server ? "" : "(default)",
4144                              ldap_err2string(rv));
4145                 } else {
4146                         struct ldap_uri *uri;
4147                         uri = list_entry(ctxt->uri->next, struct ldap_uri, list);
4148 -                       warn(LOGOPT_ANY,
4149 -                            MODPREFIX "Unable to bind to the LDAP server: "
4150 +                       info(logopt, MODPREFIX "Unable to bind to the LDAP server: "
4151                              "%s, error %s", uri->uri, ldap_err2string(rv));
4152                 }
4153                 return -1;
4154 @@ -79,12 +78,11 @@ int bind_ldap_anonymous(LDAP *ldap, struct lookup_context *ctxt)
4155         return 0;
4156  }
4157  
4158 -int unbind_ldap_connection(LDAP *ldap, struct lookup_context *ctxt)
4159 +int unbind_ldap_connection(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
4160  {
4161         int rv;
4162  
4163  #ifdef WITH_SASL
4164 -       debug(LOGOPT_NONE, "use_tls: %d", ctxt->use_tls);
4165         /*
4166          * The OpenSSL library can't handle having its message and error
4167          * string database loaded multiple times and segfaults if the
4168 @@ -102,13 +100,12 @@ int unbind_ldap_connection(LDAP *ldap, struct lookup_context *ctxt)
4169  
4170         rv = ldap_unbind_ext(ldap, NULL, NULL);
4171         if (rv != LDAP_SUCCESS)
4172 -               error(LOGOPT_ANY,
4173 -                    "unbind failed: %s", ldap_err2string(rv));
4174 +               error(logopt, "unbind failed: %s", ldap_err2string(rv));
4175  
4176         return rv;
4177  }
4178  
4179 -LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4180 +LDAP *init_ldap_connection(unsigned logopt, const char *uri, struct lookup_context *ctxt)
4181  {
4182         LDAP *ldap = NULL;
4183         struct timeval timeout     = { ctxt->timeout, 0 };
4184 @@ -120,9 +117,9 @@ LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4185         /* Initialize the LDAP context. */
4186         rv = ldap_initialize(&ldap, uri);
4187         if (rv != LDAP_OPT_SUCCESS) {
4188 -               crit(LOGOPT_ANY,
4189 -                    MODPREFIX "couldn't initialize LDAP connection to %s",
4190 -                    uri ? uri : "default server");
4191 +               info(logopt, MODPREFIX
4192 +                    "couldn't initialize LDAP connection to %s",
4193 +                    uri ? uri : "default");
4194                 return NULL;
4195         }
4196  
4197 @@ -133,7 +130,7 @@ LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4198                 ldap_unbind_ext(ldap, NULL, NULL);
4199                 rv = ldap_initialize(&ldap, uri);
4200                 if (rv != LDAP_OPT_SUCCESS) {
4201 -                       crit(LOGOPT_ANY, MODPREFIX "couldn't initialize LDAP");
4202 +                       crit(logopt, MODPREFIX "couldn't initialize LDAP");
4203                         return NULL;
4204                 }
4205                 ctxt->version = 2;
4206 @@ -144,7 +141,7 @@ LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4207                 /* Set synchronous call timeout */
4208                 rv = ldap_set_option(ldap, LDAP_OPT_TIMEOUT, &timeout);
4209                 if (rv != LDAP_OPT_SUCCESS)
4210 -                       info(LOGOPT_ANY, MODPREFIX
4211 +                       info(logopt, MODPREFIX
4212                              "failed to set synchronous call timeout to %d",
4213                              timeout.tv_sec);
4214         }
4215 @@ -152,16 +149,14 @@ LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4216         /* Sane network timeout */
4217         rv = ldap_set_option(ldap, LDAP_OPT_NETWORK_TIMEOUT, &net_timeout);
4218         if (rv != LDAP_OPT_SUCCESS)
4219 -               info(LOGOPT_ANY,
4220 -                    MODPREFIX "failed to set connection timeout to %d",
4221 +               info(logopt, MODPREFIX "failed to set connection timeout to %d",
4222                      net_timeout.tv_sec);
4223  
4224  #ifdef WITH_SASL
4225         if (ctxt->use_tls) {
4226                 if (ctxt->version == 2) {
4227                         if (ctxt->tls_required) {
4228 -                               error(LOGOPT_ANY,
4229 -                                   MODPREFIX
4230 +                               error(logopt, MODPREFIX
4231                                     "TLS required but connection is version 2");
4232                                 ldap_unbind_ext(ldap, NULL, NULL);
4233                                 return NULL;
4234 @@ -171,16 +166,15 @@ LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4235  
4236                 rv = ldap_start_tls_s(ldap, NULL, NULL);
4237                 if (rv != LDAP_SUCCESS) {
4238 -                       unbind_ldap_connection(ldap, ctxt);
4239 +                       unbind_ldap_connection(logopt, ldap, ctxt);
4240                         if (ctxt->tls_required) {
4241 -                               error(LOGOPT_ANY,
4242 -                                     MODPREFIX
4243 +                               error(logopt, MODPREFIX
4244                                       "TLS required but START_TLS failed: %s",
4245                                       ldap_err2string(rv));
4246                                 return NULL;
4247                         }
4248                         ctxt->use_tls = LDAP_TLS_DONT_USE;
4249 -                       ldap = init_ldap_connection(uri, ctxt);
4250 +                       ldap = init_ldap_connection(logopt, uri, ctxt);
4251                         if (ldap)
4252                                 ctxt->use_tls = LDAP_TLS_INIT;
4253                         return ldap;
4254 @@ -192,7 +186,7 @@ LDAP *init_ldap_connection(const char *uri, struct lookup_context *ctxt)
4255         return ldap;
4256  }
4257  
4258 -static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *class, const char *key)
4259 +static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt, const char *class, const char *key)
4260  {
4261         char buf[PARSE_MAX_BUF];
4262         char *query, *dn, *qdn;
4263 @@ -206,7 +200,7 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *cla
4264         attrs[1] = NULL;
4265  
4266         if (!ctxt->mapname && !ctxt->base) {
4267 -               error(LOGOPT_ANY, MODPREFIX "no master map to lookup");
4268 +               error(logopt, MODPREFIX "no master map to lookup");
4269                 return 0;
4270         }
4271  
4272 @@ -218,7 +212,7 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *cla
4273         query = alloca(l);
4274         if (query == NULL) {
4275                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4276 -               crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr);
4277 +               crit(logopt, MODPREFIX "alloca: %s", estr);
4278                 return NSS_STATUS_UNAVAIL;
4279         }
4280  
4281 @@ -229,14 +223,14 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *cla
4282         if (ctxt->mapname) {
4283                 if (sprintf(query, "(&(objectclass=%s)(%s=%.*s))", class,
4284                      key, (int) strlen(ctxt->mapname), ctxt->mapname) >= l) {
4285 -                       debug(LOGOPT_NONE,
4286 +                       debug(logopt,
4287                               MODPREFIX "error forming query string");
4288                         return 0;
4289                 }
4290                 scope = LDAP_SCOPE_SUBTREE;
4291         } else {
4292                 if (sprintf(query, "(objectclass=%s)", class) >= l) {
4293 -                       debug(LOGOPT_NONE,
4294 +                       debug(logopt,
4295                               MODPREFIX "error forming query string");
4296                         return 0;
4297                 }
4298 @@ -259,15 +253,14 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *cla
4299         else {
4300                 struct ldap_searchdn *this = ctxt->sdns;
4301  
4302 -               debug(LOGOPT_NONE, MODPREFIX
4303 -                             "check search base list");
4304 +               debug(logopt, MODPREFIX "check search base list");
4305  
4306                 while (this) {
4307                         rv = ldap_search_s(ldap, this->basedn,
4308                                            scope, query, attrs, 0, &result);
4309  
4310                         if ((rv == LDAP_SUCCESS) && result) {
4311 -                               debug(LOGOPT_NONE, MODPREFIX
4312 +                               debug(logopt, MODPREFIX
4313                                       "found search base under %s",
4314                                       this->basedn);
4315                                 break;
4316 @@ -283,7 +276,7 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *cla
4317         }
4318  
4319         if ((rv != LDAP_SUCCESS) || !result) {
4320 -               error(LOGOPT_NONE,
4321 +               error(logopt,
4322                       MODPREFIX "query failed for %s: %s",
4323                       query, ldap_err2string(rv));
4324                 return 0;
4325 @@ -292,9 +285,9 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *cla
4326         e = ldap_first_entry(ldap, result);
4327         if (e) {
4328                 dn = ldap_get_dn(ldap, e);
4329 -               debug(LOGOPT_NONE, MODPREFIX "found query dn %s", dn);
4330 +               debug(logopt, MODPREFIX "found query dn %s", dn);
4331         } else {
4332 -               debug(LOGOPT_NONE,
4333 +               debug(logopt,
4334                       MODPREFIX "query succeeded, no matches for %s",
4335                       query);
4336                 ldap_msgfree(result);
4337 @@ -373,7 +366,7 @@ static struct ldap_schema *alloc_common_schema(struct ldap_schema *s)
4338         return schema;
4339  }
4340  
4341 -static int find_query_dn(LDAP *ldap, struct lookup_context *ctxt)
4342 +static int find_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
4343  {
4344         struct ldap_schema *schema;
4345         unsigned int i;
4346 @@ -384,11 +377,10 @@ static int find_query_dn(LDAP *ldap, struct lookup_context *ctxt)
4347         for (i = 0; i < common_schema_count; i++) {
4348                 const char *class = common_schema[i].map_class;
4349                 const char *key = common_schema[i].map_attr;
4350 -               if (get_query_dn(ldap, ctxt, class, key)) {
4351 +               if (get_query_dn(logopt, ldap, ctxt, class, key)) {
4352                         schema = alloc_common_schema(&common_schema[i]);
4353                         if (!schema) {
4354 -                               error(LOGOPT_ANY,
4355 -                                     MODPREFIX "failed to allocate schema");
4356 +                               error(logopt, MODPREFIX "failed to allocate schema");
4357                                 return 0;
4358                         }
4359                         ctxt->schema = schema;
4360 @@ -399,28 +391,26 @@ static int find_query_dn(LDAP *ldap, struct lookup_context *ctxt)
4361         return 0;
4362  }
4363  
4364 -static int do_bind(LDAP *ldap, struct lookup_context *ctxt)
4365 +static int do_bind(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
4366  {
4367         char *host = NULL, *nhost;
4368         int rv, need_base = 1;
4369  
4370  #ifdef WITH_SASL
4371 -       debug(LOGOPT_NONE, "auth_required: %d, sasl_mech %s",
4372 +       debug(logopt, MODPREFIX "auth_required: %d, sasl_mech %s",
4373               ctxt->auth_required, ctxt->sasl_mech);
4374  
4375         if (ctxt->sasl_mech ||
4376            (ctxt->auth_required & (LDAP_AUTH_REQUIRED|LDAP_AUTH_AUTODETECT))) {
4377 -               rv = autofs_sasl_bind(ldap, ctxt);
4378 -               debug(LOGOPT_NONE, MODPREFIX
4379 -                     "autofs_sasl_bind returned %d", rv);
4380 +               rv = autofs_sasl_bind(logopt, ldap, ctxt);
4381 +               debug(logopt, MODPREFIX "autofs_sasl_bind returned %d", rv);
4382         } else {
4383 -               rv = bind_ldap_anonymous(ldap, ctxt);
4384 -               debug(LOGOPT_NONE,
4385 -                     MODPREFIX "ldap anonymous bind returned %d", rv);
4386 +               rv = bind_ldap_anonymous(logopt, ldap, ctxt);
4387 +               debug(logopt, MODPREFIX "ldap anonymous bind returned %d", rv);
4388         }
4389  #else
4390 -       rv = bind_ldap_anonymous(ldap, ctxt);
4391 -       debug(LOGOPT_NONE, MODPREFIX "ldap anonymous bind returned %d", rv);
4392 +       rv = bind_ldap_anonymous(logopt, ldap, ctxt);
4393 +       debug(logopt, MODPREFIX "ldap anonymous bind returned %d", rv);
4394  #endif
4395  
4396         if (rv != 0)
4397 @@ -428,13 +418,13 @@ static int do_bind(LDAP *ldap, struct lookup_context *ctxt)
4398  
4399         rv = ldap_get_option(ldap, LDAP_OPT_HOST_NAME, &host);
4400          if (rv != LDAP_SUCCESS || !host) {
4401 -               debug(LOGOPT_ANY, "failed to get hostname for connection");
4402 +               debug(logopt, "failed to get hostname for connection");
4403                 return 0;
4404         }
4405  
4406         nhost = strdup(host);
4407         if (!nhost) {
4408 -               debug(LOGOPT_ANY, "failed to alloc context for hostname");
4409 +               debug(logopt, "failed to alloc context for hostname");
4410                 return 0;
4411         }
4412         ldap_memfree(host);
4413 @@ -463,16 +453,16 @@ static int do_bind(LDAP *ldap, struct lookup_context *ctxt)
4414          * base dn for searches.
4415          */
4416         if (!ctxt->schema) {
4417 -               if (!find_query_dn(ldap, ctxt)) {
4418 -                       error(LOGOPT_ANY,
4419 -                             MODPREFIX "failed to find valid query dn");
4420 +               if (!find_query_dn(logopt, ldap, ctxt)) {
4421 +                       warn(logopt,
4422 +                             MODPREFIX "failed to find valid query dn");
4423                         return 0;
4424                 }
4425         } else {
4426                 const char *class = ctxt->schema->map_class;
4427                 const char *key = ctxt->schema->map_attr;
4428 -               if (!get_query_dn(ldap, ctxt, class, key)) {
4429 -                       error(LOGOPT_ANY, MODPREFIX "failed to get query dn");
4430 +               if (!get_query_dn(logopt, ldap, ctxt, class, key)) {
4431 +                       error(logopt, MODPREFIX "failed to get query dn");
4432                         return 0;
4433                 }
4434         }
4435 @@ -480,23 +470,23 @@ static int do_bind(LDAP *ldap, struct lookup_context *ctxt)
4436         return 1;
4437  }
4438  
4439 -static LDAP *do_connect(const char *uri, struct lookup_context *ctxt)
4440 +static LDAP *do_connect(unsigned logopt, const char *uri, struct lookup_context *ctxt)
4441  {
4442         LDAP *ldap;
4443  
4444 -       ldap = init_ldap_connection(uri, ctxt);
4445 +       ldap = init_ldap_connection(logopt, uri, ctxt);
4446         if (!ldap)
4447                 return NULL;
4448  
4449 -       if (!do_bind(ldap, ctxt)) {
4450 -               unbind_ldap_connection(ldap, ctxt);
4451 +       if (!do_bind(logopt, ldap, ctxt)) {
4452 +               unbind_ldap_connection(logopt, ldap, ctxt);
4453                 return NULL;
4454         }
4455  
4456         return ldap;
4457  }
4458  
4459 -static LDAP *connect_to_server(const char *uri, struct lookup_context *ctxt)
4460 +static LDAP *connect_to_server(unsigned logopt, const char *uri, struct lookup_context *ctxt)
4461  {
4462         LDAP *ldap;
4463  
4464 @@ -506,19 +496,19 @@ static LDAP *connect_to_server(const char *uri, struct lookup_context *ctxt)
4465          * authentication.
4466          */
4467         if (ctxt->auth_required & LDAP_AUTH_REQUIRED) {
4468 -               ldap = auth_init(uri, ctxt);
4469 +               ldap = auth_init(logopt, uri, ctxt);
4470                 if (!ldap && ctxt->auth_required & LDAP_AUTH_AUTODETECT)
4471 -                       warn(LOGOPT_NONE,
4472 +                       info(logopt,
4473                              "no authentication mechanisms auto detected.");
4474                 if (!ldap) {
4475 -                       error(LOGOPT_ANY, MODPREFIX
4476 +                       error(logopt, MODPREFIX
4477                               "cannot initialize authentication setup");
4478                         return NULL;
4479                 }
4480  
4481 -               if (!do_bind(ldap, ctxt)) {
4482 -                       unbind_ldap_connection(ldap, ctxt);
4483 -                       error(LOGOPT_ANY, MODPREFIX "cannot bind to server");
4484 +               if (!do_bind(logopt, ldap, ctxt)) {
4485 +                       unbind_ldap_connection(logopt, ldap, ctxt);
4486 +                       error(logopt, MODPREFIX "cannot bind to server");
4487                         return NULL;
4488                 }
4489  
4490 @@ -526,16 +516,18 @@ static LDAP *connect_to_server(const char *uri, struct lookup_context *ctxt)
4491         }
4492  #endif
4493  
4494 -       ldap = do_connect(uri, ctxt);
4495 +       ldap = do_connect(logopt, uri, ctxt);
4496         if (!ldap) {
4497 -               error(LOGOPT_ANY, MODPREFIX "cannot connect to server");
4498 +               warn(logopt,
4499 +                    MODPREFIX "couldn't connect to server %s",
4500 +                    uri ? uri : "default");
4501                 return NULL;
4502         }
4503  
4504         return ldap;
4505  }
4506  
4507 -static LDAP *find_server(struct lookup_context *ctxt)
4508 +static LDAP *find_server(unsigned logopt, struct lookup_context *ctxt)
4509  {
4510         LDAP *ldap = NULL;
4511         struct ldap_uri *this;
4512 @@ -547,10 +539,9 @@ static LDAP *find_server(struct lookup_context *ctxt)
4513         while(p != ctxt->uri) {
4514                 this = list_entry(p, struct ldap_uri, list);
4515                 p = p->next;
4516 -               debug(LOGOPT_ANY, "check uri %s", this->uri);
4517 -               ldap = connect_to_server(this->uri, ctxt);
4518 +               ldap = connect_to_server(logopt, this->uri, ctxt);
4519                 if (ldap) {
4520 -                       debug(LOGOPT_ANY, "connexted to uri %s", this->uri);
4521 +                       info(logopt, "connected to uri %s", this->uri);
4522                         break;
4523                 }
4524                 list_del_init(&this->list);
4525 @@ -568,17 +559,17 @@ static LDAP *find_server(struct lookup_context *ctxt)
4526         return ldap;
4527  }
4528  
4529 -static LDAP *do_reconnect(struct lookup_context *ctxt)
4530 +static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
4531  {
4532         LDAP *ldap;
4533  
4534         if (ctxt->server || !ctxt->uri) {
4535 -               ldap = do_connect(ctxt->server, ctxt);
4536 +               ldap = do_connect(logopt, ctxt->server, ctxt);
4537                 return ldap;
4538         } else {
4539                 struct ldap_uri *this;
4540                 this = list_entry(ctxt->uri->next, struct ldap_uri, list);
4541 -               ldap = do_connect(this->uri, ctxt);
4542 +               ldap = do_connect(logopt, this->uri, ctxt);
4543                 if (ldap)
4544                         return ldap;
4545                 /* Failed to connect, put at end of list */
4546 @@ -589,15 +580,15 @@ static LDAP *do_reconnect(struct lookup_context *ctxt)
4547         autofs_sasl_done(ctxt);
4548  
4549         /* Current server failed connect, try the rest */
4550 -       ldap = find_server(ctxt);
4551 +       ldap = find_server(logopt, ctxt);
4552         if (!ldap)
4553 -               error(LOGOPT_ANY, MODPREFIX "failed to find available server");
4554 +               error(logopt, MODPREFIX "failed to find available server");
4555  
4556         return ldap;
4557  }
4558  
4559  #ifdef WITH_SASL
4560 -int get_property(xmlNodePtr node, const char *prop, char **value)
4561 +int get_property(unsigned logopt, xmlNodePtr node, const char *prop, char **value)
4562  {
4563         xmlChar *ret;
4564         xmlChar *property = (xmlChar *) prop;
4565 @@ -608,8 +599,7 @@ int get_property(xmlNodePtr node, const char *prop, char **value)
4566         }
4567  
4568         if (!(*value = strdup((char *) ret))) {
4569 -               error(LOGOPT_ANY,
4570 -                     MODPREFIX "strdup failed with %d", errno);
4571 +               logerr(MODPREFIX "strdup failed with %d", errno);
4572                 xmlFree(ret);
4573                 return -1;
4574         }
4575 @@ -645,7 +635,7 @@ int authtype_requires_creds(const char *authtype)
4576   *  then no further action is necessary.  If it is not, the caller is free
4577   *  to then use another method to determine how to connect to the server.
4578   */
4579 -int parse_ldap_config(struct lookup_context *ctxt)
4580 +int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
4581  {
4582         int          ret = 0, fallback = 0;
4583         unsigned int auth_required = LDAP_AUTH_NOTREQUIRED;
4584 @@ -662,7 +652,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4585  
4586         auth_conf = (char *) defaults_get_auth_conf_file();
4587         if (!auth_conf) {
4588 -               error(LOGOPT_ANY,
4589 +               error(logopt,
4590                       MODPREFIX "failed to get auth config file name.");
4591                 return 0;
4592         }
4593 @@ -687,7 +677,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4594                         ctxt->client_princ = NULL;
4595                         return 0;
4596                 }
4597 -               error(LOGOPT_ANY,
4598 +               error(logopt,
4599                       MODPREFIX "stat(2) failed with error %s.",
4600                       strerror(errno));
4601                 return 0;
4602 @@ -696,8 +686,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4603         if (!S_ISREG(st.st_mode) ||
4604             st.st_uid != 0 || st.st_gid != 0 ||
4605             (st.st_mode & 0x01ff) != 0600) {
4606 -               error(LOGOPT_ANY,
4607 -                     MODPREFIX
4608 +               error(logopt, MODPREFIX
4609                       "Configuration file %s exists, but is not usable. "
4610                       "Please make sure that it is owned by root, group "
4611                       "is root, and the mode is 0600.",
4612 @@ -708,30 +697,29 @@ int parse_ldap_config(struct lookup_context *ctxt)
4613         xmlInitParser();
4614         doc = xmlParseFile(auth_conf);
4615         if (!doc) {
4616 -               warn(LOGOPT_ANY,
4617 -                    MODPREFIX "xmlParseFile failed for %s.", auth_conf);
4618 +               error(logopt, MODPREFIX
4619 +                    "xmlParseFile failed for %s.", auth_conf);
4620                 goto out;
4621         }
4622  
4623         root = xmlDocGetRootElement(doc);
4624         if (!root) {
4625 -               debug(LOGOPT_ANY,
4626 -                     MODPREFIX "empty xml document (%s).", auth_conf);
4627 +               debug(logopt, MODPREFIX
4628 +                     "empty xml document (%s).", auth_conf);
4629                 fallback = 1;
4630                 goto out;
4631         }
4632  
4633         if (xmlStrcmp(root->name, (const xmlChar *)"autofs_ldap_sasl_conf")) {
4634 -               error(LOGOPT_ANY,
4635 -                     MODPREFIX
4636 +               error(logopt, MODPREFIX
4637                       "The root node of the XML document %s is not "
4638                       "autofs_ldap_sasl_conf.", auth_conf);
4639                 goto out;
4640         }
4641  
4642 -       ret = get_property(root, "usetls", &usetls);
4643 +       ret = get_property(logopt, root, "usetls", &usetls);
4644         if (ret != 0) {
4645 -               error(LOGOPT_ANY,
4646 +               error(logopt,
4647                       MODPREFIX
4648                       "Failed read the usetls property from "
4649                       "the configuration file %s.", auth_conf);
4650 @@ -746,7 +734,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4651                 else if (!strcasecmp(usetls, "no"))
4652                         use_tls = LDAP_TLS_DONT_USE;
4653                 else {
4654 -                       error(LOGOPT_ANY,
4655 +                       error(logopt,
4656                               MODPREFIX
4657                               "The usetls property must have value "
4658                               "\"yes\" or \"no\".");
4659 @@ -756,9 +744,9 @@ int parse_ldap_config(struct lookup_context *ctxt)
4660                 free(usetls);
4661         }
4662  
4663 -       ret = get_property(root, "tlsrequired", &tlsrequired);
4664 +       ret = get_property(logopt, root, "tlsrequired", &tlsrequired);
4665         if (ret != 0) {
4666 -               error(LOGOPT_ANY,
4667 +               error(logopt,
4668                       MODPREFIX
4669                       "Failed read the tlsrequired property from "
4670                       "the configuration file %s.", auth_conf);
4671 @@ -773,7 +761,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4672                 else if (!strcasecmp(tlsrequired, "no"))
4673                         tls_required = LDAP_TLS_DONT_USE;
4674                 else {
4675 -                       error(LOGOPT_ANY,
4676 +                       error(logopt,
4677                               MODPREFIX
4678                               "The tlsrequired property must have value "
4679                               "\"yes\" or \"no\".");
4680 @@ -783,9 +771,9 @@ int parse_ldap_config(struct lookup_context *ctxt)
4681                 free(tlsrequired);
4682         }
4683  
4684 -       ret = get_property(root, "authrequired", &authrequired);
4685 +       ret = get_property(logopt, root, "authrequired", &authrequired);
4686         if (ret != 0) {
4687 -               error(LOGOPT_ANY,
4688 +               error(logopt,
4689                       MODPREFIX
4690                       "Failed read the authrequired property from "
4691                       "the configuration file %s.", auth_conf);
4692 @@ -802,7 +790,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4693                 else if (!strcasecmp(authrequired, "autodetect"))
4694                         auth_required = LDAP_AUTH_AUTODETECT;
4695                 else {
4696 -                       error(LOGOPT_ANY,
4697 +                       error(logopt,
4698                               MODPREFIX
4699                               "The authrequired property must have value "
4700                               "\"yes\", \"no\" or \"autodetect\".");
4701 @@ -812,9 +800,9 @@ int parse_ldap_config(struct lookup_context *ctxt)
4702                 free(authrequired);
4703         }
4704  
4705 -       ret = get_property(root, "authtype", &authtype);
4706 +       ret = get_property(logopt, root, "authtype", &authtype);
4707         if (ret != 0) {
4708 -               error(LOGOPT_ANY,
4709 +               error(logopt,
4710                       MODPREFIX
4711                       "Failed read the authtype property from the "
4712                       "configuration file %s.", auth_conf);
4713 @@ -822,10 +810,10 @@ int parse_ldap_config(struct lookup_context *ctxt)
4714         }
4715  
4716         if (authtype && authtype_requires_creds(authtype)) {
4717 -               ret = get_property(root, "user",  &user);
4718 -               ret |= get_property(root, "secret", &secret);
4719 +               ret = get_property(logopt, root, "user",  &user);
4720 +               ret |= get_property(logopt, root, "secret", &secret);
4721                 if (ret != 0 || (!user || !secret)) {
4722 -                       error(LOGOPT_ANY,
4723 +                       error(logopt,
4724                               MODPREFIX
4725                               "%s authentication type requires a username "
4726                               "and a secret.  Please fix your configuration "
4727 @@ -845,7 +833,7 @@ int parse_ldap_config(struct lookup_context *ctxt)
4728          * We allow the admin to specify the principal to use for the
4729          * client.  The default is "autofsclient/hostname@REALM".
4730          */
4731 -       (void)get_property(root, "clientprinc", &client_princ);
4732 +       (void)get_property(logopt, root, "clientprinc", &client_princ);
4733  
4734         ctxt->auth_conf = auth_conf;
4735         ctxt->use_tls = use_tls;
4736 @@ -856,15 +844,15 @@ int parse_ldap_config(struct lookup_context *ctxt)
4737         ctxt->secret = secret;
4738         ctxt->client_princ = client_princ;
4739  
4740 -       debug(LOGOPT_NONE,
4741 +       debug(logopt, MODPREFIX
4742               "ldap authentication configured with the following options:");
4743 -       debug(LOGOPT_NONE,
4744 +       debug(logopt, MODPREFIX
4745               "use_tls: %u, "
4746               "tls_required: %u, "
4747               "auth_required: %u, "
4748               "sasl_mech: %s",
4749               use_tls, tls_required, auth_required, authtype);
4750 -       debug(LOGOPT_NONE,
4751 +       debug(logopt, MODPREFIX
4752               "user: %s, "
4753               "secret: %s, "
4754               "client principal: %s",
4755 @@ -889,7 +877,7 @@ out:
4756   *  Returns ldap connection on success, with authtype, user and secret
4757   *  filled in as appropriate.  Returns NULL on failre.
4758   */
4759 -static LDAP *auth_init(const char *uri, struct lookup_context *ctxt)
4760 +static LDAP *auth_init(unsigned logopt, const char *uri, struct lookup_context *ctxt)
4761  {
4762         int ret;
4763         LDAP *ldap;
4764 @@ -900,11 +888,11 @@ static LDAP *auth_init(const char *uri, struct lookup_context *ctxt)
4765          *  if the permissions on the file were incorrect, or if the
4766          *  specified authentication type is not valid.
4767          */
4768 -       ret = parse_ldap_config(ctxt);
4769 +       ret = parse_ldap_config(logopt, ctxt);
4770         if (ret)
4771                 return NULL;
4772  
4773 -       ldap = init_ldap_connection(uri, ctxt);
4774 +       ldap = init_ldap_connection(logopt, uri, ctxt);
4775         if (!ldap)
4776                 return NULL;
4777  
4778 @@ -916,7 +904,7 @@ static LDAP *auth_init(const char *uri, struct lookup_context *ctxt)
4779          *  to use. If kerberos is used, it will also take care to initialize
4780          *  the credential cache and the client and service principals.
4781          */
4782 -       ret = autofs_sasl_init(ldap, ctxt);
4783 +       ret = autofs_sasl_init(logopt, ldap, ctxt);
4784         if (ret) {
4785                 ctxt->sasl_mech = NULL;
4786                 return NULL;
4787 @@ -930,7 +918,7 @@ static LDAP *auth_init(const char *uri, struct lookup_context *ctxt)
4788   *  Take an input string as specified in the master map, and break it
4789   *  down into a server name and basedn.
4790   */
4791 -static int parse_server_string(const char *url, struct lookup_context *ctxt)
4792 +static int parse_server_string(unsigned logopt, const char *url, struct lookup_context *ctxt)
4793  {
4794         char buf[MAX_ERR_BUF], *tmp = NULL, proto[9];
4795         const char *ptr, *name;
4796 @@ -939,8 +927,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4797         memset(proto, 0, 9);
4798         ptr = url;
4799  
4800 -       debug(LOGOPT_NONE,
4801 -             MODPREFIX
4802 +       debug(logopt, MODPREFIX
4803               "Attempting to parse LDAP information from string \"%s\".", ptr);
4804  
4805         ctxt->port = LDAP_PORT;
4806 @@ -974,7 +961,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4807                         if (!tmp) {
4808                                 char *estr;
4809                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
4810 -                               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4811 +                               logerr(MODPREFIX "malloc: %s", estr);
4812                                 return 0;
4813                         }
4814                         ctxt->server = tmp;
4815 @@ -987,7 +974,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4816                                 memcpy(ctxt->server, s, l);
4817                         ptr = q + 1;
4818                 } else {
4819 -                       crit(LOGOPT_ANY,
4820 +                       crit(logopt,
4821                              MODPREFIX "invalid LDAP map syntax %s", ptr);
4822                         return 0;
4823  /* TODO: why did I put this here, the parser shouldn't let this by
4824 @@ -996,7 +983,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4825                         if (!tmp) {
4826                                 char *estr;
4827                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
4828 -                               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4829 +                               crit(logopt, MODPREFIX "malloc: %s", estr);
4830                                 return 0;
4831                         }
4832                         ctxt->server = tmp;
4833 @@ -1014,7 +1001,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4834                                 q++;
4835  
4836                 if (*q != ':') {
4837 -                       crit(LOGOPT_ANY,
4838 +                       crit(logopt,
4839                              MODPREFIX "invalid LDAP map syntax %s", ptr);
4840                         return 0;
4841                 }
4842 @@ -1031,7 +1018,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4843                 if (!tmp) {
4844                         char *estr;
4845                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
4846 -                       crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4847 +                       logerr(MODPREFIX "malloc: %s", estr);
4848                         return 0;
4849                 }
4850                 ctxt->server = tmp;
4851 @@ -1072,7 +1059,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4852                         else {
4853                                 char *estr;
4854                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
4855 -                               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4856 +                               logerr(MODPREFIX "malloc: %s", estr);
4857                                 if (ctxt->server)
4858                                         free(ctxt->server);
4859                                 return 0;
4860 @@ -1083,7 +1070,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4861                         if (!base) {
4862                                 char *estr;
4863                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
4864 -                               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4865 +                               logerr(MODPREFIX "malloc: %s", estr);
4866                                 if (ctxt->server)
4867                                         free(ctxt->server);
4868                                 return 0;
4869 @@ -1097,7 +1084,7 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4870                 if (!map) {
4871                         char *estr;
4872                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
4873 -                       crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4874 +                       logerr(MODPREFIX "malloc: %s", estr);
4875                         if (ctxt->server)
4876                                 free(ctxt->server);
4877                         return 0;
4878 @@ -1109,16 +1096,16 @@ static int parse_server_string(const char *url, struct lookup_context *ctxt)
4879  
4880         if (!ctxt->server && *proto) {
4881                 if (!strncmp(proto, "ldaps", 5)) {
4882 -                       warn(LOGOPT_ANY, MODPREFIX
4883 +                       info(logopt, MODPREFIX
4884                              "server must be given to force ldaps, connection "
4885                              "will use LDAP client configured protocol");
4886                 }
4887         }
4888  done:
4889         if (ctxt->mapname)
4890 -               debug(LOGOPT_NONE, MODPREFIX "mapname %s", ctxt->mapname);
4891 +               debug(logopt, MODPREFIX "mapname %s", ctxt->mapname);
4892         else
4893 -               debug(LOGOPT_NONE, MODPREFIX "server \"%s\", base dn \"%s\"",
4894 +               debug(logopt, MODPREFIX "server \"%s\", base dn \"%s\"",
4895                         ctxt->server ? ctxt->server : "(default)",
4896                         ctxt->base);
4897  
4898 @@ -1175,8 +1162,6 @@ static void validate_uris(struct list_head *list)
4899  
4900                 /* At least we get some basic validation */
4901                 if (!ldap_is_ldap_url(this->uri)) {
4902 -                       warn(LOGOPT_ANY,
4903 -                            "removed invalid uri from list, %s", this->uri);
4904                         list_del(&this->list);
4905                         free(this->uri);
4906                         free(this);
4907 @@ -1202,7 +1187,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4908         ctxt = malloc(sizeof(struct lookup_context));
4909         if (!ctxt) {
4910                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4911 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
4912 +               logerr(MODPREFIX "malloc: %s", estr);
4913                 return 1;
4914         }
4915         memset(ctxt, 0, sizeof(struct lookup_context));
4916 @@ -1215,7 +1200,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4917          * Parse out the server name and base dn, and fill them
4918          * into the proper places in the lookup context structure.
4919          */
4920 -       if (!parse_server_string(argv[0], ctxt)) {
4921 +       if (!parse_server_string(LOGOPT_NONE, argv[0], ctxt)) {
4922                 error(LOGOPT_ANY, MODPREFIX "cannot parse server string");
4923                 free_context(ctxt);
4924                 return 1;
4925 @@ -1236,13 +1221,13 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4926         }
4927  
4928         if (ctxt->server || !ctxt->uri) {
4929 -               ldap = connect_to_server(ctxt->server, ctxt);
4930 +               ldap = connect_to_server(LOGOPT_NONE, ctxt->server, ctxt);
4931                 if (!ldap) {
4932                         free_context(ctxt);
4933                         return 1;
4934                 }
4935         } else {
4936 -               ldap = find_server(ctxt);
4937 +               ldap = find_server(LOGOPT_NONE, ctxt);
4938                 if (!ldap) {
4939                         free_context(ctxt);
4940                         error(LOGOPT_ANY, MODPREFIX
4941 @@ -1250,13 +1235,13 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
4942                         return 1;
4943                 }
4944         }
4945 -       unbind_ldap_connection(ldap, ctxt);
4946 +       unbind_ldap_connection(LOGOPT_ANY, ldap, ctxt);
4947  
4948         /* Open the parser, if we can. */
4949         ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
4950         if (!ctxt->parse) {
4951                 free_context(ctxt);
4952 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
4953 +               logerr(MODPREFIX "failed to open parse context");
4954                 return 1;
4955         }
4956         *context = ctxt;
4957 @@ -1269,6 +1254,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
4958         struct lookup_context *ctxt = (struct lookup_context *) context;
4959         unsigned int timeout = master->default_timeout;
4960         unsigned int logging = master->default_logging;
4961 +       unsigned int logopt = master->logopt;
4962         int rv, l, count, blen;
4963         char buf[PARSE_MAX_BUF];
4964         char *query;
4965 @@ -1293,45 +1279,44 @@ int lookup_read_master(struct master *master, time_t age, void *context)
4966         query = alloca(l);
4967         if (query == NULL) {
4968                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4969 -               crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr);
4970 +               logerr(MODPREFIX "alloca: %s", estr);
4971                 return NSS_STATUS_UNAVAIL;
4972         }
4973  
4974         if (sprintf(query, "(objectclass=%s)", class) >= l) {
4975 -               debug(LOGOPT_NONE, MODPREFIX "error forming query string");
4976 +               error(logopt, MODPREFIX "error forming query string");
4977                 return NSS_STATUS_UNAVAIL;
4978         }
4979         query[l] = '\0';
4980  
4981         /* Initialize the LDAP context. */
4982 -       ldap = do_reconnect(ctxt);
4983 +       ldap = do_reconnect(logopt, ctxt);
4984         if (!ldap)
4985                 return NSS_STATUS_UNAVAIL;
4986  
4987         /* Look around. */
4988 -       debug(LOGOPT_NONE,
4989 +       debug(logopt,
4990               MODPREFIX "searching for \"%s\" under \"%s\"", query, ctxt->qdn);
4991  
4992         rv = ldap_search_s(ldap, ctxt->qdn, scope, query, attrs, 0, &result);
4993  
4994         if ((rv != LDAP_SUCCESS) || !result) {
4995 -               error(LOGOPT_NONE,
4996 -                     MODPREFIX "query failed for %s: %s",
4997 +               error(logopt, MODPREFIX "query failed for %s: %s",
4998                       query, ldap_err2string(rv));
4999 -               unbind_ldap_connection(ldap, ctxt);
5000 +               unbind_ldap_connection(logging, ldap, ctxt);
5001                 return NSS_STATUS_NOTFOUND;
5002         }
5003  
5004         e = ldap_first_entry(ldap, result);
5005         if (!e) {
5006 -               debug(LOGOPT_NONE,
5007 +               debug(logopt,
5008                       MODPREFIX "query succeeded, no matches for %s",
5009                       query);
5010                 ldap_msgfree(result);
5011 -               unbind_ldap_connection(ldap, ctxt);
5012 +               unbind_ldap_connection(logging, ldap, ctxt);
5013                 return NSS_STATUS_NOTFOUND;
5014         } else
5015 -               debug(LOGOPT_NONE, MODPREFIX "examining entries");
5016 +               debug(logopt, MODPREFIX "examining entries");
5017  
5018         while (e) {
5019                 keyValue = ldap_get_values(ldap, e, entry);
5020 @@ -1346,7 +1331,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5021                  * each map entry
5022                  */
5023                 if (ldap_count_values(keyValue) > 1) {
5024 -                       error(LOGOPT_ANY,
5025 +                       error(logopt,
5026                               MODPREFIX
5027                               "key %s has duplicate entries - ignoring",
5028                               *keyValue);
5029 @@ -1358,7 +1343,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5030                  * inclusion is only valid in file maps.
5031                  */
5032                 if (**keyValue == '+') {
5033 -                       warn(LOGOPT_ANY,
5034 +                       warn(logopt,
5035                              MODPREFIX
5036                              "ignoreing '+' map entry - not in file map");
5037                         goto next;
5038 @@ -1366,7 +1351,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5039  
5040                 values = ldap_get_values(ldap, e, info);
5041                 if (!values || !*values) {
5042 -                       debug(LOGOPT_NONE,
5043 +                       debug(logopt,
5044                               MODPREFIX "no %s defined for %s", info, query);
5045                         goto next;
5046                 }
5047 @@ -1376,7 +1361,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5048                  */
5049                 count = ldap_count_values(values);
5050                 if (count > 1) {
5051 -                       error(LOGOPT_ANY,
5052 +                       error(logopt,
5053                               MODPREFIX
5054                               "one value per key allowed in master map");
5055                         ldap_value_free(values);
5056 @@ -1385,7 +1370,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5057  
5058                 blen = strlen(*keyValue) + 1 + strlen(*values) + 1;
5059                 if (blen > PARSE_MAX_BUF) {
5060 -                       error(LOGOPT_ANY, MODPREFIX "map entry too long");
5061 +                       error(logopt, MODPREFIX "map entry too long");
5062                         ldap_value_free(values);
5063                         goto next;
5064                 }
5065 @@ -1403,7 +1388,7 @@ next:
5066  
5067         /* Clean up. */
5068         ldap_msgfree(result);
5069 -       unbind_ldap_connection(ldap, ctxt);
5070 +       unbind_ldap_connection(logopt, ldap, ctxt);
5071  
5072         return NSS_STATUS_SUCCESS;
5073  }
5074 @@ -1445,7 +1430,7 @@ static int read_one_map(struct autofs_point *ap,
5075         query = alloca(l);
5076         if (query == NULL) {
5077                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5078 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
5079 +               logerr(MODPREFIX "malloc: %s", estr);
5080                 return NSS_STATUS_UNAVAIL;
5081         }
5082  
5083 @@ -1456,7 +1441,7 @@ static int read_one_map(struct autofs_point *ap,
5084         query[l] = '\0';
5085  
5086         /* Initialize the LDAP context. */
5087 -       ldap = do_reconnect(ctxt);
5088 +       ldap = do_reconnect(ap->logopt, ctxt);
5089         if (!ldap)
5090                 return NSS_STATUS_UNAVAIL;
5091  
5092 @@ -1470,7 +1455,7 @@ static int read_one_map(struct autofs_point *ap,
5093                 debug(ap->logopt,
5094                       MODPREFIX "query failed for %s: %s",
5095                       query, ldap_err2string(rv));
5096 -               unbind_ldap_connection(ldap, ctxt);
5097 +               unbind_ldap_connection(ap->logopt, ldap, ctxt);
5098                 *result_ldap = rv;
5099                 return NSS_STATUS_NOTFOUND;
5100         }
5101 @@ -1480,7 +1465,7 @@ static int read_one_map(struct autofs_point *ap,
5102                 debug(ap->logopt,
5103                       MODPREFIX "query succeeded, no matches for %s", query);
5104                 ldap_msgfree(result);
5105 -               unbind_ldap_connection(ldap, ctxt);
5106 +               unbind_ldap_connection(ap->logopt, ldap, ctxt);
5107                 return NSS_STATUS_NOTFOUND;
5108         } else
5109                 debug(ap->logopt, MODPREFIX "examining entries");
5110 @@ -1612,8 +1597,7 @@ static int read_one_map(struct autofs_point *ap,
5111                                 if (!mapent) {
5112                                         char *estr;
5113                                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
5114 -                                       error(ap->logopt,
5115 -                                             MODPREFIX "malloc: %s", estr);
5116 +                                       logerr(MODPREFIX "malloc: %s", estr);
5117                                         ldap_value_free_len(bvValues);
5118                                         goto next;
5119                                 }
5120 @@ -1633,8 +1617,7 @@ static int read_one_map(struct autofs_point *ap,
5121                                 } else {
5122                                         char *estr;
5123                                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
5124 -                                       error(ap->logopt,
5125 -                                             MODPREFIX "realloc: %s", estr);
5126 +                                       logerr(MODPREFIX "realloc: %s", estr);
5127                                 }
5128                         }
5129                 }
5130 @@ -1669,7 +1652,7 @@ next:
5131  
5132         /* Clean up. */
5133         ldap_msgfree(result);
5134 -       unbind_ldap_connection(ldap, ctxt);
5135 +       unbind_ldap_connection(ap->logopt, ldap, ctxt);
5136  
5137         source->age = age;
5138  
5139 @@ -1766,7 +1749,7 @@ static int lookup_one(struct autofs_point *ap,
5140         query[ql] = '\0';
5141  
5142         /* Initialize the LDAP context. */
5143 -       ldap = do_reconnect(ctxt);
5144 +       ldap = do_reconnect(ap->logopt, ctxt);
5145         if (!ldap)
5146                 return CHE_FAIL;
5147  
5148 @@ -1777,7 +1760,7 @@ static int lookup_one(struct autofs_point *ap,
5149  
5150         if ((rv != LDAP_SUCCESS) || !result) {
5151                 crit(ap->logopt, MODPREFIX "query failed for %s", query);
5152 -               unbind_ldap_connection(ldap, ctxt);
5153 +               unbind_ldap_connection(ap->logopt, ldap, ctxt);
5154                 return CHE_FAIL;
5155         }
5156  
5157 @@ -1789,7 +1772,7 @@ static int lookup_one(struct autofs_point *ap,
5158                 debug(ap->logopt,
5159                      MODPREFIX "got answer, but no entry for %s", query);
5160                 ldap_msgfree(result);
5161 -               unbind_ldap_connection(ldap, ctxt);
5162 +               unbind_ldap_connection(ap->logopt, ldap, ctxt);
5163                 return CHE_MISSING;
5164         }
5165  
5166 @@ -1897,8 +1880,7 @@ static int lookup_one(struct autofs_point *ap,
5167                                 if (!mapent) {
5168                                         char *estr;
5169                                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
5170 -                                       error(ap->logopt,
5171 -                                             MODPREFIX "malloc: %s", estr);
5172 +                                       logerr(MODPREFIX "malloc: %s", estr);
5173                                         ldap_value_free_len(bvValues);
5174                                         goto next;
5175                                 }
5176 @@ -1918,8 +1900,7 @@ static int lookup_one(struct autofs_point *ap,
5177                                 } else {
5178                                         char *estr;
5179                                         estr = strerror_r(errno, buf, MAX_ERR_BUF);
5180 -                                       error(ap->logopt,
5181 -                                             MODPREFIX "realloc: %s", estr);
5182 +                                       logerr(MODPREFIX "realloc: %s", estr);
5183                                 }
5184                         }
5185                 }
5186 @@ -1955,7 +1936,7 @@ next:
5187         }
5188  
5189         ldap_msgfree(result);
5190 -       unbind_ldap_connection(ldap, ctxt);
5191 +       unbind_ldap_connection(ap->logopt, ldap, ctxt);
5192  
5193         /* Failed to find wild entry, update cache if needed */
5194         pthread_cleanup_push(cache_lock_cleanup, mc);
5195 diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c
5196 index 8fa94ae..601d48e 100644
5197 --- a/modules/lookup_multi.c
5198 +++ b/modules/lookup_multi.c
5199 @@ -73,7 +73,7 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
5200         if (nsswitch_parse(&nsslist)) {
5201                 if (!list_empty(&nsslist))
5202                         free_sources(&nsslist);
5203 -               error(LOGOPT_ANY, "can't to read name service switch config.");
5204 +               logerr("can't to read name service switch config.");
5205                 return NULL;
5206         }
5207  
5208 @@ -92,7 +92,7 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
5209                         path = malloc(strlen(AUTOFS_MAP_DIR) + strlen(argv[0]) + 2);
5210                         if (!path) {
5211                                 estr = strerror_r(errno, buf, MAX_ERR_BUF);
5212 -                               crit(LOGOPT_ANY, MODPREFIX "error: %s", estr);
5213 +                               logerr(MODPREFIX "error: %s", estr);
5214                                 free_sources(&nsslist);
5215                                 return NULL;
5216                         }
5217 @@ -150,7 +150,7 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void *
5218         memset(ctxt, 0, sizeof(struct lookup_context));
5219  
5220         if (argc < 1) {
5221 -               crit(LOGOPT_ANY, MODPREFIX "No map list");
5222 +               logerr(MODPREFIX "No map list");
5223                 goto error_out;
5224         }
5225  
5226 @@ -176,8 +176,7 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void *
5227                 if (!strcmp(ctxt->argl[an], "--")) {
5228                         ctxt->argl[an] = NULL;
5229                         if (!args) {
5230 -                               crit(LOGOPT_ANY,
5231 -                                    MODPREFIX "error assigning map args");
5232 +                               logerr(MODPREFIX "error assigning map args");
5233                                 goto error_out;
5234                         }
5235                         ctxt->m[i].argv = copy_argv(ctxt->m[i].argc, (const char **) args);
5236 @@ -201,7 +200,7 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void *
5237                 ctxt->m[i].mod = nss_open_lookup(my_mapfmt,
5238                                  ctxt->m[i].argc, ctxt->m[i].argv);
5239                 if (!ctxt->m[i].mod) {
5240 -                       error(LOGOPT_ANY, MODPREFIX "error opening module");
5241 +                       logerr(MODPREFIX "error opening module");
5242                         goto error_out;
5243                 }
5244         }
5245 @@ -211,7 +210,7 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void *
5246  
5247  nomem:
5248         estr = strerror_r(errno, buf, MAX_ERR_BUF);
5249 -       crit(LOGOPT_ANY, MODPREFIX "error: %s", estr);
5250 +       logerr(MODPREFIX "error: %s", estr);
5251  error_out:
5252         if (ctxt) {
5253                 for (i = 0; i < ctxt->n; i++) {
5254 diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
5255 index 83e99e0..ff8bd49 100644
5256 --- a/modules/lookup_nisplus.c
5257 +++ b/modules/lookup_nisplus.c
5258 @@ -41,13 +41,13 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5259         ctxt = malloc(sizeof(struct lookup_context));
5260         if (!ctxt) {
5261                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5262 -               crit(LOGOPT_ANY, MODPREFIX "%s", estr);
5263 +               logerr(MODPREFIX "%s", estr);
5264                 return 1;
5265         }
5266  
5267         if (argc < 1) {
5268                 free(ctxt);
5269 -               crit(LOGOPT_ANY, MODPREFIX "No map name");
5270 +               logmsg(MODPREFIX "No map name");
5271                 return 1;
5272         }
5273         ctxt->mapname = argv[0];
5274 @@ -59,7 +59,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5275         ctxt->domainname = nis_local_directory();
5276         if (!ctxt->domainname) {
5277                 free(ctxt);
5278 -               crit(LOGOPT_ANY, MODPREFIX "NIS+ domain not set");
5279 +               logmsg(MODPREFIX "NIS+ domain not set");
5280                 return 1;
5281         }
5282  
5283 @@ -69,7 +69,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5284         ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
5285         if (!ctxt->parse) {
5286                 free(ctxt);
5287 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
5288 +               logerr(MODPREFIX "failed to open parse context");
5289                 return 1;
5290         }
5291         *context = ctxt;
5292 @@ -81,7 +81,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5293  {
5294         struct lookup_context *ctxt = (struct lookup_context *) context;
5295         unsigned int timeout = master->default_timeout;
5296 -       unsigned int logging =  master->default_logging;
5297 +       unsigned int logging = master->default_logging;
5298 +       unsigned int logopt =  master->logopt;
5299         char *tablename;
5300         nis_result *result;
5301         nis_object *this;
5302 @@ -95,7 +96,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5303         tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
5304         if (!tablename) {
5305                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5306 -               crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr);
5307 +               logerr(MODPREFIX "alloca: %s", estr);
5308                 pthread_setcancelstate(cur_state, NULL);
5309                 return NSS_STATUS_UNAVAIL;
5310         }
5311 @@ -105,8 +106,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5312         result = nis_lookup(tablename, FOLLOW_PATH | FOLLOW_LINKS);
5313         if (result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) {
5314                 nis_freeresult(result);
5315 -               crit(LOGOPT_ANY,
5316 -                    MODPREFIX "couldn't locat nis+ table %s", ctxt->mapname);
5317 +               crit(logopt,
5318 +                    MODPREFIX "couldn't locate nis+ table %s", ctxt->mapname);
5319                 pthread_setcancelstate(cur_state, NULL);
5320                 return NSS_STATUS_NOTFOUND;
5321         }
5322 @@ -116,7 +117,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5323         result = nis_list(tablename, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
5324         if (result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) {
5325                 nis_freeresult(result);
5326 -               crit(LOGOPT_ANY,
5327 +               crit(logopt,
5328                      MODPREFIX "couldn't enumrate nis+ map %s", ctxt->mapname);
5329                 pthread_setcancelstate(cur_state, NULL);
5330                 return NSS_STATUS_UNAVAIL;
5331 @@ -139,8 +140,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5332  
5333                 buffer = malloc(ENTRY_LEN(this, 0) + 1 + ENTRY_LEN(this, 1) + 1);
5334                 if (!buffer) {
5335 -                       error(LOGOPT_ANY,
5336 -                             MODPREFIX "could not malloc parse buffer");
5337 +                       logerr(MODPREFIX "could not malloc parse buffer");
5338                         continue;
5339                 }
5340  
5341 @@ -182,7 +182,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
5342         tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
5343         if (!tablename) {
5344                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5345 -               crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr);
5346 +               logerr(MODPREFIX "alloca: %s", estr);
5347                 pthread_setcancelstate(cur_state, NULL);
5348                 return NSS_STATUS_UNAVAIL;
5349         }
5350 @@ -193,7 +193,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
5351         if (result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) {
5352                 nis_freeresult(result);
5353                 crit(ap->logopt,
5354 -                    MODPREFIX "couldn't locat nis+ table %s", ctxt->mapname);
5355 +                    MODPREFIX "couldn't locate nis+ table %s", ctxt->mapname);
5356                 pthread_setcancelstate(cur_state, NULL);
5357                 return NSS_STATUS_NOTFOUND;
5358         }
5359 @@ -274,7 +274,7 @@ static int lookup_one(struct autofs_point *ap,
5360                         strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
5361         if (!tablename) {
5362                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5363 -               crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr);
5364 +               logerr(MODPREFIX "alloca: %s", estr);
5365                 pthread_setcancelstate(cur_state, NULL);
5366                 return -1;
5367         }
5368 @@ -327,7 +327,7 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
5369         tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
5370         if (!tablename) {
5371                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5372 -               crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr);
5373 +               logerr(MODPREFIX "alloca: %s", estr);
5374                 pthread_setcancelstate(cur_state, NULL);
5375                 return -1;
5376         }
5377 diff --git a/modules/lookup_program.c b/modules/lookup_program.c
5378 index 2fd521a..e28168e 100644
5379 --- a/modules/lookup_program.c
5380 +++ b/modules/lookup_program.c
5381 @@ -51,28 +51,26 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5382         ctxt = malloc(sizeof(struct lookup_context));
5383         if (!ctxt) {
5384                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5385 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
5386 +               logerr(MODPREFIX "malloc: %s", estr);
5387                 return 1;
5388         }
5389  
5390         if (argc < 1) {
5391 -               crit(LOGOPT_ANY, MODPREFIX "No map name");
5392 +               logmsg(MODPREFIX "No map name");
5393                 free(ctxt);
5394                 return 1;
5395         }
5396         ctxt->mapname = argv[0];
5397  
5398         if (ctxt->mapname[0] != '/') {
5399 -               crit(LOGOPT_ANY,
5400 -                    MODPREFIX "program map %s is not an absolute pathname",
5401 +               logmsg(MODPREFIX "program map %s is not an absolute pathname",
5402                      ctxt->mapname);
5403                 free(ctxt);
5404                 return 1;
5405         }
5406  
5407         if (access(ctxt->mapname, X_OK)) {
5408 -               crit(LOGOPT_ANY,
5409 -                    MODPREFIX "program map %s missing or not executable",
5410 +               logmsg(MODPREFIX "program map %s missing or not executable",
5411                      ctxt->mapname);
5412                 free(ctxt);
5413                 return 1;
5414 @@ -83,7 +81,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5415  
5416         ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
5417         if (!ctxt->parse) {
5418 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
5419 +               logmsg(MODPREFIX "failed to open parse context");
5420                 free(ctxt);
5421                 return 1;
5422         }
5423 @@ -163,7 +161,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5424         mapent = (char *) malloc(MAPENT_MAX_LEN + 1);
5425         if (!mapent) {
5426                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5427 -               error(ap->logopt, MODPREFIX "malloc: %s", estr);
5428 +               logerr(MODPREFIX "malloc: %s", estr);
5429                 return NSS_STATUS_UNAVAIL;
5430         }
5431  
5432 @@ -176,7 +174,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5433          */
5434         if (pipe(pipefd)) {
5435                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5436 -               error(ap->logopt, MODPREFIX "pipe: %s", estr);
5437 +               logerr(MODPREFIX "pipe: %s", estr);
5438                 goto out_free;
5439         }
5440         if (pipe(epipefd)) {
5441 @@ -188,7 +186,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5442         f = fork();
5443         if (f < 0) {
5444                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5445 -               error(ap->logopt, MODPREFIX "fork: %s", estr);
5446 +               logerr(MODPREFIX "fork: %s", estr);
5447                 close(pipefd[0]);
5448                 close(pipefd[1]);
5449                 close(epipefd[0]);
5450 @@ -271,8 +269,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5451                                                        ++alloci));
5452                                         if (!tmp) {
5453                                                 alloci--;
5454 -                                               error(ap->logopt,
5455 -                                                     MODPREFIX "realloc: %s",
5456 +                                               logerr(MODPREFIX "realloc: %s",
5457                                                       strerror(errno));
5458                                                 break;
5459                                         }
5460 @@ -308,12 +305,12 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5461                         } else if (ch == '\n') {
5462                                 *errp = '\0';
5463                                 if (errbuf[0])
5464 -                                       error(ap->logopt, ">> %s", errbuf);
5465 +                                       logmsg(">> %s", errbuf);
5466                                 errp = errbuf;
5467                         } else {
5468                                 if (errp >= &errbuf[1023]) {
5469                                         *errp = '\0';
5470 -                                       error(ap->logopt, ">> %s", errbuf);
5471 +                                       logmsg(">> %s", errbuf);
5472                                         errp = errbuf;
5473                                 }
5474                                 *(errp++) = ch;
5475 @@ -325,7 +322,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5476                 *mapp = '\0';
5477         if (errp > errbuf) {
5478                 *errp = '\0';
5479 -               error(ap->logopt, ">> %s", errbuf);
5480 +               logmsg(">> %s", errbuf);
5481         }
5482  
5483         close(pipefd[0]);
5484 @@ -333,12 +330,12 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5485  
5486         if (waitpid(f, &status, 0) != f) {
5487                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5488 -               error(ap->logopt, MODPREFIX "waitpid: %s", estr);
5489 +               logerr(MODPREFIX "waitpid: %s", estr);
5490                 goto out_free;
5491         }
5492  
5493         if (mapp == mapent || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
5494 -               msg(MODPREFIX "lookup for %s failed", name);
5495 +               info(ap->logopt, MODPREFIX "lookup for %s failed", name);
5496                 goto out_free;
5497         }
5498  
5499 diff --git a/modules/lookup_userhome.c b/modules/lookup_userhome.c
5500 index efcab0b..680ddaf 100644
5501 --- a/modules/lookup_userhome.c
5502 +++ b/modules/lookup_userhome.c
5503 @@ -73,7 +73,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5504         /* Create the appropriate symlink */
5505         if (chdir(ap->path)) {
5506                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5507 -               error(ap->logopt, MODPREFIX "chdir failed: %s", estr);
5508 +               logerr(MODPREFIX "chdir failed: %s", estr);
5509                 return NSS_STATUS_UNAVAIL;
5510         }
5511  
5512 @@ -88,7 +88,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
5513  
5514         if (symlink(pw->pw_dir, name) && errno != EEXIST) {
5515                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5516 -               error(ap->logopt, MODPREFIX "symlink failed: %s", estr);
5517 +               logerr(MODPREFIX "symlink failed: %s", estr);
5518                 return NSS_STATUS_UNAVAIL;
5519         }
5520  
5521 diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
5522 index da280cc..63fc8e3 100644
5523 --- a/modules/lookup_yp.c
5524 +++ b/modules/lookup_yp.c
5525 @@ -45,12 +45,14 @@ struct lookup_context {
5526  struct callback_master_data {
5527         unsigned timeout;
5528         unsigned logging;
5529 +       unsigned logopt;
5530         time_t age;
5531  };
5532  
5533  struct callback_data {
5534         struct autofs_point *ap;
5535         struct map_source *source;
5536 +       unsigned logopt;
5537         time_t age;
5538  };
5539  
5540 @@ -111,20 +113,18 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5541         ctxt = malloc(sizeof(struct lookup_context));
5542         if (!ctxt) {
5543                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5544 -               crit(LOGOPT_ANY, MODPREFIX "%s", estr);
5545 +               logerr(MODPREFIX "%s", estr);
5546                 return 1;
5547         }
5548         memset(ctxt, 0, sizeof(struct lookup_context));
5549  
5550         if (argc < 1) {
5551                 free(ctxt);
5552 -               crit(LOGOPT_ANY, MODPREFIX "no map name");
5553 +               logerr(MODPREFIX "no map name");
5554                 return 1;
5555         }
5556         ctxt->mapname = argv[0];
5557  
5558 -       debug(LOGOPT_NONE, MODPREFIX "ctxt->mapname=%s", ctxt->mapname);
5559 -
5560         /* This should, but doesn't, take a const char ** */
5561         err = yp_get_default_domain((char **) &ctxt->domainname);
5562         if (err) {
5563 @@ -133,8 +133,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5564                 memcpy(name, ctxt->mapname, len);
5565                 name[len] = '\0';
5566                 free(ctxt);
5567 -               debug(LOGOPT_NONE, MODPREFIX "map %s: %s", name,
5568 -                      yperr_string(err));
5569 +               logerr(MODPREFIX "map %s: %s", name, yperr_string(err));
5570                 return 1;
5571         }
5572  
5573 @@ -146,7 +145,7 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
5574         ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
5575         if (!ctxt->parse) {
5576                 free(ctxt);
5577 -               crit(LOGOPT_ANY, MODPREFIX "failed to open parse context");
5578 +               logmsg(MODPREFIX "failed to open parse context");
5579                 return 1;
5580         }
5581         *context = ctxt;
5582 @@ -161,6 +160,7 @@ int yp_all_master_callback(int status, char *ypkey, int ypkeylen,
5583                         (struct callback_master_data *) ypcb_data;
5584         unsigned int timeout = cbdata->timeout;
5585         unsigned int logging = cbdata->logging;
5586 +       unsigned int logopt = cbdata->logopt;
5587         time_t age = cbdata->age;
5588         char *buffer;
5589         unsigned int len;
5590 @@ -182,7 +182,7 @@ int yp_all_master_callback(int status, char *ypkey, int ypkeylen,
5591  
5592         buffer = alloca(len);
5593         if (!buffer) {
5594 -               error(LOGOPT_ANY, MODPREFIX "could not malloc parse buffer");
5595 +               error(logopt, MODPREFIX "could not malloc parse buffer");
5596                 return 0;
5597         }
5598         memset(buffer, 0, len);
5599 @@ -201,6 +201,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5600         struct lookup_context *ctxt = (struct lookup_context *) context;
5601         struct ypall_callback ypcb;
5602         struct callback_master_data ypcb_data;
5603 +       unsigned int logging = master->default_logging;
5604 +       unsigned int logopt = master->logopt;
5605         char *mapname;
5606         int err;
5607  
5608 @@ -211,7 +213,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5609         strcpy(mapname, ctxt->mapname);
5610  
5611         ypcb_data.timeout = master->default_timeout;
5612 -       ypcb_data.logging = master->default_logging;
5613 +       ypcb_data.logging = logging;
5614 +       ypcb_data.logopt = logopt;
5615         ypcb_data.age = age;
5616  
5617         ypcb.foreach = yp_all_master_callback;
5618 @@ -232,7 +235,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
5619                 if (err == YPERR_SUCCESS)
5620                         return NSS_STATUS_SUCCESS;
5621  
5622 -               warn(LOGOPT_ANY,
5623 +               info(logopt,
5624                      MODPREFIX "read of master map %s failed: %s",
5625                      mapname, yperr_string(err));
5626  
5627 @@ -249,6 +252,7 @@ int yp_all_callback(int status, char *ypkey, int ypkeylen,
5628         struct autofs_point *ap = cbdata->ap;
5629         struct map_source *source = cbdata->source;
5630         struct mapent_cache *mc = source->mc;
5631 +       unsigned int logopt = cbdata->logopt;
5632         time_t age = cbdata->age;
5633         char *key, *mapent;
5634         int ret;
5635 @@ -264,8 +268,10 @@ int yp_all_callback(int status, char *ypkey, int ypkeylen,
5636                 return 0;
5637  
5638         key = sanitize_path(ypkey, ypkeylen, ap->type, ap->logopt);
5639 -       if (!key)
5640 +       if (!key) {
5641 +               error(logopt, MODPREFIX "invalid path %s", ypkey);
5642                 return 0;
5643 +       }
5644  
5645         mapent = alloca(vallen + 1);
5646         strncpy(mapent, val, vallen);
5647 @@ -288,6 +294,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
5648         struct lookup_context *ctxt = (struct lookup_context *) context;
5649         struct ypall_callback ypcb;
5650         struct callback_data ypcb_data;
5651 +       unsigned int logopt = ap->logopt;
5652         struct map_source *source;
5653         char *mapname;
5654         int err;
5655 @@ -298,6 +305,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
5656  
5657         ypcb_data.ap = ap;
5658         ypcb_data.source = source;
5659 +       ypcb_data.logopt = logopt;
5660         ypcb_data.age = age;
5661  
5662         ypcb.foreach = yp_all_callback;
5663 diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c
5664 index c45b91b..356fb14 100644
5665 --- a/modules/mount_autofs.c
5666 +++ b/modules/mount_autofs.c
5667 @@ -64,7 +64,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
5668         fullpath = alloca(strlen(root) + name_len + 2);
5669         if (!fullpath) {
5670                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5671 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
5672 +               logerr(MODPREFIX "alloca: %s", estr);
5673                 return 1;
5674         }
5675  
5676 @@ -156,7 +156,6 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
5677         }
5678         nap = entry->ap;
5679         nap->parent = ap;
5680 -       set_mnt_logging(nap);
5681  
5682         argc = 1;
5683  
5684 @@ -208,7 +207,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,
5685                 return 1;
5686         }
5687  
5688 -       source->mc = cache_init(source);
5689 +       source->mc = cache_init(entry->ap, source);
5690         if (!source->mc) {
5691                 error(ap->logopt, MODPREFIX "failed to init source cache");
5692                 master_free_mapent(entry);
5693 diff --git a/modules/mount_bind.c b/modules/mount_bind.c
5694 index cb17ce4..04284f5 100644
5695 --- a/modules/mount_bind.c
5696 +++ b/modules/mount_bind.c
5697 @@ -52,16 +52,14 @@ int mount_init(void **context)
5698         if (lstat(t1_dir, &st1) == -1)
5699                 goto out;
5700  
5701 -       err = spawn_mount(log_debug, "-n", "--bind", t1_dir, t2_dir, NULL);
5702 +       err = spawn_mount(LOGOPT_NONE, "-n", "--bind", t1_dir, t2_dir, NULL);
5703         if (err == 0 &&
5704             lstat(t2_dir, &st2) == 0 &&
5705             st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
5706                 bind_works = 1;
5707         }
5708  
5709 -       debug(LOGOPT_NONE, MODPREFIX "bind_works = %d", bind_works);
5710 -
5711 -       spawn_umount(log_debug, "-n", t2_dir, NULL);
5712 +       spawn_umount(LOGOPT_NONE, "-n", t2_dir, NULL);
5713  
5714  out:
5715         rmdir(t1_dir);
5716 @@ -91,7 +89,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5717         fullpath = alloca(rlen + name_len + 2);
5718         if (!fullpath) {
5719                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5720 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
5721 +               logerr(MODPREFIX "alloca: %s", estr);
5722                 return 1;
5723         }
5724  
5725 @@ -139,7 +137,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5726                       "calling mount --bind " SLOPPY " -o %s %s %s",
5727                       options, what, fullpath);
5728  
5729 -               err = spawn_bind_mount(log_debug,
5730 +               err = spawn_bind_mount(ap->logopt,
5731                              SLOPPYOPT "-o", options, what, fullpath, NULL);
5732  
5733                 if (err) {
5734 diff --git a/modules/mount_changer.c b/modules/mount_changer.c
5735 index 6e04c7c..08d9147 100644
5736 --- a/modules/mount_changer.c
5737 +++ b/modules/mount_changer.c
5738 @@ -66,7 +66,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5739         fullpath = alloca(rlen + name_len + 2);
5740         if (!fullpath) {
5741                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5742 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
5743 +               logerr(MODPREFIX "alloca: %s", estr);
5744                 return 1;
5745         }
5746  
5747 @@ -80,7 +80,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5748  
5749         debug(ap->logopt, MODPREFIX "calling umount %s", what);
5750  
5751 -       err = spawn_umount(log_debug, what, NULL);
5752 +       err = spawn_umount(ap->logopt, what, NULL);
5753         if (err) {
5754                 error(ap->logopt,
5755                       MODPREFIX
5756 @@ -115,18 +115,18 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5757                       MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
5758                       fstype, options, what, fullpath);
5759  
5760 -               err = spawn_mount(log_debug, "-t", fstype,
5761 +               err = spawn_mount(ap->logopt, "-t", fstype,
5762                              SLOPPYOPT "-o", options, what, fullpath, NULL);
5763         } else {
5764                 debug(ap->logopt,
5765                       MODPREFIX "calling mount -t %s %s %s",
5766                       fstype, what, fullpath);
5767  
5768 -               err = spawn_mount(log_debug, "-t", fstype, what, fullpath, NULL);
5769 +               err = spawn_mount(ap->logopt, "-t", fstype, what, fullpath, NULL);
5770         }
5771  
5772         if (err) {
5773 -               msg(MODPREFIX "failed to mount %s (type %s) on %s",
5774 +               info(ap->logopt, MODPREFIX "failed to mount %s (type %s) on %s",
5775                     what, fstype, fullpath);
5776  
5777                 if (ap->type != LKP_INDIRECT)
5778 @@ -137,7 +137,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5779  
5780                 return 1;
5781         } else {
5782 -               msg(MODPREFIX "mounted %s type %s on %s",
5783 +               info(ap->logopt, MODPREFIX "mounted %s type %s on %s",
5784                     what, fstype, fullpath);
5785                 return 0;
5786         }
5787 @@ -161,7 +161,7 @@ int swapCD(const char *device, const char *slotName)
5788         /* open device */
5789         fd = open(device, O_RDONLY | O_NONBLOCK);
5790         if (fd < 0) {
5791 -               error(LOGOPT_ANY, MODPREFIX "Opening device %s failed : %s",
5792 +               logerr(MODPREFIX "Opening device %s failed : %s",
5793                       device, strerror(errno));
5794                 return 1;
5795         }
5796 @@ -174,7 +174,7 @@ int swapCD(const char *device, const char *slotName)
5797         /* Check CD player status */
5798         total_slots_available = ioctl(fd, CDROM_CHANGER_NSLOTS);
5799         if (total_slots_available <= 1) {
5800 -               error(LOGOPT_ANY, MODPREFIX
5801 +               logerr(MODPREFIX
5802                       "Device %s is not an ATAPI compliant CD changer.",
5803                       device);
5804                 return 1;
5805 @@ -183,14 +183,14 @@ int swapCD(const char *device, const char *slotName)
5806         /* load */
5807         slot = ioctl(fd, CDROM_SELECT_DISC, slot);
5808         if (slot < 0) {
5809 -               error(LOGOPT_ANY, MODPREFIX "CDROM_SELECT_DISC failed");
5810 +               logerr(MODPREFIX "CDROM_SELECT_DISC failed");
5811                 return 1;
5812         }
5813  
5814         /* close device */
5815         status = close(fd);
5816         if (status != 0) {
5817 -               error(LOGOPT_ANY, MODPREFIX "close failed for `%s': %s",
5818 +               logerr(MODPREFIX "close failed for `%s': %s",
5819                       device, strerror(errno));
5820                 return 1;
5821         }
5822 diff --git a/modules/mount_ext2.c b/modules/mount_ext2.c
5823 index 45f0615..8cf9937 100644
5824 --- a/modules/mount_ext2.c
5825 +++ b/modules/mount_ext2.c
5826 @@ -58,7 +58,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5827         fullpath = alloca(rlen + name_len + 2);
5828         if (!fullpath) {
5829                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5830 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
5831 +               logerr(MODPREFIX "alloca: %s", estr);
5832                 return 1;
5833         }
5834  
5835 @@ -108,11 +108,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5836         if (ro) {
5837                 debug(ap->logopt,
5838                       MODPREFIX "calling %s -n %s", fsck_prog, what);
5839 -               err = spawnl(log_debug, fsck_prog, fsck_prog, "-n", what, NULL);
5840 +               err = spawnl(ap->logopt, fsck_prog, fsck_prog, "-n", what, NULL);
5841         } else {
5842                 debug(ap->logopt,
5843                       MODPREFIX "calling %s -p %s", fsck_prog, what);
5844 -               err = spawnl(log_debug, fsck_prog, fsck_prog, "-p", what, NULL);
5845 +               err = spawnl(ap->logopt, fsck_prog, fsck_prog, "-p", what, NULL);
5846         }
5847  
5848         /*
5849 @@ -132,17 +132,17 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5850                 debug(ap->logopt,
5851                       MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
5852                       fstype, options, what, fullpath);
5853 -               err = spawn_mount(log_debug, "-t", fstype,
5854 +               err = spawn_mount(ap->logopt, "-t", fstype,
5855                              SLOPPYOPT "-o", options, what, fullpath, NULL);
5856         } else {
5857                 debug(ap->logopt,
5858                       MODPREFIX "calling mount -t %s %s %s",
5859                       fstype, what, fullpath);
5860 -               err = spawn_mount(log_debug, "-t", fstype, what, fullpath, NULL);
5861 +               err = spawn_mount(ap->logopt, "-t", fstype, what, fullpath, NULL);
5862         }
5863  
5864         if (err) {
5865 -               msg(MODPREFIX "failed to mount %s (type %s) on %s",
5866 +               info(ap->logopt, MODPREFIX "failed to mount %s (type %s) on %s",
5867                     what, fstype, fullpath);
5868  
5869                 if (ap->type != LKP_INDIRECT)
5870 @@ -153,7 +153,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5871  
5872                 return 1;
5873         } else {
5874 -               debug(ap->logopt,
5875 +               info(ap->logopt,
5876                       MODPREFIX "mounted %s type %s on %s",
5877                       what, fstype, fullpath);
5878                 return 0;
5879 diff --git a/modules/mount_generic.c b/modules/mount_generic.c
5880 index 1f43baa..85b4391 100644
5881 --- a/modules/mount_generic.c
5882 +++ b/modules/mount_generic.c
5883 @@ -57,7 +57,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5884         fullpath = alloca(rlen + name_len + 2);
5885         if (!fullpath) {
5886                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5887 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
5888 +               logerr(MODPREFIX "alloca: %s", estr);
5889                 return 1;
5890         }
5891  
5892 @@ -93,16 +93,16 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5893                       MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
5894                       fstype, options, what, fullpath);
5895  
5896 -               err = spawn_mount(log_debug, "-t", fstype,
5897 +               err = spawn_mount(ap->logopt, "-t", fstype,
5898                              SLOPPYOPT "-o", options, what, fullpath, NULL);
5899         } else {
5900                 debug(ap->logopt, MODPREFIX "calling mount -t %s %s %s",
5901                       fstype, what, fullpath);
5902 -               err = spawn_mount(log_debug, "-t", fstype, what, fullpath, NULL);
5903 +               err = spawn_mount(ap->logopt, "-t", fstype, what, fullpath, NULL);
5904         }
5905  
5906         if (err) {
5907 -               msg(MODPREFIX "failed to mount %s (type %s) on %s",
5908 +               info(ap->logopt, MODPREFIX "failed to mount %s (type %s) on %s",
5909                      what, fstype, fullpath);
5910  
5911                 if (ap->type != LKP_INDIRECT)
5912 @@ -113,7 +113,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5913  
5914                 return 1;
5915         } else {
5916 -               msg(MODPREFIX "mounted %s type %s on %s",
5917 +               info(ap->logopt, MODPREFIX "mounted %s type %s on %s",
5918                     what, fstype, fullpath);
5919                 return 0;
5920         }
5921 diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
5922 index e4480c5..bad21fc 100644
5923 --- a/modules/mount_nfs.c
5924 +++ b/modules/mount_nfs.c
5925 @@ -133,14 +133,14 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5926         else
5927                 vers = NFS_VERS_MASK | NFS_PROTO_MASK;
5928  
5929 -       if (!parse_location(&hosts, what)) {
5930 -               warn(ap->logopt, MODPREFIX "no hosts available");
5931 +       if (!parse_location(ap->logopt, &hosts, what)) {
5932 +               info(ap->logopt, MODPREFIX "no hosts available");
5933                 return 1;
5934         }
5935 -       prune_host_list(&hosts, vers, nfsoptions, ap->random_selection);
5936 +       prune_host_list(ap->logopt, &hosts, vers, nfsoptions, ap->random_selection);
5937  
5938         if (!hosts) {
5939 -               warn(ap->logopt, MODPREFIX "no hosts available");
5940 +               info(ap->logopt, MODPREFIX "no hosts available");
5941                 return 1;
5942         }
5943  
5944 @@ -159,7 +159,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5945         fullpath = alloca(rlen + name_len + 2);
5946         if (!fullpath) {
5947                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5948 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
5949 +               logerr(MODPREFIX "alloca: %s", estr);
5950                 free_host_list(&hosts);
5951                 return 1;
5952         }
5953 @@ -252,19 +252,19 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5954                               MODPREFIX "calling mount -t %s " SLOPPY 
5955                               "-o %s %s %s", fstype, nfsoptions, loc, fullpath);
5956  
5957 -                       err = spawn_mount(log_debug,
5958 +                       err = spawn_mount(ap->logopt,
5959                                           "-t", fstype, SLOPPYOPT "-o",
5960                                           nfsoptions, loc, fullpath, NULL);
5961                 } else {
5962                         debug(ap->logopt,
5963                               MODPREFIX "calling mount -t %s %s %s",
5964                               fstype, loc, fullpath);
5965 -                       err = spawn_mount(log_debug,
5966 +                       err = spawn_mount(ap->logopt,
5967                                           "-t", fstype, loc, fullpath, NULL);
5968                 }
5969  
5970                 if (!err) {
5971 -                       msg(MODPREFIX "mounted %s on %s", loc, fullpath);
5972 +                       info(ap->logopt, MODPREFIX "mounted %s on %s", loc, fullpath);
5973                         free(loc);
5974                         free_host_list(&hosts);
5975                         ap->ghost = save_ghost;
5976 @@ -280,7 +280,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
5977  
5978         /* If we get here we've failed to complete the mount */
5979  
5980 -       msg(MODPREFIX "nfs: mount failure %s on %s", what, fullpath);
5981 +       info(ap->logopt, MODPREFIX "nfs: mount failure %s on %s", what, fullpath);
5982  
5983         if (ap->type != LKP_INDIRECT)
5984                 return 1;
5985 diff --git a/modules/parse_sun.c b/modules/parse_sun.c
5986 index 079bda6..186e567 100644
5987 --- a/modules/parse_sun.c
5988 +++ b/modules/parse_sun.c
5989 @@ -277,7 +277,7 @@ int parse_init(int argc, const char *const *argv, void **context)
5990  
5991         if (!(ctxt = (struct parse_context *) malloc(sizeof(struct parse_context)))) {
5992                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
5993 -               crit(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
5994 +               logerr(MODPREFIX "malloc: %s", estr);
5995                 *context = NULL;
5996                 return 1;
5997         }
5998 @@ -302,7 +302,7 @@ int parse_init(int argc, const char *const *argv, void **context)
5999  
6000                                 if (!def) {
6001                                         char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6002 -                                       error(LOGOPT_ANY, MODPREFIX "strdup: %s", estr);
6003 +                                       logerr(MODPREFIX "strdup: %s", estr);
6004                                         break;
6005                                 }
6006  
6007 @@ -387,7 +387,7 @@ int parse_init(int argc, const char *const *argv, void **context)
6008                         if (!noptstr) {
6009                                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6010                                 kill_context(ctxt);
6011 -                               crit(LOGOPT_ANY, MODPREFIX "%s", estr);
6012 +                               logerr(MODPREFIX "%s", estr);
6013                                 *context = NULL;
6014                                 return 1;
6015                         }
6016 @@ -408,7 +408,7 @@ int parse_init(int argc, const char *const *argv, void **context)
6017                         char *tmp = concat_options(gbl_options, ctxt->optstr);
6018                         if (!tmp) {
6019                                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6020 -                               error(LOGOPT_ANY, MODPREFIX "concat_options: %s", estr);
6021 +                               logerr(MODPREFIX "concat_options: %s", estr);
6022                                 free(gbl_options);
6023                         } else
6024                                 ctxt->optstr = tmp;
6025 @@ -472,7 +472,7 @@ static char *concat_options(char *left, char *right)
6026  
6027         if (ret == NULL) {
6028                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6029 -               error(LOGOPT_ANY, MODPREFIX "malloc: %s", estr);
6030 +               logerr(MODPREFIX "malloc: %s", estr);
6031                 return NULL;
6032         }
6033  
6034 @@ -637,8 +637,7 @@ static int check_is_multi(const char *mapent)
6035         int not_first_chunk = 0;
6036  
6037         if (!p) {
6038 -               crit(LOGOPT_ANY,
6039 -                    MODPREFIX "unexpected NULL map entry pointer");
6040 +               logerr(MODPREFIX "unexpected NULL map entry pointer");
6041                 return 0;
6042         }
6043  
6044 @@ -1021,7 +1020,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
6045         pmapent = alloca(mapent_len + 1);
6046         if (!pmapent) { 
6047                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6048 -               error(ap->logopt, MODPREFIX "alloca: %s", estr);
6049 +               logerr(MODPREFIX "alloca: %s", estr);
6050                 ctxt->subst = removestdenv(ctxt->subst);
6051                 macro_unlock();
6052                 pthread_setcancelstate(cur_state, NULL);
6053 @@ -1041,7 +1040,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
6054         options = strdup(ctxt->optstr ? ctxt->optstr : "");
6055         if (!options) {
6056                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6057 -               error(ap->logopt, MODPREFIX "strdup: %s", estr);
6058 +               logerr(MODPREFIX "strdup: %s", estr);
6059                 return 1;
6060         }
6061         optlen = strlen(options);
6062 @@ -1119,7 +1118,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
6063                         if (!m_root) {
6064                                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6065                                 free(options);
6066 -                               error(ap->logopt, MODPREFIX "alloca: %s", estr);
6067 +                               logerr(MODPREFIX "alloca: %s", estr);
6068                                 return 1;
6069                         }
6070                         strcpy(m_root, name);
6071 @@ -1129,7 +1128,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
6072                         if (!m_root) {
6073                                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6074                                 free(options);
6075 -                               error(ap->logopt, MODPREFIX "alloca: %s", estr);
6076 +                               logerr(MODPREFIX "alloca: %s", estr);
6077                                 return 1;
6078                         }
6079                         strcpy(m_root, ap->path);
6080 diff --git a/modules/replicated.c b/modules/replicated.c
6081 index e15587c..14b20a9 100644
6082 --- a/modules/replicated.c
6083 +++ b/modules/replicated.c
6084 @@ -113,7 +113,7 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
6085         sock = socket(AF_INET, SOCK_DGRAM, 0);
6086         if (sock < 0) {
6087                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6088 -               error(LOGOPT_ANY, "socket creation failed: %s", estr);
6089 +               logerr("socket creation failed: %s", estr);
6090                 return PROXIMITY_ERROR;
6091         }
6092  
6093 @@ -127,7 +127,7 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
6094         ret = ioctl(sock, SIOCGIFCONF, &ifc);
6095         if (ret == -1) {
6096                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6097 -               error(LOGOPT_ANY, "ioctl: %s", estr);
6098 +               logerr("ioctl: %s", estr);
6099                 close(sock);
6100                 return PROXIMITY_ERROR;
6101         }
6102 @@ -176,7 +176,7 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
6103                         ret = ioctl(sock, SIOCGIFNETMASK, &nmptr);
6104                         if (ret == -1) {
6105                                 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
6106 -                               error(LOGOPT_ANY, "ioctl: %s", estr);
6107 +                               logerr("ioctl: %s", estr);
6108                                 close(sock);
6109                                 return PROXIMITY_ERROR;
6110                         }
6111 @@ -387,7 +387,7 @@ static unsigned short get_port_option(const char *options)
6112         return (unsigned short) port;
6113  }
6114  
6115 -static unsigned int get_nfs_info(struct host *host,
6116 +static unsigned int get_nfs_info(unsigned logopt, struct host *host,
6117                          struct conn_info *pm_info, struct conn_info *rpc_info,
6118                          const char *proto, unsigned int version,
6119                          const char *options, unsigned int random_selection)
6120 @@ -533,7 +533,7 @@ done_ver:
6121         return supported;
6122  }
6123  
6124 -static int get_vers_and_cost(struct host *host,
6125 +static int get_vers_and_cost(unsigned logopt, struct host *host,
6126                              unsigned int version, const char *options,
6127                              unsigned int random_selection)
6128  {
6129 @@ -559,7 +559,7 @@ static int get_vers_and_cost(struct host *host,
6130         vers &= version;
6131  
6132         if (version & UDP_REQUESTED) {
6133 -               supported = get_nfs_info(host,
6134 +               supported = get_nfs_info(logopt, host,
6135                                         &pm_info, &rpc_info, "udp", vers,
6136                                         options, random_selection);
6137                 if (supported) {
6138 @@ -569,7 +569,7 @@ static int get_vers_and_cost(struct host *host,
6139         }
6140  
6141         if (version & TCP_REQUESTED) {
6142 -               supported = get_nfs_info(host,
6143 +               supported = get_nfs_info(logopt, host,
6144                                          &pm_info, &rpc_info, "tcp", vers,
6145                                          options, random_selection);
6146                 if (supported) {
6147 @@ -581,7 +581,7 @@ static int get_vers_and_cost(struct host *host,
6148         return ret;
6149  }
6150  
6151 -static int get_supported_ver_and_cost(struct host *host,
6152 +static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
6153                                       unsigned int version, const char *options,
6154                                       unsigned int random_selection)
6155  {
6156 @@ -636,7 +636,7 @@ static int get_supported_ver_and_cost(struct host *host,
6157                 vers = NFS4_VERSION;
6158                 break;
6159         default:
6160 -               crit(LOGOPT_ANY, "called with invalid version: 0x%x\n", version);
6161 +               crit(logopt, "called with invalid version: 0x%x\n", version);
6162                 return 0;
6163         }
6164  
6165 @@ -701,7 +701,7 @@ done:
6166         return 0;
6167  }
6168  
6169 -int prune_host_list(struct host **list,
6170 +int prune_host_list(unsigned logopt, struct host **list,
6171                     unsigned int vers, const char *options,
6172                     unsigned int random_selection)
6173  {
6174 @@ -742,7 +742,7 @@ int prune_host_list(struct host **list,
6175                         break;
6176  
6177                 if (this->name) {
6178 -                       status = get_vers_and_cost(this, vers,
6179 +                       status = get_vers_and_cost(logopt, this, vers,
6180                                                    options, random_selection);
6181                         if (!status) {
6182                                 if (this == first) {
6183 @@ -833,7 +833,7 @@ int prune_host_list(struct host **list,
6184                         remove_host(list, this);
6185                         add_host(&new, this);
6186                 } else {
6187 -                       status = get_supported_ver_and_cost(this,
6188 +                       status = get_supported_ver_and_cost(logopt, this,
6189                                                 selected_version, options,
6190                                                 random_selection);
6191                         if (status) {
6192 @@ -886,11 +886,9 @@ static int add_host_addrs(struct host **list, const char *host, unsigned int wei
6193                         buf, MAX_IFC_BUF, &result, &ghn_errno);
6194         if (ret || !result) {
6195                 if (ghn_errno == -1)
6196 -                       error(LOGOPT_ANY,
6197 -                             "host %s: lookup failure %d", host, errno);
6198 +                       logmsg("host %s: lookup failure %d", host, errno);
6199                 else
6200 -                       error(LOGOPT_ANY,
6201 -                             "host %s: lookup failure %d", host, ghn_errno);
6202 +                       logmsg("host %s: lookup failure %d", host, ghn_errno);
6203                 return 0;
6204         }
6205  
6206 @@ -965,7 +963,7 @@ static int add_local_path(struct host **hosts, const char *path)
6207         return 1;
6208  }
6209  
6210 -int parse_location(struct host **hosts, const char *list)
6211 +int parse_location(unsigned logopt, struct host **hosts, const char *list)
6212  {
6213         char *str, *p, *delim;
6214         unsigned int empty = 1;
6215 @@ -1072,8 +1070,7 @@ void dump_host_list(struct host *hosts)
6216  
6217         this = hosts;
6218         while (this) {
6219 -               debug(LOGOPT_ANY,
6220 -                     "name %s path %s version %x proximity %u weight %u cost %u",
6221 +               logmsg("name %s path %s version %x proximity %u weight %u cost %u",
6222                       this->name, this->path, this->version,
6223                       this->proximity, this->weight, this->cost);
6224                 this = this->next;
This page took 1.091609 seconds and 3 git commands to generate.