[GHC] #9143: feature request: way to set actual program argv

GHC ghc-devs at haskell.org
Wed Aug 12 13:59:37 UTC 2015


#9143: feature request: way to set actual program argv
-------------------------------------+-------------------------------------
        Reporter:  joeyhess          |                   Owner:
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Runtime System    |                 Version:  7.8.2
      Resolution:                    |                Keywords:
Operating System:  Linux             |            Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by bgamari:

Old description:

> It's not currently possible to write a program with ghc that changes its
> argv, so as to change what the program name/parameters appear to be in
> ps.
>
> An example of a program that does this is sshd, which arranges for the
> process name to say which user it's serving. For example, "sshd: joey
> [priv]"
>
> I'd like to be able to write such programs using haskell too. Also, I
> have a haskell program that, due to the way it is executed, has a really
> horrible display in ps:
>
> /usr/local/propellor/docker/android-git-annex-
> builder.orca.kitenet.net.propellor.shim/lib64/ld-linux-x86-64.so.2
> --library-path /usr/local/propellor/docker/android-git-annex-
> builder.orca.kitenet.net.propellor.shim/lib/x86_64-linux-
> gnu:/usr/local/propellor/docker/android-git-annex-
> builder.orca.kitenet.net.propellor.shim/usr/lib/x86_64-linux-
> gnu:/usr/local/propellor/docker/android-git-annex-
> builder.orca.kitenet.net.propellor.shim/lib64:/usr/local/propellor/docker
> /android-git-annex-
> builder.orca.kitenet.net.propellor.shim/etc/ld.so.conf.d:/usr/local/propellor/docker
> /android-git-annex-builder.orca.kitenet.net.propellor.shim/usr/lib/x86_64
> -linux-gnu/audit:/usr/local/propellor/docker/android-git-annex-
> builder.orca.kitenet.net.propellor.shim/usr/lib/x86_64-linux-gnu/gconv
> /usr/local/propellor/propellor
>
> That's enough motivation for me to dig into this. :)
>
> In rts/RtsMain.c, progargv is set to point to argv. However, it's static,
> so this cannot be (ab)used from the FFI to change argv.
>
> So, a minimal change would be to make progargv not be static, and perhaps
> give it a more formal name or minimal FFI binding. A GHC-specific library
> could then use this to modify argv.
>
> The haskell interface I'm considering would be:
>
> displayArgv :: [String] -> IO ()
>
> It would need to truncate strings to fit within the available argv space.
>
> (This would not affect the argv used by System.Environment, which is a
> copy of argv.)

New description:

 It's not currently possible to write a program with ghc that changes its
 argv, so as to change what the program name/parameters appear to be in ps.

 An example of a program that does this is sshd, which arranges for the
 process name to say which user it's serving. For example, "sshd: joey
 [priv]"

 I'd like to be able to write such programs using haskell too. Also, I have
 a haskell program that, due to the way it is executed, has a really
 horrible display in ps:

 {{{
 /usr/local/propellor/docker/android-git-annex-
 builder.orca.kitenet.net.propellor.shim/lib64/ld-linux-x86-64.so.2
 --library-path /usr/local/propellor/docker/android-git-annex-
 builder.orca.kitenet.net.propellor.shim/lib/x86_64-linux-
 gnu:/usr/local/propellor/docker/android-git-annex-
 builder.orca.kitenet.net.propellor.shim/usr/lib/x86_64-linux-
 gnu:/usr/local/propellor/docker/android-git-annex-
 builder.orca.kitenet.net.propellor.shim/lib64:/usr/local/propellor/docker
 /android-git-annex-
 builder.orca.kitenet.net.propellor.shim/etc/ld.so.conf.d:/usr/local/propellor/docker
 /android-git-annex-builder.orca.kitenet.net.propellor.shim/usr/lib/x86_64
 -linux-gnu/audit:/usr/local/propellor/docker/android-git-annex-
 builder.orca.kitenet.net.propellor.shim/usr/lib/x86_64-linux-gnu/gconv
 /usr/local/propellor/propellor
 }}}

 That's enough motivation for me to dig into this. :)

 In rts/RtsMain.c, progargv is set to point to argv. However, it's static,
 so this cannot be (ab)used from the FFI to change argv.

 So, a minimal change would be to make progargv not be static, and perhaps
 give it a more formal name or minimal FFI binding. A GHC-specific library
 could then use this to modify argv.

 The haskell interface I'm considering would be:
 {{{
 displayArgv :: [String] -> IO ()
 }}}
 It would need to truncate strings to fit within the available argv space.

 (This would not affect the argv used by `System.Environment`, which is a
 copy of argv.)

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9143#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list