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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import ctypes
6 import ctypes.util
7 import sys
8
9
10 _CACHED_CMDLINE_LENGTH = None
11
12
13 def set_command_line(cmdline):
14 """Replaces the commandline of this process as seen by ps."""
15
16 # Get the current commandline.
17 argc = ctypes.c_int()
18 argv = ctypes.POINTER(ctypes.c_char_p)()
19 ctypes.pythonapi.Py_GetArgcArgv(ctypes.byref(argc), ctypes.byref(argv))
20
21 global _CACHED_CMDLINE_LENGTH
22 if _CACHED_CMDLINE_LENGTH is None:
23 # Each argument is terminated by a null-byte, so the length of the whole
24 # thing in memory is the sum of all the argument byte-lengths, plus 1 null
25 # byte for each.
26 _CACHED_CMDLINE_LENGTH = sum(
27 len(argv[i]) for i in xrange(0, argc.value)) + argc.value
28
29 # Pad the cmdline string to the required length. If it's longer than the
30 # current commandline, truncate it.
31 if len(cmdline) >= _CACHED_CMDLINE_LENGTH:
32 new_cmdline = ctypes.c_char_p(cmdline[:_CACHED_CMDLINE_LENGTH-1] + '\0')
33 else:
34 new_cmdline = ctypes.c_char_p(cmdline.ljust(_CACHED_CMDLINE_LENGTH, '\0'))
35
36 # Replace the old commandline.
37 libc = ctypes.CDLL(ctypes.util.find_library('c'))
38 libc.memcpy(argv.contents, new_cmdline, _CACHED_CMDLINE_LENGTH)
OLDNEW
« 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