fix(script): Trigger restart only on FDs for binaries (#3) #4

Merged
hygienic-books merged 1 commits from 3/fix-3-only-reboot-when-binaries-change into main 2024-06-19 18:17:55 +00:00

Rename variable and its echo output headline to something that
implies we're talking about binaries specifically, not all files.

Also add an awk condition that only outputs an lsof line if lsof
showed a file descriptor to a path somewhere in a /bin/ or /sbin/
directory. As a good enough approximation this will help us trigger a
system reboot when something in /usr/bin/foo or /usr/local/sbin/bar
was deleted while at the same time vastly reducing the amount of
unnecessary system reboots for random /memfd anonymous files and
shared memory objects in /dev/shm.

An awk program has multiple repetitions of 'condition { action }'
where the action is literally written inside curly braces.

Replace the pseudo-condition '1' (i.e. something that is always
truthy) with '$(NF-1) ~ //s?bin//'.

To break it down the new condition is:

  • If the second to last field in a line ...
    $(NF-1)

  • Matches an expression ...
    $(NF-1) ~ /expression/

  • That is /s?bin/ ...
    /s?bin/

Then we want to do '{ action }' which will still print affected file
descriptors as before. An awk expression is encapsulated in a slash
pair like so: '/expression/'. We want to search for any string that
contains literal slashes like so: '/s?bin/'. We unfortunately have
to escape the slashes we want to find to make sure awk doesn't treat
them as the end of its awk expression string:

                  +------+------ Backslash-escape here
                  v      v
  • Right: $(NF-1) ~ //s?bin//
  • Wrong: $(NF-1) ~ //s?bin//

The expression 's?' is probably self-explanatory. An awk expression
is related to a regular expression but not identical to it. Still, a
question mark means the same thing as in a PERL-compatible regular
expression, the preceding character is optional: we want either one
of '/sbin/' or '/bin/'.

Rename variable and its echo output headline to something that implies we're talking about binaries specifically, not all files. Also add an awk condition that only outputs an lsof line if lsof showed a file descriptor to a path somewhere in a /bin/ or /sbin/ directory. As a good enough approximation this will help us trigger a system reboot when something in /usr/bin/foo or /usr/local/sbin/bar was deleted while at the same time vastly reducing the amount of unnecessary system reboots for random /memfd anonymous files and shared memory objects in /dev/shm. An awk program has multiple repetitions of 'condition { action }' where the action is literally written inside curly braces. Replace the pseudo-condition '1' (i.e. something that is always truthy) with '$(NF-1) ~ /\/s?bin\//'. To break it down the new condition is: - If the second to last field in a line ... $(NF-1) - Matches an expression ... $(NF-1) ~ /expression/ - That is /s?bin/ ... /s?bin/ Then we want to do '{ action }' which will still print affected file descriptors as before. An awk expression is encapsulated in a slash pair like so: '/expression/'. We want to search for any string that contains literal slashes like so: '/s?bin/'. We unfortunately have to escape the slashes we want to find to make sure awk doesn't treat them as the end of its awk expression string: +------+------ Backslash-escape here v v - Right: $(NF-1) ~ /\/s?bin\// - Wrong: $(NF-1) ~ //s?bin// The expression 's?' is probably self-explanatory. An awk expression is related to a regular expression but not identical to it. Still, a question mark means the same thing as in a PERL-compatible regular expression, the preceding character is optional: we want either one of '/sbin/' or '/bin/'.
hygienic-books added 1 commit 2024-06-19 18:17:31 +00:00
Rename variable and its echo output headline to something that
implies we're talking about binaries specifically, not all files.

Also add an awk condition that only outputs an lsof line if lsof
showed a file descriptor to a path somewhere in a /bin/ or /sbin/
directory. As a good enough approximation this will help us trigger a
system reboot when something in /usr/bin/foo or /usr/local/sbin/bar
was deleted while at the same time vastly reducing the amount of
unnecessary system reboots for random /memfd anonymous files and
shared memory objects in /dev/shm.

An awk program has multiple repetitions of 'condition { action }'
where the action is literally written inside curly braces.

Replace the pseudo-condition '1' (i.e. something that is always
truthy) with '$(NF-1) ~ /\/s?bin\//'.

To break it down the new condition is:

  - If the second to last field in a line ...
    $(NF-1)

  - Matches an expression ...
    $(NF-1) ~ /expression/

  - That is /s?bin/ ...
    /s?bin/

Then we want to do '{ action }' which will still print affected file
descriptors as before. An awk expression is encapsulated in a slash
pair like so: '/expression/'. We want to search for any string that
contains literal slashes like so: '/s?bin/'. We unfortunately have
to escape the slashes we want to find to make sure awk doesn't treat
them as the end of its awk expression string:

                      +------+------ Backslash-escape here
                      v      v
  - Right: $(NF-1) ~ /\/s?bin\//
  - Wrong: $(NF-1) ~ //s?bin//

The expression 's?' is probably self-explanatory. An awk expression
is related to a regular expression but not identical to it. Still, a
question mark means the same thing as in a PERL-compatible regular
expression, the preceding character is optional: we want either one
of '/sbin/' or '/bin/'.
hygienic-books merged commit 3f97a899f3 into main 2024-06-19 18:17:55 +00:00
hygienic-books deleted branch 3/fix-3-only-reboot-when-binaries-change 2024-06-19 18:17:55 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: quico-os-setup/arch-needs-restart#4
No description provided.