summaryrefslogtreecommitdiffstats
path: root/src/launch.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-08-15 15:43:30 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-08-15 17:49:48 +0100
commit46cf4a7e875b828c7a97bd85f577721bce386bc3 (patch)
treeb99aa4912c4c5943bf26a50657df3341552fdd1b /src/launch.c
parent4b8ac437295d5420d3186a913bc3740b69a8d342 (diff)
downloadlibguestfs-46cf4a7e875b828c7a97bd85f577721bce386bc3.tar.gz
libguestfs-46cf4a7e875b828c7a97bd85f577721bce386bc3.tar.xz
libguestfs-46cf4a7e875b828c7a97bd85f577721bce386bc3.zip
launch: Move code to add a drive to the list to separate add_drive utility function.
This is just code motion / simplification.
Diffstat (limited to 'src/launch.c')
-rw-r--r--src/launch.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/launch.c b/src/launch.c
index 8e1c328c..5c023f8c 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -110,14 +110,35 @@ valid_format_iface (const char *str)
return 1;
}
+static void
+add_drive (guestfs_h *g, const char *path,
+ int readonly, const char *format,
+ const char *iface, const char *name,
+ int use_cache_none)
+{
+ struct drive **drv = &(g->drives);
+
+ while (*drv != NULL)
+ drv = &((*drv)->next);
+
+ *drv = safe_malloc (g, sizeof (struct drive));
+ (*drv)->next = NULL;
+ (*drv)->path = safe_strdup (g, path);
+ (*drv)->readonly = readonly;
+ (*drv)->format = format ? safe_strdup (g, format) : NULL;
+ (*drv)->iface = iface ? safe_strdup (g, iface) : NULL;
+ (*drv)->name = name ? safe_strdup (g, name) : NULL;
+ (*drv)->use_cache_none = use_cache_none;
+}
+
int
guestfs__add_drive_opts (guestfs_h *g, const char *filename,
const struct guestfs_add_drive_opts_argv *optargs)
{
int readonly;
- char *format;
- char *iface;
- char *name;
+ const char *format;
+ const char *iface;
+ const char *name;
int use_cache_none;
int is_null;
@@ -130,21 +151,21 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
readonly = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK
? optargs->readonly : 0;
format = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK
- ? safe_strdup (g, optargs->format) : NULL;
+ ? optargs->format : NULL;
iface = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK
- ? safe_strdup (g, optargs->iface) : NULL;
+ ? optargs->iface : NULL;
name = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_NAME_BITMASK
- ? safe_strdup (g, optargs->name) : NULL;
+ ? optargs->name : NULL;
if (format && !valid_format_iface (format)) {
error (g, _("%s parameter is empty or contains disallowed characters"),
"format");
- goto err_out;
+ return -1;
}
if (iface && !valid_format_iface (iface)) {
error (g, _("%s parameter is empty or contains disallowed characters"),
"iface");
- goto err_out;
+ return -1;
}
/* Traditionally you have been able to use /dev/null as a filename,
@@ -171,34 +192,17 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
*/
use_cache_none = readonly ? 0 : test_cache_none (g, filename);
if (use_cache_none == -1)
- goto err_out;
+ return -1;
if (readonly) {
if (access (filename, R_OK) == -1) {
perrorf (g, "%s", filename);
- goto err_out;
+ return -1;
}
}
- struct drive **i = &(g->drives);
- while (*i != NULL) i = &((*i)->next);
-
- *i = safe_malloc (g, sizeof (struct drive));
- (*i)->next = NULL;
- (*i)->path = safe_strdup (g, filename);
- (*i)->readonly = readonly;
- (*i)->format = format;
- (*i)->iface = iface;
- (*i)->name = name;
- (*i)->use_cache_none = use_cache_none;
-
+ add_drive (g, filename, readonly, format, iface, name, use_cache_none);
return 0;
-
-err_out:
- free (format);
- free (iface);
- free (name);
- return -1;
}
int