]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virthread: Make sure virOnce() returns -1 on error
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 4 May 2021 09:24:07 +0000 (11:24 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 7 May 2021 10:33:58 +0000 (12:33 +0200)
Since its introduction in v0.9.1~65 the virOnce() was expected to
follow the usual retval logic (0 for success, a negative number
for failure). However, that was never the case.

On the other hand, looking into glibc and musl the pthread_once()
never returns anything other than zero (uclibc-ng seems to not
implement pthread_once()), therefore we never really hit any
problem. But for code cleanliness (and to match POSIX
documentation), let's change to code so that our retval logic is
honoured.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virthread.c

index 5ddbf7c49a72f3bda258cdc9f62ae67e93acdc39..e89c1a09fba08c20780d63634e46404a90314ace 100644 (file)
 
 int virOnce(virOnceControl *once, virOnceFunc init)
 {
-    return pthread_once(&once->once, init);
+    int ret;
+
+    ret = pthread_once(&once->once, init);
+    if (ret != 0) {
+        errno = ret;
+        return -1;
+    }
+
+    return 0;
 }