Hi,

I'm not sure if this is really a bug or if my fix is appropriate and it's
the first time I've ever contacted the OpenBSD project so apologies if I
make some error in my etiquette :-)

I noticed that invocations of swapctl in rc always result in a non-zero
exit code even when swap is successfully initialised from fstab. It doesn't
affect the operation of rc in normal circumstances but in my case I wanted
to examine the exit code in $? and noticed that it was always 1. Using
swapctl in the same way from the shell after the system is up gave what I
expected, 0 or success.

Looking at /usr/src/sbin/swapctl.c it appears the code tolerates an EBUSY
response from the swapctl syscall and only warns on other errors. I guess
the circumstances during rc execution cause this response and this is
known. But since the variable gotone never gets set in this case, the exit
code is always 1 even though swap was successfully initialised.

Here is the patch I created with 'diff -u' which works around this problem
for me...

--- swapctl.c   Fri Oct 25 13:11:42 2013
+++ my_swapctl.c        Fri Oct 25 13:08:51 2013
@@ -427,8 +427,9 @@
                }

                if (swapctl(SWAP_ON, spec, (int)priority) < 0) {
-                       if (errno != EBUSY)
+                       if (errno != EBUSY) {
                                warn("%s", spec);
+                       } else gotone = 1;
                } else {
                        gotone = 1;
                        printf("%s: adding %s as swap device at priority
%d\n",
@@ -454,4 +455,3 @@
        fprintf(stderr, "       %s [[-l] | -s] [-k]\n", __progname);
        exit(1);
 }
-

Please feel free to do what you wish with it! Any guidance on the way I
should approach these kinds of issues would be welcome as there's another
little thing I spotted and a potential enhancement to dhclient which I'm
still thrashing out the detail/working on.

Best regards,
Matthew Harrodine.

Reply via email to