From: Richard W.M. Jones Date: Wed, 24 Jun 2009 17:25:09 +0000 (+0100) Subject: Generated code for 'mkdtemp' command. X-Git-Tag: 1.0.54~37 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=0574eab8bc7d8e72db862ec36815835938a5fdf1;p=libguestfs.git Generated code for 'mkdtemp' command. --- diff --git a/capitests/tests.c b/capitests/tests.c index 62d4805..9e3c04b 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 17ec338..7f81c1e 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 be97a86..dba0863 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 b94b322..46d6736 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 \n\nThis command creates the directory C and then fills it\nwith files until the filesystem is full, and scrubs the files\nas for C, and deletes them.\nThe intention is to scrub any free space on the partition\ncontaining C.\n\nIt is an interface to the L program. See that\nmanual page for more details."); else + if (strcasecmp (cmd, "mkdtemp") == 0) + pod2text ("mkdtemp - create a temporary directory", " mkdtemp