From: Richard Jones Date: Sat, 4 Apr 2009 09:41:34 +0000 (+0100) Subject: Implemented autosync, make it the default for guestfish. X-Git-Tag: 0.4~18 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=c9cc61940b41b1abb763a1932adfc3461372c10b;ds=sidebyside Implemented autosync, make it the default for guestfish. --- diff --git a/fish/fish.c b/fish/fish.c index fbb26de..90f3a10 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -82,6 +82,7 @@ usage (void) " -h|--cmd-help cmd Display detailed help on 'cmd'\n" " -a image Add image\n" " -m dev[:mnt] Mount dev on mnt (if omitted, /)\n" + " -n|--no-sync Don't autosync\n" /*" --ro|-r All mounts are read-only\n"*/ " -v|--verbose Verbose messages\n" "For more information, see the manpage guestfish(1).\n"); @@ -96,6 +97,7 @@ main (int argc, char *argv[]) { "cmd-help", 2, 0, 'h' }, { "help", 0, 0, '?' }, { "mount", 1, 0, 'm' }, + { "no-sync", 0, 0, 'n' }, { "verbose", 0, 0, 'v' }, { 0, 0, 0, 0 } }; @@ -113,6 +115,8 @@ main (int argc, char *argv[]) exit (1); } + guestfs_set_autosync (g, 1); + for (;;) { c = getopt_long (argc, argv, options, long_options, NULL); if (c == -1) break; @@ -153,6 +157,10 @@ main (int argc, char *argv[]) mps = mp->next; break; + case 'n': + guestfs_set_autosync (g, 0); + break; + case 'v': verbose++; guestfs_set_verbose (g, verbose); diff --git a/guestfs.pod b/guestfs.pod index 70082da..129c681 100644 --- a/guestfs.pod +++ b/guestfs.pod @@ -237,6 +237,22 @@ situations. This returns the current out of memory handler. +=head1 AUTOSYNC + +=head2 guestfs_set_autosync + + void guestfs_set_autosync (guestfs_h *handle, int autosync); + +If C is true, this enables autosync. Libguestfs will make a +best effort attempt to run C when the handle is closed +(also if the program exits without closing handles). + +=head2 guestfs_get_autosync + + int guestfs_get_autosync (guestfs_h *handle); + +Get the autosync flag. + =head1 VERBOSE MESSAGES =head2 guestfs_set_verbose diff --git a/src/guestfs.c b/src/guestfs.c index 0c0a37f..747aae5 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -116,6 +116,7 @@ struct guestfs_h int cmdline_size; int verbose; + int autosync; /* Callbacks. */ guestfs_abort_cb abort_cb; @@ -216,6 +217,10 @@ guestfs_close (guestfs_h *g) if (g->verbose) fprintf (stderr, "closing guestfs handle %p (state %d)\n", g, g->state); + /* Try to sync if autosync flag is set. */ + if (g->autosync && g->state == READY) + guestfs_sync (g); + /* Remove any handlers that might be called back before we kill the * subprocess. */ @@ -378,6 +383,18 @@ guestfs_get_verbose (guestfs_h *g) return g->verbose; } +void +guestfs_set_autosync (guestfs_h *g, int a) +{ + g->autosync = a; +} + +int +guestfs_get_autosync (guestfs_h *g) +{ + return g->autosync; +} + /* Add a string to the current command line. */ static void incr_cmdline_size (guestfs_h *g) diff --git a/src/guestfs.h b/src/guestfs.h index fbfcb3c..3a09b95 100644 --- a/src/guestfs.h +++ b/src/guestfs.h @@ -51,8 +51,11 @@ extern guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g, void ** extern void guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb); extern guestfs_abort_cb guestfs_get_out_of_memory_handler (guestfs_h *g); +/* Misc. */ extern void guestfs_set_verbose (guestfs_h *g, int verbose); extern int guestfs_get_verbose (guestfs_h *g); +extern void guestfs_set_autosync (guestfs_h *g, int a); +extern int guestfs_get_autosync (guestfs_h *g); #include