Project

General

Profile

Bug #10047

mktemp(1) sometimes ignores its -p option

Added by Hubert Garavel almost 2 years ago. Updated almost 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2018-12-06
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

On a fresh OpenIndiana installation
(The Illumos Project SunOS 5.11 illumos-7d1eae8c55 December 2018)

the mktemp(1) command seems sensitive to the order of its -p and -t options
and may ignore the existence of "-p DIRECTORY" option, using /tmp rather
than DIRECTORY. The error is strange, as it only occurs if mktemp is invoked
within a shell script, but not from the command-line in a terminal window.
The error also requires that mktemp is invoked without absolute path.

Create a file named SHOWBUG containing the following code

#! /bin/sh

# to know the current shell
echo $SHELL

# to know which mktemp is invoked
which mktemp

# to create a working directory
mkdir -p "$HOME/tmp" 

mktemp -d -p "$HOME/tmp" -t "file.XXXX" 
mktemp -d -t -p "$HOME/tmp" "file.XXXX" 

/bin/mktemp -d -p "$HOME/tmp" -t "file.XXXX" 
/bin/mktemp -d -t -p "$HOME/tmp" "file.XXXX" 

/usr/bin/mktemp -d -p "$HOME/tmp" -t "file.XXXX" 
/usr/bin/mktemp -d -t -p "$HOME/tmp" "file.XXXX" 

Then, type the commands

$ chmod a+rx SHOWBUG
$ ./SHOWBUG

which produces output such as:

/bin/bash
/usr/bin/mktemp
/tmp/file.3k9r
/export/home/cadp/tmp/file.1u8s
/export/home/cadp/tmp/file.IgXR
/export/home/cadp/tmp/file.KoXR
/export/home/cadp/tmp/file.MwXR
/export/home/cadp/tmp/file.NUWR

The 3rd line is clearly incorrect.

The problem does not seem to occur if the commands
are typed in a terminal windows rather than being put
in the SHOWBUG file.

#1

Updated by Gary Mills almost 2 years ago

Which version are you talking about? There are two in OI. One is /usr/bin/mktemp . The other is /usr/gnu/bin/mktemp .

#2

Updated by Hubert Garavel almost 2 years ago

Hi,

/usr/bin/mktemp (this is confirmed by the "which" command in the script)

Also available in: Atom PDF