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

Side by Side Diff: scripts/master/master_utils.py

Issue 1963583002: Set argv[0] of the buildbot master process to the name of the master. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Only enable on two infra masters Created 4 years, 7 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 | « no previous file | no next file » | 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 import ctypes
6 import ctypes.util
5 import os 7 import os
6 import random 8 import random
7 import re 9 import re
10 import sys
8 11
9 import buildbot 12 import buildbot
10 from buildbot import interfaces, util 13 from buildbot import interfaces, util
11 from buildbot.buildslave import BuildSlave 14 from buildbot.buildslave import BuildSlave
12 from buildbot.interfaces import IRenderable 15 from buildbot.interfaces import IRenderable
13 from buildbot.status import mail 16 from buildbot.status import mail
14 from buildbot.status.builder import BuildStatus 17 from buildbot.status.builder import BuildStatus
15 from buildbot.status.status_push import HttpStatusPush 18 from buildbot.status.status_push import HttpStatusPush
16 from twisted.python import log 19 from twisted.python import log
17 from zope.interface import implements 20 from zope.interface import implements
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if 'port' in values and 'user' in values and 'password' in values: 470 if 'port' in values and 'user' in values and 'password' in values:
468 c['manhole'] = manhole.PasswordManhole(interface, values['user'], 471 c['manhole'] = manhole.PasswordManhole(interface, values['user'],
469 values['password']) 472 values['password'])
470 elif 'port' in values: 473 elif 'port' in values:
471 c['manhole'] = manhole.AuthorizedKeysManhole(interface, 474 c['manhole'] = manhole.AuthorizedKeysManhole(interface,
472 os.path.expanduser("~/.ssh/authorized_keys")) 475 os.path.expanduser("~/.ssh/authorized_keys"))
473 476
474 if active_master.buildbucket_bucket and active_master.service_account_path: 477 if active_master.buildbucket_bucket and active_master.service_account_path:
475 SetupBuildbucket(c, active_master) 478 SetupBuildbucket(c, active_master)
476 479
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
477 485
478 def SetupBuildbucket(c, active_master): 486 def SetupBuildbucket(c, active_master):
479 def params_hook(params, build): 487 def params_hook(params, build):
480 config_hook = c.get('buildbucket_params_hook') 488 config_hook = c.get('buildbucket_params_hook')
481 if callable(config_hook): 489 if callable(config_hook):
482 config_hook(params, build) 490 config_hook(params, build)
483 491
484 properties = params.setdefault('properties', {}) 492 properties = params.setdefault('properties', {})
485 properties.pop('requester', None) # Ignore externally set requester. 493 properties.pop('requester', None) # Ignore externally set requester.
486 if build['created_by']: 494 if build['created_by']:
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 """ 660 """
653 661
654 def __call__(self, builder, slave_builders): 662 def __call__(self, builder, slave_builders):
655 if not slave_builders: 663 if not slave_builders:
656 return None 664 return None
657 665
658 preferred_slaves = [ 666 preferred_slaves = [
659 s for s in slave_builders 667 s for s in slave_builders
660 if s.slave.properties.getProperty('preferred_builder') == builder.name] 668 if s.slave.properties.getProperty('preferred_builder') == builder.name]
661 return random.choice(preferred_slaves or slave_builders) 669 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)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698