Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Tue, Oct 11, 2022 at 01:32:43PM +0200, Janne Johansson wrote: > > On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: > > > It's been explained a few times that being up-to-date is not an error. > > > It's a good thing, and no action is neccessary when up-to-date. > > > Any non-zero value indicates an error, that would include 2. You are > > > marking this as an error, when it isn't. > > > > It's been said that being up-to-date is not an error, but if it's been > > explained, I've failed to find an explanation. > > > > Usually, when a utility fails to perform its intended task, it gives an > > error. > > I don't personally care what exit code it throws, I only use the tool > > manually, I'd just like to know the rationale if anyone cares to > > elaborate. > > Simplest explanation is probably: > > ./some-program && do something on success > > If you understand this part of shell scripting, then you would see why > returning > 2 (or 1 or 3 or 102444) will throw off the logic, especially if 1 > means some kind > of error. > > As for "intended task", sysupgrade might be viewed as a tool to make > sure you have > the latest it knows about. If no upgrade is needed or the mirror is > old, then that task is done. > > Someone else might think it is a tool to stress the network and disk > by always downloading > things from the internet, and that it is a grave error if this can't > be done, but those people > would have a view that differs from the obsd devs idea of what to use > sysupgrade for. > > Also, if you replace your "mkdir /foo with missing /foo" with "install > -d /foo", you'd see it can > run twice without throwing errors. It makes sure a dir named foo is > created if not exists. > That is its task when run with -d. And you can && a command behind it > so it catches errors > if a file/pipe/socket is there instead. Or add -p to mkdir to get the > same behaviour. > > -- > May the most significant bit of your life be positive. Aha. I didn't know install worked that way (though mkdir -p does too, now that I think of it). I guess my actual confusion was perhaps due to this behavior being implied whereas other utilities are rather explicit about it, at least in terms of man files. Thanks!
Re: sysupgrade: exit 1 instead of exit 0 when ending early
> After reading the script, I'd nitpick that it merely advances the > version by one step rather than ensures the system is up-to-date, but I Then again, this seem to match exactly what the manpage says it should be doing: sysupgrade is a utility to upgrade OpenBSD to the next release or a new snapshot if available. -- May the most significant bit of your life be positive.
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Tue, Oct 11, 2022 at 01:34:08PM +0200, Renaud Allard wrote: > > > On 10/11/22 13:10, bug wrote: > > On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: > > > It's been explained a few times that being up-to-date is not an error. > > > It's a good thing, and no action is neccessary when up-to-date. > > > > > > Any non-zero value indicates an error, that would include 2. You are > > > marking this as an error, when it isn't. > > > > It's been said that being up-to-date is not an error, but if it's been > > explained, I've failed to find an explanation. > > It didn't fail, your system is up-to-date as requested. So, it's successful. > > > > > Usually, when a utility fails to perform its intended task, it gives an > > error. This includes when the task is not necessary, e.g. using rm to > > remove a file which doesn't exist, using mkdir to make a directory which > > already exists, or using gzip to compress a file that wouldn't benefit > > from compression (unless you tell it to do so anyway, of course). > > > > I'm not an expert on sysupgrade, but it seems to me like it could in > > fact fail incorrectly if one's system is pointed to a mirror that, for > > whatever reason, is itself outdated. In a macabre sense, this is > > inevitable if one maintains an older copy of OpenBSD that outlives > > OpenBSD itself, as URLs are not permanent. > > And how is it supposed to know your mirror is out of date? Giving an error > there won't help as if your mirror is outdated, it will also tell you that > your system is up to date as of this mirror. > Besides, for some testing purposes, you might need an outdated repo. > > > > > Given all this, I don't understand why it's a "good thing" if sysupgrade > > decides partway through that it doesn't need to do anything after all. > > It did things, it verified your system was up-to-date as you asked. > > > > > I don't personally care what exit code it throws, I only use the tool > > manually, I'd just like to know the rationale if anyone cares to > > elaborate. > > After reading the script, I'd nitpick that it merely advances the version by one step rather than ensures the system is up-to-date, but I suppose one could then argue that somehow advancing beyond the latest version would be incorrect (nevermind impossible), thus leaving "doing nothing" as the only correct action. In any case, thank you for the explanation!
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On 10/11/22 13:10, bug wrote: On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: It's been explained a few times that being up-to-date is not an error. It's a good thing, and no action is neccessary when up-to-date. Any non-zero value indicates an error, that would include 2. You are marking this as an error, when it isn't. It's been said that being up-to-date is not an error, but if it's been explained, I've failed to find an explanation. It didn't fail, your system is up-to-date as requested. So, it's successful. Usually, when a utility fails to perform its intended task, it gives an error. This includes when the task is not necessary, e.g. using rm to remove a file which doesn't exist, using mkdir to make a directory which already exists, or using gzip to compress a file that wouldn't benefit from compression (unless you tell it to do so anyway, of course). I'm not an expert on sysupgrade, but it seems to me like it could in fact fail incorrectly if one's system is pointed to a mirror that, for whatever reason, is itself outdated. In a macabre sense, this is inevitable if one maintains an older copy of OpenBSD that outlives OpenBSD itself, as URLs are not permanent. And how is it supposed to know your mirror is out of date? Giving an error there won't help as if your mirror is outdated, it will also tell you that your system is up to date as of this mirror. Besides, for some testing purposes, you might need an outdated repo. Given all this, I don't understand why it's a "good thing" if sysupgrade decides partway through that it doesn't need to do anything after all. It did things, it verified your system was up-to-date as you asked. I don't personally care what exit code it throws, I only use the tool manually, I'd just like to know the rationale if anyone cares to elaborate. smime.p7s Description: S/MIME Cryptographic Signature
Re: sysupgrade: exit 1 instead of exit 0 when ending early
> On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: > > It's been explained a few times that being up-to-date is not an error. > > It's a good thing, and no action is neccessary when up-to-date. > > Any non-zero value indicates an error, that would include 2. You are > > marking this as an error, when it isn't. > > It's been said that being up-to-date is not an error, but if it's been > explained, I've failed to find an explanation. > > Usually, when a utility fails to perform its intended task, it gives an > error. > I don't personally care what exit code it throws, I only use the tool > manually, I'd just like to know the rationale if anyone cares to > elaborate. Simplest explanation is probably: ./some-program && do something on success If you understand this part of shell scripting, then you would see why returning 2 (or 1 or 3 or 102444) will throw off the logic, especially if 1 means some kind of error. As for "intended task", sysupgrade might be viewed as a tool to make sure you have the latest it knows about. If no upgrade is needed or the mirror is old, then that task is done. Someone else might think it is a tool to stress the network and disk by always downloading things from the internet, and that it is a grave error if this can't be done, but those people would have a view that differs from the obsd devs idea of what to use sysupgrade for. Also, if you replace your "mkdir /foo with missing /foo" with "install -d /foo", you'd see it can run twice without throwing errors. It makes sure a dir named foo is created if not exists. That is its task when run with -d. And you can && a command behind it so it catches errors if a file/pipe/socket is there instead. Or add -p to mkdir to get the same behaviour. -- May the most significant bit of your life be positive.
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: > It's been explained a few times that being up-to-date is not an error. > It's a good thing, and no action is neccessary when up-to-date. > > Any non-zero value indicates an error, that would include 2. You are > marking this as an error, when it isn't. It's been said that being up-to-date is not an error, but if it's been explained, I've failed to find an explanation. Usually, when a utility fails to perform its intended task, it gives an error. This includes when the task is not necessary, e.g. using rm to remove a file which doesn't exist, using mkdir to make a directory which already exists, or using gzip to compress a file that wouldn't benefit from compression (unless you tell it to do so anyway, of course). I'm not an expert on sysupgrade, but it seems to me like it could in fact fail incorrectly if one's system is pointed to a mirror that, for whatever reason, is itself outdated. In a macabre sense, this is inevitable if one maintains an older copy of OpenBSD that outlives OpenBSD itself, as URLs are not permanent. Given all this, I don't understand why it's a "good thing" if sysupgrade decides partway through that it doesn't need to do anything after all. I don't personally care what exit code it throws, I only use the tool manually, I'd just like to know the rationale if anyone cares to elaborate.
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On 2022/10/11 03:44, Mikolaj Kucharski wrote: > On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: > > > Any non-zero value indicates an error, that would include 2. You are > > marking this as an error, when it isn't. > > > > You think this will help your scripting. Do you not realize the proposed > > changes will break someone else's scripting? > > I don't insist on this approach. I just propose a patch. > > I do recognize that it is going to break someone else's workflow. And relying on it also means that your own scripts won't work on older versions, whereas if you just check for /bsd.upgrade then they'll work in both cases (and won't break things for anyone else who uses "set -e" in their sysupgrade wrapper scripts).
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Mon, Oct 10, 2022 at 11:17:32AM -0600, Theo de Raadt wrote: > It's been explained a few times that being up-to-date is not an error. > It's a good thing, and no action is neccessary when up-to-date. No action when up-to-date is not the same as action when not up-to-date, when you use -n and additional own tooling around sysupgrade(8). > Any non-zero value indicates an error, that would include 2. You are > marking this as an error, when it isn't. > > You think this will help your scripting. Do you not realize the proposed > changes will break someone else's scripting? I don't insist on this approach. I just propose a patch. I do recognize that it is going to break someone else's workflow. -- Regards, Mikolaj
Re: sysupgrade: exit 1 instead of exit 0 when ending early
It's been explained a few times that being up-to-date is not an error. It's a good thing, and no action is neccessary when up-to-date. Any non-zero value indicates an error, that would include 2. You are marking this as an error, when it isn't. You think this will help your scripting. Do you not realize the proposed changes will break someone else's scripting? Mikolaj Kucharski wrote: > On Fri, Oct 07, 2022 at 02:39:01PM -0400, Josh Grosse wrote: > > For ease of running sysupgrade from within a script. > > > > > diff --git a/usr.sbin/sysupgrade/sysupgrade.sh > > b/usr.sbin/sysupgrade/sysupgrade.sh > > index d80ff127ffa..ce5800093c9 100644 > > --- a/usr.sbin/sysupgrade/sysupgrade.sh > > +++ b/usr.sbin/sysupgrade/sysupgrade.sh > > @@ -153,7 +153,7 @@ rm SHA256.sig > > > > if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then > > echo "Already on latest snapshot." > > - exit 0 > > + exit 1 > > fi > > > > # INSTALL.*, bsd*, *.tgz > > Maybe something like this? > > > Index: sysupgrade.8 > === > RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.8,v > retrieving revision 1.13 > diff -u -p -u -r1.13 sysupgrade.8 > --- sysupgrade.8 8 Jun 2022 09:03:11 - 1.13 > +++ sysupgrade.8 10 Oct 2022 06:59:49 - > @@ -89,6 +89,10 @@ mirror top-level URL for fetching an upg > .It Pa /home/_sysupgrade > Directory the upgrade is downloaded to. > .El > +.Sh EXIT STATUS > +.Ex -std sysupgrade > +In particular, 2 indicates upgraded was requested but > +system is already on the latest snapshot. > .Sh SEE ALSO > .Xr signify 1 , > .Xr installurl 5 , > Index: sysupgrade.sh > === > RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v > retrieving revision 1.48 > diff -u -p -u -r1.48 sysupgrade.sh > --- sysupgrade.sh 8 Jun 2022 09:03:11 - 1.48 > +++ sysupgrade.sh 10 Oct 2022 06:59:49 - > @@ -153,7 +153,7 @@ rm SHA256.sig > > if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then > echo "Already on latest snapshot." > - exit 0 > + exit 2 > fi > > # INSTALL.*, bsd*, *.tgz > > > -- > Regards, > Mikolaj >
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Fri, Oct 07, 2022 at 02:39:01PM -0400, Josh Grosse wrote: > For ease of running sysupgrade from within a script. > > diff --git a/usr.sbin/sysupgrade/sysupgrade.sh > b/usr.sbin/sysupgrade/sysupgrade.sh > index d80ff127ffa..ce5800093c9 100644 > --- a/usr.sbin/sysupgrade/sysupgrade.sh > +++ b/usr.sbin/sysupgrade/sysupgrade.sh > @@ -153,7 +153,7 @@ rm SHA256.sig > > if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then > echo "Already on latest snapshot." > - exit 0 > + exit 1 > fi > > # INSTALL.*, bsd*, *.tgz Maybe something like this? Index: sysupgrade.8 === RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.8,v retrieving revision 1.13 diff -u -p -u -r1.13 sysupgrade.8 --- sysupgrade.88 Jun 2022 09:03:11 - 1.13 +++ sysupgrade.810 Oct 2022 06:59:49 - @@ -89,6 +89,10 @@ mirror top-level URL for fetching an upg .It Pa /home/_sysupgrade Directory the upgrade is downloaded to. .El +.Sh EXIT STATUS +.Ex -std sysupgrade +In particular, 2 indicates upgraded was requested but +system is already on the latest snapshot. .Sh SEE ALSO .Xr signify 1 , .Xr installurl 5 , Index: sysupgrade.sh === RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v retrieving revision 1.48 diff -u -p -u -r1.48 sysupgrade.sh --- sysupgrade.sh 8 Jun 2022 09:03:11 - 1.48 +++ sysupgrade.sh 10 Oct 2022 06:59:49 - @@ -153,7 +153,7 @@ rm SHA256.sig if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then echo "Already on latest snapshot." - exit 0 + exit 2 fi # INSTALL.*, bsd*, *.tgz -- Regards, Mikolaj
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Sat, Oct 08, 2022 at 11:14:34AM +, Mikolaj Kucharski wrote: > On Sat, Oct 08, 2022 at 09:57:54AM +, Klemens Nanni wrote: > > On Sat, Oct 08, 2022 at 07:33:38AM +0200, Florian Obser wrote: > > > Being up2date doesn't feel like an error to me, what am I missing? > > > > I concur. > > > > I think Josh is looking for similar behaviour to syspatch(8). To be able > to distinguish, upgrade is ready (exit 0), system is up to date (exit 2) > or error occurred (exit 1). > > I have the same need to distinguish between nothing to do - you are on > latest snapshot (sysupgrade -s -n) versus pending upgrade, as I use > `sysupgrade -s -n` a lot. Yes, a non-zero exit allows for: /usr/sbin/sysupgrade -s -n || exit > On my side I just check that non-zero /bsd.upgrade file exists. I > think what Josh is trying to achieve make sense, but I would make it > exit code 2, the same way like syspatch(8). That would also work. Thanks, Mikolaj!
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Sat, Oct 08, 2022 at 09:57:54AM +, Klemens Nanni wrote: > On Sat, Oct 08, 2022 at 07:33:38AM +0200, Florian Obser wrote: > > Being up2date doesn't feel like an error to me, what am I missing? > > I concur. > I think Josh is looking for similar behaviour to syspatch(8). To be able to distinguish, upgrade is ready (exit 0), system is up to date (exit 2) or error occurred (exit 1). I have the same need to distinguish between nothing to do - you are on latest snapshot (sysupgrade -s -n) versus pending upgrade, as I use `sysupgrade -s -n` a lot. On my side I just check that non-zero /bsd.upgrade file exists. I think what Josh is trying to achieve make sense, but I would make it exit code 2, the same way like syspatch(8). -- Regards, Mikolaj
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On Sat, Oct 08, 2022 at 07:33:38AM +0200, Florian Obser wrote: > Being up2date doesn't feel like an error to me, what am I missing? I concur.
Re: sysupgrade: exit 1 instead of exit 0 when ending early
On 2022-10-07 14:39 -04, Josh Grosse wrote: > For ease of running sysupgrade from within a script. > > diff --git a/usr.sbin/sysupgrade/sysupgrade.sh > b/usr.sbin/sysupgrade/sysupgrade.sh > index d80ff127ffa..ce5800093c9 100644 > --- a/usr.sbin/sysupgrade/sysupgrade.sh > +++ b/usr.sbin/sysupgrade/sysupgrade.sh > @@ -153,7 +153,7 @@ rm SHA256.sig > > if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then > echo "Already on latest snapshot." > - exit 0 > + exit 1 > fi > > # INSTALL.*, bsd*, *.tgz > Being up2date doesn't feel like an error to me, what am I missing? -- I'm not entirely sure you are real.
sysupgrade: exit 1 instead of exit 0 when ending early
For ease of running sysupgrade from within a script. diff --git a/usr.sbin/sysupgrade/sysupgrade.sh b/usr.sbin/sysupgrade/sysupgrade.sh index d80ff127ffa..ce5800093c9 100644 --- a/usr.sbin/sysupgrade/sysupgrade.sh +++ b/usr.sbin/sysupgrade/sysupgrade.sh @@ -153,7 +153,7 @@ rm SHA256.sig if cmp -s /var/db/installed.SHA256 SHA256 && ! $FORCE; then echo "Already on latest snapshot." - exit 0 + exit 1 fi # INSTALL.*, bsd*, *.tgz