<div dir="ltr">Of course I understand that Exec can't be directly passed to execve. What I meant is it to do unescaping, unquoting and expanding field codes first and then pass the resulting array to execve.<div>I just want spec to be a bit more clear on reasons behind all this "reserved characters" stuff. It would be less confusing that way. </div><div>Whatever intentions the spec authors had when they added these rules, they should be included in spec too. It's too hard to get it right if implementer does not understand the reasons of why things're done the way they're done. It would be also beneficial to have more examples like "string as written in desktop file" -> "unescaped string" -> "array of unquoted strings" -> "array of unquoted strings with expanded field codes" so implementers be sure that they get all these rules correctly.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 23, 2017 at 3:24 PM, Simon McVittie <span dir="ltr"><<a href="mailto:smcv@collabora.com" target="_blank">smcv@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, 20 Mar 2017 at 05:09:19 +0300, Роман Чистоходов wrote:<br>
> Should it be considered shell command line<br>
<br>
</span>No, the content of Exec= is not a one-line shell script. If you need<br>
to use shell constructs like if...fi, ``, ${} then you must invoke a<br>
shell yourself:<br>
<br>
    Exec=sh -c "if foo; then bar; else baz; fi"<br>
<span class=""><br>
> or something that can be called via execve.<br>
<br>
</span>You can't directly pass the value of the Exec key to execve, because<br>
it's a single string and execve wants an array of strings, but it's close.<br>
<br>
To parse an Exec value, you must unquote it according to the generic<br>
.desktop file syntax, then break it into an array at unquoted whitespace,<br>
then undo shell-style quoting within each entry of that array.<br>
The desktop entry spec does describe this, although from the perspective<br>
of a .desktop file author (there are many of those) rather than from the<br>
perspective of an implementor (there are only a few of those).<br>
GLib's g_shell_parse_argv() is one common C implementation of those<br>
operations; there is another in dbus-daemon.<br>
<br>
(For a general implementation you also need to expand *field codes* like %f,<br>
some of which expand to more than one argument in the output argv. In GLib<br>
this is done in a different layer - see GDesktopAppInfo for an implementation.)<br>
<span class=""><br>
> Giving that desktop-file-validate does not like unquoted backticks I would say<br>
> the latter, but all this stuff about quotation rules makes me think about the<br>
> former.<br>
> This is probably due the legacy code that makes behavior of Exec similar to the<br>
> one if this command line was to be run in shell. <br>
<br>
</span>It is essentially a subset of /bin/sh syntax. I believe the intention<br>
is that every Exec value that is valid according to the Desktop Entry<br>
Specification has the same meaning in /bin/sh and in a spec-compliant<br>
.desktop file parser. However, many Exec values are not considered valid,<br>
and would produce different results from g_shell_parse_argv() and a full<br>
/bin/sh shell; it is probably not considered to be a bug in GLib's<br>
g_shell_parse_argv(), KDE's equivalent, your equivalent, etc. if they<br>
produce different results for an invalid .desktop file.<br>
<br>
    S<br>
______________________________<wbr>_________________<br>
xdg mailing list<br>
<a href="mailto:xdg@lists.freedesktop.org">xdg@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/xdg" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/xdg</a><br>
</blockquote></div><br></div>