1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
6320 status = pthread_cond_signal (&_cond[index]);
6321 assert (status == 0, "invariant");
6322 }
6323 } else {
6324 pthread_mutex_unlock(_mutex);
6325 assert (status == 0, "invariant") ;
6326 }
6327 } else {
6328 pthread_mutex_unlock(_mutex);
6329 assert (status == 0, "invariant") ;
6330 }
6331 }
6332
6333
6334 extern char** environ;
6335
6336 // Run the specified command in a separate process. Return its exit value,
6337 // or -1 on failure (e.g. can't fork a new process).
6338 // Unlike system(), this function can be called from signal handler. It
6339 // doesn't block SIGINT et al.
6340 int os::fork_and_exec(char* cmd) {
6341 const char * argv[4] = {"sh", "-c", cmd, NULL};
6342
6343 pid_t pid = fork();
6344
6345 if (pid < 0) {
6346 // fork failed
6347 return -1;
6348
6349 } else if (pid == 0) {
6350 // child process
6351
6352 execve("/bin/sh", (char* const*)argv, environ);
6353
6354 // execve failed
6355 _exit(-1);
6356
6357 } else {
6358 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
6359 // care about the actual exit code, for now.
6360
6361 int status;
6362
6363 // Wait for the child process to exit. This returns immediately if
|
1 /*
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
6320 status = pthread_cond_signal (&_cond[index]);
6321 assert (status == 0, "invariant");
6322 }
6323 } else {
6324 pthread_mutex_unlock(_mutex);
6325 assert (status == 0, "invariant") ;
6326 }
6327 } else {
6328 pthread_mutex_unlock(_mutex);
6329 assert (status == 0, "invariant") ;
6330 }
6331 }
6332
6333
6334 extern char** environ;
6335
6336 // Run the specified command in a separate process. Return its exit value,
6337 // or -1 on failure (e.g. can't fork a new process).
6338 // Unlike system(), this function can be called from signal handler. It
6339 // doesn't block SIGINT et al.
6340 int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
6341 const char * argv[4] = {"sh", "-c", cmd, NULL};
6342
6343 pid_t pid ;
6344
6345 if (use_vfork_if_available) {
6346 pid = vfork();
6347 } else {
6348 pid = fork();
6349 }
6350
6351 if (pid < 0) {
6352 // fork failed
6353 return -1;
6354
6355 } else if (pid == 0) {
6356 // child process
6357
6358 execve("/bin/sh", (char* const*)argv, environ);
6359
6360 // execve failed
6361 _exit(-1);
6362
6363 } else {
6364 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
6365 // care about the actual exit code, for now.
6366
6367 int status;
6368
6369 // Wait for the child process to exit. This returns immediately if
|