On Fri, Aug 08, 2014 at 04:03:52PM +0200, Pino Toscano wrote:
Just call close on the specified fd, if valid. --- daemon/daemon.h | 3 +++ daemon/guestfsd.c | 9 +++++++++ 2 files changed, 12 insertions(+)
diff --git a/daemon/daemon.h b/daemon/daemon.h index fb74e91..0caad45 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -173,6 +173,7 @@ asprintf_nowarn (char **strp, const char *fmt, ...) extern void cleanup_free (void *ptr); extern void cleanup_free_string_list (void *ptr); extern void cleanup_unlink_free (void *ptr); +extern void cleanup_close (void *ptr);
/*-- in names.c (auto-generated) --*/ extern const char *function_names[]; @@ -405,10 +406,12 @@ is_zero (const char *buffer, size_t size) #define CLEANUP_FREE_STRING_LIST \ __attribute__((cleanup(cleanup_free_string_list))) #define CLEANUP_UNLINK_FREE __attribute__((cleanup(cleanup_unlink_free))) +#define CLEANUP_CLOSE __attribute__((cleanup(cleanup_close))) #else #define CLEANUP_FREE #define CLEANUP_FREE_STRING_LIST #define CLEANUP_UNLINK_FREE +#define CLEANUP_CLOSE #endif
#endif /* GUESTFSD_DAEMON_H */ diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 622bda1..0a59c84 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -1482,3 +1482,12 @@ cleanup_unlink_free (void *ptr) free (filename); } } + +void +cleanup_close (void *ptr) +{ + int fd = * (int *) ptr; + + if (fd >= 0) + close (fd); +} --
ACK. I needed this -- I don't at the moment remember what for, but it might have been for an earlier version of qemu-speed-test. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW