diff options
author | Andrew de los Reyes <adlr@chromium.org> | 2010-04-15 14:02:17 -0700 |
---|---|---|
committer | Andrew de los Reyes <adlr@chromium.org> | 2010-04-15 14:02:17 -0700 |
commit | 08c4e27baaa7b40732b99642e1f21bf889d022ef (patch) | |
tree | 816583a62961b5caa1f1e13ba74e88ff070cf2c6 /subprocess.cc | |
parent | b10320d4f76a2d263566f6eed471921382fae800 (diff) |
update engine: 32- and 64-bit compile
Review URL: http://codereview.chromium.org/1599029
Diffstat (limited to 'subprocess.cc')
-rw-r--r-- | subprocess.cc | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/subprocess.cc b/subprocess.cc index 89b6cadd..3a6597eb 100644 --- a/subprocess.cc +++ b/subprocess.cc @@ -9,6 +9,7 @@ #include <vector> #include "chromeos/obsolete_logging.h" #include "base/scoped_ptr.h" +#include "base/string_util.h" using std::string; using std::vector; @@ -18,7 +19,7 @@ namespace chromeos_update_engine { void Subprocess::GChildExitedCallback(GPid pid, gint status, gpointer data) { COMPILE_ASSERT(sizeof(guint) == sizeof(uint32), guint_uint32_size_mismatch); - guint *tag = reinterpret_cast<guint*>(data); + guint* tag = reinterpret_cast<guint*>(data); const SubprocessCallbackRecord& record = Get().callback_records_[*tag]; if (record.callback) record.callback(status, record.callback_data); @@ -38,16 +39,22 @@ void FreeArgv(char** argv) { uint32 Subprocess::Exec(const std::vector<std::string>& cmd, ExecCallback callback, - void *p) { + void* p) { GPid child_pid; - GError *err; - scoped_array<char *> argv(new char*[cmd.size() + 1]); + GError* err; + scoped_array<char*> argv(new char*[cmd.size() + 1]); for (unsigned int i = 0; i < cmd.size(); i++) { argv[i] = strdup(cmd[i].c_str()); } argv[cmd.size()] = NULL; - char *argp[1]; - argp[0] = 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()); + } SubprocessCallbackRecord callback_record; callback_record.callback = callback; @@ -55,7 +62,7 @@ uint32 Subprocess::Exec(const std::vector<std::string>& cmd, bool success = g_spawn_async(NULL, // working directory argv.get(), - argp, + argp.get(), G_SPAWN_DO_NOT_REAP_CHILD, // flags NULL, // child setup function NULL, // child setup data pointer @@ -66,7 +73,7 @@ uint32 Subprocess::Exec(const std::vector<std::string>& cmd, LOG(ERROR) << "g_spawn_async failed"; return 0; } - guint *tag = new guint; + guint* tag = new guint; *tag = g_child_watch_add(child_pid, GChildExitedCallback, tag); callback_records_[*tag] = callback_record; return *tag; @@ -80,13 +87,13 @@ void Subprocess::CancelExec(uint32 tag) { bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd, int* return_code) { - GError *err = NULL; - scoped_array<char *> argv(new char*[cmd.size() + 1]); + GError* err = NULL; + scoped_array<char*> argv(new char*[cmd.size() + 1]); for (unsigned int i = 0; i < cmd.size(); i++) { argv[i] = strdup(cmd[i].c_str()); } argv[cmd.size()] = NULL; - char *argp[1]; + char* argp[1]; argp[0] = NULL; bool success = g_spawn_sync(NULL, // working directory |