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

xserver: check case of multiple keyboard layouts #26984

Closed
wants to merge 1 commit into from

Conversation

lheckemann
Copy link
Member

Motivation for this change

#26961

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Sorry, something went wrong.

@mention-bot
Copy link

@lheckemann, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @aszlig and @nbp to be potential reviewers.

@lheckemann
Copy link
Member Author

cc @aszlig

missing=()
for layout in "''${layouts[@]}" ; do
if ! sed -n -e ':i /^! \(layout\|variant\) *$/ {
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl
Copy link
Contributor

Choose a reason for hiding this comment

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

Holy Batman for your sed invocation. I doubt many people would be able to read that without consulting a manual.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not mine, @aszlig's. It seems to work so I just left it as is.

Copy link
Member

Choose a reason for hiding this comment

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

@0xABAB: Although I think the expression is quite simple (if you know sed), I'm going to add a comment with a description anyway.

for layout in "''${layouts[@]}" ; do
if ! sed -n -e ':i /^! \(layout\|variant\) *$/ {
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl
}' "$xkbDir/rules/base.lst" | grep -qxF "$layout"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be safer to add -- to stop processing options.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would result in it searching the file named by "$layout". But in a similar vein, I should add -e.

cat >&2 <<-EOF

The selected keyboard layout definition does not exist:
The selected keyboard layout definitions do not exist:
Copy link
Contributor

Choose a reason for hiding this comment

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

Good that you are trying to help the user, but you could also just output all the valid values (a constructive reply from the machine) with the file name, instead of letting the machine say that the user messed up without any help.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are too many valid values for printing all of them to be useful.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I think we can do that if we pipe them into column.


EOF
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened to this exit 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't necessary, the build will fail because it didn't produce $out. I suppose it's better to have it explicit rather than implicit though, so I'll put it back.

Copy link
Contributor

@0xABAB 0xABAB left a comment

Choose a reason for hiding this comment

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

I feel many of my concerns need to be addressed.

}' "$xkbDir/rules/base.lst" | grep -qxF "$layout"
then
touch "$out"
IFS=, read -a layouts <<<'${cfg.layout}'
Copy link
Member

Choose a reason for hiding this comment

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

This is not well escaped, because if the layout option contains a single quote you can inject arbitrary shell commands, like let's say layout = "' || exit 0. In this case it's better to use $layout here, because we already have that in the builder environment.

missing=()
for layout in "''${layouts[@]}" ; do
if ! sed -n -e ':i /^! \(layout\|variant\) *$/ {
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl
Copy link
Member

Choose a reason for hiding this comment

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

@0xABAB: Although I think the expression is quite simple (if you know sed), I'm going to add a comment with a description anyway.

cat >&2 <<-EOF

The selected keyboard layout definition does not exist:
The selected keyboard layout definitions do not exist:
Copy link
Member

Choose a reason for hiding this comment

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

Hm, I think we can do that if we pipe them into column.

layout (check $xkbDir/rules/base.lst for options).
Set \`services.xserver.layout' to include only names of
existing keyboard layouts (check $xkbDir/rules/base.lst
for options).
Copy link
Member

Choose a reason for hiding this comment

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

We probably should just use echo here, so the lines wrap around the actual line width of the users terminal, because $xkbDir clearly stands out in length here and might be confusing if you just glimpse over it.

@aszlig
Copy link
Member

aszlig commented Jul 3, 2017

I'm going to commit a different fix of #26961 which is similar to your PR, but with the comments addressed. Basically I was the one who broke it, so I'll fix it :-D

@lheckemann
Copy link
Member Author

Alright.

@lheckemann lheckemann closed this Jul 3, 2017
aszlig added a commit that referenced this pull request Jul 3, 2017
This was brought up by @0xABAB in #26984 by the following comment:

#26984 (comment)

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
aszlig added a commit that referenced this pull request Jul 3, 2017
Regression introduced by 44c64fe.

The services.xserver.layout option allows to specify more than one
layout separated by comma, which the commit above didn't take into
account.

This is very similar to @lheckemann's pull request (#26984) but differs
in the following ways:

  * Print out the full list available layouts (as suggested by @0xABAB
    in [1]).
  * Loop over $layout using the default IFS (and thus no need for
    escaping ${cfg.layout}), because the layouts won't contain white
    spaces.
  * Re-do the error message, which now uses multiple echos instead of a
    heredoc, so the line is wrapped according to the viewers terminal
    width.

I've tested this with several good and bad layouts and also against the
keymap NixOS VM subtests.

[1]: #26984 (comment)

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Fixes: #26961
Closes: #26984
jerith666 pushed a commit to jerith666/nixpkgs that referenced this pull request Jul 10, 2017
This was brought up by @0xABAB in NixOS#26984 by the following comment:

NixOS#26984 (comment)

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
(cherry picked from commit d97cdfc)
jerith666 pushed a commit to jerith666/nixpkgs that referenced this pull request Jul 10, 2017
Regression introduced by 44c64fe.

The services.xserver.layout option allows to specify more than one
layout separated by comma, which the commit above didn't take into
account.

This is very similar to @lheckemann's pull request (NixOS#26984) but differs
in the following ways:

  * Print out the full list available layouts (as suggested by @0xABAB
    in [1]).
  * Loop over $layout using the default IFS (and thus no need for
    escaping ${cfg.layout}), because the layouts won't contain white
    spaces.
  * Re-do the error message, which now uses multiple echos instead of a
    heredoc, so the line is wrapped according to the viewers terminal
    width.

I've tested this with several good and bad layouts and also against the
keymap NixOS VM subtests.

[1]: NixOS#26984 (comment)

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Fixes: NixOS#26961
Closes: NixOS#26984
(cherry picked from commit 69da180)
@lheckemann lheckemann deleted the xkb-multiple branch January 18, 2019 18:29
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.

None yet

4 participants