python os.execv* bug

Bug #174830 reported by Joe_Bishop
4
Affects Status Importance Assigned to Milestone
python-defaults (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: python

Two python executables, main and prog:

>main:
>#!/usr/bin/env python
>#coding=utf8
>
>import os
>os.execvp('./prog', ['a','b','c','d','e'])

>prog:
>#!/usr/bin/env python
>#coding=utf8
>
>import sys
>print sys.argv

./main gives output:
>['./prog', 'b', 'c', 'd', 'e']

although
>['./prog', 'a', 'b', 'c', 'd', 'e']
is expected

Revision history for this message
Robert Collins (lifeless) wrote :

it looks correct to me. argv[0] of the underlying os call execve is the first argument given to the process that is being run, which is how you can run a symlink to a program and have the binary image be FOO but argv[0] be BAR.

So 'a' is passed in to execv, and then an additional redirection occurs where the #! line is evaluated, and the new image of /usr/bin/env is chosen, - man execve explains this. So the final thing executed is
[/usr/bin/env python b c d e] with a argv[0] of 'a', but then it exec's again to run python.

Changed in python-defaults:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.