[patch iwhd 1/3] Add dc-rhev-image
Jim Meyering
jim at meyering.net
Tue Mar 1 15:21:26 UTC 2011
Pete Zaitcev wrote:
> This patch adds a "script" that does the same thing dc-register-image
> does for EC2, only for RHEV-M. Unfortunately, it wasn't feasible to get
> away with a shell script, so dc-rhev-image is actually a C program.
>
> Instead of /bin/cp, gnulib's copy_file_preserving is used.
>
> This version adds the invocation harness to iwhd proper, with a type
> of "fs-rhev-m".
>
> Documentation is not updated for now. The usual "?op=register" on a
> pre-existing object is used to drive the registration. Generally the
> RHEV-M registration looks very similar to EC2.
>
> Signed-off-by: Pete Zaitcev <zaitcev at redhat.com>
>
> ---
> .gitignore | 1
> Makefile.am | 13
> backend.c | 268 ++++++
> bootstrap.conf | 2
> configure.ac | 5
> dc-rhev-image.c | 1568 ++++++++++++++++++++++++++++++++++++++
> gnulib-tests/.gitignore | 22
> iwhd.spec.in | 1
> lib/.gitignore | 23
> setup.c | 8
> 10 files changed, 1907 insertions(+), 4 deletions(-)
...
> + if (!json_is_string(elem)) {
> + fprintf(stderr,
> + "ERROR configuration %s: tag %s is not a string\n",
> + cfgname, cfgtag);
> + exit(2);
In place of each use of fprintf, iwhd makes an effort to use error.
That assures that the diagnostic starts with the program name, i.e.,
"iwhd: ...", among other benefits. For example, the above would
become this, where ERR_INVAL is defined to 2:
error (ERR_INVAL, 0,
"ERROR configuration %s: tag %s is not a string\n",
cfgname, cfgtag);
Another advantage: in the common case where there is just one
statement in the new if-block, you can leave off the braces and
thus save a line -- or not, depending on which style you prefer.
I prefer to omit braces when the if body is just one line, so that
I get more lines of actual code per vertical viewing area.
Another advantage of using error is that you can avoid strerror,
which is not thread-safe. For example, instead of this,
> + if (mkdir(tmpovfdir, 0770) < 0) {
> + fprintf(stderr, "ERROR Failed to make directory %s: %s\n",
> + tmpovfdir, strerror(errno));
+ exit(1);
+ }
I'd write this:
if (mkdir(tmpovfdir, 0770) < 0)
error(EXIT_FAILURE, error,
"ERROR Failed to make directory %s\n", tmpovfdir);
More information about the iwhd-devel
mailing list