fix: idempotent unit files in mount_virtiofs, safe glob in retention.sh#19
Draft
troglodyne wants to merge 1 commit into
Draft
fix: idempotent unit files in mount_virtiofs, safe glob in retention.sh#19troglodyne wants to merge 1 commit into
troglodyne wants to merge 1 commit into
Conversation
mount_virtiofs used echo-append for systemd unit files — on every re-run the .mount and .automount files would accumulate duplicate sections, producing invalid units. Switch to cat-heredoc (overwrite) so the file is always written cleanly. Also validate ACTUAL_TARGET is non-empty before writing anything, and quote variables throughout. retention.sh iterated unquoted $dir/* which produces the literal glob string when the directory is empty, causing a bogus `date` call and a harmless but noisy error. Also: an unparseable basename would leave CUR_TIME empty, making the subsequent [ -lt ] comparison fail with "integer expression expected". Fixed with nullglob + a guard on the date parse. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
troglodyne
commented
Apr 26, 2026
|
|
||
| # Actually mount it | ||
| MNTFILE="/usr/lib/systemd/system/$LINK_NAME_REPLACED.mount" | ||
| LINK_NAME_REPLACED=$(echo "$LINK_NAME" | sed -e "s|^/||" -e "s|/|-|g") |
Contributor
Author
There was a problem hiding this comment.
interesting paranoia here, just not sure it'll actually ever happen
troglodyne
commented
Apr 26, 2026
| echo "Type=virtiofs" >> $MNTFILE | ||
| echo "[Install]" >> $MNTFILE | ||
| echo "WantedBy=multi-user.target" >> $MNTFILE | ||
| MNTFILE="/usr/lib/systemd/system/${LINK_NAME_REPLACED}.mount" |
Contributor
Author
There was a problem hiding this comment.
pretty sure this represents a behavior change, the .mount file used to automount
troglodyne
commented
Apr 26, 2026
| echo "TimeoutIdleSec=10" >> $AUTOMNTFILE | ||
| echo "[Install]" >> $AUTOMNTFILE | ||
| echo "WantedBy=multi-user.target" >> $AUTOMNTFILE | ||
| cat > "$MNTFILE" << EOF |
Contributor
Author
There was a problem hiding this comment.
heredoc usage is nice tho
troglodyne
commented
Apr 26, 2026
Contributor
Author
There was a problem hiding this comment.
This one more or less looks ok though it's mostly paranoia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two script fixes: idempotent systemd unit file creation in
mount_virtiofsand safe directory iteration inretention.sh.Why
mount_virtiofs: Usedecho >> $MNTFILEfor every line of the.mountand.automountunit files. On any re-provisioning run the files accumulate duplicate[Unit],[Mount],[Automount]sections — systemd rejects malformed units. Also: ifACTUAL_TARGETis empty (device not found indevices.map), the script silently wrote a brokenWhat=entry; and the singlesed -e "s|/|-|"only replaced the first/, leaving mount unit names malformed for paths with multiple components.retention.sh: Two bugs in the inner loop — unquoted$dir/*expands to the literal glob string when the directory is empty, and an unparseablebasename(a non-date-named directory) leavesCUR_TIMEempty, making[ $CUR_TIME -lt $CUTOFF ]fail with "integer expression expected".How
mount_virtiofs: Replaceecho >>chains withcat >heredocs (always write clean file); validateACTUAL_TARGETis non-empty before touching anything; fix sed tos|/|-|g(global replace); quote all variables.retention.sh: Addshopt -s nullglobso an empty directory produces zero iterations; quote$dirand$subdirthroughout; suppressdatestderr and skip entries whose basename doesn't parse as a date.Testing
bash -npasses on both scripts. Logic changes are mechanical guards following patterns already used elsewhere in the repo.