check the pid is > 0 before calling waitpid()
[libguestfs.git] / src / guestfs.c
index e4f74e0..8b7ab4d 100644 (file)
@@ -189,10 +189,8 @@ guestfs_close (guestfs_h *g)
   guestfs___free_inspect_info (g);
 
   /* Try to sync if autosync flag is set. */
-  if (g->autosync && g->state == READY) {
-    guestfs_umount_all (g);
-    guestfs_sync (g);
-  }
+  if (g->autosync && g->state == READY)
+    guestfs_internal_autosync (g);
 
   /* Remove any handlers that might be called back before we kill the
    * subprocess.
@@ -427,6 +425,22 @@ guestfs_safe_memdup (guestfs_h *g, void *ptr, size_t size)
   return p;
 }
 
+char *
+guestfs_safe_asprintf (guestfs_h *g, const char *fs, ...)
+{
+  va_list args;
+  char *msg;
+
+  va_start (args, fs);
+  int err = vasprintf (&msg, fs, args);
+  va_end (args);
+
+  if (err == -1)
+    g->abort_cb ();
+
+  return msg;
+}
+
 void
 guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb cb)
 {
@@ -631,6 +645,51 @@ guestfs__get_network (guestfs_h *g)
   return g->enable_network;
 }
 
+int
+guestfs__set_attach_method (guestfs_h *g, const char *method)
+{
+  if (STREQ (method, "appliance")) {
+    g->attach_method = ATTACH_METHOD_APPLIANCE;
+    free (g->attach_method_arg);
+    g->attach_method_arg = NULL;
+  }
+  else if (STRPREFIX (method, "unix:") && strlen (method) > 5) {
+    g->attach_method = ATTACH_METHOD_UNIX;
+    free (g->attach_method_arg);
+    g->attach_method_arg = safe_strdup (g, method + 5);
+    /* Note that we don't check the path exists until launch is called. */
+  }
+  else {
+    error (g, "invalid attach method: %s", method);
+    return -1;
+  }
+
+  return 0;
+}
+
+char *
+guestfs__get_attach_method (guestfs_h *g)
+{
+  char *ret;
+
+  switch (g->attach_method) {
+  case ATTACH_METHOD_APPLIANCE:
+    ret = safe_strdup (g, "appliance");
+    break;
+
+  case ATTACH_METHOD_UNIX:
+    ret = safe_malloc (g, strlen (g->attach_method_arg) + 5 + 1);
+    strcpy (ret, "unix:");
+    strcat (ret, g->attach_method_arg);
+    break;
+
+  default: /* keep GCC happy - this is not reached */
+    abort ();
+  }
+
+  return ret;
+}
+
 void
 guestfs_set_log_message_callback (guestfs_h *g,
                                   guestfs_log_message_cb cb, void *opaque)
@@ -774,3 +833,18 @@ guestfs___print_BufferIn (FILE *out, const char *buf, size_t buf_size)
     fprintf (out,
              _("<truncated, original size %zu bytes>"), orig_size);
 }
+
+void
+guestfs___print_BufferOut (FILE *out, const char *buf, size_t buf_size)
+{
+  guestfs___print_BufferIn (out, buf, buf_size);
+}
+
+void
+guestfs___free_string_list (char **argv)
+{
+  size_t i;
+  for (i = 0; argv[i] != NULL; ++i)
+    free (argv[i]);
+  free (argv);
+}