diff options
| author | 2025-01-25 16:45:06 +0000 | |
|---|---|---|
| committer | 2025-01-25 16:45:06 +0000 | |
| commit | 777b1b931e057bac216ecfe05223893a9b7444a8 (patch) | |
| tree | b6c21fbb486d441234a562dbe71de6b98bd6b2c1 | |
| parent | e896b4aa2fa981287aa8804ef4041e798e308eb7 (diff) | |
`Fix' race on $wobfifo.
Also:
* Normalise copyright dates, remove redundant licence permission
* `Optimise' sed script
Scare quotes abound.
| -rw-r--r-- | README.md | 10 | ||||
| -rwxr-xr-x | swob.sh | 28 |
2 files changed, 21 insertions, 17 deletions
@@ -53,14 +53,14 @@ controls to swob.sh. Example configuration is provided for the following: href="dwl-config.h.patch">dwl-config.h.patch</a></dd> </dl> </li> -<li> Put swob.sh on your PATH, or your wayland compositor's config to point to - its exact location. </li> +<li> Put swob.sh on your PATH, or set your wayland compositor's config to + point to its absolute location. </li> </ul> Copying ------- -Copyright © 2024 The Remph <lhr@disroot.org> +Copyright © 2023-2025 The Remph <lhr@disroot.org> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -73,7 +73,3 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the full GPL can be found at <https://www.gnu.org/licenses/GPL>. - -As an additional permission under GNU GPL version 3 section 7, the section 4 -requirement to distribute a copy of the GPL along with the work is waived, -provided that the above notices are distributed intact instead. @@ -1,10 +1,18 @@ #!/bin/sh -# SPDX-FileCopyrightText: 2023-2024 The Remph <lhr@disroot.org> +# SPDX-FileCopyrightText: 2023-2025 The Remph <lhr@disroot.org> # SPDX-License-Identifier: GPL-3.0-or-later set ${BASH_VERSION:+-o pipefail} -efu -wobfifo=$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY.swob -wobini= SWOB_AUDIO= + +# $wobdir is a `wrapper' directory that prevents a race between `test -p +# $wobfifo` and `>$wobfifo', during which $wobfifo can be removed, causing +# it to be created again as a regular file. If the removal also removes the +# parent directory $wobdir, then sh's > operator can't creat(2). Of course, +# the race could still happen between removing $wobfifo and $wobdir, but +# this is less likely. +wobdir=$XDG_RUNTIME_DIR/swob.$WAYLAND_DISPLAY + +wobfifo=$wobdir/pipe wobini= SWOB_AUDIO= scan_confdirs() { for dir in ${XDG_CONFIG_HOME:+"$XDG_CONFIG_HOME"} ~/.config /etc "${0%/*}"/../etc; do @@ -39,21 +47,21 @@ EOF } start_wob() { - if test -e "$wobfifo"; then + if test -p "$wobfifo"; then return # Already started fi + rm -rf "$wobdir" # clear the decks + # temporary fifo (call mkfifo(1) asap to minimise possibility of races) - # TODO: should this be in C, so we can call mkfifo(2) and check for - # EEXIST, rather than using test(1)? Alternatively, there is flock(1), - # or any other IPC or SHM system + mkdir "$wobdir" mkfifo -m600 "$wobfifo" test -n "$wobini" || new_wobini # spawn wob process with temporary file(s) { - trap 'rm "$wobfifo"' 0 + trap 'rm -r "$wobdir"' 0 # Don't `exec' wob here, else the trap won't work wob -c "$wobini" <$wobfifo } & @@ -138,12 +146,12 @@ d x # Test if audio is muted /\[off\]/ { - g + x s/$/ mute/ b } # else -g +x s/$/ volume/' ;; esac |
