mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Check for error from some guestfs_set_* calls (found by Coverity).
For some guestfs_set_* calls, add checks for error, when error might possibly occur. eg. It's plausible that guestfs_set_network might fail if the attach-method being used doesn't support it (although this doesn't happen at the moment). In other cases, don't check for errors, eg. if the error doesn't matter or there's nothing we could plausibly do about it.
This commit is contained in:
@@ -269,7 +269,8 @@ main (int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
} else if (STREQ (long_options[option_index].name, "selinux")) {
|
||||
guestfs_set_selinux (g, 1);
|
||||
if (guestfs_set_selinux (g, 1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
} else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
|
||||
keys_from_stdin = 1;
|
||||
} else if (STREQ (long_options[option_index].name, "progress-bars")) {
|
||||
@@ -290,7 +291,8 @@ main (int argc, char *argv[])
|
||||
} else if (STREQ (long_options[option_index].name, "pipe-error")) {
|
||||
pipe_error = 1;
|
||||
} else if (STREQ (long_options[option_index].name, "network")) {
|
||||
guestfs_set_network (g, 1);
|
||||
if (guestfs_set_network (g, 1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
} else {
|
||||
fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
|
||||
program_name, long_options[option_index].name, option_index);
|
||||
|
||||
@@ -219,9 +219,10 @@ main (int argc, char *argv[])
|
||||
dir_cache_timeout = atoi (optarg);
|
||||
else if (STREQ (long_options[option_index].name, "fuse-help"))
|
||||
fuse_help ();
|
||||
else if (STREQ (long_options[option_index].name, "selinux"))
|
||||
guestfs_set_selinux (g, 1);
|
||||
else if (STREQ (long_options[option_index].name, "format")) {
|
||||
else if (STREQ (long_options[option_index].name, "selinux")) {
|
||||
if (guestfs_set_selinux (g, 1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
} else if (STREQ (long_options[option_index].name, "format")) {
|
||||
if (!optarg || STREQ (optarg, ""))
|
||||
format = NULL;
|
||||
else
|
||||
@@ -357,7 +358,8 @@ main (int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* If we're forking, we can't use the recovery process. */
|
||||
guestfs_set_recovery_proc (g, !do_fork);
|
||||
if (guestfs_set_recovery_proc (g, !do_fork) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
/* Do the guest drives and mountpoints. */
|
||||
add_drives (drvs, 'a');
|
||||
|
||||
@@ -156,7 +156,8 @@ main (int argc, char *argv[])
|
||||
switch (c) {
|
||||
case 0: /* options which are long only */
|
||||
if (STREQ (long_options[option_index].name, "selinux")) {
|
||||
guestfs_set_selinux (g, 1);
|
||||
if (guestfs_set_selinux (g, 1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
} else if (STREQ (long_options[option_index].name, "append")) {
|
||||
append = optarg;
|
||||
} else if (STREQ (long_options[option_index].name, "network")) {
|
||||
@@ -309,7 +310,8 @@ main (int argc, char *argv[])
|
||||
usage (EXIT_FAILURE);
|
||||
|
||||
/* Setting "direct mode" is required for the rescue appliance. */
|
||||
guestfs_set_direct (g, 1);
|
||||
if (guestfs_set_direct (g, 1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
/* The libvirt backend doesn't support direct mode. As a temporary
|
||||
* workaround, force the appliance backend, but warn about it.
|
||||
@@ -321,18 +323,22 @@ main (int argc, char *argv[])
|
||||
fprintf (stderr, _("%s: warning: virt-rescue doesn't work with the libvirt backend\n"
|
||||
"at the moment. As a workaround, forcing attach-method = 'appliance'.\n"),
|
||||
program_name);
|
||||
guestfs_set_attach_method (g, "appliance");
|
||||
if (guestfs_set_attach_method (g, "appliance") == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
free (attach_method);
|
||||
}
|
||||
|
||||
/* Set other features. */
|
||||
if (memsize > 0)
|
||||
guestfs_set_memsize (g, memsize);
|
||||
if (guestfs_set_memsize (g, memsize) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
if (network)
|
||||
guestfs_set_network (g, 1);
|
||||
if (guestfs_set_network (g, 1) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
if (smp >= 1)
|
||||
guestfs_set_smp (g, smp);
|
||||
if (guestfs_set_smp (g, smp) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
/* Kernel command line must include guestfs_rescue=1 (see
|
||||
* appliance/init) as well as other options.
|
||||
@@ -340,7 +346,8 @@ main (int argc, char *argv[])
|
||||
append_full = xasprintf ("guestfs_rescue=1%s%s",
|
||||
append ? " " : "",
|
||||
append ? append : "");
|
||||
guestfs_set_append (g, append_full);
|
||||
if (guestfs_set_append (g, append_full) == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
free (append_full);
|
||||
|
||||
/* Add drives. */
|
||||
|
||||
Reference in New Issue
Block a user