82
82
import java .util .Set ;
83
83
import java .util .concurrent .TimeUnit ;
84
84
85
+ import org .graalvm .nativeimage .ImageInfo ;
86
+
85
87
import com .oracle .graal .python .PythonLanguage ;
86
88
import com .oracle .graal .python .builtins .Builtin ;
87
89
import com .oracle .graal .python .builtins .CoreFunctions ;
@@ -278,6 +280,18 @@ public void postInitialize(PythonCore core) {
278
280
Map <String , String > getenv = System .getenv ();
279
281
PDict environ = core .factory ().createDict ();
280
282
for (Entry <String , String > entry : getenv .entrySet ()) {
283
+ if (!ImageInfo .inImageCode ()) {
284
+ // both _JAVA_OPTIONS and JAVA_TOOL_OPTIONS are adeed during JVM
285
+ // startup automatically. We do not want to repeat these, they
286
+ // are already in our ExecutableList if we're running on the
287
+ // JVM. OTOH, some script may set these explicitly later on. So
288
+ // whatever they are right now, we'll empty them, so that any
289
+ // subprocess launched later will not inherit them.
290
+ if ("_JAVA_OPTIONS" .equals (entry .getKey ()) || "JAVA_TOOL_OPTIONS" .equals (entry .getKey ())) {
291
+ continue ;
292
+ }
293
+ }
294
+
281
295
String value ;
282
296
if ("__PYVENV_LAUNCHER__" .equals (entry .getKey ())) {
283
297
// On Mac, the CPython launcher uses this env variable to specify the real Python
@@ -350,6 +364,7 @@ Object doExecuteInternal(PythonModule thisModule, String path, PSequence args) t
350
364
PDict environ = (PDict ) thisModule .getAttribute ("environ" );
351
365
ProcessBuilder builder = new ProcessBuilder (cmd );
352
366
Map <String , String > environment = builder .environment ();
367
+ environment .clear ();
353
368
environ .entries ().forEach (entry -> {
354
369
environment .put (new String (toBytes .execute (null , entry .key )), new String (toBytes .execute (null , entry .value )));
355
370
});
@@ -1481,11 +1496,12 @@ PTuple waitpidFallback(VirtualFrame frame, Object pid, Object options,
1481
1496
}
1482
1497
}
1483
1498
1484
- @ Builtin (name = "system" , minNumOfPositionalArgs = 1 )
1499
+ @ Builtin (name = "system" , minNumOfPositionalArgs = 1 , declaresExplicitSelf = true )
1485
1500
@ GenerateNodeFactory
1486
1501
@ TypeSystemReference (PythonArithmeticTypes .class )
1487
1502
abstract static class SystemNode extends PythonBuiltinNode {
1488
1503
private static final TruffleLogger LOGGER = PythonLanguage .getLogger (SystemNode .class );
1504
+ @ Child private BytesNodes .ToBytesNode toBytes = BytesNodes .ToBytesNode .create ();
1489
1505
1490
1506
static final String [] shell ;
1491
1507
static {
@@ -1536,7 +1552,7 @@ public void finish() {
1536
1552
1537
1553
@ TruffleBoundary
1538
1554
@ Specialization
1539
- int system (String cmd ) {
1555
+ int system (PythonModule thisModule , String cmd ) {
1540
1556
PythonContext context = getContext ();
1541
1557
if (!context .isExecutableAccessAllowed ()) {
1542
1558
return -1 ;
@@ -1546,6 +1562,13 @@ int system(String cmd) {
1546
1562
Env env = context .getEnv ();
1547
1563
try {
1548
1564
ProcessBuilder pb = new ProcessBuilder (command );
1565
+ PDict environ = (PDict ) thisModule .getAttribute ("environ" );
1566
+ ProcessBuilder builder = new ProcessBuilder (cmd );
1567
+ Map <String , String > environment = pb .environment ();
1568
+ environment .clear ();
1569
+ environ .entries ().forEach (entry -> {
1570
+ environment .put (new String (toBytes .execute (null , entry .key )), new String (toBytes .execute (null , entry .value )));
1571
+ });
1549
1572
pb .directory (new File (env .getCurrentWorkingDirectory ().getPath ()));
1550
1573
PipePump stdout = null , stderr = null ;
1551
1574
boolean stdsArePipes = !terminalIsInteractive (context );
0 commit comments