Kaynağa Gözat

monitor: Report errors from monitor_fdset_dup_fd_add

I'm keeping the EACCES because callers expect to be able to look at
errno.

Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Fabiano Rosas 1 yıl önce
ebeveyn
işleme
960f29b347
4 değiştirilmiş dosya ile 12 ekleme ve 12 silme
  1. 1 1
      include/monitor/monitor.h
  2. 9 1
      monitor/fds.c
  3. 1 1
      stubs/fdset.c
  4. 1 9
      util/osdep.c

+ 1 - 1
include/monitor/monitor.h

@@ -51,7 +51,7 @@ int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
 
 
 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
                                 const char *opaque, Error **errp);
                                 const char *opaque, Error **errp);
-int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
+int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 
 
 void monitor_register_hmp(const char *name, bool info,
 void monitor_register_hmp(const char *name, bool info,

+ 9 - 1
monitor/fds.c

@@ -409,9 +409,10 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
     return fdinfo;
     return fdinfo;
 }
 }
 
 
-int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
+int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp)
 {
 {
 #ifdef _WIN32
 #ifdef _WIN32
+    error_setg(errp, "Platform does not support fd passing (fdset)");
     return -ENOENT;
     return -ENOENT;
 #else
 #else
     MonFdset *mon_fdset;
     MonFdset *mon_fdset;
@@ -431,6 +432,8 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
         QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
         QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
             mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL);
             mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL);
             if (mon_fd_flags == -1) {
             if (mon_fd_flags == -1) {
+                error_setg(errp, "Failed to read file status flags for fd=%d",
+                           mon_fdset_fd->fd);
                 return -1;
                 return -1;
             }
             }
 
 
@@ -442,11 +445,15 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
 
 
         if (fd == -1) {
         if (fd == -1) {
             errno = EACCES;
             errno = EACCES;
+            error_setg(errp,
+                       "Failed to find file descriptor with matching flags=0x%x",
+                       flags);
             return -1;
             return -1;
         }
         }
 
 
         dup_fd = qemu_dup_flags(fd, flags);
         dup_fd = qemu_dup_flags(fd, flags);
         if (dup_fd == -1) {
         if (dup_fd == -1) {
+            error_setg(errp, "Failed to dup() given file descriptor fd=%d", fd);
             return -1;
             return -1;
         }
         }
 
 
@@ -456,6 +463,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
         return dup_fd;
         return dup_fd;
     }
     }
 
 
+    error_setg(errp, "Failed to find fdset /dev/fdset/%" PRId64, fdset_id);
     errno = ENOENT;
     errno = ENOENT;
     return -1;
     return -1;
 #endif
 #endif

+ 1 - 1
stubs/fdset.c

@@ -3,7 +3,7 @@
 #include "monitor/monitor.h"
 #include "monitor/monitor.h"
 #include "../monitor/monitor-internal.h"
 #include "../monitor/monitor-internal.h"
 
 
-int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
+int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp)
 {
 {
     errno = ENOSYS;
     errno = ENOSYS;
     return -1;
     return -1;

+ 1 - 9
util/osdep.c

@@ -310,7 +310,6 @@ qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp)
     /* Attempt dup of fd from fd set */
     /* Attempt dup of fd from fd set */
     if (strstart(name, "/dev/fdset/", &fdset_id_str)) {
     if (strstart(name, "/dev/fdset/", &fdset_id_str)) {
         int64_t fdset_id;
         int64_t fdset_id;
-        int dupfd;
 
 
         fdset_id = qemu_parse_fdset(fdset_id_str);
         fdset_id = qemu_parse_fdset(fdset_id_str);
         if (fdset_id == -1) {
         if (fdset_id == -1) {
@@ -319,14 +318,7 @@ qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp)
             return -1;
             return -1;
         }
         }
 
 
-        dupfd = monitor_fdset_dup_fd_add(fdset_id, flags);
-        if (dupfd == -1) {
-            error_setg_errno(errp, errno, "Could not dup FD for %s flags %x",
-                             name, flags);
-            return -1;
-        }
-
-        return dupfd;
+        return monitor_fdset_dup_fd_add(fdset_id, flags, errp);
     }
     }
 #endif
 #endif