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

Unified Diff: client/third_party/infra_libs/_command_line_linux.py

Issue 2465423002: Roll infra_libs to 564aaf7480f24c90687df79d9cef910cc342a54d (Closed)
Patch Set: update readmes Created 4 years, 1 month 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 | « client/third_party/infra_libs/README.swarming ('k') | client/third_party/infra_libs/_command_line_stub.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/third_party/infra_libs/_command_line_linux.py
diff --git a/client/third_party/infra_libs/_command_line_linux.py b/client/third_party/infra_libs/_command_line_linux.py
new file mode 100644
index 0000000000000000000000000000000000000000..7e0cc4d5fe8024ace331e12173e7ff96d3482894
--- /dev/null
+++ b/client/third_party/infra_libs/_command_line_linux.py
@@ -0,0 +1,38 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# 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 sys
+
+
+_CACHED_CMDLINE_LENGTH = None
+
+
+def set_command_line(cmdline):
+ """Replaces the commandline of this process as seen by ps."""
+
+ # 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))
+
+ global _CACHED_CMDLINE_LENGTH
+ if _CACHED_CMDLINE_LENGTH is None:
+ # Each argument is terminated by a null-byte, so the length of the whole
+ # thing in memory is the sum of all the argument byte-lengths, plus 1 null
+ # byte for each.
+ _CACHED_CMDLINE_LENGTH = 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
+ # current commandline, truncate it.
+ if len(cmdline) >= _CACHED_CMDLINE_LENGTH:
+ new_cmdline = ctypes.c_char_p(cmdline[:_CACHED_CMDLINE_LENGTH-1] + '\0')
+ else:
+ new_cmdline = ctypes.c_char_p(cmdline.ljust(_CACHED_CMDLINE_LENGTH, '\0'))
+
+ # Replace the old commandline.
+ libc = ctypes.CDLL(ctypes.util.find_library('c'))
+ libc.memcpy(argv.contents, new_cmdline, _CACHED_CMDLINE_LENGTH)
« no previous file with comments | « client/third_party/infra_libs/README.swarming ('k') | client/third_party/infra_libs/_command_line_stub.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698