From: Jim Meyering Date: Fri, 20 Nov 2009 11:09:42 +0000 (+0100) Subject: maint: use EXIT_SUCCESS and EXIT_FAILURE, not 0 and 1 to exit X-Git-Tag: 1.0.80~81 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=c372c7c23a298a940b8a0868396ef2ae0d824e4d maint: use EXIT_SUCCESS and EXIT_FAILURE, not 0 and 1 to exit Convert all uses automatically, via these two commands: git grep -l '\:\": %s\n", vmchannel); - exit (1); + exit (EXIT_FAILURE); } memset (&hints, 0, sizeof hints); @@ -263,7 +263,7 @@ main (int argc, char *argv[]) if (r != 0) { fprintf (stderr, "%s:%s: %s\n", host, port, gai_strerror (r)); - exit (1); + exit (EXIT_FAILURE); } /* Connect to the given TCP socket. */ @@ -284,7 +284,7 @@ main (int argc, char *argv[]) "unknown vmchannel connection type: %s\n" "expecting \"tcp::\"\n", vmchannel); - exit (1); + exit (EXIT_FAILURE); } if (sock == -1) { @@ -303,7 +303,7 @@ main (int argc, char *argv[]) "or on the libguestfs redhat com mailing list.\n" "\n", vmchannel); - exit (1); + exit (EXIT_FAILURE); } /* Send the magic length message which indicates that @@ -316,7 +316,7 @@ main (int argc, char *argv[]) xdr_uint32_t (&xdr, &len); if (xwrite (sock, lenbuf, sizeof lenbuf) == -1) - exit (1); + exit (EXIT_FAILURE); xdr_destroy (&xdr); @@ -324,14 +324,14 @@ main (int argc, char *argv[]) if (!dont_fork) { if (daemon (0, 1) == -1) { perror ("daemon"); - exit (1); + exit (EXIT_FAILURE); } } /* Enter the main loop, reading and performing actions. */ main_loop (sock); - exit (0); + exit (EXIT_SUCCESS); } /* Read /proc/cmdline. */ diff --git a/daemon/proto.c b/daemon/proto.c index a0d3736..284037d 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -63,7 +63,7 @@ main_loop (int _sock) /* Read the length word. */ if (xread (sock, lenbuf, 4) == -1) - exit (1); + exit (EXIT_FAILURE); xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE); xdr_uint32_t (&xdr, &len); @@ -72,7 +72,7 @@ main_loop (int _sock) if (len > GUESTFS_MESSAGE_MAX) { fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n", len); - exit (1); + exit (EXIT_FAILURE); } buf = malloc (len); @@ -82,7 +82,7 @@ main_loop (int _sock) } if (xread (sock, buf, len) == -1) - exit (1); + exit (EXIT_FAILURE); #ifdef ENABLE_PACKET_DUMP if (verbose) { @@ -115,7 +115,7 @@ main_loop (int _sock) xdrmem_create (&xdr, buf, len, XDR_DECODE); if (!xdr_guestfs_message_header (&xdr, &hdr)) { fprintf (stderr, "guestfsd: could not decode message header\n"); - exit (1); + exit (EXIT_FAILURE); } /* Check the version etc. */ @@ -218,14 +218,14 @@ send_error (const char *msg) if (!xdr_guestfs_message_header (&xdr, &hdr)) { fprintf (stderr, "guestfsd: failed to encode error message header\n"); - exit (1); + exit (EXIT_FAILURE); } err.error_message = (char *) msg; if (!xdr_guestfs_message_error (&xdr, &err)) { fprintf (stderr, "guestfsd: failed to encode error message body\n"); - exit (1); + exit (EXIT_FAILURE); } len = xdr_getpos (&xdr); @@ -237,11 +237,11 @@ send_error (const char *msg) if (xwrite (sock, lenbuf, 4) == -1) { fprintf (stderr, "xwrite failed\n"); - exit (1); + exit (EXIT_FAILURE); } if (xwrite (sock, buf, len) == -1) { fprintf (stderr, "xwrite failed\n"); - exit (1); + exit (EXIT_FAILURE); } } @@ -265,7 +265,7 @@ reply (xdrproc_t xdrp, char *ret) if (!xdr_guestfs_message_header (&xdr, &hdr)) { fprintf (stderr, "guestfsd: failed to encode reply header\n"); - exit (1); + exit (EXIT_FAILURE); } if (xdrp) { @@ -289,11 +289,11 @@ reply (xdrproc_t xdrp, char *ret) if (xwrite (sock, lenbuf, 4) == -1) { fprintf (stderr, "xwrite failed\n"); - exit (1); + exit (EXIT_FAILURE); } if (xwrite (sock, buf, len) == -1) { fprintf (stderr, "xwrite failed\n"); - exit (1); + exit (EXIT_FAILURE); } } @@ -311,7 +311,7 @@ receive_file (receive_cb cb, void *opaque) for (;;) { /* Read the length word. */ if (xread (sock, lenbuf, 4) == -1) - exit (1); + exit (EXIT_FAILURE); xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE); xdr_uint32_t (&xdr, &len); @@ -323,7 +323,7 @@ receive_file (receive_cb cb, void *opaque) if (len > GUESTFS_MESSAGE_MAX) { fprintf (stderr, "guestfsd: incoming message is too long (%u bytes)\n", len); - exit (1); + exit (EXIT_FAILURE); } buf = malloc (len); @@ -333,7 +333,7 @@ receive_file (receive_cb cb, void *opaque) } if (xread (sock, buf, len) == -1) - exit (1); + exit (EXIT_FAILURE); xdrmem_create (&xdr, buf, len, XDR_DECODE); memset (&chunk, 0, sizeof chunk); @@ -503,7 +503,7 @@ send_chunk (const guestfs_chunk *chunk) && xwrite (sock, buf, len) == 0 ? 0 : -1); if (err) { fprintf (stderr, "send_chunk: write failed\n"); - exit (1); + exit (EXIT_FAILURE); } return err; diff --git a/examples/hello.c b/examples/hello.c index 8b36ed4..b4d5d8c 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -19,18 +19,18 @@ main (int argc, char *argv[]) if (argc != 3 || access (argv[1], F_OK) != 0) { fprintf (stderr, "Usage: hello disk-image partition\n"); - exit (1); + exit (EXIT_FAILURE); } - if (!(g = guestfs_create ())) exit (1); + if (!(g = guestfs_create ())) exit (EXIT_FAILURE); - if (guestfs_add_drive (g, argv[1]) == -1) exit (1); + if (guestfs_add_drive (g, argv[1]) == -1) exit (EXIT_FAILURE); - if (guestfs_launch (g) == -1) exit (1); + if (guestfs_launch (g) == -1) exit (EXIT_FAILURE); - if (guestfs_mount (g, argv[2], "/") == -1) exit (1); + if (guestfs_mount (g, argv[2], "/") == -1) exit (EXIT_FAILURE); - if (guestfs_touch (g, "/hello") == -1) exit (1); + if (guestfs_touch (g, "/hello") == -1) exit (EXIT_FAILURE); guestfs_sync (g); guestfs_close (g); diff --git a/examples/to-xml.c b/examples/to-xml.c index 6d0a1df..537ae91 100644 --- a/examples/to-xml.c +++ b/examples/to-xml.c @@ -25,7 +25,7 @@ * to stderr already. */ #define CALL(call,errcode) \ - if ((call) == (errcode)) exit (1); + if ((call) == (errcode)) exit (EXIT_FAILURE); static void display_partition (guestfs_h *g, const char *dev); static void display_partitions (guestfs_h *g, const char *dev); @@ -39,12 +39,12 @@ main (int argc, char *argv[]) if (argc < 2 || access (argv[1], F_OK) != 0) { fprintf (stderr, "Usage: to-xml guest.img [guest.img ...]\n"); - exit (1); + exit (EXIT_FAILURE); } if (!(g = guestfs_create ())) { fprintf (stderr, "Cannot create libguestfs handle.\n"); - exit (1); + exit (EXIT_FAILURE); } for (i = 1; i < argc; ++i) diff --git a/fish/fish.c b/fish/fish.c index 41c6cbf..4f51503 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -182,7 +182,7 @@ main (int argc, char *argv[]) g = guestfs_create (); if (g == NULL) { fprintf (stderr, _("guestfs_create: failed to create handle\n")); - exit (1); + exit (EXIT_FAILURE); } guestfs_set_autosync (g, 1); @@ -222,7 +222,7 @@ main (int argc, char *argv[]) if (sscanf (optarg, "%d", &remote_control) != 1) { fprintf (stderr, _("%s: --listen=PID: PID was not a number: %s\n"), program_name, optarg); - exit (1); + exit (EXIT_FAILURE); } } else { p = getenv ("GUESTFISH_PID"); @@ -230,7 +230,7 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: remote: $GUESTFISH_PID must be set" " to the PID of the remote process\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } } } else if (STREQ (long_options[option_index].name, "selinux")) { @@ -238,19 +238,19 @@ main (int argc, char *argv[]) } else { fprintf (stderr, _("%s: unknown long option: %s (%d)\n"), program_name, long_options[option_index].name, option_index); - exit (1); + exit (EXIT_FAILURE); } break; case 'a': if (access (optarg, R_OK) != 0) { perror (optarg); - exit (1); + exit (EXIT_FAILURE); } drv = malloc (sizeof (struct drv)); if (!drv) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } drv->filename = optarg; drv->next = drvs; @@ -265,7 +265,7 @@ main (int argc, char *argv[]) if (file) { fprintf (stderr, _("%s: only one -f parameter can be given\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } file = optarg; break; @@ -277,7 +277,7 @@ main (int argc, char *argv[]) display_command (argv[optind++]); else list_commands (); - exit (0); + exit (EXIT_SUCCESS); case 'i': inspector = 1; @@ -287,7 +287,7 @@ main (int argc, char *argv[]) mp = malloc (sizeof (struct mp)); if (!mp) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } p = strchr (optarg, ':'); if (p) { @@ -315,7 +315,7 @@ main (int argc, char *argv[]) case 'V': printf ("%s %s\n", program_name, PACKAGE_VERSION); - exit (0); + exit (EXIT_SUCCESS); case 'x': echo_commands = 1; @@ -339,13 +339,13 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: cannot use -i option with -a, -m," " --listen, --remote or --selinux\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } if (optind >= argc) { fprintf (stderr, _("%s: -i requires a libvirt domain or path(s) to disk image(s)\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } strcpy (cmd, "a=`virt-inspector"); @@ -355,7 +355,7 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: virt-inspector command too long for fixed-size buffer\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } strcat (cmd, " '"); strcat (cmd, argv[optind]); @@ -382,7 +382,7 @@ main (int argc, char *argv[]) r = system (cmd); if (r == -1) { perror ("system"); - exit (1); + exit (EXIT_FAILURE); } exit (WEXITSTATUS (r)); } @@ -392,7 +392,7 @@ main (int argc, char *argv[]) /* If we've got mountpoints, we must launch the guest and mount them. */ if (mps != NULL) { - if (launch (g) == -1) exit (1); + if (launch (g) == -1) exit (EXIT_FAILURE); mount_mps (mps); } @@ -401,7 +401,7 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: cannot use --listen and --remote options at the same time\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } if (remote_control_listen) { @@ -409,13 +409,13 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: extra parameters on the command line with --listen flag\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } if (file) { fprintf (stderr, _("%s: cannot use --listen and --file options at the same time\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } rc_listen (); } @@ -425,7 +425,7 @@ main (int argc, char *argv[]) close (0); if (open (file, O_RDONLY) == -1) { perror (file); - exit (1); + exit (EXIT_FAILURE); } } @@ -441,7 +441,7 @@ main (int argc, char *argv[]) cleanup_readline (); - exit (0); + exit (EXIT_SUCCESS); } void @@ -475,7 +475,7 @@ mount_mps (struct mp *mp) else r = guestfs_mount_ro (g, mp->device, mp->mountpoint); if (r == -1) - exit (1); + exit (EXIT_FAILURE); } } @@ -491,7 +491,7 @@ add_drives (struct drv *drv) else r = guestfs_add_drive_ro (g, drv->filename); if (r == -1) - exit (1); + exit (EXIT_FAILURE); } } @@ -597,7 +597,7 @@ script (int prompt) (WIFSIGNALED (r) && (WTERMSIG (r) == SIGINT || WTERMSIG (r) == SIGQUIT)) || WEXITSTATUS (r) != 0) - exit (1); + exit (EXIT_FAILURE); } continue; } @@ -639,14 +639,14 @@ script (int prompt) len = strcspn (p, "\""); if (p[len] == '\0') { fprintf (stderr, _("%s: unterminated double quote\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } if (p[len+1] && (p[len+1] != ' ' && p[len+1] != '\t')) { fprintf (stderr, _("%s: command arguments not separated by whitespace\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } p[len] = '\0'; @@ -656,14 +656,14 @@ script (int prompt) len = strcspn (p, "'"); if (p[len] == '\0') { fprintf (stderr, _("%s: unterminated single quote\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } if (p[len+1] && (p[len+1] != ' ' && p[len+1] != '\t')) { fprintf (stderr, _("%s: command arguments not separated by whitespace\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } p[len] = '\0'; @@ -685,14 +685,14 @@ script (int prompt) if (c != 0) { fprintf (stderr, _("%s: unterminated \"[...]\" sequence\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } if (*pend && (*pend != ' ' && *pend != '\t')) { fprintf (stderr, _("%s: command arguments not separated by whitespace\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } *(pend-1) = '\0'; @@ -728,7 +728,7 @@ script (int prompt) if (i == sizeof argv / sizeof argv[0]) { fprintf (stderr, _("%s: too many arguments\n"), program_name); - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); goto next_command; } @@ -736,7 +736,7 @@ script (int prompt) got_command: if (issue_command (cmd, argv, pipe) == -1) { - if (exit_on_error) exit (1); + if (exit_on_error) exit (EXIT_FAILURE); } next_command:; @@ -757,7 +757,7 @@ cmdline (char *argv[], int optind, int argc) cmd = argv[optind++]; if (STREQ (cmd, ":")) { fprintf (stderr, _("%s: empty command on command line\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } params = &argv[optind]; @@ -766,10 +766,10 @@ cmdline (char *argv[], int optind, int argc) optind++; if (optind == argc) { - if (issue_command (cmd, params, NULL) == -1) exit (1); + if (issue_command (cmd, params, NULL) == -1) exit (EXIT_FAILURE); } else { argv[optind] = NULL; - if (issue_command (cmd, params, NULL) == -1) exit (1); + if (issue_command (cmd, params, NULL) == -1) exit (EXIT_FAILURE); cmdline (argv, optind+1, argc); } } @@ -1191,7 +1191,7 @@ parse_string_list (const char *str) perror ("realloc"); free_n_strings (argv, argv_len); free (tok); - exit (1); + exit (EXIT_FAILURE); } tok = tok_new; @@ -1237,7 +1237,7 @@ parse_string_list (const char *str) perror ("realloc"); free_n_strings (argv, argv_len-1); free (tok); - exit (1); + exit (EXIT_FAILURE); } argv = argv_new; @@ -1251,7 +1251,7 @@ parse_string_list (const char *str) if (NULL == argv_new) { perror ("realloc"); free_n_strings (argv, argv_len-1); - exit (1); + exit (EXIT_FAILURE); } argv = argv_new; diff --git a/fish/rc.c b/fish/rc.c index a9eb578..dbaf953 100644 --- a/fish/rc.c +++ b/fish/rc.c @@ -66,7 +66,7 @@ receive_stdout (int s) cmptr = malloc (controllen); if (NULL == cmptr) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } } @@ -88,7 +88,7 @@ receive_stdout (int s) ssize_t n = recvmsg (s, &msg, 0); if (n < 0) { perror ("recvmsg stdout fd"); - exit (1); + exit (EXIT_FAILURE); } h = CMSG_FIRSTHDR(&msg); @@ -135,7 +135,7 @@ send_stdout (int s) cmptr = malloc (controllen); if (NULL == cmptr) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } } cmptr->cmsg_level = SOL_SOCKET; @@ -152,7 +152,7 @@ send_stdout (int s) if (sendmsg (s, &msg, 0) != 1) { perror ("sendmsg stdout fd"); - exit (1); + exit (EXIT_FAILURE); } } @@ -192,7 +192,7 @@ rc_listen (void) pid = fork (); if (pid == -1) { perror ("fork"); - exit (1); + exit (EXIT_FAILURE); } if (pid > 0) { @@ -217,16 +217,16 @@ rc_listen (void) sock = socket (AF_UNIX, SOCK_STREAM, 0); if (sock == -1) { perror ("socket"); - exit (1); + exit (EXIT_FAILURE); } unlink (sockpath); if (bind (sock, (struct sockaddr *) &addr, sizeof addr) == -1) { perror (sockpath); - exit (1); + exit (EXIT_FAILURE); } if (listen (sock, 4) == -1) { perror ("listen"); - exit (1); + exit (EXIT_FAILURE); } /* Now close stdout and substitute /dev/null. This is necessary @@ -265,7 +265,7 @@ rc_listen (void) argv = realloc (call.args.args_val, (argc+1) * sizeof (char *)); if (argv == NULL) { perror ("realloc"); - exit (1); + exit (EXIT_FAILURE); } call.args.args_val = argv; argv[argc] = NULL; @@ -290,7 +290,7 @@ rc_listen (void) /* Exit on error? */ if (call.exit_on_error && reply.r == -1) { unlink (sockpath); - exit (1); + exit (EXIT_FAILURE); } } @@ -302,7 +302,7 @@ rc_listen (void) } unlink (sockpath); - exit (0); + exit (EXIT_SUCCESS); } /* Remote control client. */ diff --git a/fish/tilde.c b/fish/tilde.c index 64b5b39..c599e16 100644 --- a/fish/tilde.c +++ b/fish/tilde.c @@ -62,7 +62,7 @@ try_tilde_expansion (char *str) str = malloc (len); if (str == NULL) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } strcpy (str, home); strcat (str, rest); @@ -89,7 +89,7 @@ expand_home (const char *append) str = malloc (len); if (str == NULL) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } strcpy (str, home); diff --git a/fuse/dircache.c b/fuse/dircache.c index 86760f0..157035e 100644 --- a/fuse/dircache.c +++ b/fuse/dircache.c @@ -138,7 +138,7 @@ init_dir_caches (void) rlc_ht = hash_initialize (1024, NULL, gen_hash, gen_compare, rlc_free); if (!lsc_ht || !xac_ht || !rlc_ht) { fprintf (stderr, "guestmount: could not initialize dir cache hashtables\n"); - exit (1); + exit (EXIT_FAILURE); } } diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 05cacef..07c28c0 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -858,7 +858,7 @@ fuse_help (void) { const char *tmp_argv[] = { program_name, "--help", NULL }; fuse_main (2, (char **) tmp_argv, &fg_operations, NULL); - exit (0); + exit (EXIT_SUCCESS); } static void __attribute__((noreturn)) @@ -936,7 +936,7 @@ main (int argc, char *argv[]) fuse_argv = realloc (fuse_argv, (1+fuse_argc) * sizeof (char *)); \ if (!fuse_argv) { \ perror ("realloc"); \ - exit (1); \ + exit (EXIT_FAILURE); \ } \ fuse_argv[fuse_argc-1] = (str); \ fuse_argv[fuse_argc] = NULL; \ @@ -959,7 +959,7 @@ main (int argc, char *argv[]) g = guestfs_create (); if (g == NULL) { fprintf (stderr, _("guestfs_create: failed to create handle\n")); - exit (1); + exit (EXIT_FAILURE); } guestfs_set_autosync (g, 1); @@ -1005,19 +1005,19 @@ main (int argc, char *argv[]) else { fprintf (stderr, _("%s: unknown long option: %s (%d)\n"), program_name, long_options[option_index].name, option_index); - exit (1); + exit (EXIT_FAILURE); } break; case 'a': if (access (optarg, R_OK) != 0) { perror (optarg); - exit (1); + exit (EXIT_FAILURE); } drv = malloc (sizeof (struct drv)); if (!drv) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } drv->filename = optarg; drv->next = drvs; @@ -1028,7 +1028,7 @@ main (int argc, char *argv[]) mp = malloc (sizeof (struct mp)); if (!mp) { perror ("malloc"); - exit (1); + exit (EXIT_FAILURE); } p = strchr (optarg, ':'); if (p) { @@ -1061,7 +1061,7 @@ main (int argc, char *argv[]) case 'V': printf ("%s %s\n", program_name, PACKAGE_VERSION); - exit (0); + exit (EXIT_SUCCESS); case HELP_OPTION: usage (0); @@ -1076,7 +1076,7 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: must have at least one -a and at least one -m option\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } /* We'd better have a mountpoint. */ @@ -1084,18 +1084,18 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: you must specify a mountpoint in the host filesystem\n"), program_name); - exit (1); + exit (EXIT_FAILURE); } /* Do the guest drives and mountpoints. */ add_drives (drvs); if (guestfs_launch (g) == -1) - exit (1); + exit (EXIT_FAILURE); mount_mps (mps); /* FUSE example does this, not clear if it's necessary, but ... */ if (guestfs_umask (g, 0) == -1) - exit (1); + exit (EXIT_FAILURE); /* At the last minute, remove the libguestfs error handler. In code * above this point, the default error handler has been used which @@ -1144,7 +1144,7 @@ add_drives (struct drv *drv) else r = guestfs_add_drive_ro (g, drv->filename); if (r == -1) - exit (1); + exit (EXIT_FAILURE); } } @@ -1161,6 +1161,6 @@ mount_mps (struct mp *mp) else r = guestfs_mount_ro (g, mp->device, mp->mountpoint); if (r == -1) - exit (1); + exit (EXIT_FAILURE); } } diff --git a/hivex/hivexget.c b/hivex/hivexget.c index 04c854f..8cc395a 100644 --- a/hivex/hivexget.c +++ b/hivex/hivexget.c @@ -32,7 +32,7 @@ main (int argc, char *argv[]) { if (argc < 3 || argc > 4) { fprintf (stderr, "hivexget regfile path [key]\n"); - exit (1); + exit (EXIT_FAILURE); } char *file = argv[1]; char *path = argv[2]; @@ -40,19 +40,19 @@ main (int argc, char *argv[]) if (path[0] != '\\') { fprintf (stderr, "hivexget: path must start with a \\ character\n"); - exit (1); + exit (EXIT_FAILURE); } if (path[1] == '\\') { doubled: fprintf (stderr, "hivexget: %s: \\ characters in path are doubled - are you escaping the path parameter correctly?\n", path); - exit (1); + exit (EXIT_FAILURE); } hive_h *h = hivex_open (file, 0); if (h == NULL) { error: perror (file); - exit (1); + exit (EXIT_FAILURE); } /* Navigate to the desired node. */ @@ -264,5 +264,5 @@ main (int argc, char *argv[]) if (hivex_close (h) == -1) goto error; - exit (0); + exit (EXIT_SUCCESS); } diff --git a/hivex/hivexml.c b/hivex/hivexml.c index 9dd394e..7fb419f 100644 --- a/hivex/hivexml.c +++ b/hivex/hivexml.c @@ -59,7 +59,7 @@ static struct hivex_visitor visitor = { do { \ if ((proc args) == -1) { \ fprintf (stderr, "%s: failed to write XML document\n", #proc); \ - exit (1); \ + exit (EXIT_FAILURE); \ } \ } while (0) @@ -80,19 +80,19 @@ main (int argc, char *argv[]) break; default: fprintf (stderr, "hivexml [-dk] regfile > output.xml\n"); - exit (1); + exit (EXIT_FAILURE); } } if (optind + 1 != argc) { fprintf (stderr, "hivexml: missing name of input file\n"); - exit (1); + exit (EXIT_FAILURE); } hive_h *h = hivex_open (argv[optind], open_flags); if (h == NULL) { perror (argv[optind]); - exit (1); + exit (EXIT_FAILURE); } /* Note both this macro, and xmlTextWriterStartDocument leak memory. There @@ -105,7 +105,7 @@ main (int argc, char *argv[]) writer = xmlNewTextWriterFilename ("/dev/stdout", 0); if (writer == NULL) { fprintf (stderr, "xmlNewTextWriterFilename: failed to create XML writer\n"); - exit (1); + exit (EXIT_FAILURE); } XML_CHECK (xmlTextWriterStartDocument, (writer, NULL, "utf-8", NULL)); @@ -113,19 +113,19 @@ main (int argc, char *argv[]) if (hivex_visit (h, &visitor, sizeof visitor, writer, visit_flags) == -1) { perror (argv[optind]); - exit (1); + exit (EXIT_FAILURE); } if (hivex_close (h) == -1) { perror (argv[optind]); - exit (1); + exit (EXIT_FAILURE); } XML_CHECK (xmlTextWriterEndElement, (writer)); XML_CHECK (xmlTextWriterEndDocument, (writer)); xmlFreeTextWriter (writer); - exit (0); + exit (EXIT_SUCCESS); } static int diff --git a/src/generator.ml b/src/generator.ml index a1d3549..6bc9b28 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -5975,7 +5975,7 @@ int main (int argc, char *argv[]) g = guestfs_create (); if (g == NULL) { printf (\"guestfs_create FAILED\\n\"); - exit (1); + exit (EXIT_FAILURE); } guestfs_set_error_handler (g, print_error, NULL); @@ -5986,94 +5986,94 @@ int main (int argc, char *argv[]) fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); if (fd == -1) { perror (filename); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, %d, SEEK_SET) == -1) { perror (\"lseek\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, &c, 1) == -1) { perror (\"write\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror (filename); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, filename) == -1) { printf (\"guestfs_add_drive %%s FAILED\\n\", filename); - exit (1); + exit (EXIT_FAILURE); } filename = \"test2.img\"; fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); if (fd == -1) { perror (filename); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, %d, SEEK_SET) == -1) { perror (\"lseek\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, &c, 1) == -1) { perror (\"write\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror (filename); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, filename) == -1) { printf (\"guestfs_add_drive %%s FAILED\\n\", filename); - exit (1); + exit (EXIT_FAILURE); } filename = \"test3.img\"; fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); if (fd == -1) { perror (filename); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, %d, SEEK_SET) == -1) { perror (\"lseek\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, &c, 1) == -1) { perror (\"write\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror (filename); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, filename) == -1) { printf (\"guestfs_add_drive %%s FAILED\\n\", filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive_ro (g, \"../images/test.iso\") == -1) { printf (\"guestfs_add_drive_ro ../images/test.iso FAILED\\n\"); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_launch (g) == -1) { printf (\"guestfs_launch FAILED\\n\"); - exit (1); + exit (EXIT_FAILURE); } /* Set a timeout in case qemu hangs during launch (RHBZ#505329). */ @@ -6105,11 +6105,11 @@ int main (int argc, char *argv[]) pr " if (n_failed > 0) {\n"; pr " printf (\"***** %%lu / %%d tests FAILED *****\\n\", n_failed, nr_tests);\n"; - pr " exit (1);\n"; + pr " exit (EXIT_FAILURE);\n"; pr " }\n"; pr "\n"; - pr " exit (0);\n"; + pr " exit (EXIT_SUCCESS);\n"; pr "}\n" and generate_one_test name i (init, prereq, test) = diff --git a/test-tool/helper.c b/test-tool/helper.c index 3395f21..731b053 100644 --- a/test-tool/helper.c +++ b/test-tool/helper.c @@ -42,32 +42,32 @@ main (void) if (mkdir ("/tmp", 0700) == -1) { perror ("mkdir"); fprintf (stderr, "This program should not be run directly. Use libguestfs-test-tool instead.\n"); - exit (1); + exit (EXIT_FAILURE); } if (geteuid () != 0) { fprintf (stderr, "helper: This program doesn't appear to be running as root.\n"); - exit (1); + exit (EXIT_FAILURE); } if (mkdir ("/tmp/helper", 0700) == -1) { perror ("/tmp/helper"); - exit (1); + exit (EXIT_FAILURE); } fd = open ("/tmp/helper/a", O_CREAT|O_EXCL|O_WRONLY, 0600); if (fd == -1) { perror ("create /tmp/helper/a"); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, buffer, sizeof buffer) != sizeof buffer) { perror ("write"); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror ("close"); - exit (1); + exit (EXIT_FAILURE); } - exit (0); + exit (EXIT_SUCCESS); } diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c index 93aaca2..f38490a 100644 --- a/test-tool/test-tool.c +++ b/test-tool/test-tool.c @@ -120,7 +120,7 @@ main (int argc, char *argv[]) fprintf (stderr, _("libguestfs-test-tool: unknown long option: %s (%d)\n"), long_options[option_index].name, option_index); - exit (1); + exit (EXIT_FAILURE); } break; @@ -129,19 +129,19 @@ main (int argc, char *argv[]) fprintf (stderr, _("libguestfs-test-tool: invalid timeout: %s\n"), optarg); - exit (1); + exit (EXIT_FAILURE); } break; case '?': usage (); - exit (0); + exit (EXIT_SUCCESS); default: fprintf (stderr, _("libguestfs-test-tool: unexpected command line option 0x%x\n"), c); - exit (1); + exit (EXIT_FAILURE); } } @@ -163,26 +163,26 @@ main (int argc, char *argv[]) if (g == NULL) { fprintf (stderr, _("libguestfs-test-tool: failed to create libguestfs handle\n")); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, tmpf) == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to add drive '%s'\n"), tmpf); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, isof) == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to add drive '%s'\n"), isof); - exit (1); + exit (EXIT_FAILURE); } /* Print any version info etc. */ vers = guestfs_version (g); if (vers == NULL) { fprintf (stderr, _("libguestfs-test-tool: guestfs_version failed\n")); - exit (1); + exit (EXIT_FAILURE); } printf ("library version: %"PRIi64".%"PRIi64".%"PRIi64"%s\n", vers->major, vers->minor, vers->release, vers->extra); @@ -204,7 +204,7 @@ main (int argc, char *argv[]) if (guestfs_launch (g) == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to launch appliance\n")); - exit (1); + exit (EXIT_FAILURE); } alarm (0); @@ -216,31 +216,31 @@ main (int argc, char *argv[]) if (guestfs_sfdiskM (g, "/dev/sda", sfdisk_lines) == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to run sfdisk\n")); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_mkfs (g, "ext2", "/dev/sda1") == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to mkfs.ext2\n")); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_mount (g, "/dev/sda1", "/") == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to mount /dev/sda1 on /\n")); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_mkdir (g, "/iso") == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to mkdir /iso\n")); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_mount (g, "/dev/sdb", "/iso") == -1) { fprintf (stderr, _("libguestfs-test-tool: failed to mount /dev/sdb on /iso\n")); - exit (1); + exit (EXIT_FAILURE); } /* Let's now run some simple tests using the helper program. */ @@ -248,12 +248,12 @@ main (int argc, char *argv[]) if (str == NULL) { fprintf (stderr, _("libguestfs-test-tool: could not run helper program, or helper failed\n")); - exit (1); + exit (EXIT_FAILURE); } free (str); printf ("===== TEST FINISHED OK =====\n"); - exit (0); + exit (EXIT_SUCCESS); } static char qemuwrapper[] = "/tmp/libguestfs-test-tool-wrapper-XXXXXX"; @@ -280,7 +280,7 @@ set_qemu (const char *path, int use_wrapper) fprintf (stderr, _("LIBGUESTFS_QEMU environment variable is already set, so\n" "--qemu/--qemudir options cannot be used.\n")); - exit (1); + exit (EXIT_FAILURE); } if (!use_wrapper) { @@ -288,7 +288,7 @@ set_qemu (const char *path, int use_wrapper) fprintf (stderr, _("Binary '%s' does not exist or is not executable\n"), path); - exit (1); + exit (EXIT_FAILURE); } setenv ("LIBGUESTFS_QEMU", path, 1); @@ -302,14 +302,14 @@ set_qemu (const char *path, int use_wrapper) fprintf (stderr, _("%s: does not look like a qemu source directory\n"), path); - exit (1); + exit (EXIT_FAILURE); } /* Make a wrapper script. */ fd = mkstemp (qemuwrapper); if (fd == -1) { perror (qemuwrapper); - exit (1); + exit (EXIT_FAILURE); } fchmod (fd, 0700); @@ -354,19 +354,19 @@ preruncheck (void) "\n" "Use the --helper option to specify the location of this program.\n"), helper); - exit (1); + exit (EXIT_FAILURE); } snprintf (cmd, sizeof cmd, "file '%s'", helper); fp = popen (cmd, "r"); if (fp == NULL) { perror (cmd); - exit (1); + exit (EXIT_FAILURE); } r = fread (buffer, 1, sizeof buffer - 1, fp); if (r == 0) { fprintf (stderr, _("command failed: %s"), cmd); - exit (1); + exit (EXIT_FAILURE); } pclose (fp); buffer[r] = '\0'; @@ -377,7 +377,7 @@ preruncheck (void) "is not statically linked. This is a build error when this test tool\n" "was built.\n"), helper); - exit (1); + exit (EXIT_FAILURE); } } @@ -398,7 +398,7 @@ make_files (void) fd = mkstemp (isof); if (fd == -1) { perror (isof); - exit (1); + exit (EXIT_FAILURE); } close (fd); @@ -408,7 +408,7 @@ make_files (void) if (r == -1 || WEXITSTATUS(r) != 0) { fprintf (stderr, _("mkisofs command failed: %s\n"), cmd); - exit (1); + exit (EXIT_FAILURE); } /* Allocate the sparse file for /dev/sda. */ @@ -416,7 +416,7 @@ make_files (void) if (fd == -1) { perror (tmpf); unlink (isof); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, 100 * 1024 * 1024 - 1, SEEK_SET) == -1) { @@ -424,7 +424,7 @@ make_files (void) close (fd); unlink (tmpf); unlink (isof); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, "\0", 1) == -1) { @@ -432,7 +432,7 @@ make_files (void) close (fd); unlink (tmpf); unlink (isof); - exit (1); + exit (EXIT_FAILURE); } close (fd);