Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Unified Diff: runtime/bin/platform_fuchsia.cc

Issue 2941873002: [Fuchsia] Fix Platform.executable and Platform.resolvedExecutable (Closed)
Patch Set: Format Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/platform_android.cc ('k') | runtime/bin/platform_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_fuchsia.cc
diff --git a/runtime/bin/platform_fuchsia.cc b/runtime/bin/platform_fuchsia.cc
index 1225cef370ac37b3b40ce72cccbc147ccf07d029..cf6e52377b426128e1b6a46696d208fab55c363c 100644
--- a/runtime/bin/platform_fuchsia.cc
+++ b/runtime/bin/platform_fuchsia.cc
@@ -7,8 +7,11 @@
#include "bin/platform.h"
-#include <string.h> // NOLINT
-#include <unistd.h> // NOLINT
+#include <magenta/process.h>
+#include <magenta/status.h>
+#include <magenta/syscalls.h>
+#include <string.h>
+#include <unistd.h>
#include "bin/dartutils.h"
#include "bin/fdutils.h"
@@ -79,42 +82,54 @@ char** Platform::Environment(intptr_t* count) {
}
+const char* Platform::GetExecutableName() {
+ if (executable_name_ != NULL) {
+ return executable_name_;
+ }
+ char* name = DartUtils::ScopedCString(MX_MAX_NAME_LEN);
+ mx_status_t status = mx_object_get_property(mx_process_self(), MX_PROP_NAME,
+ name, MX_MAX_NAME_LEN);
+ if (status != MX_OK) {
+ return NULL;
+ }
+ return name;
+}
+
+
const char* Platform::ResolveExecutablePath() {
- // The string used on the command line to spawn the executable is in argv_[0].
- // If that string is a relative or absolute path, i.e. it contains a '/', then
- // we make the path absolute if it is not already and return it. If argv_[0]
- // does not contain a '/', we assume it is a program whose location is
- // resolved via the PATH environment variable, and search for it using the
- // paths found there.
- const char* path = getenv("PATH");
- if ((strchr(argv_[0], '/') != NULL) || (path == NULL)) {
- if (argv_[0][0] == '/') {
- return File::GetCanonicalPath(argv_[0]);
- } else {
- char* result = DartUtils::ScopedCString(PATH_MAX + 1);
- char* cwd = DartUtils::ScopedCString(PATH_MAX + 1);
- getcwd(cwd, PATH_MAX);
- snprintf(result, PATH_MAX, "%s/%s", cwd, argv_[0]);
- result[PATH_MAX] = '\0';
- ASSERT(File::Exists(result));
- return File::GetCanonicalPath(result);
+ const char* executable_name = Platform::GetExecutableName();
+ if (executable_name == NULL) {
+ return NULL;
+ }
+ if ((executable_name[0] == '/') && File::Exists(executable_name)) {
+ return File::GetCanonicalPath(executable_name);
+ }
+ if (strchr(executable_name, '/') != NULL) {
+ const char* result = File::GetCanonicalPath(executable_name);
+ if (File::Exists(result)) {
+ return result;
}
} else {
+ const char* path = getenv("PATH");
+ if (path == NULL) {
+ // If PATH isn't set, make some guesses about where we should look.
+ path = "/system/bin:/system/apps:/boot/bin";
+ }
char* pathcopy = DartUtils::ScopedCopyCString(path);
char* result = DartUtils::ScopedCString(PATH_MAX + 1);
char* save = NULL;
while ((pathcopy = strtok_r(pathcopy, ":", &save)) != NULL) {
- snprintf(result, PATH_MAX, "%s/%s", pathcopy, argv_[0]);
+ snprintf(result, PATH_MAX, "%s/%s", pathcopy, executable_name);
result[PATH_MAX] = '\0';
if (File::Exists(result)) {
return File::GetCanonicalPath(result);
}
pathcopy = NULL;
}
- // Couldn't find it. This causes null to be returned for
- // Platform.resovledExecutable.
- return NULL;
}
+ // Couldn't find it. This causes null to be returned for
+ // Platform.resovledExecutable.
+ return NULL;
}
« no previous file with comments | « runtime/bin/platform_android.cc ('k') | runtime/bin/platform_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698