ctladm: Fix a race when loading ctl.ko

If multiple ctladm processes try to load ctl.ko at the same time, only
one will succeed.  Handle this possibility by retrying the operation
(open /dev/cam/ctl) if kldload returns EEXIST, rather than bailing.
This at least helps ensure that ctladm tests can be run in parallel
when ctl.ko is not preloaded.

Reviewed by:	asomers
MFC after:	1 week
This commit is contained in:
Mark Johnston 2024-06-24 11:09:18 -04:00
parent f29bdea047
commit 7d6932d20a

View file

@ -4469,7 +4469,7 @@ main(int argc, char **argv)
if (fd == -1 && errno == ENOENT) {
saved_errno = errno;
retval = kldload("ctl");
if (retval != -1)
if (retval != -1 || errno == EEXIST)
fd = open(device, O_RDWR);
else
errno = saved_errno;