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

Unified Diff: subprocess.cc

Issue 2805027: AU: Changes for deltas on traditional bios machines. (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: fixes for review and merging in petkov's recent changes Created 10 years, 5 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 | « postinstall_runner_action.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: subprocess.cc
diff --git a/subprocess.cc b/subprocess.cc
old mode 100644
new mode 100755
index 87d82532a8886750c715b7cb4d4642e3f7fa5ff6..696779f6473e659cee53c6055cf3ae7dbdfdceca
--- a/subprocess.cc
+++ b/subprocess.cc
@@ -35,11 +35,42 @@ void FreeArgv(char** argv) {
argv[i] = NULL;
}
}
+
+// Note: Caller responsible for free()ing the returned value!
+char** ArgPointer() {
+ const char* keys[] = {"LD_LIBRARY_PATH", "PATH"};
+ char** ret = new char*[arraysize(keys) + 1];
+ int pointer = 0;
+ for (size_t i = 0; i < arraysize(keys); i++) {
+ ret[i] = NULL;
+ if (getenv(keys[i])) {
+ ret[pointer] = strdup(StringPrintf("%s=%s", keys[i],
+ getenv(keys[i])).c_str());
+ pointer++;
+ }
+ }
+ return ret;
+}
+
+class ScopedFreeArgPointer {
+ public:
+ ScopedFreeArgPointer(char** arr) : arr_(arr) {}
+ ~ScopedFreeArgPointer() {
+ if (!arr_)
+ return;
+ for (int i = 0; arr_[i]; i++)
+ free(arr_[i]);
+ delete[] arr_;
+ }
+ private:
+ char** arr_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedFreeArgPointer);
+};
} // namespace {}
uint32_t Subprocess::Exec(const std::vector<std::string>& cmd,
- ExecCallback callback,
- void* p) {
+ ExecCallback callback,
+ void* p) {
GPid child_pid;
GError* err;
scoped_array<char*> argv(new char*[cmd.size() + 1]);
@@ -48,13 +79,8 @@ uint32_t Subprocess::Exec(const std::vector<std::string>& cmd,
}
argv[cmd.size()] = NULL;
- scoped_array<char*> argp(new char*[2]);
- argp[0] = argp[1] = NULL;
- const char* kLdLibraryPathKey = "LD_LIBRARY_PATH";
- if (getenv(kLdLibraryPathKey)) {
- argp[0] = strdup(StringPrintf("%s=%s", kLdLibraryPathKey,
- getenv(kLdLibraryPathKey)).c_str());
- }
+ char** argp = ArgPointer();
+ ScopedFreeArgPointer argp_free(argp);
SubprocessCallbackRecord callback_record;
callback_record.callback = callback;
@@ -62,7 +88,7 @@ uint32_t Subprocess::Exec(const std::vector<std::string>& cmd,
bool success = g_spawn_async(NULL, // working directory
argv.get(),
- argp.get(),
+ argp,
G_SPAWN_DO_NOT_REAP_CHILD, // flags
NULL, // child setup function
NULL, // child setup data pointer
@@ -93,8 +119,12 @@ bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd,
argv[i] = strdup(cmd[i].c_str());
}
argv[cmd.size()] = NULL;
- char* argp[1];
- argp[0] = NULL;
+
+ char** argp = ArgPointer();
+ ScopedFreeArgPointer argp_free(argp);
+
+ char* child_stdout;
+ char* child_stderr;
bool success = g_spawn_sync(NULL, // working directory
argv.get(),
@@ -102,13 +132,17 @@ bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd,
static_cast<GSpawnFlags>(NULL), // flags
NULL, // child setup function
NULL, // data for child setup function
- NULL, // return location for stdout
- NULL, // return location for stderr
+ &child_stdout,
+ &child_stderr,
return_code,
&err);
FreeArgv(argv.get());
if (err)
LOG(INFO) << "err is: " << err->code << ", " << err->message;
+ if (child_stdout)
+ LOG(INFO) << "Postinst stdout:" << child_stdout;
+ if (child_stderr)
+ LOG(INFO) << "Postinst stderr:" << child_stderr;
return success;
}
« no previous file with comments | « postinstall_runner_action.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698