< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




5750       }
5751     }
5752 
5753     if (WIFEXITED(status)) {
5754       // The child exited normally; get its exit code.
5755       return WEXITSTATUS(status);
5756     } else if (WIFSIGNALED(status)) {
5757       // The child exited because of a signal
5758       // The best value to return is 0x80 + signal number,
5759       // because that is what all Unix shells do, and because
5760       // it allows callers to distinguish between process exit and
5761       // process death by signal.
5762       return 0x80 + WTERMSIG(status);
5763     } else {
5764       // Unknown exit code; pass it through
5765       return status;
5766     }
5767   }
5768 }
5769 























































5770 // Get the default path to the core file
5771 // Returns the length of the string
5772 int os::get_core_path(char* buffer, size_t bufferSize) {
5773   /*
5774    * Max length of /proc/sys/kernel/core_pattern is 128 characters.
5775    * See https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
5776    */
5777   const int core_pattern_len = 129;
5778   char core_pattern[core_pattern_len] = {0};
5779 
5780   int core_pattern_file = ::open("/proc/sys/kernel/core_pattern", O_RDONLY);
5781   if (core_pattern_file == -1) {
5782     return -1;
5783   }
5784 
5785   ssize_t ret = ::read(core_pattern_file, core_pattern, core_pattern_len);
5786   ::close(core_pattern_file);
5787   if (ret <= 0 || ret >= core_pattern_len || core_pattern[0] == '\n') {
5788     return -1;
5789   }




5750       }
5751     }
5752 
5753     if (WIFEXITED(status)) {
5754       // The child exited normally; get its exit code.
5755       return WEXITSTATUS(status);
5756     } else if (WIFSIGNALED(status)) {
5757       // The child exited because of a signal
5758       // The best value to return is 0x80 + signal number,
5759       // because that is what all Unix shells do, and because
5760       // it allows callers to distinguish between process exit and
5761       // process death by signal.
5762       return 0x80 + WTERMSIG(status);
5763     } else {
5764       // Unknown exit code; pass it through
5765       return status;
5766     }
5767   }
5768 }
5769 
5770 
5771 // Run the specified command in a separate process. Return its exit value,
5772 // or -1 on failure (e.g. can't fork a new process).
5773 // Unlike system(), this function can be called from signal handler. It
5774 // doesn't block SIGINT et al.
5775 int os::vfork_and_exec(char* cmd) {
5776   const char * argv[4] = {"sh", "-c", cmd, NULL};
5777 
5778   pid_t pid = vfork();
5779 
5780   if (pid < 0) {
5781     // fork failed
5782     return -1;
5783 
5784   } else if (pid == 0) {
5785     // child process
5786 
5787     execve("/bin/sh", (char* const*)argv, environ);
5788 
5789     // execve failed
5790     _exit(-1);
5791 
5792   } else  {
5793     // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
5794     // care about the actual exit code, for now.
5795 
5796     int status;
5797 
5798     // Wait for the child process to exit.  This returns immediately if
5799     // the child has already exited. */
5800     while (waitpid(pid, &status, 0) < 0) {
5801       switch (errno) {
5802       case ECHILD: return 0;
5803       case EINTR: break;
5804       default: return -1;
5805       }
5806     }
5807 
5808     if (WIFEXITED(status)) {
5809       // The child exited normally; get its exit code.
5810       return WEXITSTATUS(status);
5811     } else if (WIFSIGNALED(status)) {
5812       // The child exited because of a signal
5813       // The best value to return is 0x80 + signal number,
5814       // because that is what all Unix shells do, and because
5815       // it allows callers to distinguish between process exit and
5816       // process death by signal.
5817       return 0x80 + WTERMSIG(status);
5818     } else {
5819       // Unknown exit code; pass it through
5820       return status;
5821     }
5822   }
5823 }
5824 
5825 // Get the default path to the core file
5826 // Returns the length of the string
5827 int os::get_core_path(char* buffer, size_t bufferSize) {
5828   /*
5829    * Max length of /proc/sys/kernel/core_pattern is 128 characters.
5830    * See https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
5831    */
5832   const int core_pattern_len = 129;
5833   char core_pattern[core_pattern_len] = {0};
5834 
5835   int core_pattern_file = ::open("/proc/sys/kernel/core_pattern", O_RDONLY);
5836   if (core_pattern_file == -1) {
5837     return -1;
5838   }
5839 
5840   ssize_t ret = ::read(core_pattern_file, core_pattern, core_pattern_len);
5841   ::close(core_pattern_file);
5842   if (ret <= 0 || ret >= core_pattern_len || core_pattern[0] == '\n') {
5843     return -1;
5844   }


< prev index next >