Skip to content

Conversation

@dcantah
Copy link
Contributor

@dcantah dcantah commented Jul 23, 2021

Relative paths supplying a dot don't make it through our commandline
parsing for job containers, this change fixes that.

In addition to this, this change adds logic to actually honor the working
directory specified for the container.

Signed-off-by: Daniel Canter [email protected]

@dcantah dcantah requested a review from a team as a code owner July 23, 2021 01:48
workDir = c.replaceWithMountPoint(conf.WorkingDirectory)
}

absPath, commandLine, err := getApplicationName(commandLine, workDir, os.Getenv("PATH"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to follow what is happening with the commandLine here. Why is assigned above and then re-assigned here? Are they expected to be difference values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the first thing we do is replace any instances of the env variable if there are any in the commandline.

Then on line 184 we reassign commandLine as it may have changed depending on if it needed to be quoted or not.

For instance, if someone passed foo bar baz, and foo bar.exe exists and baz was simply an argument, we need to quote the commandline to "foo bar" baz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll comment the heck out of this, and re-push. It is a bit hard to follow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is outside the scope of this PR but the getApplicationName isn't clear as to what it does and that caused some confusion when reading. Comments help though it be better long term to refactor this a bit for clarity. Maybe its harder than it looks... just an observation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pretty close interpretation of the c++ logic for windows server containers, so this likely played a role in its complexity :P. I'll keep a note of this.

t.Fatal(err)
}

_, _, err = getApplicationName("./ping", cwd, os.Getenv("PATH"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not test what the path and commandLine variables are here? Is not getting an error enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly just testing that we found the application, so we resolved to C:\windows\system32\ping.exe, I can add an explicit check to make sure this is true however


// Asking for a relative path via "./", so trim the front. We handle relative paths such as "path/to/thing" and "path\\to\\thing", so just
// get rid of the prefix.
if len(commandLine) >= 3 && commandLine[0:2] == "./" || commandLine[0:2] == ".\\" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't filepath.Clean work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More than likely, but then I don't get to add all of this fun logic :). Joking of course, this slipped my mind

@dcantah dcantah force-pushed the jobcontainer-workdir branch 2 times, most recently from 30c307a to 981c7dd Compare July 23, 2021 18:36
Relative paths supplying a dot don't make it through our commandline
parsing for job containers, this change fixes that.

In addition to this, this change adds logic to actually honor the working
directory specified for the container.

Signed-off-by: Daniel Canter <[email protected]>
@dcantah dcantah force-pushed the jobcontainer-workdir branch from 981c7dd to 7a1ce51 Compare July 23, 2021 18:43
@dcantah
Copy link
Contributor Author

dcantah commented Jul 23, 2021

@anmaxvl ptal again

@dcantah
Copy link
Contributor Author

dcantah commented Jul 23, 2021

@jsturtevant Let me know if you have any other feedback

@jsturtevant
Copy link
Contributor

/ltgm

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants