[VM-Runtime] set environment when creating detached process
environ variable should be updated if user provides environment. It only update for normal processes. Bug= https://github.com/dart-lang/sdk/issues/36132 Change-Id: I2a4639ed53e7376534578a0b1b251025ffaa2278 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96147 Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Zichang Guo <zichangguo@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
578fdb0408
commit
0bd674c374
@@ -546,6 +546,9 @@ class ProcessStarter {
|
||||
!Directory::SetCurrent(namespc_, working_directory_)) {
|
||||
ReportChildError();
|
||||
}
|
||||
if (program_environment_ != NULL) {
|
||||
environ = program_environment_;
|
||||
}
|
||||
|
||||
// Report the final PID and do the exec.
|
||||
ReportPid(getpid()); // getpid cannot fail.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
void main() {
|
||||
print(Platform.environment);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
const String childFile = 'process_environment_lib.dart';
|
||||
const String fakeKey = 'Artificial';
|
||||
const String fakeValue = 'fakepath';
|
||||
|
||||
void main() async {
|
||||
Map<String, String> environ = Platform.environment;
|
||||
String baseDirectory = path.dirname(Platform.script.path);
|
||||
//DETACHED PROCESS WITHOUT includeParentEnvironment
|
||||
var WithoutEnviron = await Process.start(
|
||||
Platform.executable, [path.join(baseDirectory, childFile)],
|
||||
mode: ProcessStartMode.detachedWithStdio,
|
||||
includeParentEnvironment: false,
|
||||
environment: <String, String>{fakeKey: fakeValue});
|
||||
|
||||
Map<String, String> notInclude = new Map();
|
||||
await for (final line in WithoutEnviron.stdout
|
||||
.transform(systemEncoding.decoder)
|
||||
.transform(LineSplitter())) {
|
||||
notInclude = RestoreToMap(line);
|
||||
}
|
||||
|
||||
//Ensure the child process has the passed environment
|
||||
Expect.isTrue(notInclude.length >= 1);
|
||||
Expect.isTrue(notInclude.keys.contains(fakeKey));
|
||||
|
||||
//DETACHED PROCESS WITH includeParentEnvironment
|
||||
var WithEnviron = await Process.start(
|
||||
Platform.executable, [path.join(baseDirectory, childFile)],
|
||||
mode: ProcessStartMode.detachedWithStdio,
|
||||
includeParentEnvironment: true,
|
||||
environment: <String, String>{fakeKey: fakeValue});
|
||||
|
||||
Map<String, String> include = new Map();
|
||||
await for (final line in WithEnviron.stdout
|
||||
.transform(systemEncoding.decoder)
|
||||
.transform(LineSplitter())) {
|
||||
include = RestoreToMap(line);
|
||||
}
|
||||
|
||||
//Parent environment and one fake path
|
||||
Expect.isTrue(include.length == environ.length + 1);
|
||||
Expect.isTrue(include[fakeKey] == fakeValue);
|
||||
}
|
||||
|
||||
Map<String, String> RestoreToMap(String s) {
|
||||
s = s.substring(1, s.length - 1);
|
||||
Map<String, String> result = new Map();
|
||||
for (String line in s.split(", ")) {
|
||||
var i = line.indexOf(": ");
|
||||
result.putIfAbsent(line.substring(0, i), () => line.substring(i + 2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user