+
+ /* If end of service, wait for process status */
+ if (n == 0) {
+ t = 0;
+ pid = waitpid(as->pid, &retstat, WNOHANG);
+ while (t<5 && pid == 0) {
+ sleep(1);
+ t++;
+ pid = waitpid(as->pid, &retstat, WNOHANG);
+ }
+
+ if (pid > 0) {
+ what = NULL;
+ if (! WIFEXITED(retstat)) {
+ what = _("signal");
+ code = WTERMSIG(retstat);
+ } else if (WEXITSTATUS(retstat) != 0) {
+ what = _("code");
+ code = WEXITSTATUS(retstat);
+ }
+ if (what) {
+ dbprintf(_("service %s failed: pid %u exited with %s %d\n"),
+ (as->cmd)?as->cmd:_("??UNKONWN??"),
+ (unsigned)as->pid,
+ what, code);
+ msg = vstrallocf(
+ _("ERROR service %s failed: pid %u exited with %s %d\n"),
+ (as->cmd)?as->cmd:_("??UNKONWN??"), (unsigned)as->pid,
+ what, code);
+ if (as->repbufsize + strlen(msg) >= (as->bufsize - 1)) {
+ as->bufsize *= 2;
+ repbuf_temp = alloc(as->bufsize);
+ memcpy(repbuf_temp, as->repbuf, as->repbufsize + 1);
+ amfree(as->repbuf);
+ as->repbuf = repbuf_temp;
+ }
+ strcpy(as->repbuf + as->repbufsize, msg);
+ as->repbufsize += strlen(msg);
+ }
+ }
+ }
+