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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/master/master_utils.py
diff --git a/scripts/master/master_utils.py b/scripts/master/master_utils.py
index 190bf7966901ed7c25d91ee6f82fbca3c789c69e..3139e8c6275d8c164c30accc24910e67ef61e1fe 100644
--- a/scripts/master/master_utils.py
+++ b/scripts/master/master_utils.py
@@ -2,9 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import ctypes
+import ctypes.util
import os
import random
import re
+import sys
import buildbot
from buildbot import interfaces, util
@@ -474,6 +477,11 @@ def AutoSetupMaster(c, active_master, mail_notifier=False,
if active_master.buildbucket_bucket and active_master.service_account_path:
SetupBuildbucket(c, active_master)
+ # TODO(dsansome): enable this on all masters if it works, remove completely
+ # if it doesn't.
+ if GetMastername() in {'chromium.infra', 'chromium.infra.cron'}:
+ SetMasterProcessName()
+
def SetupBuildbucket(c, active_master):
def params_hook(params, build):
@@ -659,3 +667,34 @@ class PreferredBuilderNextSlaveFunc(object):
s for s in slave_builders
if s.slave.properties.getProperty('preferred_builder') == builder.name]
return random.choice(preferred_slaves or slave_builders)
+
+
+def SetMasterProcessName():
+ """Sets the name of this process to the name of the master. Linux only."""
+
+ if sys.platform != 'linux2':
+ sys.exit(2)
+ return
+
+ SetCommandLine("master: %s" % GetMastername())
+
+
+def SetCommandLine(cmdline):
+ # Get the current commandline.
+ argc = ctypes.c_int()
+ argv = ctypes.POINTER(ctypes.c_char_p)()
+ ctypes.pythonapi.Py_GetArgcArgv(ctypes.byref(argc), ctypes.byref(argv))
+
+ # Calculate its length.
+ cmdlen = sum([len(argv[i]) for i in xrange(0, argc.value)]) + argc.value
+
+ # Pad the cmdline string to the required length. If it's longer than the
+ # currentl commandline, truncate it.
+ if len(cmdline) >= cmdlen:
+ new_cmdline = ctypes.c_char_p(cmdline[:cmdlen-1] + '\0')
+ else:
+ new_cmdline = ctypes.c_char_p(cmdline.ljust(cmdlen, '\0'))
+
+ # Replace the old commandline.
+ libc = ctypes.CDLL(ctypes.util.find_library('c'))
+ libc.memcpy(argv.contents, new_cmdline, cmdlen)
« 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