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

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

Issue 2401863004: Revert of Open MessagePumpLibevent's pipe with O_CLOEXEC (Closed)
Patch Set: 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
377 bool SetNonBlocking(int fd) { 354 bool SetNonBlocking(int fd) {
378 const int flags = fcntl(fd, F_GETFL); 355 const int flags = fcntl(fd, F_GETFL);
379 if (flags == -1) 356 if (flags == -1)
380 return false; 357 return false;
381 if (flags & O_NONBLOCK) 358 if (flags & O_NONBLOCK)
382 return true; 359 return true;
383 if (HANDLE_EINTR(fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1) 360 if (HANDLE_EINTR(fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1)
384 return false; 361 return false;
385 return true; 362 return true;
386 } 363 }
387
388 bool SetCloseOnExec(int fd) {
389 const int flags = fcntl(fd, F_GETFD);
390 if (flags == -1)
391 return false;
392 if (flags & FD_CLOEXEC)
393 return true;
394 if (HANDLE_EINTR(fcntl(fd, F_SETFD, flags | FD_CLOEXEC)) == -1)
395 return false;
396 return true;
397 }
398 364
399 bool PathExists(const FilePath& path) { 365 bool PathExists(const FilePath& path) {
400 ThreadRestrictions::AssertIOAllowed(); 366 ThreadRestrictions::AssertIOAllowed();
401 #if defined(OS_ANDROID) 367 #if defined(OS_ANDROID)
402 if (path.IsContentUri()) { 368 if (path.IsContentUri()) {
403 return ContentUriExists(path); 369 return ContentUriExists(path);
404 } 370 }
405 #endif 371 #endif
406 return access(path.value().c_str(), F_OK) == 0; 372 return access(path.value().c_str(), F_OK) == 0;
407 } 373 }
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 return false; 947 return false;
982 948
983 DeleteFile(from_path, true); 949 DeleteFile(from_path, true);
984 return true; 950 return true;
985 } 951 }
986 952
987 } // namespace internal 953 } // namespace internal
988 954
989 #endif // !defined(OS_NACL_NONSFI) 955 #endif // !defined(OS_NACL_NONSFI)
990 } // namespace base 956 } // 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