diff options
| author | Ron Yorston <rmy@tigress.co.uk> | 2012-10-08 11:47:22 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-10-08 11:47:22 +0200 |
| commit | eab343e7e1e5331df833aa69f14584e4a6c738f1 (patch) | |
| tree | ca06fdb10773a4ff8481cb72468849c7b55cf150 /debianutils | |
| parent | 8dc6d1a813e2be33ecfcf3fa97a1b5aae05a8631 (diff) | |
| download | busybox-w32-eab343e7e1e5331df833aa69f14584e4a6c738f1.tar.gz busybox-w32-eab343e7e1e5331df833aa69f14584e4a6c738f1.tar.bz2 busybox-w32-eab343e7e1e5331df833aa69f14584e4a6c738f1.zip | |
mktemp: fix mktemp -u temp.XXXXXX returning garbage when TMPDIR is set
Use mktemp instead of tempnam for compatibility with real mktemp.
Don't let mktemp fail silently, print some simple error messages.
Don't ignore -q.
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/mktemp.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index dbe430955..983d7a246 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c | |||
| @@ -38,7 +38,7 @@ | |||
| 38 | //usage: "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n" | 38 | //usage: "TEMPLATE must end with XXXXXX (e.g. [/dir/]nameXXXXXX).\n" |
| 39 | //usage: "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n" | 39 | //usage: "Without TEMPLATE, -t tmp.XXXXXX is assumed.\n" |
| 40 | //usage: "\n -d Make directory, not file" | 40 | //usage: "\n -d Make directory, not file" |
| 41 | ////usage: "\n -q Fail silently on errors" - we ignore this opt | 41 | //usage: "\n -q Fail silently on errors" |
| 42 | //usage: "\n -t Prepend base directory name to TEMPLATE" | 42 | //usage: "\n -t Prepend base directory name to TEMPLATE" |
| 43 | //usage: "\n -p DIR Use DIR as a base directory (implies -t)" | 43 | //usage: "\n -p DIR Use DIR as a base directory (implies -t)" |
| 44 | //usage: "\n -u Do not create anything; print a name" | 44 | //usage: "\n -u Do not create anything; print a name" |
| @@ -71,7 +71,6 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 71 | if (!path || path[0] == '\0') | 71 | if (!path || path[0] == '\0') |
| 72 | path = "/tmp"; | 72 | path = "/tmp"; |
| 73 | 73 | ||
| 74 | /* -q is ignored */ | ||
| 75 | opt_complementary = "?1"; /* 1 argument max */ | 74 | opt_complementary = "?1"; /* 1 argument max */ |
| 76 | opts = getopt32(argv, "dqtp:u", &path); | 75 | opts = getopt32(argv, "dqtp:u", &path); |
| 77 | 76 | ||
| @@ -83,33 +82,32 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 83 | chp = xstrdup("tmp.XXXXXX"); | 82 | chp = xstrdup("tmp.XXXXXX"); |
| 84 | opts |= OPT_t; | 83 | opts |= OPT_t; |
| 85 | } | 84 | } |
| 86 | 85 | #if 0 | |
| 87 | if (opts & OPT_u) { | 86 | /* Don't allow directory separator in template */ |
| 88 | /* Remove (up to) 6 X's */ | 87 | if ((opts & OPT_t) && bb_basename(chp) != chp) { |
| 89 | unsigned len = strlen(chp); | 88 | errno = EINVAL; |
| 90 | int cnt = len > 6 ? 6 : len; | 89 | goto error; |
| 91 | while (--cnt >= 0 && chp[--len] == 'X') | ||
| 92 | chp[len] = '\0'; | ||
| 93 | |||
| 94 | chp = tempnam(opts & (OPT_t|OPT_p) ? path : "./", chp); | ||
| 95 | if (!chp) | ||
| 96 | return EXIT_FAILURE; | ||
| 97 | if (!(opts & (OPT_t|OPT_p))) | ||
| 98 | chp += 2; | ||
| 99 | goto ret; | ||
| 100 | } | 90 | } |
| 101 | 91 | #endif | |
| 102 | if (opts & (OPT_t|OPT_p)) | 92 | if (opts & (OPT_t|OPT_p)) |
| 103 | chp = concat_path_file(path, chp); | 93 | chp = concat_path_file(path, chp); |
| 104 | 94 | ||
| 105 | if (opts & OPT_d) { | 95 | if (opts & OPT_u) { |
| 96 | chp = mktemp(chp); | ||
| 97 | if (chp[0] == '\0') | ||
| 98 | goto error; | ||
| 99 | } else if (opts & OPT_d) { | ||
| 106 | if (mkdtemp(chp) == NULL) | 100 | if (mkdtemp(chp) == NULL) |
| 107 | return EXIT_FAILURE; | 101 | goto error; |
| 108 | } else { | 102 | } else { |
| 109 | if (mkstemp(chp) < 0) | 103 | if (mkstemp(chp) < 0) |
| 110 | return EXIT_FAILURE; | 104 | goto error; |
| 111 | } | 105 | } |
| 112 | ret: | ||
| 113 | puts(chp); | 106 | puts(chp); |
| 114 | return EXIT_SUCCESS; | 107 | return EXIT_SUCCESS; |
| 108 | error: | ||
| 109 | if (opts & OPT_q) | ||
| 110 | return EXIT_FAILURE; | ||
| 111 | /* don't use chp as it gets mangled in case of error */ | ||
| 112 | bb_perror_nomsg_and_die(); | ||
| 115 | } | 113 | } |
