< prev index next >

src/os/solaris/vm/os_solaris.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 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  *


6136   int s, status ;
6137   status = os::Solaris::mutex_lock (_mutex) ;
6138   assert (status == 0, "invariant") ;
6139   s = _counter;
6140   _counter = 1;
6141   status = os::Solaris::mutex_unlock (_mutex) ;
6142   assert (status == 0, "invariant") ;
6143 
6144   if (s < 1) {
6145     status = os::Solaris::cond_signal (_cond) ;
6146     assert (status == 0, "invariant") ;
6147   }
6148 }
6149 
6150 extern char** environ;
6151 
6152 // Run the specified command in a separate process. Return its exit value,
6153 // or -1 on failure (e.g. can't fork a new process).
6154 // Unlike system(), this function can be called from signal handler. It
6155 // doesn't block SIGINT et al.
6156 int os::fork_and_exec(char* cmd) {
6157   char * argv[4];
6158   argv[0] = (char *)"sh";
6159   argv[1] = (char *)"-c";
6160   argv[2] = cmd;
6161   argv[3] = NULL;
6162 
6163   // fork is async-safe, fork1 is not so can't use in signal handler
6164   pid_t pid;
6165   Thread* t = ThreadLocalStorage::get_thread_slow();
6166   if (t != NULL && t->is_inside_signal_handler()) {
6167     pid = fork();
6168   } else {
6169     pid = fork1();
6170   }
6171 
6172   if (pid < 0) {
6173     // fork failed
6174     warning("fork failed: %s", strerror(errno));
6175     return -1;
6176 


   1 /*
   2  * Copyright (c) 1997, 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  *


6136   int s, status ;
6137   status = os::Solaris::mutex_lock (_mutex) ;
6138   assert (status == 0, "invariant") ;
6139   s = _counter;
6140   _counter = 1;
6141   status = os::Solaris::mutex_unlock (_mutex) ;
6142   assert (status == 0, "invariant") ;
6143 
6144   if (s < 1) {
6145     status = os::Solaris::cond_signal (_cond) ;
6146     assert (status == 0, "invariant") ;
6147   }
6148 }
6149 
6150 extern char** environ;
6151 
6152 // Run the specified command in a separate process. Return its exit value,
6153 // or -1 on failure (e.g. can't fork a new process).
6154 // Unlike system(), this function can be called from signal handler. It
6155 // doesn't block SIGINT et al.
6156 int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
6157   char * argv[4];
6158   argv[0] = (char *)"sh";
6159   argv[1] = (char *)"-c";
6160   argv[2] = cmd;
6161   argv[3] = NULL;
6162 
6163   // fork is async-safe, fork1 is not so can't use in signal handler
6164   pid_t pid;
6165   Thread* t = ThreadLocalStorage::get_thread_slow();
6166   if (t != NULL && t->is_inside_signal_handler()) {
6167     pid = fork();
6168   } else {
6169     pid = fork1();
6170   }
6171 
6172   if (pid < 0) {
6173     // fork failed
6174     warning("fork failed: %s", strerror(errno));
6175     return -1;
6176 


< prev index next >