OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "ipc/ipc_channel_posix.h" | 5 #include "ipc/ipc_channel_posix.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { | 160 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { |
161 PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_name; | 161 PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_name; |
162 if (HANDLE_EINTR(close(fd)) < 0) | 162 if (HANDLE_EINTR(close(fd)) < 0) |
163 PLOG(ERROR) << "close " << pipe_name; | 163 PLOG(ERROR) << "close " << pipe_name; |
164 return false; | 164 return false; |
165 } | 165 } |
166 | 166 |
167 // Delete any old FS instances. | 167 // Delete any old FS instances. |
168 unlink(pipe_name.c_str()); | 168 unlink(pipe_name.c_str()); |
169 | 169 |
170 // Make sure the path we need exists. | 170 // Make sure the path we need exists. |
dmac
2011/01/19 23:54:37
thanks for catching the comments
| |
171 FilePath path(pipe_name); | 171 FilePath path(pipe_name); |
172 FilePath dir_path = path.DirName(); | 172 FilePath dir_path = path.DirName(); |
173 if (!file_util::CreateDirectory(dir_path)) { | 173 if (!file_util::CreateDirectory(dir_path)) { |
174 return false; | 174 return false; |
175 } | 175 } |
176 | 176 |
177 // Create unix_addr structure | 177 // Create unix_addr structure. |
178 struct sockaddr_un unix_addr; | 178 struct sockaddr_un unix_addr; |
179 memset(&unix_addr, 0, sizeof(unix_addr)); | 179 memset(&unix_addr, 0, sizeof(unix_addr)); |
180 unix_addr.sun_family = AF_UNIX; | 180 unix_addr.sun_family = AF_UNIX; |
181 int path_len = snprintf(unix_addr.sun_path, IPC::kMaxPipeNameLength, | 181 int path_len = snprintf(unix_addr.sun_path, IPC::kMaxPipeNameLength, |
182 "%s", pipe_name.c_str()); | 182 "%s", pipe_name.c_str()); |
183 DCHECK_EQ(static_cast<int>(pipe_name.length()), path_len); | 183 DCHECK_EQ(static_cast<int>(pipe_name.length()), path_len); |
184 size_t unix_addr_len = offsetof(struct sockaddr_un, | 184 size_t unix_addr_len = offsetof(struct sockaddr_un, |
185 sun_path) + path_len + 1; | 185 sun_path) + path_len + 1; |
186 | 186 |
187 // Bind the socket. | 187 // Bind the socket. |
188 if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr), | 188 if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr), |
189 unix_addr_len) != 0) { | 189 unix_addr_len) != 0) { |
190 PLOG(ERROR) << "bind " << pipe_name; | 190 PLOG(ERROR) << "bind " << pipe_name; |
191 if (HANDLE_EINTR(close(fd)) < 0) | 191 if (HANDLE_EINTR(close(fd)) < 0) |
192 PLOG(ERROR) << "close " << pipe_name; | 192 PLOG(ERROR) << "close " << pipe_name; |
193 return false; | 193 return false; |
194 } | 194 } |
195 | 195 |
196 // Adjust the socket permissions. | |
197 fchmod(fd, 0600); | |
dmac
2011/01/19 23:54:37
can you check this for errors? and then PLOG as ap
dtu
2011/01/19 23:59:18
Done.
| |
198 | |
196 // Start listening on the socket. | 199 // Start listening on the socket. |
197 const int listen_queue_length = 1; | 200 const int listen_queue_length = 1; |
198 if (listen(fd, listen_queue_length) != 0) { | 201 if (listen(fd, listen_queue_length) != 0) { |
199 PLOG(ERROR) << "listen " << pipe_name; | 202 PLOG(ERROR) << "listen " << pipe_name; |
200 if (HANDLE_EINTR(close(fd)) < 0) | 203 if (HANDLE_EINTR(close(fd)) < 0) |
201 PLOG(ERROR) << "close " << pipe_name; | 204 PLOG(ERROR) << "close " << pipe_name; |
202 return false; | 205 return false; |
203 } | 206 } |
204 | 207 |
205 *server_listen_fd = fd; | 208 *server_listen_fd = fd; |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 | 1152 |
1150 bool Channel::HasAcceptedConnection() const { | 1153 bool Channel::HasAcceptedConnection() const { |
1151 return channel_impl_->HasAcceptedConnection(); | 1154 return channel_impl_->HasAcceptedConnection(); |
1152 } | 1155 } |
1153 | 1156 |
1154 void Channel::ResetToAcceptingConnectionState() { | 1157 void Channel::ResetToAcceptingConnectionState() { |
1155 channel_impl_->ResetToAcceptingConnectionState(); | 1158 channel_impl_->ResetToAcceptingConnectionState(); |
1156 } | 1159 } |
1157 | 1160 |
1158 } // namespace IPC | 1161 } // namespace IPC |
OLD | NEW |