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

Side by Side Diff: base/files/file_util_posix.cc

Issue 2398253004: Reland "Open MessagePumpLibevent's pipe with O_CLOEXEC" (Closed)
Patch Set: More robust NaCl workaround Created 4 years, 2 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
« no previous file with comments | « base/files/file_util.h ('k') | base/message_loop/message_pump_libevent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <libgen.h> 10 #include <libgen.h>
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 344
345 current = traversal.Next(); 345 current = traversal.Next();
346 if (!current.empty()) 346 if (!current.empty())
347 from_stat = traversal.GetInfo().stat(); 347 from_stat = traversal.GetInfo().stat();
348 } 348 }
349 349
350 return success; 350 return success;
351 } 351 }
352 #endif // !defined(OS_NACL_NONSFI) 352 #endif // !defined(OS_NACL_NONSFI)
353 353
354 bool CreateLocalNonBlockingPipe(int fds[2]) {
355 #if defined(OS_LINUX)
356 return pipe2(fds, O_CLOEXEC | O_NONBLOCK) == 0;
357 #else
358 int raw_fds[2];
359 if (pipe(raw_fds) != 0)
360 return false;
361 ScopedFD fd_out(raw_fds[0]);
362 ScopedFD fd_in(raw_fds[1]);
363 if (!SetCloseOnExec(fd_out.get()))
364 return false;
365 if (!SetCloseOnExec(fd_in.get()))
366 return false;
367 if (!SetNonBlocking(fd_out.get()))
368 return false;
369 if (!SetNonBlocking(fd_in.get()))
370 return false;
371 fds[0] = fd_out.release();
372 fds[1] = fd_in.release();
373 return true;
374 #endif
375 }
376
354 bool SetNonBlocking(int fd) { 377 bool SetNonBlocking(int fd) {
355 const int flags = fcntl(fd, F_GETFL); 378 const int flags = fcntl(fd, F_GETFL);
356 if (flags == -1) 379 if (flags == -1)
357 return false; 380 return false;
358 if (flags & O_NONBLOCK) 381 if (flags & O_NONBLOCK)
359 return true; 382 return true;
360 if (HANDLE_EINTR(fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1) 383 if (HANDLE_EINTR(fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1)
361 return false; 384 return false;
362 return true; 385 return true;
363 } 386 }
364 387
388 bool SetCloseOnExec(int fd) {
389 #if defined(OS_NACL_NONSFI)
390 const int flags = 0;
391 #else
392 const int flags = fcntl(fd, F_GETFD);
393 if (flags == -1)
394 return false;
395 if (flags & FD_CLOEXEC)
396 return true;
397 #endif // defined(OS_NACL_NONSFI)
398 if (HANDLE_EINTR(fcntl(fd, F_SETFD, flags | FD_CLOEXEC)) == -1)
399 return false;
400 return true;
401 }
402
365 bool PathExists(const FilePath& path) { 403 bool PathExists(const FilePath& path) {
366 ThreadRestrictions::AssertIOAllowed(); 404 ThreadRestrictions::AssertIOAllowed();
367 #if defined(OS_ANDROID) 405 #if defined(OS_ANDROID)
368 if (path.IsContentUri()) { 406 if (path.IsContentUri()) {
369 return ContentUriExists(path); 407 return ContentUriExists(path);
370 } 408 }
371 #endif 409 #endif
372 return access(path.value().c_str(), F_OK) == 0; 410 return access(path.value().c_str(), F_OK) == 0;
373 } 411 }
374 412
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return false; 985 return false;
948 986
949 DeleteFile(from_path, true); 987 DeleteFile(from_path, true);
950 return true; 988 return true;
951 } 989 }
952 990
953 } // namespace internal 991 } // namespace internal
954 992
955 #endif // !defined(OS_NACL_NONSFI) 993 #endif // !defined(OS_NACL_NONSFI)
956 } // namespace base 994 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util.h ('k') | base/message_loop/message_pump_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698