Pino Toscano
2014-Aug-07 08:48 UTC
[Libguestfs] [PATCH] daemon: add and use a reply_with_unavailable_feature macro
Handy macro to reply the right way for an unavailable feature. While generally used so far in generated code, it can shorten that a bit, and avoid copy&paste when wanting to do manual feature checking. --- daemon/daemon.h | 6 ++++++ generator/daemon.ml | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index 94537b7..fb74e91 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -245,6 +245,12 @@ extern void reply_with_perror_errno (int err, const char *fs, ...) __attribute__((format (printf,2,3))); #define reply_with_error(...) reply_with_error_errno(0, __VA_ARGS__) #define reply_with_perror(...) reply_with_perror_errno(errno, __VA_ARGS__) +#define reply_with_unavailable_feature(feature) \ + reply_with_error_errno (ENOTSUP, \ + "feature '%s' is not available in this\n" \ + "build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\n" \ + "how to check for the availability of features.", \ + feature) /* daemon functions that receive files (FileIn) should call * receive_file for each FileIn parameter. diff --git a/generator/daemon.ml b/generator/daemon.ml index ca748d2..951729c 100644 --- a/generator/daemon.ml +++ b/generator/daemon.ml @@ -280,11 +280,7 @@ cleanup_free_mountable (mountable_t *mountable) pr " if (! optgroup_%s_available ()) {\n" group; if is_filein then pr " cancel_receive ();\n"; - pr " reply_with_error_errno (ENOTSUP,\n"; - pr " \"feature '%%s' is not available in this\\n\"\n"; - pr " \"build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\\n\"\n"; - pr " \"how to check for the availability of features.\",\n"; - pr " \"%s\");\n" group; + pr " reply_with_unavailable_feature (\"%s\");\n" group; pr " goto done_no_free;\n"; pr " }\n"; pr "\n" -- 1.9.3
Richard W.M. Jones
2014-Aug-07 09:19 UTC
Re: [Libguestfs] [PATCH] daemon: add and use a reply_with_unavailable_feature macro
On Thu, Aug 07, 2014 at 10:48:25AM +0200, Pino Toscano wrote:> Handy macro to reply the right way for an unavailable feature. > While generally used so far in generated code, it can shorten that a > bit, and avoid copy&paste when wanting to do manual feature checking.ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/