in src/native/unix/native/jsvc-unix.c [1157:1296]
int main(int argc, char *argv[])
{
arg_data *args = NULL;
home_data *data = NULL;
pid_t pid = 0;
uid_t uid = 0;
gid_t gid = 0;
int res;
/* Parse command line arguments */
args = arguments(argc, argv);
if (args == NULL)
return 1;
/* Stop running jsvc if required */
if (args->stop == true)
return (stop_child(args));
/* Let's check if we can switch user/group IDs */
if (checkuser(args->user, &uid, &gid) == false)
return 1;
/* Retrieve JAVA_HOME layout */
data = home(args->home);
if (data == NULL)
return 1;
/* Check for help */
if (args->help == true) {
help(data);
return 0;
}
#ifdef OS_LINUX
/* On some UNIX operating systems, we need to REPLACE this current
process image with another one (thru execve) to allow the correct
loading of VMs (notably this is for Linux). Set, replace, and go. */
if (strcmp(argv[0], args->procname) != 0) {
char *oldpath = getenv("LD_LIBRARY_PATH");
char *libf = java_library(args, data);
char *filename;
char buf[2048];
int ret;
char *tmp = NULL;
char *p1 = NULL;
char *p2 = NULL;
/* We don't want to use a form of exec() that searches the
* PATH, so require that argv[0] be either an absolute or
* relative path. Error out if this isn't the case.
*/
tmp = strchr(argv[0], '/');
if (tmp == NULL) {
log_error("JSVC re-exec requires execution with an absolute or relative path");
return 1;
}
/*
* There is no need to change LD_LIBRARY_PATH
* if we were not able to find a path to libjvm.so
* (additionally a strdup(NULL) cores dump on my machine).
*/
if (libf != NULL) {
p1 = strdup(libf);
tmp = strrchr(p1, '/');
if (tmp != NULL)
tmp[0] = '\0';
p2 = strdup(p1);
tmp = strrchr(p2, '/');
if (tmp != NULL)
tmp[0] = '\0';
if (oldpath == NULL)
snprintf(buf, 2048, "%s:%s", p1, p2);
else
snprintf(buf, 2048, "%s:%s:%s", oldpath, p1, p2);
tmp = strdup(buf);
setenv("LD_LIBRARY_PATH", tmp, 1);
log_debug("Invoking w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
}
/* execve needs a full path */
ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
if (ret <= 0)
strcpy(buf, argv[0]);
else
buf[ret] = '\0';
filename = buf;
argv[0] = args->procname;
execve(filename, argv, environ);
log_error("Cannot execute JSVC executor process (%s)", filename);
return 1;
}
log_debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
#endif /* ifdef OS_LINUX */
/* If we have to detach, let's do it now */
if (args->dtch == true) {
pid = fork();
if (pid == -1) {
log_error("Cannot detach from parent process");
return 1;
}
/* If we're in the parent process */
if (pid != 0) {
if (args->wait >= 10)
return wait_child(args, pid);
else
return 0;
}
#ifndef NO_SETSID
setsid();
#endif
}
if (chdir(args->cwd)) {
log_error("ERROR: jsvc was unable to " "change directory to: %s", args->cwd);
}
/*
* umask() uses inverse logic; bits are CLEAR for allowed access.
*/
if (~args->umask & 0022) {
log_error("NOTICE: jsvc umask of %03o allows "
"write permission to group and/or other", args->umask);
}
envmask = umask(args->umask);
set_output(args->outfile, args->errfile, args->redirectstdin, args->procname);
log_debug("Switching umask from %03o to %03o", envmask, args->umask);
res = run_controller(args, data, uid, gid);
if (logger_pid != 0) {
kill(logger_pid, SIGTERM);
}
return res;
}