/* 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;
{
int so_size = 0, se_size = 0;
int so_fd[2], se_fd[2];
- int pid, r, quit, i;
+ pid_t pid;
+ int r, quit, i;
fd_set rset, rset2;
char buf[256];
char *p;
* 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')
}
/* Get the exit status of the command. */
- waitpid (pid, &r, 0);
+ if (waitpid (pid, &r, 0) != pid) {
+ perror ("waitpid");
+ return -1;
+ }
if (WIFEXITED (r)) {
return WEXITSTATUS (r);
*
* See guestfs(3) for the algorithm.
*
- * We have to open the device and test for ENODEV, because
+ * We have to open the device and test for ENXIO, because
* the device nodes themselves will exist in the appliance.
*/
int
return 0;
}
- if (errno != ENODEV) {
+ 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);
+}