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

exec command doesn't strip trailing spaces #521

Closed
TheLQ opened this issue Mar 18, 2016 · 12 comments
Closed

exec command doesn't strip trailing spaces #521

TheLQ opened this issue Mar 18, 2016 · 12 comments

Comments

@TheLQ
Copy link

TheLQ commented Mar 18, 2016

Reproducible for a while, but just tested on freshly built master of WLC and sway

The default firefox.desktop file contains this entry

Exec=firefox %u

When running from dmenu the following command gets sent

i3-msg 'exec "firefox "'

Under i3 this opens firefox. Under sway -v -d this is in the log

Handling command 'exec "firefox "'
find_handler(exec) 0
Executing "firefox "
Child process created with pid 4934
{ "success": true }
IPC Client -1 disconnected
/bin/sh: 1: firefox : not found

Presumably its failing because it's trying to run a binary called firefox instead of firefox. I can't imagine a process where ending or starting spaces not inside quotes are relevant. Even bash strips out spaces

@ddevault
Copy link
Contributor

Related to #519?

@TheLQ
Copy link
Author

TheLQ commented Mar 18, 2016

It's been happening for a long time, I've only now made an issue for it. The top of the log says

Starting sway version 378a45c (2016-03-18, branch "master")

which is that merge commit

@ddevault
Copy link
Contributor

Got it. I'm pretty sure exec just runs the command with sh, but worth double checking.

@mikkeloscar
Copy link
Collaborator

exec will run it as /bin/sh -c '"firefox "'.

I would argue that it's wrong to run i3-msg 'exec "firefox "' if you don't intend to run the command "firefox ". How should exec know it isn't meant as a single argument when passed as a single argument?

Unless this should be a valid way to use exec: exec "/bin/prog -a -b -c", but I think that will just be confusing.

@ddevault
Copy link
Contributor

I'm inclinded to agree with @mikkeloscar on this one.

@ddevault
Copy link
Contributor

Closing as intended behavior.

@TheLQ
Copy link
Author

TheLQ commented Mar 19, 2016

The problem is on Ubuntu 15.10 using the default i3-dmenu-desktop I cannot open firefox, gedit, libreoffice, or any app that takes an optional parameter. The only way I've been able to run most apps is by opening a terminal and running the command from there which is very frustrating

Sway's handling of exec is incompatible with i3 and scripts that run i3-msg 'exec "someCommand $optionalArgs"'. It handles arguments completely differently as the above example with an argument like -v will try to run a binary called someCommand -v as you see below with libreoffice writer.

While I agree the usage of quoting is questionable, the fact that i3's exec command, i3-dmenu-desktop (and maybe other launchers), and peoples configs, scripts, and apps assume that i3-msg 'exec "firefox http://google.com"'' means run a binary called firefox with the argument http://google.com and not a binary called firefox http://google.com should mean that sway does the same to remain compatible.

Here's the logs of trying to run those apps. I tested all of the commands with the same quoting under i3 and they worked fine

Event on IPC listening socket
Handling command 'exec  "libreoffice --writer "'
find_handler(exec) 0
Executing "libreoffice --writer "
Child process created with pid 29722
{ "success": true }
IPC Client -1 disconnected
/bin/sh: 1: libreoffice --writer : not found

Event on IPC listening socket
Handling command 'exec  "gedit "'
find_handler(exec) 0
Executing "gedit "
Child process created with pid 29892
IPC Client -1 disconnected
{ "success": true }
/bin/sh: 1: gedit : not found

Event on IPC listening socket
Handling command 'exec  "steam steam://rungameid/49520"'
find_handler(exec) 0
Executing "steam steam://rungameid/49520"
Child process created with pid 29906
{ "success": true }
IPC Client -1 disconnected
/bin/sh: 1: steam steam://rungameid/49520: not found

Event on IPC listening socket
Handling command 'exec  "shotwell "'
find_handler(exec) 0
Executing "shotwell "
Child process created with pid 29915
{ "success": true }
IPC Client -1 disconnected
/bin/sh: 1: shotwell : not found

@ddevault
Copy link
Contributor

Well, if it's not the behavior of i3, I'll concede. I'd consider that a failing of i3, for what it's worth.

@ddevault ddevault reopened this Mar 19, 2016
@mikkeloscar
Copy link
Collaborator

I see this as an opportunity to correct a poor design choice. It seems to be a single line patch to fix the behavior of i3-dmenu-desktop and I doubt that many people have custom scripts with this weird exec format (but you never know).

I'll make a PR for i3-dmenu-desktop and see what they say about it.

@ddevault
Copy link
Contributor

I'll make a PR for i3-dmenu-desktop and see what they say about it.

If it gets merged, we're golden, but I'm not going to break backwards compatability with i3 over this if necessary.

@mikkeloscar
Copy link
Collaborator

It turns out that the way i3 handles exec arguments is more crazy than I thought so my PR won't work because it breaks some edge cases in i3.
For instance you can't use a shell command with , even if you quote it, because i3 thinks it chaining i3 commands. The whole command must be quoted in that case (i.e. exec "firefox http://example.com/bad,url" instead of exec firefox "http://example.com/bad,url").

@ddevault
Copy link
Contributor

Closed in favor of i3/i3#2329

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

No branches or pull requests

3 participants