help-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [UX] real names exposed


From: Troy Sankey
Subject: Re: [UX] real names exposed
Date: Sat, 03 Sep 2016 11:30:18 -0400
User-agent: alot/0.3.7

Quoting Ludovic Courtès (2016-09-01 04:59:02)
> ‘exec -a’ works as advertised:
> 
> --8<---------------cut here---------------start------------->8---
> $ sh -c 'exec -a FOO guile -c "(pk (command-line))"'
> 
> ;;; (("FOO"))
> --8<---------------cut here---------------end--------------->8---

So, here /proc/self/cmdline would be: guile\0
and bash changed it to: FOO\0

> Yet:
> 
> --8<---------------cut here---------------start------------->8---
> $ sh -c 'exec -a FOO 
> /gnu/store/6vmniz83k46l8jpry50wdvwxsncz1r5w-khal-0.7.0/bin/.khal-wrap-01  
> --version'
> .khal-real, version 0.7.0
> --8<---------------cut here---------------end--------------->8---

here it's: python3\0.khal-real\0--version\0
bash changed it to: FOO\0.khal-real\0--version\0

> And in fact:
> 
> --8<---------------cut here---------------start------------->8---
> $ cat > t.py
> import sys
> print(sys.argv[0])
> $ sh -c 'exec -a FOO python3 t.py'
> t.py
> --8<---------------cut here---------------end--------------->8---

here it's: python3\0t.py\0
bash changed it to: FOO\0t.py\0

> … even though argv[0] is initially correct:
> 
> --8<---------------cut here---------------start------------->8---
> $ sh -c 'exec -a FOO python3 --help' | head -1
> usage: FOO [option] ... [-c cmd | -m mod | file | -] [arg] ...
> --8<---------------cut here---------------end--------------->8---
> 
> So somewhere, Python finds out the real name, but it doesn’t seem to be
> via /proc/cmdline or anything like that, and I couldn’t find the exact
> hack in the source.
>
> Ideas?

Seems that there is no reason to think python doesn't simply use
/proc/self/cmdline.  Before script interpretation, but after spawning,
the python interpreter appears to modify the arguments list to hide the
first element:

  argv = argv[1:]  # I made this up, but it's probably something like this

> I would really like to fix it in ‘core-updates’.
> 
> Ludo’.

Attachment: signature.asc
Description: signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]