| OLD | NEW |
| 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 import ctypes | |
| 6 import ctypes.util | |
| 7 import os | 5 import os |
| 8 import random | 6 import random |
| 9 import re | 7 import re |
| 10 import sys | |
| 11 | 8 |
| 12 import buildbot | 9 import buildbot |
| 13 from buildbot import interfaces, util | 10 from buildbot import interfaces, util |
| 14 from buildbot.buildslave import BuildSlave | 11 from buildbot.buildslave import BuildSlave |
| 15 from buildbot.interfaces import IRenderable | 12 from buildbot.interfaces import IRenderable |
| 16 from buildbot.status import mail | 13 from buildbot.status import mail |
| 17 from buildbot.status.builder import BuildStatus | 14 from buildbot.status.builder import BuildStatus |
| 18 from buildbot.status.status_push import HttpStatusPush | 15 from buildbot.status.status_push import HttpStatusPush |
| 19 from twisted.python import log | 16 from twisted.python import log |
| 20 from zope.interface import implements | 17 from zope.interface import implements |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 if 'port' in values and 'user' in values and 'password' in values: | 467 if 'port' in values and 'user' in values and 'password' in values: |
| 471 c['manhole'] = manhole.PasswordManhole(interface, values['user'], | 468 c['manhole'] = manhole.PasswordManhole(interface, values['user'], |
| 472 values['password']) | 469 values['password']) |
| 473 elif 'port' in values: | 470 elif 'port' in values: |
| 474 c['manhole'] = manhole.AuthorizedKeysManhole(interface, | 471 c['manhole'] = manhole.AuthorizedKeysManhole(interface, |
| 475 os.path.expanduser("~/.ssh/authorized_keys")) | 472 os.path.expanduser("~/.ssh/authorized_keys")) |
| 476 | 473 |
| 477 if active_master.buildbucket_bucket and active_master.service_account_path: | 474 if active_master.buildbucket_bucket and active_master.service_account_path: |
| 478 SetupBuildbucket(c, active_master) | 475 SetupBuildbucket(c, active_master) |
| 479 | 476 |
| 480 # TODO(dsansome): enable this on all masters if it works, remove completely | |
| 481 # if it doesn't. | |
| 482 if GetMastername() in {'chromium.infra', 'chromium.infra.cron'}: | |
| 483 SetMasterProcessName() | |
| 484 | |
| 485 | 477 |
| 486 def SetupBuildbucket(c, active_master): | 478 def SetupBuildbucket(c, active_master): |
| 487 def params_hook(params, build): | 479 def params_hook(params, build): |
| 488 config_hook = c.get('buildbucket_params_hook') | 480 config_hook = c.get('buildbucket_params_hook') |
| 489 if callable(config_hook): | 481 if callable(config_hook): |
| 490 config_hook(params, build) | 482 config_hook(params, build) |
| 491 | 483 |
| 492 properties = params.setdefault('properties', {}) | 484 properties = params.setdefault('properties', {}) |
| 493 properties.pop('requester', None) # Ignore externally set requester. | 485 properties.pop('requester', None) # Ignore externally set requester. |
| 494 if build['created_by']: | 486 if build['created_by']: |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 """ | 652 """ |
| 661 | 653 |
| 662 def __call__(self, builder, slave_builders): | 654 def __call__(self, builder, slave_builders): |
| 663 if not slave_builders: | 655 if not slave_builders: |
| 664 return None | 656 return None |
| 665 | 657 |
| 666 preferred_slaves = [ | 658 preferred_slaves = [ |
| 667 s for s in slave_builders | 659 s for s in slave_builders |
| 668 if s.slave.properties.getProperty('preferred_builder') == builder.name] | 660 if s.slave.properties.getProperty('preferred_builder') == builder.name] |
| 669 return random.choice(preferred_slaves or slave_builders) | 661 return random.choice(preferred_slaves or slave_builders) |
| 670 | |
| 671 | |
| 672 def SetMasterProcessName(): | |
| 673 """Sets the name of this process to the name of the master. Linux only.""" | |
| 674 | |
| 675 if sys.platform != 'linux2': | |
| 676 sys.exit(2) | |
| 677 return | |
| 678 | |
| 679 SetCommandLine("master: %s" % GetMastername()) | |
| 680 | |
| 681 | |
| 682 def SetCommandLine(cmdline): | |
| 683 # Get the current commandline. | |
| 684 argc = ctypes.c_int() | |
| 685 argv = ctypes.POINTER(ctypes.c_char_p)() | |
| 686 ctypes.pythonapi.Py_GetArgcArgv(ctypes.byref(argc), ctypes.byref(argv)) | |
| 687 | |
| 688 # Calculate its length. | |
| 689 cmdlen = sum([len(argv[i]) for i in xrange(0, argc.value)]) + argc.value | |
| 690 | |
| 691 # Pad the cmdline string to the required length. If it's longer than the | |
| 692 # currentl commandline, truncate it. | |
| 693 if len(cmdline) >= cmdlen: | |
| 694 new_cmdline = ctypes.c_char_p(cmdline[:cmdlen-1] + '\0') | |
| 695 else: | |
| 696 new_cmdline = ctypes.c_char_p(cmdline.ljust(cmdlen, '\0')) | |
| 697 | |
| 698 # Replace the old commandline. | |
| 699 libc = ctypes.CDLL(ctypes.util.find_library('c')) | |
| 700 libc.memcpy(argv.contents, new_cmdline, cmdlen) | |
| OLD | NEW |