Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/back/exec_md.c
32285 views
1
/*
2
* Copyright (c) 1998, 2013, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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 "jni.h"
31
#include "sys.h"
32
#include "util.h"
33
34
#if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(AIX)
35
/* Linux, BSD, AIX */
36
#define FORK() fork()
37
#else
38
/* Solaris (make sure we always get the POSIX-specified behavior) */
39
#define FORK() fork1()
40
#endif
41
42
static char *skipWhitespace(char *p) {
43
while ((*p != '\0') && isspace(*p)) {
44
p++;
45
}
46
return p;
47
}
48
49
static char *skipNonWhitespace(char *p) {
50
while ((*p != '\0') && !isspace(*p)) {
51
p++;
52
}
53
return p;
54
}
55
56
int
57
dbgsysExec(char *cmdLine)
58
{
59
int i;
60
int argc;
61
pid_t pid_err = (pid_t)(-1); /* this is the error return value */
62
pid_t pid;
63
char **argv = NULL;
64
char *p;
65
char *args;
66
67
/* Skip leading whitespace */
68
cmdLine = skipWhitespace(cmdLine);
69
70
/*LINTED*/
71
args = jvmtiAllocate((jint)strlen(cmdLine)+1);
72
if (args == NULL) {
73
return SYS_NOMEM;
74
}
75
(void)strcpy(args, cmdLine);
76
77
p = args;
78
79
argc = 0;
80
while (*p != '\0') {
81
p = skipNonWhitespace(p);
82
argc++;
83
if (*p == '\0') {
84
break;
85
}
86
p = skipWhitespace(p);
87
}
88
89
/*LINTED*/
90
argv = jvmtiAllocate((argc + 1) * (jint)sizeof(char *));
91
if (argv == 0) {
92
jvmtiDeallocate(args);
93
return SYS_NOMEM;
94
}
95
96
for (i = 0, p = args; i < argc; i++) {
97
argv[i] = p;
98
p = skipNonWhitespace(p);
99
*p++ = '\0';
100
p = skipWhitespace(p);
101
}
102
argv[i] = NULL; /* NULL terminate */
103
104
if ((pid = FORK()) == 0) {
105
/* Child process */
106
int i;
107
long max_fd;
108
109
/* close everything */
110
max_fd = sysconf(_SC_OPEN_MAX);
111
/*LINTED*/
112
for (i = 3; i < (int)max_fd; i++) {
113
(void)close(i);
114
}
115
116
(void)execvp(argv[0], argv);
117
118
exit(-1);
119
}
120
jvmtiDeallocate(args);
121
jvmtiDeallocate(argv);
122
if (pid == pid_err) {
123
return SYS_ERR;
124
} else {
125
return SYS_OK;
126
}
127
}
128
129