< prev index next >

src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c

Print this page
rev 59104 : imported patch serviceability


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <stdlib.h>
  27 #include <unistd.h>
  28 #include <string.h>
  29 #include <ctype.h>
  30 #include "sys.h"
  31 #include "util.h"
  32 
  33 #if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(AIX)
  34   /* Linux, BSD, AIX */
  35   #define FORK() fork()
  36 #else
  37   /* Solaris (make sure we always get the POSIX-specified behavior) */
  38   #define FORK() fork1()
  39 #endif
  40 
  41 static char *skipWhitespace(char *p) {
  42     while ((*p != '\0') && isspace(*p)) {
  43         p++;
  44     }
  45     return p;
  46 }
  47 
  48 static char *skipNonWhitespace(char *p) {
  49     while ((*p != '\0') && !isspace(*p)) {
  50         p++;
  51     }
  52     return p;
  53 }
  54 
  55 int
  56 dbgsysExec(char *cmdLine)
  57 {
  58     int i;
  59     int argc;
  60     pid_t pid_err = (pid_t)(-1); /* this is the error return value */


  83             break;
  84         }
  85         p = skipWhitespace(p);
  86     }
  87 
  88     /*LINTED*/
  89     argv = jvmtiAllocate((argc + 1) * (jint)sizeof(char *));
  90     if (argv == 0) {
  91         jvmtiDeallocate(args);
  92         return SYS_NOMEM;
  93     }
  94 
  95     for (i = 0, p = args; i < argc; i++) {
  96         argv[i] = p;
  97         p = skipNonWhitespace(p);
  98         *p++ = '\0';
  99         p = skipWhitespace(p);
 100     }
 101     argv[i] = NULL;  /* NULL terminate */
 102 
 103     if ((pid = FORK()) == 0) {
 104         /* Child process */
 105         int i;
 106         long max_fd;
 107 
 108         /* close everything */
 109         max_fd = sysconf(_SC_OPEN_MAX);
 110         /*LINTED*/
 111         for (i = 3; i < (int)max_fd; i++) {
 112             (void)close(i);
 113         }
 114 
 115         (void)execvp(argv[0], argv);
 116 
 117         exit(-1);
 118     }
 119     jvmtiDeallocate(args);
 120     jvmtiDeallocate(argv);
 121     if (pid == pid_err) {
 122         return SYS_ERR;
 123     } else {


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <stdlib.h>
  27 #include <unistd.h>
  28 #include <string.h>
  29 #include <ctype.h>
  30 #include "sys.h"
  31 #include "util.h"
  32 








  33 static char *skipWhitespace(char *p) {
  34     while ((*p != '\0') && isspace(*p)) {
  35         p++;
  36     }
  37     return p;
  38 }
  39 
  40 static char *skipNonWhitespace(char *p) {
  41     while ((*p != '\0') && !isspace(*p)) {
  42         p++;
  43     }
  44     return p;
  45 }
  46 
  47 int
  48 dbgsysExec(char *cmdLine)
  49 {
  50     int i;
  51     int argc;
  52     pid_t pid_err = (pid_t)(-1); /* this is the error return value */


  75             break;
  76         }
  77         p = skipWhitespace(p);
  78     }
  79 
  80     /*LINTED*/
  81     argv = jvmtiAllocate((argc + 1) * (jint)sizeof(char *));
  82     if (argv == 0) {
  83         jvmtiDeallocate(args);
  84         return SYS_NOMEM;
  85     }
  86 
  87     for (i = 0, p = args; i < argc; i++) {
  88         argv[i] = p;
  89         p = skipNonWhitespace(p);
  90         *p++ = '\0';
  91         p = skipWhitespace(p);
  92     }
  93     argv[i] = NULL;  /* NULL terminate */
  94 
  95     if ((pid = fork()) == 0) {
  96         /* Child process */
  97         int i;
  98         long max_fd;
  99 
 100         /* close everything */
 101         max_fd = sysconf(_SC_OPEN_MAX);
 102         /*LINTED*/
 103         for (i = 3; i < (int)max_fd; i++) {
 104             (void)close(i);
 105         }
 106 
 107         (void)execvp(argv[0], argv);
 108 
 109         exit(-1);
 110     }
 111     jvmtiDeallocate(args);
 112     jvmtiDeallocate(argv);
 113     if (pid == pid_err) {
 114         return SYS_ERR;
 115     } else {
< prev index next >