[Twisted-Python] A useful value for argv[0]
Jp Calderone
exarkun at intarweb.us
Thu Feb 13 14:09:39 MST 2003
Patch attached.
Pluses: It works.
Minuses: It causes some startup work to be done twice.
Jp
--
up 5 days, 2:28, 4 users, load average: 0.05, 0.03, 0.05
-------------- next part --------------
Index: internet/app.py
===================================================================
RCS file: /cvs/Twisted/twisted/internet/app.py,v
retrieving revision 1.76
diff -u -r1.76 app.py
--- internet/app.py 5 Feb 2003 00:53:19 -0000 1.76
+++ internet/app.py 13 Feb 2003 13:08:43 -0000
@@ -241,6 +241,8 @@
"""
running = 0
+ processName = None
+
def __init__(self, name, uid=None, gid=None, authorizer=None, authorizer_=None):
"""Initialize me.
@@ -282,7 +284,7 @@
self.uid = uid or os.getuid()
self.gid = gid or os.getgid()
- persistenceVersion = 11
+ persistenceVersion = 12
_authorizer = None
@@ -293,6 +295,9 @@
self._authorizer = DefaultAuthorizer()
self._authorizer.setApplication(self)
return self._authorizer
+
+ def upgradeToVersion12(self):
+ self.processName = None
def upgradeToVersion11(self):
self._extraListeners = {}
Index: scripts/mktap.py
===================================================================
RCS file: /cvs/Twisted/twisted/scripts/mktap.py,v
retrieving revision 1.24
diff -u -r1.24 mktap.py
--- scripts/mktap.py 3 Feb 2003 12:09:07 -0000 1.24
+++ scripts/mktap.py 13 Feb 2003 13:08:43 -0000
@@ -70,7 +70,8 @@
optParameters = [['uid', 'u', '0'],
['gid', 'g', '0'],
['append', 'a', None, "An existing .tap file to append the plugin to, rather than creating a new one."],
- ['type', 't', 'pickle', "The output format to use; this can be 'pickle', 'xml', or 'source'."]]
+ ['type', 't', 'pickle', "The output format to use; this can be 'pickle', 'xml', or 'source'."],
+ ['appname', 'n', None, "The process name to use for this application."]]
optFlags = [['xml', 'x', "DEPRECATED: same as --type=xml"],
['source', 's', "DEPRECATED: same as --type=source"],
@@ -155,6 +156,9 @@
print "Usage Error: %s" % ue
options.subOptions.opt_help()
sys.exit(1)
+
+ if options['appname']:
+ app.processName = options['appname']
# backwards compatible interface
if hasattr(mod, "getPorts"):
Index: scripts/twistd.py
===================================================================
RCS file: /cvs/Twisted/twisted/scripts/twistd.py,v
retrieving revision 1.36
diff -u -r1.36 twistd.py
--- scripts/twistd.py 19 Jan 2003 10:03:33 -0000 1.36
+++ scripts/twistd.py 13 Feb 2003 13:08:43 -0000
@@ -50,6 +50,7 @@
['debug', 'b', "run the application in the Python Debugger (implies nodaemon), sending SIGINT will drop into debugger"],
['quiet','q', "be a little more quiet"],
['no_save','o', "do not save state on shutdown"],
+ ['originalname', None, "Don't try to change the process name"],
['syslog', None, "Log to syslog, not to file"],
['euid', '', "Set only effective user-id rather than real user-id. "
"(This option has no effect unless the server is running as root, "
@@ -318,6 +319,13 @@
log.msg(s)
log.deferr()
sys.exit('\n' + s + '\n')
+
+ if not config['originalname']:
+ if application.processName and application.processName != sys.argv[0]:
+ exe = os.path.realpath(sys.executable)
+ args = (application.processName, sys.argv[0], '--originalname') + tuple(sys.argv[1:])
+ log.msg('Changing process name to ' + application.processName)
+ os.execl(exe, *args)
# If we're asked to chroot and os.chroot does not exist,
# just fail.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20030213/df869e2e/attachment.sig>
More information about the Twisted-Python
mailing list