]> git.pld-linux.org Git - packages/autofs.git/blob - autofs-5.0.2-foreground-logging.patch
- 5.0.3 with few official patches. ldap fixes needed
[packages/autofs.git] / autofs-5.0.2-foreground-logging.patch
1 diff --git a/CHANGELOG b/CHANGELOG
2 index 933b1a1..0340940 100644
3 --- a/CHANGELOG
4 +++ b/CHANGELOG
5 @@ -28,6 +28,7 @@
6  - work around segv at exit due to libxml2 tsd usage.
7  - re-read config on HUP signal.
8  - add LDAP_URI, LDAP_TIMEOUT and LDAP_NETWORK_TIMEOUT configuration options.
9 +- fix forground logging and add option to man page.
10  
11  18/06/2007 autofs-5.0.2
12  -----------------------
13 diff --git a/daemon/automount.c b/daemon/automount.c
14 index 58f1901..51f6a8b 100644
15 --- a/daemon/automount.c
16 +++ b/daemon/automount.c
17 @@ -58,14 +58,13 @@ unsigned int global_random_selection;       /* use random policy when selecting
18  static int start_pipefd[2];
19  static int st_stat = 0;
20  static int *pst_stat = &st_stat;
21 +static pthread_t state_mach_thid;
22  
23  /* Pre-calculated kernel packet length */
24  static size_t kpkt_len;
25  
26  /* Attribute to create detached thread */
27  pthread_attr_t thread_attr;
28 -/* Attribute to create normal thread */
29 -pthread_attr_t thread_attr_nodetach;
30  
31  struct master_readmap_cond mrc = {
32         PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, NULL, 0, 0, 0, 0};
33 @@ -75,9 +74,6 @@ struct startup_cond suc = {
34  
35  pthread_key_t key_thread_stdenv_vars;
36  
37 -/* re-entrant syslog default context data */
38 -#define AUTOFS_SYSLOG_CONTEXT {-1, 0, 0, LOG_PID, (const char *)0, LOG_DAEMON, 0xff};
39 -
40  #define MAX_OPEN_FILES         10240
41  
42  static int umount_all(struct autofs_point *ap, int force);
43 @@ -792,7 +788,6 @@ static void become_daemon(unsigned foreground)
44  {
45         FILE *pidfp;
46         char buf[MAX_ERR_BUF];
47 -       unsigned to_stderr = 0;
48         pid_t pid;
49  
50         /* Don't BUSY any directories unnecessarily */
51 @@ -809,7 +804,9 @@ static void become_daemon(unsigned foreground)
52         }
53  
54         /* Detach from foreground process */
55 -       if (!foreground) {
56 +       if (foreground)
57 +               log_to_stderr();
58 +       else {
59                 pid = fork();
60                 if (pid > 0) {
61                         int r;
62 @@ -834,13 +831,8 @@ static void become_daemon(unsigned foreground)
63                         fprintf(stderr, "setsid: %s", estr);
64                         exit(1);
65                 }
66 -       }
67 -
68 -       /* Setup logging */
69 -       if (to_stderr)
70 -               log_to_stderr();
71 -       else
72                 log_to_syslog();
73 +       }
74  
75         /* Write pid file if requested */
76         if (pid_file) {
77 @@ -929,7 +921,7 @@ static pthread_t do_signals(struct master *master, int sig)
78         if (status)
79                 fatal(status);
80  
81 -       status = pthread_create(&thid, &thread_attr_nodetach, do_notify_state, &r_sig);
82 +       status = pthread_create(&thid, &thread_attr, do_notify_state, &r_sig);
83         if (status) {
84                 error(master->default_logging,
85                       "mount state notify thread create failed");
86 @@ -1045,7 +1037,6 @@ static int do_hup_signal(struct master *master, time_t age)
87  /* Deal with all the signal-driven events in the state machine */
88  static void *statemachine(void *arg)
89  {
90 -       pthread_t thid = 0;
91         sigset_t signalset;
92         int sig;
93  
94 @@ -1058,15 +1049,12 @@ static void *statemachine(void *arg)
95  
96                 switch (sig) {
97                 case SIGTERM:
98 +               case SIGINT:
99                 case SIGUSR2:
100 +                       if (master_list_empty(master_list))
101 +                               return NULL;
102                 case SIGUSR1:
103 -                       thid = do_signals(master_list, sig);
104 -                       if (thid) {
105 -                               pthread_join(thid, NULL);
106 -                               if (master_list_empty(master_list))
107 -                                       return NULL;
108 -                               thid = 0;
109 -                       }
110 +                       do_signals(master_list, sig);
111                         break;
112  
113                 case SIGHUP:
114 @@ -1181,6 +1169,10 @@ static void handle_mounts_cleanup(void *arg)
115  
116         msg("shut down path %s", path);
117  
118 +       /* If we are the last tell the state machine to shutdown */
119 +       if (!submount && master_list_empty(master_list))
120 +               pthread_kill(state_mach_thid, SIGTERM);
121 +       
122         return;
123  }
124  
125 @@ -1375,7 +1367,7 @@ static void usage(void)
126                 "       -v --verbose    be verbose\n"
127                 "       -d --debug      log debuging info\n"
128                 "       -D --define     define global macro variable\n"
129 -               /*"     -f --foreground do not fork into background\n" */
130 +               "       -f --foreground do not fork into background\n"
131                 "       -r --random-multimount-selection\n"
132                 "                       use ramdom replicated server selection\n"
133                 "       -O --global-options\n"
134 @@ -1650,14 +1642,6 @@ int main(int argc, char *argv[])
135         }
136  #endif
137  
138 -       if (pthread_attr_init(&thread_attr_nodetach)) {
139 -               crit(LOGOPT_ANY,
140 -                    "%s: failed to init thread attribute struct!",
141 -                    program);
142 -               close(start_pipefd[1]);
143 -               exit(1);
144 -       }
145 -
146         msg("Starting automounter version %s, master map %s",
147                 version, master_list->name);
148         msg("using kernel protocol version %d.%02d",
149 @@ -1702,6 +1686,7 @@ int main(int argc, char *argv[])
150         res = write(start_pipefd[1], pst_stat, sizeof(pst_stat));
151         close(start_pipefd[1]);
152  
153 +       state_mach_thid = pthread_self();
154         statemachine(NULL);
155  
156         master_kill(master_list);
157 diff --git a/lib/log.c b/lib/log.c
158 index e639e60..b747e12 100644
159 --- a/lib/log.c
160 +++ b/lib/log.c
161 @@ -27,9 +27,6 @@
162  
163  #include "automount.h"
164  
165 -/* re-entrant syslog default context data */
166 -#define AUTOFS_SYSLOG_CONTEXT {-1, 0, 0, LOG_PID, (const char *) 0, LOG_DAEMON, 0xff};
167 -
168  /*
169  struct syslog_data syslog_context = AUTOFS_SYSLOG_CONTEXT;
170  struct syslog_data *slc = &syslog_context;
171 @@ -134,30 +131,40 @@ static void syslog_debug(unsigned int logopt, const char *msg, ...)
172         va_end(ap);
173  }
174  
175 +static void to_stderr(unsigned int logopt, const char *msg, ...)
176 +{
177 +       va_list ap;
178 +       va_start(ap, msg);
179 +       vfprintf(stderr, msg, ap);
180 +       fputc('\n',stderr);
181 +       va_end(ap);
182 +}
183 +
184  void set_mnt_logging(struct autofs_point *ap)
185  {
186         unsigned int opt_verbose = ap->logopt & LOGOPT_VERBOSE;
187         unsigned int opt_debug = ap->logopt & LOGOPT_DEBUG;
188  
189 -       if (opt_debug)
190 -               log_debug = syslog_debug;
191 +       if (opt_debug) {
192 +               if (logging_to_syslog)
193 +                       log_debug = syslog_debug;
194 +               else
195 +                       log_debug = to_stderr;
196 +       }
197  
198         if (opt_verbose || opt_debug) {
199 -               log_info = syslog_info;
200 -               log_notice = syslog_notice;
201 -               log_warn = syslog_warn;
202 +               if (logging_to_syslog) {
203 +                       log_info = syslog_info;
204 +                       log_notice = syslog_notice;
205 +                       log_warn = syslog_warn;
206 +               } else {
207 +                       log_info = to_stderr;
208 +                       log_notice = to_stderr;
209 +                       log_warn = to_stderr;
210 +               }
211         }
212  }
213  
214 -static void to_stderr(unsigned int logopt, const char *msg, ...)
215 -{
216 -       va_list ap;
217 -       va_start(ap, msg);
218 -       vfprintf(stderr, msg, ap);
219 -       fputc('\n',stderr);
220 -       va_end(ap);
221 -}
222 -
223  void log_to_syslog(void)
224  {
225         char buf[MAX_ERR_BUF];
226 diff --git a/lib/master.c b/lib/master.c
227 index 637ce04..abc3bc2 100644
228 --- a/lib/master.c
229 +++ b/lib/master.c
230 @@ -954,6 +954,7 @@ void master_notify_state_change(struct master *master, int sig)
231  
232                 switch (sig) {
233                 case SIGTERM:
234 +               case SIGINT:
235                         if (ap->state != ST_SHUTDOWN_PENDING &&
236                             ap->state != ST_SHUTDOWN_FORCE) {
237                                 next = ST_SHUTDOWN_PENDING;
238 diff --git a/man/automount.8 b/man/automount.8
239 index da67a5c..e203a3e 100644
240 --- a/man/automount.8
241 +++ b/man/automount.8
242 @@ -47,6 +47,9 @@ Define a global macro substitution variable. Global definitions
243  are over-ridden macro definitions of the same name specified in
244  mount entries.
245  .TP
246 +.I "\-f, \-\-foreground"
247 +Run the daemon in the forground and log to stderr instead of syslog."
248 +.TP
249  .I "\-r, \-\-random-multimount-selection"
250  Enables the use of ramdom selection when choosing a host from a
251  list of replicated servers.
252 diff --git a/modules/cyrus-sasl.c b/modules/cyrus-sasl.c
253 index 9aac792..68e5dd7 100644
254 --- a/modules/cyrus-sasl.c
255 +++ b/modules/cyrus-sasl.c
256 @@ -197,7 +197,7 @@ get_server_SASL_mechanisms(LDAP *ld)
257         if (mechanisms == NULL) {
258                 /* Well, that was a waste of time. */
259                 msg("No SASL authentication mechanisms are supported"
260 -                   " by the LDAP server.\n");
261 +                   " by the LDAP server.");
262                 return NULL;
263         }
264  
265 diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
266 index 4068561..c0f228b 100644
267 --- a/modules/lookup_ldap.c
268 +++ b/modules/lookup_ldap.c
269 @@ -857,17 +857,17 @@ int parse_ldap_config(struct lookup_context *ctxt)
270         ctxt->client_princ = client_princ;
271  
272         debug(LOGOPT_NONE,
273 -             "ldap authentication configured with the following options:\n");
274 +             "ldap authentication configured with the following options:");
275         debug(LOGOPT_NONE,
276               "use_tls: %u, "
277               "tls_required: %u, "
278               "auth_required: %u, "
279 -             "sasl_mech: %s\n",
280 +             "sasl_mech: %s",
281               use_tls, tls_required, auth_required, authtype);
282         debug(LOGOPT_NONE,
283               "user: %s, "
284               "secret: %s, "
285 -             "client principal: %s\n",
286 +             "client principal: %s",
287               user, secret ? "specified" : "unspecified",
288               client_princ);
289  
This page took 0.137304 seconds and 3 git commands to generate.