Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line parsing logic of ps output is wrong #14

Closed
uranusjr opened this issue Oct 11, 2018 · 3 comments
Closed

Command line parsing logic of ps output is wrong #14

uranusjr opened this issue Oct 11, 2018 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@uranusjr
Copy link
Member

From #12. Is there a specification on how ps formats the command line if it contains special characters (spaces in argument, quotes, etc.)? It seems that it is not using the “normal” shell escaping syntax, which makes the it unsuitable to parse with shlex.split().

@uranusjr uranusjr added help wanted Extra attention is needed question Further information is requested labels Oct 11, 2018
@uranusjr
Copy link
Member Author

uranusjr commented Nov 5, 2018

https://github.com/freebsd/freebsd/blob/d843b0f4abd4782caf9abffd5f7628b51d65d541/bin/ps/fmt.c#L83-L93

Heh that’s interesting. If I’m reading it right, ps only escapes newlines and unprintable characters, but separate arguments with spaces. So a command line like this cmd foo 'bar baz' would be reported as cmd foo bar baz, and there’s no way to unambigiously tell what is what.

I guess all we can do is to split with space, and hope for the best. Or maybe we forgo ps altogether and tap into POSIX C API directly. We already do that for Windows anyway.

@uranusjr uranusjr added bug Something isn't working and removed question Further information is requested labels Nov 5, 2018
@uranusjr uranusjr changed the title Investigate command line parsing logic of ps output Command line parsing logic of ps output is wrong Nov 5, 2018
uranusjr added a commit that referenced this issue Nov 5, 2018
@techalchemy
Copy link
Member

While I’m sure it’s technically possible, I’ve never seen a shell named with a space on posix

@uranusjr
Copy link
Member Author

uranusjr commented Nov 6, 2018

It’s likely because it is technically unfeasible. A lot of things won’t work if you do that, e.g. shebang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants