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

Side by Side Diff: base/process_util_posix.cc

Issue 9429039: Cleanup: Remove base::environment_vector and base::file_handle_mapping_vector to StudlyCaps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 | « base/process_util.h ('k') | base/process_util_unittest.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 <dirent.h> 5 #include <dirent.h>
6 #include <errno.h> 6 #include <errno.h>
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/resource.h> 10 #include <sys/resource.h>
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // own use and will complain if we try to close them. All of 408 // own use and will complain if we try to close them. All of
409 // these FDs are >= |max_fds|, so we can check against that here 409 // these FDs are >= |max_fds|, so we can check against that here
410 // before closing. See https://bugs.kde.org/show_bug.cgi?id=191758 410 // before closing. See https://bugs.kde.org/show_bug.cgi?id=191758
411 if (fd < static_cast<int>(max_fds)) { 411 if (fd < static_cast<int>(max_fds)) {
412 int ret = HANDLE_EINTR(close(fd)); 412 int ret = HANDLE_EINTR(close(fd));
413 DPCHECK(ret == 0); 413 DPCHECK(ret == 0);
414 } 414 }
415 } 415 }
416 } 416 }
417 417
418 char** AlterEnvironment(const environment_vector& changes, 418 char** AlterEnvironment(const EnvironmentVector& changes,
419 const char* const* const env) { 419 const char* const* const env) {
420 unsigned count = 0; 420 unsigned count = 0;
421 unsigned size = 0; 421 unsigned size = 0;
422 422
423 // First assume that all of the current environment will be included. 423 // First assume that all of the current environment will be included.
424 for (unsigned i = 0; env[i]; i++) { 424 for (unsigned i = 0; env[i]; i++) {
425 const char *const pair = env[i]; 425 const char *const pair = env[i];
426 count++; 426 count++;
427 size += strlen(pair) + 1 /* terminating NUL */; 427 size += strlen(pair) + 1 /* terminating NUL */;
428 } 428 }
429 429
430 for (environment_vector::const_iterator 430 for (EnvironmentVector::const_iterator j = changes.begin();
431 j = changes.begin(); j != changes.end(); j++) { 431 j != changes.end();
432 ++j) {
432 bool found = false; 433 bool found = false;
433 const char *pair; 434 const char *pair;
434 435
435 for (unsigned i = 0; env[i]; i++) { 436 for (unsigned i = 0; env[i]; i++) {
436 pair = env[i]; 437 pair = env[i];
437 const char *const equals = strchr(pair, '='); 438 const char *const equals = strchr(pair, '=');
438 if (!equals) 439 if (!equals)
439 continue; 440 continue;
440 const unsigned keylen = equals - pair; 441 const unsigned keylen = equals - pair;
441 if (keylen == j->first.size() && 442 if (keylen == j->first.size() &&
(...skipping 29 matching lines...) Expand all
471 const char *const equals = strchr(pair, '='); 472 const char *const equals = strchr(pair, '=');
472 if (!equals) { 473 if (!equals) {
473 const unsigned len = strlen(pair); 474 const unsigned len = strlen(pair);
474 ret[k++] = scratch; 475 ret[k++] = scratch;
475 memcpy(scratch, pair, len + 1); 476 memcpy(scratch, pair, len + 1);
476 scratch += len + 1; 477 scratch += len + 1;
477 continue; 478 continue;
478 } 479 }
479 const unsigned keylen = equals - pair; 480 const unsigned keylen = equals - pair;
480 bool handled = false; 481 bool handled = false;
481 for (environment_vector::const_iterator 482 for (EnvironmentVector::const_iterator
482 j = changes.begin(); j != changes.end(); j++) { 483 j = changes.begin(); j != changes.end(); j++) {
483 if (j->first.size() == keylen && 484 if (j->first.size() == keylen &&
484 memcmp(j->first.data(), pair, keylen) == 0) { 485 memcmp(j->first.data(), pair, keylen) == 0) {
485 if (!j->second.empty()) { 486 if (!j->second.empty()) {
486 ret[k++] = scratch; 487 ret[k++] = scratch;
487 memcpy(scratch, pair, keylen + 1); 488 memcpy(scratch, pair, keylen + 1);
488 scratch += keylen + 1; 489 scratch += keylen + 1;
489 memcpy(scratch, j->second.c_str(), j->second.size() + 1); 490 memcpy(scratch, j->second.c_str(), j->second.size() + 1);
490 scratch += j->second.size() + 1; 491 scratch += j->second.size() + 1;
491 } 492 }
492 handled = true; 493 handled = true;
493 break; 494 break;
494 } 495 }
495 } 496 }
496 497
497 if (!handled) { 498 if (!handled) {
498 const unsigned len = strlen(pair); 499 const unsigned len = strlen(pair);
499 ret[k++] = scratch; 500 ret[k++] = scratch;
500 memcpy(scratch, pair, len + 1); 501 memcpy(scratch, pair, len + 1);
501 scratch += len + 1; 502 scratch += len + 1;
502 } 503 }
503 } 504 }
504 505
505 // Now handle new elements 506 // Now handle new elements
506 for (environment_vector::const_iterator 507 for (EnvironmentVector::const_iterator
507 j = changes.begin(); j != changes.end(); j++) { 508 j = changes.begin(); j != changes.end(); j++) {
508 if (j->second.empty()) 509 if (j->second.empty())
509 continue; 510 continue;
510 511
511 bool found = false; 512 bool found = false;
512 for (unsigned i = 0; env[i]; i++) { 513 for (unsigned i = 0; env[i]; i++) {
513 const char *const pair = env[i]; 514 const char *const pair = env[i];
514 const char *const equals = strchr(pair, '='); 515 const char *const equals = strchr(pair, '=');
515 if (!equals) 516 if (!equals)
516 continue; 517 continue;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 ioctl(options.ctrl_terminal_fd, TIOCSCTTY, NULL)) == -1) { 690 ioctl(options.ctrl_terminal_fd, TIOCSCTTY, NULL)) == -1) {
690 RAW_LOG(WARNING, "ioctl(TIOCSCTTY), ctrl terminal not set"); 691 RAW_LOG(WARNING, "ioctl(TIOCSCTTY), ctrl terminal not set");
691 } 692 }
692 } else { 693 } else {
693 RAW_LOG(WARNING, "setsid failed, ctrl terminal not set"); 694 RAW_LOG(WARNING, "setsid failed, ctrl terminal not set");
694 } 695 }
695 } 696 }
696 #endif // defined(OS_CHROMEOS) 697 #endif // defined(OS_CHROMEOS)
697 698
698 if (options.fds_to_remap) { 699 if (options.fds_to_remap) {
699 for (file_handle_mapping_vector::const_iterator 700 for (FileHandleMappingVector::const_iterator
700 it = options.fds_to_remap->begin(); 701 it = options.fds_to_remap->begin();
701 it != options.fds_to_remap->end(); ++it) { 702 it != options.fds_to_remap->end(); ++it) {
702 fd_shuffle1.push_back(InjectionArc(it->first, it->second, false)); 703 fd_shuffle1.push_back(InjectionArc(it->first, it->second, false));
703 fd_shuffle2.push_back(InjectionArc(it->first, it->second, false)); 704 fd_shuffle2.push_back(InjectionArc(it->first, it->second, false));
704 } 705 }
705 } 706 }
706 707
707 #if defined(OS_MACOSX) 708 #if defined(OS_MACOSX)
708 if (options.synchronize) { 709 if (options.synchronize) {
709 // Remap the read side of the synchronization pipe back onto itself, 710 // Remap the read side of the synchronization pipe back onto itself,
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 if (IsChildDead(process)) 1324 if (IsChildDead(process))
1324 return; 1325 return;
1325 1326
1326 BackgroundReaper* reaper = new BackgroundReaper(process, 0); 1327 BackgroundReaper* reaper = new BackgroundReaper(process, 0);
1327 PlatformThread::CreateNonJoinable(0, reaper); 1328 PlatformThread::CreateNonJoinable(0, reaper);
1328 } 1329 }
1329 1330
1330 #endif // !defined(OS_MACOSX) 1331 #endif // !defined(OS_MACOSX)
1331 1332
1332 } // namespace base 1333 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698