OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "update_engine/subprocess.h" | 5 #include "update_engine/subprocess.h" |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "chromeos/obsolete_logging.h" | 10 #include "chromeos/obsolete_logging.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 void Subprocess::CancelExec(uint32 tag) { | 75 void Subprocess::CancelExec(uint32 tag) { |
76 if (callback_records_[tag].callback) { | 76 if (callback_records_[tag].callback) { |
77 callback_records_[tag].callback = NULL; | 77 callback_records_[tag].callback = NULL; |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd, | 81 bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd, |
82 int* return_code) { | 82 int* return_code) { |
83 GError *err; | 83 GError *err = NULL; |
84 scoped_array<char *> argv(new char*[cmd.size() + 1]); | 84 scoped_array<char *> argv(new char*[cmd.size() + 1]); |
85 for (unsigned int i = 0; i < cmd.size(); i++) { | 85 for (unsigned int i = 0; i < cmd.size(); i++) { |
86 argv[i] = strdup(cmd[i].c_str()); | 86 argv[i] = strdup(cmd[i].c_str()); |
87 } | 87 } |
88 argv[cmd.size()] = NULL; | 88 argv[cmd.size()] = NULL; |
89 char *argp[1]; | 89 char *argp[1]; |
90 argp[0] = NULL; | 90 argp[0] = NULL; |
91 | 91 |
92 bool success = g_spawn_sync(NULL, // working directory | 92 bool success = g_spawn_sync(NULL, // working directory |
93 argv.get(), | 93 argv.get(), |
94 argp, | 94 argp, |
95 static_cast<GSpawnFlags>(NULL), // flags | 95 static_cast<GSpawnFlags>(NULL), // flags |
96 NULL, // child setup function | 96 NULL, // child setup function |
97 NULL, // data for child setup function | 97 NULL, // data for child setup function |
98 NULL, // return location for stdout | 98 NULL, // return location for stdout |
99 NULL, // return location for stderr | 99 NULL, // return location for stderr |
100 return_code, | 100 return_code, |
101 &err); | 101 &err); |
102 FreeArgv(argv.get()); | 102 FreeArgv(argv.get()); |
| 103 if (err) |
| 104 LOG(INFO) << "err is: " << err->code << ", " << err->message; |
103 return success; | 105 return success; |
104 } | 106 } |
105 | 107 |
106 Subprocess* Subprocess::subprocess_singleton_ = NULL; | 108 Subprocess* Subprocess::subprocess_singleton_ = NULL; |
107 | 109 |
108 } // namespace chromeos_update_engine | 110 } // namespace chromeos_update_engine |
OLD | NEW |