Skip to content

command line arguments parsing #137

Closed

Description

@crayxt

When I supply file name of video as relative path in command line argument to AppImage file (VLC), it is treated as relative to appimage's internal file structure.
To make it work, one must specify absolute path of file

Also when file name in command line argument contains spaces, AppImage is not able to open it.

Activity

  1. RazZziel commented on Apr 14, 2016

    @RazZziel

    I've got a fix for that in PortableLinuxGames, I'll look for it hopefully this evening

  2. probonopd commented on Apr 14, 2016

    @probonopd
    Member

    Yes @crayxt this is because in order to make some binaries relocateable, we patch /usr to ././ at AppDir creation time which means "the current directory". Hence at runtime we cd to the AppDir's usr/ before running the payload.

    Cool @RazZziel looking forward to it.

  3. RazZziel commented on Apr 15, 2016

    @RazZziel

    Ok, first, I try to avoid using absolute paths instead of cd'ing in my AppRun as much as possible (see for instance this generic AppRun for simple games)
    However, because some apps need the binary to be run from a specific local directory and I need to cd, I have a script that turns all relative arguments in absolute arguments before cd'ing

    . "$APPDIR/util.sh"
    
    # Uncomment this if the app needs relative paths specified on the command line
    eval arguments="$(patch_relative_paths "$@")"
    set -- "${arguments[@]}"
    

    The script is located here and you can see it in action here.

  4. probonopd commented on Apr 15, 2016

    @probonopd
    Member

    Can you do this in C?

  5. RazZziel commented on Apr 21, 2016

    @RazZziel

    Thechnically, it shouldn't be a problem, it would be something like this:

        char *pwd = getenv("PWD");
        int pdw_len = strlen(pwd);
        int i;
        for (i=1; i<argc; ++i)
        {
            if (argv[i] != NULL && argv[i][0] != '/')
            {
                if (access(argv[i], F_OK) != -1)
                {
                    char *new_arg = malloc(pdw_len + strlen(argv[i]) + 2);
                    strcpy(new_arg, pwd);
                    strcat(new_arg, "/");
                    strcat(new_arg, argv[i]);
                    argv[i] = new_arg;
                    printf("+ %s\n", argv[i]);
                }
                else
                {
                    printf("= %s\n", argv[i]);
                }
            }
        }
    

    Which is executed before the line:

    ret = chdir(path);
    

    Output:

    $ ./AppRun bleh blah md5.h ../AppImageKit/ derp
    
    = bleh
    = blah
    + /home/raziel/dev/AppImageKit/md5.h
    + /home/raziel/dev/AppImageKit/../AppImageKit/
    = derp
    

    The problem is:

    • It only works on files that exist, that's the only way I have of knowing when to transform an argument. It would work in vim existing_file_to_edit.txt but not in vim new_file_to_create.txt
    • It's a bit intrussive, as we're rewriting all the relative paths, and some app may not want that
  6. probonopd commented on Apr 21, 2016

    @probonopd
    Member

    Thanks @RazZziel. I'd say, let's go for it' but I'd like to hear the opinion of others too. Maybe add a --appimage-no-path-rewrite option?

  7. shoogle commented on Jun 19, 2016

    @shoogle

    This patch is a neat workaround, but when a binary cannot be relocated it should really be reported as a bug to the upstream developers. If upstream relies on absolute paths for locating resources normally found in /usr/share then a 2-step solution like this one can be used in the upstream code.

  8. probonopd commented on Nov 5, 2016

    @probonopd
    Member

    The new union: true option for .yml files might mitigate the need for this, because when set, then no chdir is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions