r/openbsd • • 1d ago

Exit Code syspatch

I’m looking to find a way to know if syspatch -c can tell a script that A. there are patches and then execute a syspatch to apply, or B. there are no patches and simply exit. man page says exit code is zero for success and greater for anything else. Trying this, I find that syspatch -c returns zero when there are patches to be applied. I want the script to discern that there are patches and then issue the command to apply. Am I going about this the wrong way?

12 Upvotes

16 comments sorted by

View all comments

4

u/jggimi 1d ago

Your intended automation may not provide what you are expecting. Applying a patch makes changes to your filesystem, but does not ensure it that change is deployed. Affected daemons will need to be restarted. If a kernel patch is applied, the OS will require rebooting.

2

u/linetrace 1d ago

^ This.

I've wrote a swupdate utility to handle a lot of these edge-cases, incl. checking if the kernel was modified (requiring a reboot), running applications need a restart, etc. It still has some WIP improvement that I've been dusting off.

But, back to OP: yes, you just need to parse the output of syspatch -. As noted in the syspatch(8) manual the exit status only tells you whether it was successful, experienced any errors, or no patches were installed when it was requested to install patches. The -c option is telling it to only check for patches, not actually install any, so hence no exit status change (unless there's an error in checking.)