From 8228eec99045ae720d8ef35851aa8c278f6b4e5c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 24 Jun 2009 18:22:37 +0100 Subject: [PATCH] Add mkdtemp command. --- daemon/dir.c | 30 ++++++++++++++++++++++++++++++ src/generator.ml | 22 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/daemon/dir.c b/daemon/dir.c index 83536ef..753323d 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -201,3 +201,33 @@ do_is_dir (char *path) return S_ISDIR (buf.st_mode); } + +char * +do_mkdtemp (char *template) +{ + char *r; + + NEED_ROOT (NULL); + ABS_PATH (template, NULL); + + CHROOT_IN; + r = mkdtemp (template); + CHROOT_OUT; + + if (r == NULL) { + reply_with_perror ("mkdtemp: %s", template); + return NULL; + } + + /* The caller will free template AND try to free the return value, + * so we must make a copy here. + */ + if (r == template) { + r = strdup (template); + if (r == NULL) { + reply_with_perror ("strdup"); + return NULL; + } + } + return r; +} diff --git a/src/generator.ml b/src/generator.ml index 51d3235..e378395 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2442,6 +2442,28 @@ containing C. It is an interface to the L program. See that manual page for more details."); + ("mkdtemp", (RString "dir", [String "template"]), 117, [], + [InitBasicFS, Always, TestRun ( + [["mkdir"; "/tmp"]; + ["mkdtemp"; "/tmp/tmpXXXXXX"]])], + "create a temporary directory", + "\ +This command creates a temporary directory. The +C