… | |
… | |
129 | return 0; |
129 | return 0; |
130 | } |
130 | } |
131 | |
131 | |
132 | bool run_script (const run_script_cb &cb, bool wait) |
132 | bool run_script (const run_script_cb &cb, bool wait) |
133 | { |
133 | { |
134 | int pid; |
134 | if (wait) |
|
|
135 | signal (SIGCHLD, SIG_DFL); // this is extremely ugly, but I did not feel like implementing a complete wait() event logic. It's easier to write this long comment to make your editor happy. |
135 | |
136 | |
136 | if ((pid = fork ()) == 0) |
137 | int pid = fork (); |
|
|
138 | |
|
|
139 | if (pid == 0) |
137 | { |
140 | { |
138 | execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0); |
141 | execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0); |
139 | exit (EXIT_FAILURE); |
142 | exit (EXIT_FAILURE); |
140 | } |
143 | } |
141 | else if (pid > 0) |
144 | else if (pid > 0) |
142 | { |
145 | { |
143 | if (wait) |
146 | if (wait) |
144 | { |
147 | { |
145 | int status; |
148 | int status; |
146 | |
|
|
147 | if (waitpid (pid, &status, 0) < 0) |
149 | int res = waitpid (pid, &status, 0); |
|
|
150 | |
|
|
151 | signal (SIGCHLD, SIG_IGN); |
|
|
152 | |
|
|
153 | if (res < 0) |
148 | { |
154 | { |
149 | slog (L_WARN, _("waiting for an external command failed: %s."), |
155 | slog (L_WARN, _("waiting for an external command failed: %s."), |
150 | strerror (errno)); |
156 | strerror (errno)); |
151 | return false; |
157 | return false; |
152 | } |
158 | } |
… | |
… | |
156 | WEXITSTATUS (status), status); |
162 | WEXITSTATUS (status), status); |
157 | return false; |
163 | return false; |
158 | } |
164 | } |
159 | } |
165 | } |
160 | } |
166 | } |
|
|
167 | else |
|
|
168 | { |
|
|
169 | slog (L_ERR, _("unable to fork, exiting: %s"), strerror (errno)); |
|
|
170 | exit (EXIT_FAILURE); |
|
|
171 | } |
161 | |
172 | |
162 | return true; |
173 | return true; |
163 | } |
174 | } |
164 | |
175 | |
165 | #if ENABLE_HTTP_PROXY |
176 | #if ENABLE_HTTP_PROXY |