]> xenbits.xensource.com Git - libvirt.git/commitdiff
virbpf: Set errno instead of reporting errors
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 26 Feb 2020 08:24:27 +0000 (09:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 10 Mar 2020 16:10:57 +0000 (17:10 +0100)
The virbpf module wraps syscalls to BPF. However, if the kernel
headers used at the compile time don't have support for BPF the
module offers stubs which return a negative one to signal error
to the caller. But there is a slight discrepancy between real
functions and these stubs. While the former set errno and return
-1 the latter report an error (without setting the errno) and
return -1. This is not optimal because the caller might see stale
errno and overwrite the error message with a less accurate one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
po/POTFILES.in
src/util/virbpf.c

index 982f2ebc365651eeb0ef4a80acd8b1b5245bf9ff..8af457aa3686e12e7efce67d7308d5c1be4018df 100644 (file)
 @SRCDIR@/src/util/virauth.c
 @SRCDIR@/src/util/virauthconfig.c
 @SRCDIR@/src/util/virbitmap.c
-@SRCDIR@/src/util/virbpf.c
 @SRCDIR@/src/util/vircgroup.c
 @SRCDIR@/src/util/vircgroupbackend.c
 @SRCDIR@/src/util/vircgroupbackend.h
index dec8d0133a1f241eabac202de5b1341417544cdd..987fc34ef46bbcdf4084ab79e90eb00ac41e2b9c 100644 (file)
@@ -302,8 +302,7 @@ virBPFCreateMap(unsigned int mapType G_GNUC_UNUSED,
                 unsigned int valSize G_GNUC_UNUSED,
                 unsigned int maxEntries G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -313,8 +312,7 @@ virBPFLoadProg(struct bpf_insn *insns G_GNUC_UNUSED,
                int progType G_GNUC_UNUSED,
                unsigned int insnCnt G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -324,8 +322,7 @@ virBPFAttachProg(int progfd G_GNUC_UNUSED,
                  int targetfd G_GNUC_UNUSED,
                  int attachType G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -335,8 +332,7 @@ virBPFDetachProg(int progfd G_GNUC_UNUSED,
                  int targetfd G_GNUC_UNUSED,
                  int attachType G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -348,8 +344,7 @@ virBPFQueryProg(int targetfd G_GNUC_UNUSED,
                 unsigned int *progcnt G_GNUC_UNUSED,
                 void *progids G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -357,8 +352,7 @@ virBPFQueryProg(int targetfd G_GNUC_UNUSED,
 int
 virBPFGetProg(unsigned int id G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -368,8 +362,7 @@ virBPFGetProgInfo(int progfd G_GNUC_UNUSED,
                   struct bpf_prog_info *info G_GNUC_UNUSED,
                   unsigned int **mapIDs G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -377,8 +370,7 @@ virBPFGetProgInfo(int progfd G_GNUC_UNUSED,
 int
 virBPFGetMap(unsigned int id G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -387,8 +379,7 @@ int
 virBPFGetMapInfo(int mapfd G_GNUC_UNUSED,
                  struct bpf_map_info *info G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -398,8 +389,7 @@ virBPFLookupElem(int mapfd G_GNUC_UNUSED,
                  void *key G_GNUC_UNUSED,
                  void *val G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -409,8 +399,7 @@ virBPFGetNextElem(int mapfd G_GNUC_UNUSED,
                   void *key G_GNUC_UNUSED,
                   void *nextKey G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -420,8 +409,7 @@ virBPFUpdateElem(int mapfd G_GNUC_UNUSED,
                  void *key G_GNUC_UNUSED,
                  void *val G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 
@@ -430,8 +418,7 @@ int
 virBPFDeleteElem(int mapfd G_GNUC_UNUSED,
                  void *key G_GNUC_UNUSED)
 {
-    virReportSystemError(ENOSYS, "%s",
-                         _("BPF not supported with this kernel"));
+    errno = ENOSYS;
     return -1;
 }
 #endif /* !HAVE_SYS_SYSCALL_H || !HAVE_DECL_BPF_PROG_QUERY */