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

Side by Side Diff: chromeos/process.h

Issue 6865041: libchromeos: Support setting uid/gid of child processes in process.h (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/common.git@master
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chromeos/process.cc » ('j') | chromeos/process.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium OS 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 #ifndef CHROMEOS_PROCESS_H_ 5 #ifndef CHROMEOS_PROCESS_H_
6 #define CHROMEOS_PROCESS_H_ 6 #define CHROMEOS_PROCESS_H_
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 // Redirects stderr and stdout to |output_file|. 46 // Redirects stderr and stdout to |output_file|.
47 virtual void RedirectOutput(const std::string& output_file) = 0; 47 virtual void RedirectOutput(const std::string& output_file) = 0;
48 48
49 // Indicates we want to redirect |child_fd| in the child process's 49 // Indicates we want to redirect |child_fd| in the child process's
50 // file table to a pipe. |child_fd| will be available for reading 50 // file table to a pipe. |child_fd| will be available for reading
51 // from child process's perspective iff |is_input|. 51 // from child process's perspective iff |is_input|.
52 virtual void RedirectUsingPipe(int child_fd, bool is_input) = 0; 52 virtual void RedirectUsingPipe(int child_fd, bool is_input) = 0;
53 53
54 // Set the real/effective/saved user ID of the child process.
55 virtual void SetUid(uid_t uid) = 0;
56
57 // Set the real/effective/saved group ID of the child process.
58 virtual void SetGid(gid_t gid) = 0;
59
54 // Gets the pipe file descriptor mapped to the process's |child_fd|. 60 // Gets the pipe file descriptor mapped to the process's |child_fd|.
55 virtual int GetPipe(int child_fd) = 0; 61 virtual int GetPipe(int child_fd) = 0;
56 62
57 // Starts this process, returning true if successful. 63 // Starts this process, returning true if successful.
58 virtual bool Start() = 0; 64 virtual bool Start() = 0;
59 65
60 // Waits for this process to finish. Returns the process's exit 66 // Waits for this process to finish. Returns the process's exit
61 // status if it exited normally, or otherwise returns -1. 67 // status if it exited normally, or otherwise returns -1.
62 virtual int Wait() = 0; 68 virtual int Wait() = 0;
63 69
(...skipping 29 matching lines...) Expand all
93 }; 99 };
94 100
95 class ProcessImpl : public Process { 101 class ProcessImpl : public Process {
96 public: 102 public:
97 ProcessImpl(); 103 ProcessImpl();
98 virtual ~ProcessImpl(); 104 virtual ~ProcessImpl();
99 105
100 virtual void AddArg(const std::string& arg); 106 virtual void AddArg(const std::string& arg);
101 virtual void RedirectOutput(const std::string& output_file); 107 virtual void RedirectOutput(const std::string& output_file);
102 virtual void RedirectUsingPipe(int child_fd, bool is_input); 108 virtual void RedirectUsingPipe(int child_fd, bool is_input);
109 virtual void SetUid(uid_t uid);
110 virtual void SetGid(gid_t gid);
103 virtual int GetPipe(int child_fd); 111 virtual int GetPipe(int child_fd);
104 virtual bool Start(); 112 virtual bool Start();
105 virtual int Wait(); 113 virtual int Wait();
106 virtual int Run(); 114 virtual int Run();
107 virtual pid_t pid(); 115 virtual pid_t pid();
108 virtual bool Kill(int signal, int timeout); 116 virtual bool Kill(int signal, int timeout);
109 virtual void Reset(pid_t pid); 117 virtual void Reset(pid_t pid);
110 virtual bool ResetPidByFile(const std::string& pid_file); 118 virtual bool ResetPidByFile(const std::string& pid_file);
111 virtual pid_t Release(); 119 virtual pid_t Release();
112 120
113 protected: 121 protected:
114 struct PipeInfo { 122 struct PipeInfo {
115 PipeInfo() : parent_fd_(-1), child_fd_(-1), is_input_(false) {} 123 PipeInfo() : parent_fd_(-1), child_fd_(-1), is_input_(false) {}
116 // Parent (our) side of the pipe to the the child process. 124 // Parent (our) side of the pipe to the the child process.
117 int parent_fd_; 125 int parent_fd_;
118 // Child's side of the pipe to the parent. 126 // Child's side of the pipe to the parent.
119 int child_fd_; 127 int child_fd_;
120 // Is this an input or output pipe from child's perspective. 128 // Is this an input or output pipe from child's perspective.
121 bool is_input_; 129 bool is_input_;
122 }; 130 };
123 typedef std::map<int, PipeInfo> PipeMap; 131 typedef std::map<int, PipeInfo> PipeMap;
124 132
125 std::string output_file_;
126 std::vector<std::string> arguments_;
127 // Map of child target file descriptors (first) to information about
128 // pipes created (second).
129 PipeMap pipe_map_;
130
131 void UpdatePid(pid_t new_pid); 133 void UpdatePid(pid_t new_pid);
132 bool PopulatePipeMap(); 134 bool PopulatePipeMap();
133 135
134 private: 136 private:
135 // Pid of currently managed process or 0 if no currently managed 137 // Pid of currently managed process or 0 if no currently managed
136 // process. pid must not be modified except by calling 138 // process. pid must not be modified except by calling
137 // UpdatePid(new_pid). 139 // UpdatePid(new_pid).
138 pid_t pid_; 140 pid_t pid_;
141 std::string output_file_;
142 std::vector<std::string> arguments_;
143 // Map of child target file descriptors (first) to information about
144 // pipes created (second).
145 PipeMap pipe_map_;
146 uid_t uid_;
147 gid_t gid_;
139 }; 148 };
140 149
141 } // namespace chromeos 150 } // namespace chromeos
142 151
143 #endif // CHROMEOS_PROCESS_H 152 #endif // CHROMEOS_PROCESS_H
OLDNEW
« no previous file with comments | « no previous file | chromeos/process.cc » ('j') | chromeos/process.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698