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

Side by Side Diff: src/platform/update_engine/subprocess.cc

Issue 1718001: AU: Class to perform delta updates. (Closed)
Patch Set: fixes for review Created 10 years, 8 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 13
14 using std::string; 14 using std::string;
15 using std::vector; 15 using std::vector;
16 16
17 namespace chromeos_update_engine { 17 namespace chromeos_update_engine {
18 18
19 void Subprocess::GChildExitedCallback(GPid pid, gint status, gpointer data) { 19 void Subprocess::GChildExitedCallback(GPid pid, gint status, gpointer data) {
20 COMPILE_ASSERT(sizeof(guint) == sizeof(uint32), 20 COMPILE_ASSERT(sizeof(guint) == sizeof(uint32_t),
21 guint_uint32_size_mismatch); 21 guint_uint32_size_mismatch);
22 guint* tag = reinterpret_cast<guint*>(data); 22 guint* tag = reinterpret_cast<guint*>(data);
23 const SubprocessCallbackRecord& record = Get().callback_records_[*tag]; 23 const SubprocessCallbackRecord& record = Get().callback_records_[*tag];
24 if (record.callback) 24 if (record.callback)
25 record.callback(status, record.callback_data); 25 record.callback(status, record.callback_data);
26 g_spawn_close_pid(pid); 26 g_spawn_close_pid(pid);
27 Get().callback_records_.erase(*tag); 27 Get().callback_records_.erase(*tag);
28 delete tag; 28 delete tag;
29 } 29 }
30 30
31 namespace { 31 namespace {
32 void FreeArgv(char** argv) { 32 void FreeArgv(char** argv) {
33 for (int i = 0; argv[i]; i++) { 33 for (int i = 0; argv[i]; i++) {
34 free(argv[i]); 34 free(argv[i]);
35 argv[i] = NULL; 35 argv[i] = NULL;
36 } 36 }
37 } 37 }
38 } // namespace {} 38 } // namespace {}
39 39
40 uint32 Subprocess::Exec(const std::vector<std::string>& cmd, 40 uint32_t Subprocess::Exec(const std::vector<std::string>& cmd,
41 ExecCallback callback, 41 ExecCallback callback,
42 void* p) { 42 void* p) {
43 GPid child_pid; 43 GPid child_pid;
44 GError* err; 44 GError* err;
45 scoped_array<char*> argv(new char*[cmd.size() + 1]); 45 scoped_array<char*> argv(new char*[cmd.size() + 1]);
46 for (unsigned int i = 0; i < cmd.size(); i++) { 46 for (unsigned int i = 0; i < cmd.size(); i++) {
47 argv[i] = strdup(cmd[i].c_str()); 47 argv[i] = strdup(cmd[i].c_str());
48 } 48 }
49 argv[cmd.size()] = NULL; 49 argv[cmd.size()] = NULL;
50 50
(...skipping 21 matching lines...) Expand all
72 if (!success) { 72 if (!success) {
73 LOG(ERROR) << "g_spawn_async failed"; 73 LOG(ERROR) << "g_spawn_async failed";
74 return 0; 74 return 0;
75 } 75 }
76 guint* tag = new guint; 76 guint* tag = new guint;
77 *tag = g_child_watch_add(child_pid, GChildExitedCallback, tag); 77 *tag = g_child_watch_add(child_pid, GChildExitedCallback, tag);
78 callback_records_[*tag] = callback_record; 78 callback_records_[*tag] = callback_record;
79 return *tag; 79 return *tag;
80 } 80 }
81 81
82 void Subprocess::CancelExec(uint32 tag) { 82 void Subprocess::CancelExec(uint32_t tag) {
83 if (callback_records_[tag].callback) { 83 if (callback_records_[tag].callback) {
84 callback_records_[tag].callback = NULL; 84 callback_records_[tag].callback = NULL;
85 } 85 }
86 } 86 }
87 87
88 bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd, 88 bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd,
89 int* return_code) { 89 int* return_code) {
90 GError* err = NULL; 90 GError* err = NULL;
91 scoped_array<char*> argv(new char*[cmd.size() + 1]); 91 scoped_array<char*> argv(new char*[cmd.size() + 1]);
92 for (unsigned int i = 0; i < cmd.size(); i++) { 92 for (unsigned int i = 0; i < cmd.size(); i++) {
(...skipping 15 matching lines...) Expand all
108 &err); 108 &err);
109 FreeArgv(argv.get()); 109 FreeArgv(argv.get());
110 if (err) 110 if (err)
111 LOG(INFO) << "err is: " << err->code << ", " << err->message; 111 LOG(INFO) << "err is: " << err->code << ", " << err->message;
112 return success; 112 return success;
113 } 113 }
114 114
115 Subprocess* Subprocess::subprocess_singleton_ = NULL; 115 Subprocess* Subprocess::subprocess_singleton_ = NULL;
116 116
117 } // namespace chromeos_update_engine 117 } // namespace chromeos_update_engine
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698