/* 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
setenv ("SHELL", "/bin/sh", 1);
setenv ("LANG", "C", 1);
+ /* We document that umask defaults to 022 (it should be this anyway). */
+ umask (022);
+
/* Resolve the hostname. */
memset (&hints, 0, sizeof hints);
hints.ai_socktype = SOCK_STREAM;
* 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);
+}