fprintf (stderr, "warning: \"guestfs_e2fsck_f\" has no tests\n");
}
+static int test_sleep_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_SLEEP_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_SLEEP");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_sleep_0 (void)
+{
+ if (test_sleep_0_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_sleep_0");
+ return 0;
+ }
+
+ /* InitNone|InitEmpty for test_sleep_0 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ /* TestRun for sleep (0) */
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_sleep (g, 1);
+ if (r == -1)
+ return -1;
+ }
+ return 0;
+}
+
static int test_find_0_skip (void)
{
const char *str;
free (devs[i]);
free (devs);
- nr_tests = 143;
+ nr_tests = 144;
test_num++;
+ printf ("%3d/%3d test_sleep_0\n", test_num, nr_tests);
+ if (test_sleep_0 () == -1) {
+ printf ("test_sleep_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_find_0\n", test_num, nr_tests);
if (test_find_0 () == -1) {
printf ("test_find_0 FAILED\n");
extern int do_resize2fs (const char *device);
extern char **do_find (const char *directory);
extern int do_e2fsck_f (const char *device);
+extern int do_sleep (int secs);
xdr_free ((xdrproc_t) xdr_guestfs_e2fsck_f_args, (char *) &args);
}
+static void sleep_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_sleep_args args;
+ int secs;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_sleep_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "sleep");
+ return;
+ }
+ secs = args.secs;
+
+ r = do_sleep (secs);
+ if (r == -1)
+ /* do_sleep has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_sleep_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_E2FSCK_F:
e2fsck_f_stub (xdr_in);
break;
+ case GUESTFS_PROC_SLEEP:
+ sleep_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "sfdisk-disk-geometry", "display the disk geometry from the partition table");
printf ("%-20s %s\n", "sfdisk-kernel-geometry", "display the kernel geometry");
printf ("%-20s %s\n", "sfdisk-l", "display the partition table");
+ printf ("%-20s %s\n", "sleep", "sleep for some seconds");
printf ("%-20s %s\n", "stat", "get file information");
printf ("%-20s %s\n", "statvfs", "get file system statistics");
printf ("%-20s %s\n", "strings", "print the printable strings in a file");
if (strcasecmp (cmd, "e2fsck_f") == 0 || strcasecmp (cmd, "e2fsck-f") == 0)
pod2text ("e2fsck-f - check an ext2/ext3 filesystem", " e2fsck-f <device>\n\nThis runs C<e2fsck -p -f device>, ie. runs the ext2/ext3\nfilesystem checker on C<device>, noninteractively (C<-p>),\neven if the filesystem appears to be clean (C<-f>).\n\nThis command is only needed because of C<resize2fs>\n(q.v.). Normally you should use C<fsck>.");
else
+ if (strcasecmp (cmd, "sleep") == 0)
+ pod2text ("sleep - sleep for some seconds", " sleep <secs>\n\nSleep for C<secs> seconds.");
+ else
display_builtin_command (cmd);
}
return r;
}
+static int run_sleep (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ int secs;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ secs = atoi (argv[0]);
+ r = guestfs_sleep (g, secs);
+ return r;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "e2fsck_f") == 0 || strcasecmp (cmd, "e2fsck-f") == 0)
return run_e2fsck_f (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "sleep") == 0)
+ return run_sleep (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"resize2fs",
"find",
"e2fsck-f",
+ "sleep",
NULL
};
human-readable output of the L<sfdisk(8)> command. It is
not intended to be parsed.
+=head2 sleep
+
+ sleep secs
+
+Sleep for C<secs> seconds.
+
=head2 stat
stat path
This function returns a string, or NULL on error.
I<The caller must free the returned string after use>.
+=head2 guestfs_sleep
+
+ int guestfs_sleep (guestfs_h *handle,
+ int secs);
+
+Sleep for C<secs> seconds.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_stat
struct guestfs_stat *guestfs_stat (guestfs_h *handle,
private native void _e2fsck_f (long g, String device)
throws LibGuestFSException;
+ /**
+ * sleep for some seconds
+ * <p>
+ * Sleep for "secs" seconds.
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public void sleep (int secs)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("sleep: handle is closed");
+ _sleep (g, secs);
+ }
+ private native void _sleep (long g, int secs)
+ throws LibGuestFSException;
+
}
}
}
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1sleep
+ (JNIEnv *env, jobject obj, jlong jg, jint jsecs)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ int secs;
+
+ secs = jsecs;
+ r = guestfs_sleep (g, secs);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
external resize2fs : t -> string -> unit = "ocaml_guestfs_resize2fs"
external find : t -> string -> string array = "ocaml_guestfs_find"
external e2fsck_f : t -> string -> unit = "ocaml_guestfs_e2fsck_f"
+external sleep : t -> int -> unit = "ocaml_guestfs_sleep"
val e2fsck_f : t -> string -> unit
(** check an ext2/ext3 filesystem *)
+val sleep : t -> int -> unit
+(** sleep for some seconds *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_sleep (value gv, value secsv)
+{
+ CAMLparam2 (gv, secsv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("sleep: used handle after closing it");
+
+ int secs = Int_val (secsv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_sleep (g, secs);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "sleep");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
if (r == -1)
croak ("e2fsck_f: %s", guestfs_last_error (g));
+void
+sleep (g, secs)
+ guestfs_h *g;
+ int secs;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_sleep (g, secs);
+ if (r == -1)
+ croak ("sleep: %s", guestfs_last_error (g));
+
human-readable output of the L<sfdisk(8)> command. It is
not intended to be parsed.
+=item $h->sleep ($secs);
+
+Sleep for C<secs> seconds.
+
=item %statbuf = $h->stat ($path);
Returns file information for the given C<path>.
return py_r;
}
+static PyObject *
+py_guestfs_sleep (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ int secs;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oi:guestfs_sleep",
+ &py_g, &secs))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_sleep (g, secs);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
{ (char *) "resize2fs", py_guestfs_resize2fs, METH_VARARGS, NULL },
{ (char *) "find", py_guestfs_find, METH_VARARGS, NULL },
{ (char *) "e2fsck_f", py_guestfs_e2fsck_f, METH_VARARGS, NULL },
+ { (char *) "sleep", py_guestfs_sleep, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.e2fsck_f (self._o, device)
+ def sleep (self, secs):
+ u"""Sleep for "secs" seconds.
+ """
+ return libguestfsmod.sleep (self._o, secs)
+
return Qnil;
}
+static VALUE ruby_guestfs_sleep (VALUE gv, VALUE secsv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "sleep");
+
+ int secs = NUM2INT (secsv);
+
+ int r;
+
+ r = guestfs_sleep (g, secs);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_find, 1);
rb_define_method (c_guestfs, "e2fsck_f",
ruby_guestfs_e2fsck_f, 1);
+ rb_define_method (c_guestfs, "sleep",
+ ruby_guestfs_sleep, 1);
}
return 0;
}
+struct sleep_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void sleep_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct sleep_ctx *ctx = (struct sleep_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_sleep");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_sleep");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_sleep");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_sleep (guestfs_h *g,
+ int secs)
+{
+ struct guestfs_sleep_args args;
+ struct sleep_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_sleep") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.secs = secs;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_SLEEP,
+ (xdrproc_t) xdr_guestfs_sleep_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, sleep_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_sleep");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SLEEP, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
extern int guestfs_resize2fs (guestfs_h *handle, const char *device);
extern char **guestfs_find (guestfs_h *handle, const char *directory);
extern int guestfs_e2fsck_f (guestfs_h *handle, const char *device);
+extern int guestfs_sleep (guestfs_h *handle, int secs);
}
bool_t
+xdr_guestfs_sleep_args (XDR *xdrs, guestfs_sleep_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_int (xdrs, &objp->secs))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
};
typedef struct guestfs_e2fsck_f_args guestfs_e2fsck_f_args;
+struct guestfs_sleep_args {
+ int secs;
+};
+typedef struct guestfs_sleep_args guestfs_sleep_args;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_RESIZE2FS = 106,
GUESTFS_PROC_FIND = 107,
GUESTFS_PROC_E2FSCK_F = 108,
- GUESTFS_PROC_NR_PROCS = 108 + 1,
+ GUESTFS_PROC_SLEEP = 109,
+ GUESTFS_PROC_NR_PROCS = 109 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_find_args (XDR *, guestfs_find_args*);
extern bool_t xdr_guestfs_find_ret (XDR *, guestfs_find_ret*);
extern bool_t xdr_guestfs_e2fsck_f_args (XDR *, guestfs_e2fsck_f_args*);
+extern bool_t xdr_guestfs_sleep_args (XDR *, guestfs_sleep_args*);
extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*);
extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*);
extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*);
extern bool_t xdr_guestfs_find_args ();
extern bool_t xdr_guestfs_find_ret ();
extern bool_t xdr_guestfs_e2fsck_f_args ();
+extern bool_t xdr_guestfs_sleep_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
string device<>;
};
+struct guestfs_sleep_args {
+ int secs;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_RESIZE2FS = 106,
GUESTFS_PROC_FIND = 107,
GUESTFS_PROC_E2FSCK_F = 108,
+ GUESTFS_PROC_SLEEP = 109,
GUESTFS_PROC_NR_PROCS
};