ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.C
(Generate patch)

Comparing gvpe/src/util.C (file contents):
Revision 1.22 by pcg, Thu Aug 7 17:54:27 2008 UTC vs.
Revision 1.23 by pcg, Thu Aug 7 19:07:03 2008 UTC

137 slog (L_INFO, _("gvpe daemon %s (%s %s) starting"), VERSION, __DATE__, __TIME__); 137 slog (L_INFO, _("gvpe daemon %s (%s %s) starting"), VERSION, __DATE__, __TIME__);
138 138
139 return 0; 139 return 0;
140} 140}
141 141
142pid_t
142bool run_script (const run_script_cb &cb, bool wait) 143run_script (const run_script_cb &cb, bool wait)
143{ 144{
145 sigset_t oldset;
146
144 if (wait) 147 if (wait)
145 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. 148 {
149 sigset_t sigchld;
150 sigemptyset (&sigchld);
151 sigaddset (&sigchld, SIGCHLD);
152 sigprocmask (SIG_BLOCK, &sigchld, &oldset);
153 }
146 154
147 int pid = fork (); 155 pid_t pid = fork ();
148 156
149 if (pid == 0) 157 if (pid == 0)
150 { 158 {
159 sigprocmask (SIG_SETMASK, &oldset, 0);
160
151 execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0); 161 execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0);
152 exit (EXIT_FAILURE); 162 exit (EXIT_FAILURE);
153 } 163 }
154 else if (pid > 0) 164 else if (pid > 0)
155 { 165 {
156 if (wait) 166 if (wait)
157 { 167 {
158 int status; 168 int status;
159 int res = waitpid (pid, &status, 0); 169 int res = waitpid (pid, &status, 0);
160 170
161 signal (SIGCHLD, SIG_IGN); 171 sigprocmask (SIG_SETMASK, &oldset, 0);
162 172
163 if (res < 0) 173 if (res < 0)
164 { 174 {
165 slog (L_WARN, _("waiting for an external command failed: %s."), 175 slog (L_WARN, _("waiting for an external command failed: %s."),
166 strerror (errno)); 176 strerror (errno));
167 return false; 177 return 0;
168 } 178 }
169 else if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS) 179 else if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS)
170 { 180 {
171 slog (L_WARN, _("external command returned with exit status %d (%04x)."), 181 slog (L_WARN, _("external command returned with exit status %d (%04x)."),
172 WEXITSTATUS (status), status); 182 WEXITSTATUS (status), status);
173 return false; 183 return 0;
174 } 184 }
175 } 185 }
176 } 186 }
177 else 187 else
178 { 188 {
179 slog (L_ERR, _("unable to fork, exiting: %s"), strerror (errno)); 189 slog (L_ERR, _("unable to fork, exiting: %s"), strerror (errno));
180 exit (EXIT_FAILURE); 190 exit (EXIT_FAILURE);
181 } 191 }
182 192
183 return true; 193 return pid;
184} 194}
185 195
186#if ENABLE_HTTP_PROXY 196#if ENABLE_HTTP_PROXY
187// works like strdup 197// works like strdup
188u8 * 198u8 *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines