]>
Commit | Line | Data |
---|---|---|
e5fd101c PS |
1 | autofs-5.0.4 - fix return start status on fail |
2 | ||
3 | From: Ian Kent <raven@themaw.net> | |
4 | ||
5 | We're not returning the status to the parent when automount(8) is waiting | |
6 | for the daemon to finish its startup. | |
7 | --- | |
8 | ||
9 | CHANGELOG | 1 + | |
10 | daemon/automount.c | 27 +++++++++++++++++++++------ | |
11 | 2 files changed, 22 insertions(+), 6 deletions(-) | |
12 | ||
13 | ||
14 | diff --git a/CHANGELOG b/CHANGELOG | |
15 | index fdde400..2cb35dc 100644 | |
16 | --- a/CHANGELOG | |
17 | +++ b/CHANGELOG | |
18 | @@ -27,6 +27,7 @@ | |
19 | - add WITH_LIBTIRPC to -V status report. | |
20 | - add nfs mount protocol default configuration option. | |
21 | - fix bad token declaration in master map parser. | |
22 | +- fix return start status on fail. | |
23 | ||
24 | 4/11/2008 autofs-5.0.4 | |
25 | ----------------------- | |
26 | diff --git a/daemon/automount.c b/daemon/automount.c | |
27 | index 776c92c..80691fa 100644 | |
28 | --- a/daemon/automount.c | |
29 | +++ b/daemon/automount.c | |
30 | @@ -60,7 +60,7 @@ long global_negative_timeout = -1; | |
31 | int do_force_unlink = 0; /* Forceably unlink mount tree at startup */ | |
32 | ||
33 | static int start_pipefd[2]; | |
34 | -static int st_stat = 0; | |
35 | +static int st_stat = 1; | |
36 | static int *pst_stat = &st_stat; | |
37 | static pthread_t state_mach_thid; | |
38 | ||
39 | @@ -1046,6 +1046,7 @@ static void become_daemon(unsigned foreground, unsigned daemon_check) | |
40 | { | |
41 | FILE *pidfp; | |
42 | char buf[MAX_ERR_BUF]; | |
43 | + int res; | |
44 | pid_t pid; | |
45 | ||
46 | /* Don't BUSY any directories unnecessarily */ | |
47 | @@ -1072,10 +1073,9 @@ static void become_daemon(unsigned foreground, unsigned daemon_check) | |
48 | } else { | |
49 | pid = fork(); | |
50 | if (pid > 0) { | |
51 | - int r; | |
52 | close(start_pipefd[1]); | |
53 | - r = read(start_pipefd[0], pst_stat, sizeof(*pst_stat)); | |
54 | - if (r < 0) | |
55 | + res = read(start_pipefd[0], pst_stat, sizeof(*pst_stat)); | |
56 | + if (res < 0) | |
57 | exit(1); | |
58 | exit(*pst_stat); | |
59 | } else if (pid < 0) { | |
60 | @@ -1088,8 +1088,13 @@ static void become_daemon(unsigned foreground, unsigned daemon_check) | |
61 | if (daemon_check && !aquire_flag_file()) { | |
62 | fprintf(stderr, "%s: program is already running.\n", | |
63 | program); | |
64 | + /* Return success if already running */ | |
65 | + st_stat = 0; | |
66 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
67 | + if (res < 0) | |
68 | + exit(1); | |
69 | close(start_pipefd[1]); | |
70 | - exit(1); | |
71 | + exit(*pst_stat); | |
72 | } | |
73 | ||
74 | /* | |
75 | @@ -1099,8 +1104,9 @@ static void become_daemon(unsigned foreground, unsigned daemon_check) | |
76 | if (setsid() == -1) { | |
77 | char *estr = strerror_r(errno, buf, MAX_ERR_BUF); | |
78 | fprintf(stderr, "setsid: %s", estr); | |
79 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
80 | close(start_pipefd[1]); | |
81 | - exit(1); | |
82 | + exit(*pst_stat); | |
83 | } | |
84 | log_to_syslog(); | |
85 | } | |
86 | @@ -1991,6 +1997,7 @@ int main(int argc, char *argv[]) | |
87 | if (!master_list) { | |
88 | logerr("%s: can't create master map %s", | |
89 | program, argv[0]); | |
90 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
91 | close(start_pipefd[1]); | |
92 | release_flag_file(); | |
93 | exit(1); | |
94 | @@ -1999,6 +2006,7 @@ int main(int argc, char *argv[]) | |
95 | if (pthread_attr_init(&th_attr)) { | |
96 | logerr("%s: failed to init thread attribute struct!", | |
97 | program); | |
98 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
99 | close(start_pipefd[1]); | |
100 | release_flag_file(); | |
101 | exit(1); | |
102 | @@ -2007,6 +2015,7 @@ int main(int argc, char *argv[]) | |
103 | if (pthread_attr_init(&th_attr_detached)) { | |
104 | logerr("%s: failed to init thread attribute struct!", | |
105 | program); | |
106 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
107 | close(start_pipefd[1]); | |
108 | release_flag_file(); | |
109 | exit(1); | |
110 | @@ -2016,6 +2025,7 @@ int main(int argc, char *argv[]) | |
111 | &th_attr_detached, PTHREAD_CREATE_DETACHED)) { | |
112 | logerr("%s: failed to set detached thread attribute!", | |
113 | program); | |
114 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
115 | close(start_pipefd[1]); | |
116 | release_flag_file(); | |
117 | exit(1); | |
118 | @@ -2026,6 +2036,7 @@ int main(int argc, char *argv[]) | |
119 | &th_attr_detached, PTHREAD_STACK_MIN*64)) { | |
120 | logerr("%s: failed to set stack size thread attribute!", | |
121 | program); | |
122 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
123 | close(start_pipefd[1]); | |
124 | release_flag_file(); | |
125 | exit(1); | |
126 | @@ -2043,6 +2054,7 @@ int main(int argc, char *argv[]) | |
127 | logerr("%s: failed to create thread data key for std env vars!", | |
128 | program); | |
129 | master_kill(master_list); | |
130 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
131 | close(start_pipefd[1]); | |
132 | release_flag_file(); | |
133 | exit(1); | |
134 | @@ -2053,6 +2065,7 @@ int main(int argc, char *argv[]) | |
135 | if (!alarm_start_handler()) { | |
136 | logerr("%s: failed to create alarm handler thread!", program); | |
137 | master_kill(master_list); | |
138 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
139 | close(start_pipefd[1]); | |
140 | release_flag_file(); | |
141 | exit(1); | |
142 | @@ -2061,6 +2074,7 @@ int main(int argc, char *argv[]) | |
143 | if (!st_start_handler()) { | |
144 | logerr("%s: failed to create FSM handler thread!", program); | |
145 | master_kill(master_list); | |
146 | + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
147 | close(start_pipefd[1]); | |
148 | release_flag_file(); | |
149 | exit(1); | |
150 | @@ -2092,6 +2106,7 @@ int main(int argc, char *argv[]) | |
151 | */ | |
152 | do_force_unlink = 0; | |
153 | ||
154 | + st_stat = 0; | |
155 | res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); | |
156 | close(start_pipefd[1]); | |
157 |