in src/native/unix/native/jsvc-unix.c [732:791]
static int wait_child(arg_data *args, int pid)
{
int count = 10;
bool havejvm = false;
int fd;
char buff[80];
int i, status, waittime;
log_debug("wait_child %d", pid);
waittime = args->wait / 10;
if (waittime > 10) {
count = waittime;
waittime = 10;
}
while (count > 0) {
sleep(1);
/* check if the controler is still running */
if (waitpid(pid, &status, WNOHANG) == pid) {
if (WIFEXITED(status))
return (WEXITSTATUS(status));
else
return 1;
}
/* check if the pid file process exists */
fd = open(args->pidf, O_RDONLY);
if (fd < 0 && havejvm) {
/* something has gone wrong the JVM has stopped */
return 1;
}
lockf(fd, F_LOCK, 0);
i = read(fd, buff, sizeof(buff));
lockf(fd, F_ULOCK, 0);
close(fd);
if (i > 0) {
buff[i] = '\0';
i = atoi(buff);
if (kill(i, 0) == 0) {
/* the JVM process has started */
havejvm = true;
if (check_tmp_file(args) == 0) {
/* the JVM is started */
if (waitpid(pid, &status, WNOHANG) == pid) {
if (WIFEXITED(status))
return (WEXITSTATUS(status));
else
return 1;
}
return 0; /* ready JVM started */
}
}
}
sleep(waittime);
count--;
}
/* It takes more than the wait time to start,
* something must be wrong
*/
return 1;
}