Menu ▾ ▴

#2 PARSE SOURCE not working under ANY Unix; WORKAROUND INSIDE

open-works-for-me
nobody
None
5
2008-03-03
2008-02-15
cniggeler
No

Hi,

I've built RexxWrapper 3.4 for use under SGI Irix 6.5 and have Regina 3.3. I'm linking statically (libregina.a). After wrapping this simple test program,
parse source mypath
say mypath

I get
UNIX COMMAND testparse

If I run the same test program through the Rexx interpreter (rexx testparse.rexx), I get
UNIX COMMAND /usr/people/chris/build/testparse.rexx

which is the correct output. I do not experience this problem under Linux, which is configured exactly the same (i.e., RW 2.4, Regina 3.3, static link). Does anyone know what is going on here?

Thanks,
Chris

Discussion

  • Mark Hessling

    Mark Hessling - 2008-02-15

    Logged In: YES
    user_id=86185
    Originator: NO

    Hi Chris,

    When the executable built by Rexx/Wrapper runs it attempts to find a fully qualified name for the current executable. Under Linux this is achieved by calling readlink( /proc/self/exe ) which will return the fully qualified (ie full path) of the executable that is currently running. Even on Linux it will only return /usr/people/chris/build/testparse (no .rexx).
    See getargv0.c in the Rexx/Wrapper distro.

    The readlink() doesn't work on Irix. It will return whatever is available to the executable based on how it was executed. Examples:
    ./testparse should result in "say mypath" returning "./testparse"
    /usr/people/chris/build/testparse should result in "say mypath" returning "/usr/people/chris/build/testparse"

    Cheers, Mark

     
  • cniggeler

    cniggeler - 2008-02-15

    Logged In: YES
    user_id=1774519
    Originator: YES

    Hi Mark,

    Thanks for the prompt reply. At least in Irix 6.5, the situation is much worse than that. For the RexxWrapped program mentioned before, the results are almost always only the name without path or extension! So the commands
    ./testparse
    cd ..
    build/testparse

    ALWAYS return
    UNIX COMMAND testparse

    The one exception is if the fully qualified pathname is given:
    /home/chris/build/testparse
    returns
    UNIX COMMAND /home/chris/build/testparse

    I have a rather extensive workaround, and I'll put that in the next comment.

     
  • cniggeler

    cniggeler - 2008-02-15

    Logged In: YES
    user_id=1774519
    Originator: YES

    WORKAROUND -
    Assuming the program is named "testparse":

    if uname('s') = "IRIX" then do
    ls. = "<NIL>"
    whoami = ''
    prod="testparse"
    address system 'ps -ef | grep "'||prod'||" | grep -v grep' with output stem ls.
    do i=1 while ls.i <> "<NIL>"
    do j=1 to words(ls.i)
    if right(word(ls.i, j), length(prod)) = prod then do
    whoami = word(ls.i, j)
    signal gotit
    end
    end
    end
    end
    else parse source . . whoami

    gotit:
    ...

     
  • cniggeler

    cniggeler - 2008-02-15
    • status: open --> open-works-for-me
     
  • cniggeler

    cniggeler - 2008-03-03

    Logged In: YES
    user_id=1774519
    Originator: YES

    The same stated (mis)behavior occurs in all the *nixes I've ported to: Irix 6.5, Solaris 8, HP-UX 11.1, and AIX 5.2. Only Linux and Windows(!) seem to behave like they're supposed to.

    FULL WORKAROUND
    Caveat - this workaround assumes you're inspecting "whoami" and the results of "ps" in an application started from the command line - it is not a daemon. I don't know what happens if you start it from a GUI.

    mysys=translate(left(uname('S'), 3))
    if mysys="WIN" then slash='\'
    else slash='/'

    if mysys<>"WIN" & mysys<>"LIN" then do
    found=0 /* Flag to get us out of the loops */
    ls. ="<NIL>"
    prod ="testparse" /* <- Insert your program name */

    address system 'ps -ef | grep "'prod'" | grep -v grep' with output stem ls.
    do i=1 while ls.i <> "<NIL>" & \found
    do j=1 to words(ls.i) while \found
    if right(word(ls.i, j), length(prod)) = prod then do
    whoami = word(ls.i, j)
    if left(whoami, 1) <> slash then do
    address system 'pwd' with output stem ls.
    if ls.1 <> slash then whoami=ls.1||slash||whoami
    else whoami=ls.1||whoami
    end
    found=1
    end
    end
    end
    end

    else parse source . . whoami
    mydir = left(whoami, lastpos(slash, whoami)-1)

     
  • cniggeler

    cniggeler - 2008-03-03
    • summary: PARSE SOURCE not working under Irix --> PARSE SOURCE not working under ANY Unix
     
  • cniggeler

    cniggeler - 2008-03-03
    • summary: PARSE SOURCE not working under ANY Unix --> PARSE SOURCE not working under ANY Unix; WORKAROUND INSIDE