Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#43661 - [mkinitcpio] systemd hook: Please use less arcane syntax, fix (possible) syntax error

Attached to Project: Arch Linux
Opened by Alain Kalker (ackalker) - Sunday, 01 February 2015, 17:24 GMT
Last edited by Dave Reisner (falconindy) - Sunday, 01 February 2015, 22:49 GMT
Task Type Bug Report
Category Arch Projects
Status Closed
Assigned To Dave Reisner (falconindy)
Architecture All
Severity Very Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

Visiting /usr/lib/initcpio/install/systemd (or the equivalent file in the package source) in Emacs greatly confuses the syntax highlighting because of lines like:

4: local len=${#1} quotes=$'[\'"]' str=${!1}

Please consider changing this to the more readable and machine-parsable:

4: local len=${#1} quotes=[\'\"] str=${!1}

After this change, Emacs' syntax highlighting no longer treats the rest of the file as an unterminated string.

Similarly, on this line:

28: [[ -z $rule || $rule = @(+([[:space:]])|#*) ]] && continue

Emacs syntax highlighting treats this part as a comment:

#*) ]] && continue

Please consider changing this line to:

28: [[ -z $rule || $rule = "@(+([[:space:]])|#*)" ]] && continue

if only to make syntax highlighters happy.

Finally, on line 33, there appears to be a syntax error (found by Emacs Flycheck):

/bin/bash: line 33: syntax error near unexpected token `('
/bin/bash: line 33: ` RUN@({program}|+)|IMPORT{program}|ENV{REMOVE_CMD})'

I'm guessing that this wasn't caught before is that hooks are sourced, not executed, by mkinitcpio.
I know that there are subtle differences in how sourced and executed scripts are handled, but I don't think it is wise to rely on those for correct operation, in paticular if they limit the use of tools like syntax checkers.

Additional info:
* package version(s)
mkinitcpio 18-2
* config and/or log files etc.


Steps to reproduce:
$ echo $SHELL
/bin/bash
$ bash /usr/lib/initcpio/install/systemd
bash /usr/lib/initcpio/install/systemd
/usr/lib/initcpio/install/systemd: line 33: syntax error near unexpected token `('
/usr/lib/initcpio/install/systemd: line 33: ` RUN@({program}|+)|IMPORT{program}|ENV{REMOVE_CMD})'
$ echo $?
2
$ . /usr/lib/initcpio/install/systemd
$ echo $?
0
(or use Emacs with Flycheck)
This task depends upon

Closed by  Dave Reisner (falconindy)
Sunday, 01 February 2015, 22:49 GMT
Reason for closing:  Not a bug
Additional comments about closing:  Please work with your editor's upstream to improve the syntax highlighting.
Comment by Alain Kalker (ackalker) - Sunday, 01 February 2015, 18:04 GMT
Ah, found that the syntax error occurs because of mismatching 'extglob' shopt setting.
Apparently, `bash -n` doesn't act on `shopt -s extglob` inside scripts, so that doesn't help either.
Comment by Alain Kalker (ackalker) - Sunday, 01 February 2015, 18:16 GMT
Please consider changing the following line:

33: RUN@({program}|+)|IMPORT{program}|ENV{REMOVE_CMD})

to:

33: RUN{program}|RUN+|IMPORT{program}|ENV{REMOVE_CMD})

This resolves the "syntax error" in Flycheck and `bash -n ...`, is slightly better readable for anyone not familiar with extglob extended pattern matching operators, and has zero cost in number of bytes.
Comment by Dave Reisner (falconindy) - Sunday, 01 February 2015, 20:23 GMT
> Please consider changing this line to:
> 28: [[ -z $rule || $rule = "@(+([[:space:]])|#*)" ]] && continue

This isn't even functionally equivalent. Quoting the glob makes it no longer a glob.

> Apparently, `bash -n` doesn't act on `shopt -s extglob` inside scripts, so that doesn't help either.
Sure, bash -n won't execute commands (which includes shopts). Use: bash -n -O extglob ...

Please fix your editor, there's nothing "arcane" about the syntax used here. Rather, it's all well-documented shell constructs.
Comment by Alain Kalker (ackalker) - Sunday, 01 February 2015, 22:38 GMT
> This isn't even functionally equivalent. Quoting the glob makes it no longer a glob.

Sorry about the first one, I didn't realize that it was an extended glob pattern until reading on, see my previous comment.

> Please fix your editor, there's nothing "arcane" about the syntax used here.

Vim indeed has no trouble with it.

Loading...