/* libguestfs - the guestfsd daemon
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
int verbose = 0;
+/* Location to mount root device. */
+const char *sysroot = "/sysroot"; /* No trailing slash. */
+int sysroot_len = 8;
+
int
main (int argc, char *argv[])
{
exit (0);
}
+/* Turn "/path" into "/sysroot/path".
+ *
+ * Caller must check for NULL and call reply_with_perror ("malloc")
+ * if it is. Caller must also free the string.
+ */
+char *
+sysroot_path (const char *path)
+{
+ char *r;
+ int len = strlen (path) + sysroot_len + 1;
+
+ r = malloc (len);
+ if (r == NULL)
+ return NULL;
+
+ snprintf (r, len, "%s%s", sysroot, path);
+ return r;
+}
+
int
xwrite (int sock, const void *buf, size_t len)
{
* trailing \n characters from the error buffer (not from stdout).
*/
if (stdoutput) {
- *stdoutput = realloc (*stdoutput, so_size+1);
- if (*stdoutput == NULL) {
+ void *q = realloc (*stdoutput, so_size+1);
+ if (q == NULL) {
perror ("realloc");
- *stdoutput = NULL;
- } else
+ free (*stdoutput);
+ }
+ *stdoutput = q;
+ if (*stdoutput)
(*stdoutput)[so_size] = '\0';
}
if (stderror) {
- *stderror = realloc (*stderror, se_size+1);
- if (*stderror == NULL) {
+ void *q = realloc (*stderror, se_size+1);
+ if (q == NULL) {
perror ("realloc");
- *stderror = NULL;
- } else {
+ free (*stderror);
+ }
+ *stderror = q;
+ if (*stderror) {
(*stderror)[se_size] = '\0';
se_size--;
while (se_size >= 0 && (*stderror)[se_size] == '\n')
return 0;
}
- if (errno != ENXIO) {
+ if (errno != ENXIO && errno != ENOENT) {
error:
reply_with_perror ("%s: %s", func, device);
return -1;
device[5] = 's'; /* Restore original device name. */
goto error;
}
+
+/* LVM and other commands aren't synchronous, especially when udev is
+ * involved. eg. You can create or remove some device, but the /dev
+ * device node won't appear until some time later. This means that
+ * you get an error if you run one command followed by another.
+ * Use 'udevadm settle' after certain commands, but don't be too
+ * fussed if it fails.
+ */
+void
+udev_settle (void)
+{
+ command (NULL, NULL, "/sbin/udevadm", "settle", NULL);
+}