[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Determining initial cmd with ctypes rather than ps
commit 175fde6c4a92e1b52f060ef82baf35bf7d722639
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon May 2 21:28:54 2011 -0700
Determining initial cmd with ctypes rather than ps
Using the ctypes argv rather than querying for our command via ps (thanks to
ioerror).
---
src/util/procname.py | 28 +++++++++++-----------------
1 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/src/util/procname.py b/src/util/procname.py
index 14a82b8..97dc707 100644
--- a/src/util/procname.py
+++ b/src/util/procname.py
@@ -9,13 +9,10 @@
# argument replacement (ie, replace argv[0], argv[1], etc but with a string
# the same size).
-import os
import sys
import ctypes
import ctypes.util
-from util import sysTools
-
# flag for setting the process name, found in '/usr/include/linux/prctl.h'
PR_SET_NAME = 15
@@ -65,24 +62,21 @@ def _setArgv(processName):
if currentProcessName == None:
# Getting argv via...
# currentProcessName = " ".join(["python"] + sys.argv)
- #
+ #
# doesn't do the trick since this will miss interpretor arguments like...
# python -W ignore::DeprecationWarning myScript.py
#
- # hence simply getting an outside opinion of our command.
-
- psResults = sysTools.call("ps -p %i -o args" % os.getpid())
+ # Hence we're fetching this via our ctypes argv. Alternatively we could
+ # use ps, though this is less desirable:
+ # "ps -p %i -o args" % os.getpid()
- if len(psResults) == 2:
- # output looks like:
- # COMMAND
- # python ./src/starter.py
-
- currentProcessName = psResults[1]
- maxNameLength = len(currentProcessName)
+ args = []
+ for i in range(100):
+ if argc[i] == None: break
+ args.append(str(argc[i]))
- if not currentProcessName:
- raise IOError("unable to determine our process name")
+ currentProcessName = " ".join(args)
+ maxNameLength = len(currentProcessName)
if len(processName) > maxNameLength:
msg = "can't rename process to something longer than our initial name since this would overwrite memory used for the env"
@@ -93,7 +87,7 @@ def _setArgv(processName):
ctypes.memset(argc.contents, 0, zeroSize + 1) # null terminate the string's end
ctypes.memmove(argc.contents, processName, len(processName))
- currentProcessName = processName[:MAX_CHAR]
+ currentProcessName = processName
def _setPrctlName(processName):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits