Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting values for command line arguments separately #23

Closed
dvarrazzo opened this issue Sep 21, 2012 · 1 comment
Closed

Support setting values for command line arguments separately #23

dvarrazzo opened this issue Sep 21, 2012 · 1 comment
Labels

Comments

@dvarrazzo
Copy link
Owner

Originally submitted by vkoukis as issue 23:

What steps will reproduce the problem?

  1. Do this inside Python:
    import setproctitle; setproctitle.setproctitle('exec arg1 arg2')

What is the expected output? What do you see instead?
Everything looks ok in ps:

vkoukis 32321 32287 3 12:54 pts/3 00:00:00 exec arg1 arg2

But not in /proc/32321/cmdline:
$ cat /proc/32321/cmdline
exec arg1 arg2

The problem is that arguments should be separated from the actual name of the executable by NUL bytes, e.g.:

$ hexdump -vC /proc/32137/cmdline
00000000 2f 75 73 72 2f 73 62 69 6e 2f 61 70 61 63 68 65 |/usr/sbin/apache|
00000010 32 00 2d 6b 00 73 74 61 72 74 00 |2.-k.start.|
0000001b

Otherwise one cannot tell apart the name of the executable from the rest of the arguments.

When trying to use NUL bytes expicitly:

In [7]: setproctitle.setproctitle('exec\x00arg1\x00')

TypeError Traceback (most recent call last)

/home/vkoukis/<ipython console> in <module>()

TypeError: argument 1 must be string without null bytes, not str

What version of the product are you using? On what operating system?

I am using the package that comes with Debian Squeeze:

$ dpkg -l python-setproctitle
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
+++-=====================-=====================-==========================================================
ii python-setproctitle 1.0.1-1 A setproctitle implementation for Python

Please provide any additional information below.

I think it would make sense to support setting the names of command-line arguments explicitly, either by supporting an arbitrary number of arguments, e.g. setproctitle('exec', 'arg1', 'arg2'), or by allowing NUL bytes inside the string.

@dvarrazzo
Copy link
Owner Author

Comment by daniele.varrazzo:

It is not possible to pass nulls to the underlying libraries: the postgres wrapper don't support it and the procfs won't behave correctly after a certain point.

setproctitle is to set some useful info in the process title, not to fake a different executable and arguments set.

rndusr added a commit to rndusr/stig that referenced this issue Jan 22, 2018
/proc/PID/cmdline uses \0 as separator between arguments, which isn't supported
by setproctitle:
dvarrazzo/py-setproctitle#23 (comment)

Using space as separator technically means that everything in /proc/PID/cmdline
is the name of the executable. This is also who it is displayed in tools like
htop.

Leaving the cmdline untouched unless we're in tmux is the best compromise I can
think of.
rndusr added a commit to rndusr/stig that referenced this issue Jan 22, 2018
/proc/PID/cmdline uses \0 as separator between arguments, which isn't supported
by setproctitle:
dvarrazzo/py-setproctitle#23 (comment)

Using space as separator technically means that everything in /proc/PID/cmdline
is the name of the executable. This is also who it is displayed in tools like
htop.

Leaving the cmdline untouched unless we're in tmux is the best compromise I can
think of.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant