diff options
-rw-r--r-- | capitests/tests.c | 101 | ||||
-rw-r--r-- | daemon/actions.h | 1 | ||||
-rw-r--r-- | daemon/stubs.c | 30 | ||||
-rw-r--r-- | fish/cmds.c | 24 | ||||
-rw-r--r-- | fish/completion.c | 1 | ||||
-rw-r--r-- | guestfish-actions.pod | 20 | ||||
-rw-r--r-- | guestfs-actions.pod | 24 | ||||
-rw-r--r-- | java/com/redhat/et/libguestfs/GuestFS.java | 31 | ||||
-rw-r--r-- | java/com_redhat_et_libguestfs_GuestFS.c | 21 | ||||
-rw-r--r-- | ocaml/guestfs.ml | 1 | ||||
-rw-r--r-- | ocaml/guestfs.mli | 3 | ||||
-rw-r--r-- | ocaml/guestfs_c_actions.c | 24 | ||||
-rw-r--r-- | perl/Guestfs.xs | 15 | ||||
-rw-r--r-- | perl/lib/Sys/Guestfs.pm | 18 | ||||
-rw-r--r-- | python/guestfs-py.c | 26 | ||||
-rw-r--r-- | python/guestfs.py | 19 | ||||
-rw-r--r-- | ruby/ext/guestfs/_guestfs.c | 26 | ||||
-rw-r--r-- | src/MAX_PROC_NR | 2 | ||||
-rw-r--r-- | src/guestfs-actions.c | 92 | ||||
-rw-r--r-- | src/guestfs-actions.h | 1 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 20 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 17 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 9 |
23 files changed, 523 insertions, 3 deletions
diff --git a/capitests/tests.c b/capitests/tests.c index 62d4805f..9e3c04ba 100644 --- a/capitests/tests.c +++ b/capitests/tests.c @@ -153,6 +153,99 @@ static void no_test_warnings (void) fprintf (stderr, "warning: \"guestfs_scrub_freespace\" has no tests\n"); } +static int test_mkdtemp_0_skip (void) +{ + const char *str; + + str = getenv ("SKIP_TEST_MKDTEMP_0"); + if (str && strcmp (str, "1") == 0) return 1; + str = getenv ("SKIP_TEST_MKDTEMP"); + if (str && strcmp (str, "1") == 0) return 1; + return 0; +} + +static int test_mkdtemp_0 (void) +{ + if (test_mkdtemp_0_skip ()) { + printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdtemp_0"); + return 0; + } + + /* InitBasicFS for test_mkdtemp_0: create ext2 on /dev/sda1 */ + { + char device[] = "/dev/sda"; + 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; + } + { + char device[] = "/dev/sda"; + char lines_0[] = ","; + char *lines[] = { + lines_0, + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, device, 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + char fstype[] = "ext2"; + char device[] = "/dev/sda1"; + int r; + suppress_error = 0; + r = guestfs_mkfs (g, fstype, device); + if (r == -1) + return -1; + } + { + char device[] = "/dev/sda1"; + char mountpoint[] = "/"; + int r; + suppress_error = 0; + r = guestfs_mount (g, device, mountpoint); + if (r == -1) + return -1; + } + /* TestRun for mkdtemp (0) */ + { + char path[] = "/tmp"; + int r; + suppress_error = 0; + r = guestfs_mkdir (g, path); + if (r == -1) + return -1; + } + { + char template[] = "/tmp/tmpXXXXXX"; + char *r; + suppress_error = 0; + r = guestfs_mkdtemp (g, template); + if (r == NULL) + return -1; + free (r); + } + return 0; +} + static int test_scrub_file_0_skip (void) { const char *str; @@ -16313,9 +16406,15 @@ int main (int argc, char *argv[]) /* Cancel previous alarm. */ alarm (0); - nr_tests = 151; + nr_tests = 152; test_num++; + printf ("%3d/%3d test_mkdtemp_0\n", test_num, nr_tests); + if (test_mkdtemp_0 () == -1) { + printf ("test_mkdtemp_0 FAILED\n"); + failed++; + } + test_num++; printf ("%3d/%3d test_scrub_file_0\n", test_num, nr_tests); if (test_scrub_file_0 () == -1) { printf ("test_scrub_file_0 FAILED\n"); diff --git a/daemon/actions.h b/daemon/actions.h index 17ec338c..7f81c1ec 100644 --- a/daemon/actions.h +++ b/daemon/actions.h @@ -137,3 +137,4 @@ extern char **do_glob_expand (char *pattern); extern int do_scrub_device (char *device); extern int do_scrub_file (char *file); extern int do_scrub_freespace (char *dir); +extern char *do_mkdtemp (char *template); diff --git a/daemon/stubs.c b/daemon/stubs.c index be97a863..dba08630 100644 --- a/daemon/stubs.c +++ b/daemon/stubs.c @@ -2926,6 +2926,33 @@ done: xdr_free ((xdrproc_t) xdr_guestfs_scrub_freespace_args, (char *) &args); } +static void mkdtemp_stub (XDR *xdr_in) +{ + char *r; + struct guestfs_mkdtemp_args args; + char *template; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_mkdtemp_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "mkdtemp"); + return; + } + template = args.template; + + r = do_mkdtemp (template); + if (r == NULL) + /* do_mkdtemp has already called reply_with_error */ + goto done; + + struct guestfs_mkdtemp_ret ret; + ret.dir = r; + reply ((xdrproc_t) &xdr_guestfs_mkdtemp_ret, (char *) &ret); + free (r); +done: + xdr_free ((xdrproc_t) xdr_guestfs_mkdtemp_args, (char *) &args); +} + void dispatch_incoming_message (XDR *xdr_in) { switch (proc_nr) { @@ -3277,6 +3304,9 @@ void dispatch_incoming_message (XDR *xdr_in) case GUESTFS_PROC_SCRUB_FREESPACE: scrub_freespace_stub (xdr_in); break; + case GUESTFS_PROC_MKDTEMP: + mkdtemp_stub (xdr_in); + break; default: reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr); } diff --git a/fish/cmds.c b/fish/cmds.c index b94b322a..46d67369 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -108,6 +108,7 @@ void list_commands (void) printf ("%-20s %s\n", "lvs-full", "list the LVM logical volumes (LVs)"); printf ("%-20s %s\n", "mkdir", "create a directory"); printf ("%-20s %s\n", "mkdir-p", "create a directory and parents"); + printf ("%-20s %s\n", "mkdtemp", "create a temporary directory"); printf ("%-20s %s\n", "mkfs", "make a filesystem"); printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem"); printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options"); @@ -584,6 +585,9 @@ void display_command (const char *cmd) if (strcasecmp (cmd, "scrub_freespace") == 0 || strcasecmp (cmd, "scrub-freespace") == 0) pod2text ("scrub-freespace - scrub (securely wipe) free space", " scrub-freespace <dir>\n\nThis command creates the directory C<dir> and then fills it\nwith files until the filesystem is full, and scrubs the files\nas for C<scrub_file>, and deletes them.\nThe intention is to scrub any free space on the partition\ncontaining C<dir>.\n\nIt is an interface to the L<scrub(1)> program. See that\nmanual page for more details."); else + if (strcasecmp (cmd, "mkdtemp") == 0) + pod2text ("mkdtemp - create a temporary directory", " mkdtemp <template>\n\nThis command creates a temporary directory. The\nC<template> parameter should be a full pathname for the\ntemporary directory with the six characters being\n\"XXXXXX\".\n\nFor example: \"/tmp/tmpXXXXXX\" or \"/Temp/tmpXXXXXX\",\nthe second one being suitable for Windows.\n\nThe name of the temporary directory that was created\nis returned.\n\nThe caller is responsible for deleting the temporary\ndirectory and its contents after use.\n\nSee also: L<mkdtemp(3)>"); + else display_builtin_command (cmd); } @@ -2855,6 +2859,23 @@ static int run_scrub_freespace (const char *cmd, int argc, char *argv[]) return r; } +static int run_mkdtemp (const char *cmd, int argc, char *argv[]) +{ + char *r; + const char *template; + 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; + } + template = argv[0]; + r = guestfs_mkdtemp (g, template); + if (r == NULL) return -1; + printf ("%s\n", r); + free (r); + return 0; +} + int run_action (const char *cmd, int argc, char *argv[]) { if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0) @@ -3268,6 +3289,9 @@ int run_action (const char *cmd, int argc, char *argv[]) if (strcasecmp (cmd, "scrub_freespace") == 0 || strcasecmp (cmd, "scrub-freespace") == 0) return run_scrub_freespace (cmd, argc, argv); else + if (strcasecmp (cmd, "mkdtemp") == 0) + return run_mkdtemp (cmd, argc, argv); + else { fprintf (stderr, "%s: unknown command\n", cmd); return -1; diff --git a/fish/completion.c b/fish/completion.c index 92843e56..8564e9d8 100644 --- a/fish/completion.c +++ b/fish/completion.c @@ -183,6 +183,7 @@ static const char *const commands[] = { "scrub-device", "scrub-file", "scrub-freespace", + "mkdtemp", NULL }; diff --git a/guestfish-actions.pod b/guestfish-actions.pod index d4f49301..eee402c6 100644 --- a/guestfish-actions.pod +++ b/guestfish-actions.pod @@ -907,6 +907,26 @@ Create a directory named C<path>. Create a directory named C<path>, creating any parent directories as necessary. This is like the C<mkdir -p> shell command. +=head2 mkdtemp + + mkdtemp template + +This command creates a temporary directory. The +C<template> parameter should be a full pathname for the +temporary directory with the six characters being +"XXXXXX". + +For example: "/tmp/tmpXXXXXX" or "/Temp/tmpXXXXXX", +the second one being suitable for Windows. + +The name of the temporary directory that was created +is returned. + +The caller is responsible for deleting the temporary +directory and its contents after use. + +See also: L<mkdtemp(3)> + =head2 mkfs mkfs fstype device diff --git a/guestfs-actions.pod b/guestfs-actions.pod index 9afa5de9..82746a5a 100644 --- a/guestfs-actions.pod +++ b/guestfs-actions.pod @@ -1191,6 +1191,30 @@ as necessary. This is like the C<mkdir -p> shell command. This function returns 0 on success or -1 on error. +=head2 guestfs_mkdtemp + + char *guestfs_mkdtemp (guestfs_h *handle, + const char *template); + +This command creates a temporary directory. The +C<template> parameter should be a full pathname for the +temporary directory with the six characters being +"XXXXXX". + +For example: "/tmp/tmpXXXXXX" or "/Temp/tmpXXXXXX", +the second one being suitable for Windows. + +The name of the temporary directory that was created +is returned. + +The caller is responsible for deleting the temporary +directory and its contents after use. + +See also: L<mkdtemp(3)> + +This function returns a string, or NULL on error. +I<The caller must free the returned string after use>. + =head2 guestfs_mkfs int guestfs_mkfs (guestfs_h *handle, diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java index 36689700..dff2373b 100644 --- a/java/com/redhat/et/libguestfs/GuestFS.java +++ b/java/com/redhat/et/libguestfs/GuestFS.java @@ -3534,4 +3534,35 @@ public HashMap<String,String> test0rhashtableerr () private native void _scrub_freespace (long g, String dir) throws LibGuestFSException; + /** + * create a temporary directory + * <p> + * This command creates a temporary directory. The + * "template" parameter should be a full pathname for the + * temporary directory with the six characters being + * "XXXXXX". + * <p> + * For example: "/tmp/tmpXXXXXX" or "/Temp/tmpXXXXXX", the + * second one being suitable for Windows. + * <p> + * The name of the temporary directory that was created is + * returned. + * <p> + * The caller is responsible for deleting the temporary + * directory and its contents after use. + * <p> + * See also: mkdtemp(3) + * <p> + * @throws LibGuestFSException + */ + public String mkdtemp (String template) + throws LibGuestFSException + { + if (g == 0) + throw new LibGuestFSException ("mkdtemp: handle is closed"); + return _mkdtemp (g, template); + } + private native String _mkdtemp (long g, String template) + throws LibGuestFSException; + } diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c index 37cd4c9a..3048cef6 100644 --- a/java/com_redhat_et_libguestfs_GuestFS.c +++ b/java/com_redhat_et_libguestfs_GuestFS.c @@ -4124,3 +4124,24 @@ Java_com_redhat_et_libguestfs_GuestFS__1scrub_1freespace } } +JNIEXPORT jstring JNICALL +Java_com_redhat_et_libguestfs_GuestFS__1mkdtemp + (JNIEnv *env, jobject obj, jlong jg, jstring jtemplate) +{ + guestfs_h *g = (guestfs_h *) (long) jg; + jstring jr; + char *r; + const char *template; + + template = (*env)->GetStringUTFChars (env, jtemplate, NULL); + r = guestfs_mkdtemp (g, template); + (*env)->ReleaseStringUTFChars (env, jtemplate, template); + if (r == NULL) { + throw_exception (env, guestfs_last_error (g)); + return NULL; + } + jr = (*env)->NewStringUTF (env, r); + free (r); + return jr; +} + diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml index f0c789ba..a48b5264 100644 --- a/ocaml/guestfs.ml +++ b/ocaml/guestfs.ml @@ -283,3 +283,4 @@ external glob_expand : t -> string -> string array = "ocaml_guestfs_glob_expand" external scrub_device : t -> string -> unit = "ocaml_guestfs_scrub_device" external scrub_file : t -> string -> unit = "ocaml_guestfs_scrub_file" external scrub_freespace : t -> string -> unit = "ocaml_guestfs_scrub_freespace" +external mkdtemp : t -> string -> string = "ocaml_guestfs_mkdtemp" diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli index d93cfdc8..d26d5bb0 100644 --- a/ocaml/guestfs.mli +++ b/ocaml/guestfs.mli @@ -628,3 +628,6 @@ val scrub_file : t -> string -> unit val scrub_freespace : t -> string -> unit (** scrub (securely wipe) free space *) +val mkdtemp : t -> string -> string +(** create a temporary directory *) + diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c index a8204e8a..f4079564 100644 --- a/ocaml/guestfs_c_actions.c +++ b/ocaml/guestfs_c_actions.c @@ -4343,3 +4343,27 @@ ocaml_guestfs_scrub_freespace (value gv, value dirv) CAMLreturn (rv); } +CAMLprim value +ocaml_guestfs_mkdtemp (value gv, value templatev) +{ + CAMLparam2 (gv, templatev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("mkdtemp: used handle after closing it"); + + const char *template = String_val (templatev); + char *r; + + caml_enter_blocking_section (); + r = guestfs_mkdtemp (g, template); + caml_leave_blocking_section (); + if (r == NULL) + ocaml_guestfs_raise_error (g, "mkdtemp"); + + rv = caml_copy_string (r); + free (r); + CAMLreturn (rv); +} + diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs index 4b059101..96b02f9b 100644 --- a/perl/Guestfs.xs +++ b/perl/Guestfs.xs @@ -2635,3 +2635,18 @@ PREINIT: if (r == -1) croak ("scrub_freespace: %s", guestfs_last_error (g)); +SV * +mkdtemp (g, template) + guestfs_h *g; + char *template; +PREINIT: + char *dir; + CODE: + dir = guestfs_mkdtemp (g, template); + if (dir == NULL) + croak ("mkdtemp: %s", guestfs_last_error (g)); + RETVAL = newSVpv (dir, 0); + free (dir); + OUTPUT: + RETVAL + diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm index 9c5aa183..bd2a80c9 100644 --- a/perl/lib/Sys/Guestfs.pm +++ b/perl/lib/Sys/Guestfs.pm @@ -852,6 +852,24 @@ Create a directory named C<path>. Create a directory named C<path>, creating any parent directories as necessary. This is like the C<mkdir -p> shell command. +=item $dir = $h->mkdtemp ($template); + +This command creates a temporary directory. The +C<template> parameter should be a full pathname for the +temporary directory with the six characters being +"XXXXXX". + +For example: "/tmp/tmpXXXXXX" or "/Temp/tmpXXXXXX", +the second one being suitable for Windows. + +The name of the temporary directory that was created +is returned. + +The caller is responsible for deleting the temporary +directory and its contents after use. + +See also: L<mkdtemp(3)> + =item $h->mkfs ($fstype, $device); This creates a filesystem on C<device> (usually a partition diff --git a/python/guestfs-py.c b/python/guestfs-py.c index b1623fe5..263d3d9f 100644 --- a/python/guestfs-py.c +++ b/python/guestfs-py.c @@ -4606,6 +4606,31 @@ py_guestfs_scrub_freespace (PyObject *self, PyObject *args) return py_r; } +static PyObject * +py_guestfs_mkdtemp (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + char *r; + const char *template; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_mkdtemp", + &py_g, &template)) + return NULL; + g = get_handle (py_g); + + r = guestfs_mkdtemp (g, template); + if (r == NULL) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyString_FromString (r); + free (r); + return py_r; +} + static PyMethodDef methods[] = { { (char *) "create", py_guestfs_create, METH_VARARGS, NULL }, { (char *) "close", py_guestfs_close, METH_VARARGS, NULL }, @@ -4777,6 +4802,7 @@ static PyMethodDef methods[] = { { (char *) "scrub_device", py_guestfs_scrub_device, METH_VARARGS, NULL }, { (char *) "scrub_file", py_guestfs_scrub_file, METH_VARARGS, NULL }, { (char *) "scrub_freespace", py_guestfs_scrub_freespace, METH_VARARGS, NULL }, + { (char *) "mkdtemp", py_guestfs_mkdtemp, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; diff --git a/python/guestfs.py b/python/guestfs.py index 0bc041e6..fec12a71 100644 --- a/python/guestfs.py +++ b/python/guestfs.py @@ -1704,3 +1704,22 @@ class GuestFS: """ return libguestfsmod.scrub_freespace (self._o, dir) + def mkdtemp (self, template): + u"""This command creates a temporary directory. The + "template" parameter should be a full pathname for the + temporary directory with the six characters being + "XXXXXX". + + For example: "/tmp/tmpXXXXXX" or "/Temp/tmpXXXXXX", the + second one being suitable for Windows. + + The name of the temporary directory that was created is + returned. + + The caller is responsible for deleting the temporary + directory and its contents after use. + + See also: mkdtemp(3) + """ + return libguestfsmod.mkdtemp (self._o, template) + diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index ba9de13e..5eb892ff 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -4309,6 +4309,30 @@ static VALUE ruby_guestfs_scrub_freespace (VALUE gv, VALUE dirv) return Qnil; } +static VALUE ruby_guestfs_mkdtemp (VALUE gv, VALUE templatev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "mkdtemp"); + + Check_Type (templatev, T_STRING); + const char *template = StringValueCStr (templatev); + if (!template) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "template", "mkdtemp"); + + char *r; + + r = guestfs_mkdtemp (g, template); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + VALUE rv = rb_str_new2 (r); + free (r); + return rv; +} + /* Initialize the module. */ void Init__guestfs () { @@ -4655,4 +4679,6 @@ void Init__guestfs () ruby_guestfs_scrub_file, 1); rb_define_method (c_guestfs, "scrub_freespace", ruby_guestfs_scrub_freespace, 1); + rb_define_method (c_guestfs, "mkdtemp", + ruby_guestfs_mkdtemp, 1); } diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4699eb3c..5bc6609e 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -116 +117 diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 74021053..791c3874 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -10621,3 +10621,95 @@ int guestfs_scrub_freespace (guestfs_h *g, return 0; } +struct mkdtemp_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; + struct guestfs_mkdtemp_ret ret; +}; + +static void mkdtemp_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct mkdtemp_ctx *ctx = (struct mkdtemp_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_mkdtemp"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_mkdtemp"); + 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_mkdtemp"); + return; + } + goto done; + } + if (!xdr_guestfs_mkdtemp_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_mkdtemp"); + return; + } + done: + ctx->cb_sequence = 1; +} + +char *guestfs_mkdtemp (guestfs_h *g, + const char *template) +{ + struct guestfs_mkdtemp_args args; + struct mkdtemp_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_mkdtemp") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + args.template = (char *) template; + serial = guestfs__send_sync (g, GUESTFS_PROC_MKDTEMP, + (xdrproc_t) xdr_guestfs_mkdtemp_args, (char *) &args); + if (serial == -1) { + guestfs_end_busy (g); + return NULL; + } + + guestfs__switch_to_receiving (g); + ctx.cb_sequence = 0; + guestfs_set_reply_callback (g, mkdtemp_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_mkdtemp"); + guestfs_end_busy (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDTEMP, serial) == -1) { + guestfs_end_busy (g); + return NULL; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + free (ctx.err.error_message); + guestfs_end_busy (g); + return NULL; + } + + guestfs_end_busy (g); + return ctx.ret.dir; /* caller will free */ +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 0f85df7a..d2f026c1 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -187,3 +187,4 @@ extern char **guestfs_glob_expand (guestfs_h *handle, const char *pattern); extern int guestfs_scrub_device (guestfs_h *handle, const char *device); extern int guestfs_scrub_file (guestfs_h *handle, const char *file); extern int guestfs_scrub_freespace (guestfs_h *handle, const char *dir); +extern char *guestfs_mkdtemp (guestfs_h *handle, const char *template); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index a241aa0e..e8aea4bf 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1963,6 +1963,26 @@ xdr_guestfs_scrub_freespace_args (XDR *xdrs, guestfs_scrub_freespace_args *objp) } bool_t +xdr_guestfs_mkdtemp_args (XDR *xdrs, guestfs_mkdtemp_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->template, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_mkdtemp_ret (XDR *xdrs, guestfs_mkdtemp_ret *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->dir, ~0)) + return FALSE; + return TRUE; +} + +bool_t xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp) { register int32_t *buf; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index dc88c70f..df91dd40 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -997,6 +997,16 @@ struct guestfs_scrub_freespace_args { }; typedef struct guestfs_scrub_freespace_args guestfs_scrub_freespace_args; +struct guestfs_mkdtemp_args { + char *template; +}; +typedef struct guestfs_mkdtemp_args guestfs_mkdtemp_args; + +struct guestfs_mkdtemp_ret { + char *dir; +}; +typedef struct guestfs_mkdtemp_ret guestfs_mkdtemp_ret; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1114,7 +1124,8 @@ enum guestfs_procedure { GUESTFS_PROC_SCRUB_DEVICE = 114, GUESTFS_PROC_SCRUB_FILE = 115, GUESTFS_PROC_SCRUB_FREESPACE = 116, - GUESTFS_PROC_NR_PROCS = 116 + 1, + GUESTFS_PROC_MKDTEMP = 117, + GUESTFS_PROC_NR_PROCS = 117 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1324,6 +1335,8 @@ extern bool_t xdr_guestfs_glob_expand_ret (XDR *, guestfs_glob_expand_ret*); extern bool_t xdr_guestfs_scrub_device_args (XDR *, guestfs_scrub_device_args*); extern bool_t xdr_guestfs_scrub_file_args (XDR *, guestfs_scrub_file_args*); extern bool_t xdr_guestfs_scrub_freespace_args (XDR *, guestfs_scrub_freespace_args*); +extern bool_t xdr_guestfs_mkdtemp_args (XDR *, guestfs_mkdtemp_args*); +extern bool_t xdr_guestfs_mkdtemp_ret (XDR *, guestfs_mkdtemp_ret*); 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*); @@ -1492,6 +1505,8 @@ extern bool_t xdr_guestfs_glob_expand_ret (); extern bool_t xdr_guestfs_scrub_device_args (); extern bool_t xdr_guestfs_scrub_file_args (); extern bool_t xdr_guestfs_scrub_freespace_args (); +extern bool_t xdr_guestfs_mkdtemp_args (); +extern bool_t xdr_guestfs_mkdtemp_ret (); extern bool_t xdr_guestfs_procedure (); extern bool_t xdr_guestfs_message_direction (); extern bool_t xdr_guestfs_message_status (); diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x index 094200eb..13dbb532 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -768,6 +768,14 @@ struct guestfs_scrub_freespace_args { string dir<>; }; +struct guestfs_mkdtemp_args { + string template<>; +}; + +struct guestfs_mkdtemp_ret { + string dir<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -885,6 +893,7 @@ enum guestfs_procedure { GUESTFS_PROC_SCRUB_DEVICE = 114, GUESTFS_PROC_SCRUB_FILE = 115, GUESTFS_PROC_SCRUB_FREESPACE = 116, + GUESTFS_PROC_MKDTEMP = 117, GUESTFS_PROC_NR_PROCS }; |