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

Commented out line with trailing backslash affects next (non-commented) line #7188

Open
ThomasLamprecht opened this issue Sep 27, 2022 · 0 comments
Labels
bug Not working as intended

Comments

@ThomasLamprecht
Copy link

  • Sway Version: sway version 1.7

  • Debug Log:

00:00:00.033 [sway/config.c:824] Read line 39: ### Idle configuration
00:00:00.033 [sway/config.c:824] Read line 40: #
00:00:00.033 [sway/config.c:824] Read line 47:          #timeout 345 'notify-send -t 13000 "Locking imminent" "Desktop will be locked in 15s"' exec swayidle -w          timeout 350 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"'          timeout 360 'swaylock -e -f -c 464D4D'          timeout 60 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi'          before-sleep 'swaylock -e -f -c 464D4D'          lock 'swaylock -e -f -c 464D4D'
00:00:00.033 [sway/config.c:824] Read line 48: 
00:00:00.033 [sway/config.c:824] Read line 49: ### Notifications
00:00:00.033 [sway/config.c:824] Read line 50: exec mako
  • Configuration File:

Example snipped that triggered the issue here with a few line extra context:

### Idle configuration
#
         #timeout 345 'notify-send -t 13000 "Locking imminent" "Desktop will be locked in 15s"' \
exec swayidle -w \
         timeout 350 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
         timeout 360 'swaylock -e -f -c 464D4D' \
         timeout 60 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi' \
         before-sleep 'swaylock -e -f -c 464D4D' \
         lock 'swaylock -e -f -c 464D4D'

### Notifications
exec mako
  • Description:

Played around with swayidle exec in sway config and moved an earlier line commented out above as quick save. I often lock my session manually, so I only noticed a few boots later when talking with a colleague for well over 20 minutes, without being near my desk at all, that my PC was still unlocked. As idle locking definitively worked before with a similar config where that commented line still was part of the exec line, I checked if swayidle even ran, put a quick pgrep -a sway came back empty. Starting the exact same swayidle command manually worked, so it wasn't an issue with the used arguments.

Checking sway -dC made me notice that the whole swayidle line was parsed as comment, I guessed that trailing new line escape through \ was a bit overly eager, and triggered also in commented-out lines. To confirm that I simply added a single # character to the end of the commented-out line and checked sway -dC again, and it was indeed working again:

00:00.027 [sway/config.c:824] Read line 41:          #timeout 345 'notify-send -t 13000 "Locking imminent" "Desktop will be locked in 15s"' \#
00:00:00.027 [sway/config.c:824] Read line 47: exec swayidle -w          timeout 350 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"'          timeout 360 'swaylock -e -f -c 464D4D'          timeout 60 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi'          before-sleep 'swaylock -e -f -c 464D4D'          lock 'swaylock -e -f -c 464D4D'

Anyhow, checking the config parser code I saw that a basic comment check is there for continuation checking in the getline_with_cont function:
while (nread >= 2 && strcmp(&(*lineptr)[nread - 2], "\\\n") == 0 && (*lineptr)[0] != '#') {
But it only works if the comment character is the very first one, i.e., no whitespace before.

Now, as comments are also accepted with initial whitespace the question is if that is a by-design limitation to keep the parser simple, or if this should be improved so that it is slightly less surprising.

  • Possible WIP Fix

One (untested and a bit ugly) possibility may be to directly using the strspn function from strings.h to get the index of the first non-whitespace of the line to check for #, iow., something like:

while (nread >= 2 && strcmp(&(*lineptr)[nread - 2], "\\\n") == 0
		&& (*lineptr)[strspn(*lineptr, "\t ")] != '#') {
	// ...
}

What do you think? I could prepare a pull-request if above seems OK in general, or adapt it if you'd favor another approach.
If this is desired behavior I'd like to prepare at least a documentation patch, as I did not find any note w.r.t. comments, continuation or their possible interference with each other in man 5 sway.

@ThomasLamprecht ThomasLamprecht added the bug Not working as intended label Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Development

No branches or pull requests

1 participant