Skip to content

run_and_print_on_failure(): fixed mktemp not found on AIX#1834

Merged
larsewi merged 2 commits into
cfengine:masterfrom
larsewi:mktemp
Aug 12, 2025
Merged

run_and_print_on_failure(): fixed mktemp not found on AIX#1834
larsewi merged 2 commits into
cfengine:masterfrom
larsewi:mktemp

Conversation

@larsewi
Copy link
Copy Markdown
Contributor

@larsewi larsewi commented Aug 7, 2025

Ticket: ENT-13158
Signed-off-by: Lars Erik Wik lars.erik.wik@northern.tech

Build on AIX & Ubuntu with no tests
Build Status

@larsewi larsewi marked this pull request as ready for review August 7, 2025 08:47
Comment thread build-scripts/functions Outdated
{
local temp_output_file
temp_output_file=$(mktemp)
if command mktemp; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in functions here there is already func_mktemp(). I think you should move this AIX case there and use that function instead if that fits the bill.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, it only works as mktemp -d

# Only works as mktemp -d /path/to/tmpdir.XXXX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I feel like I have worked around this in other places too :( so maybe let's look a little harder and make a compatibility layer of some sort ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be better to adjust the function we have and augment with what I worked up for cf-support for mktemp -d at https://github.com/cfengine/core/blob/master/misc/cf-support#L116

make_temp_dir()
{
  if command -v mktemp >/dev/null && [ "$OS" != "hpux" ]; then
    mktemp -d
  else
    # shellcheck disable=SC2021
    # ^^ legacy/POSIX requires square brackets
    _tmp="/tmp/`LC_CTYPE=C tr -dc "[A-Z][a-z][0-9]" </dev/urandom | dd count=1 bs=8 2>/dev/null`"
    mkdir "$_tmp"
    echo "$_tmp"
  fi
}

Probably though, the minimal and recommended change would be to add 2>/dev/null in your existing code.

Suggested change
if command mktemp; then
if command -v mktemp 2>/dev/null; then

You want -v so it doesn't run the command and probably 2>/dev/null to keep things quiet. :)

Copy link
Copy Markdown
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just add -v and 2>/dev/null to "command mktemp" and think this is awesome. 👍

Comment thread build-scripts/functions Outdated
{
local temp_output_file
temp_output_file=$(mktemp)
if command mktemp; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be better to adjust the function we have and augment with what I worked up for cf-support for mktemp -d at https://github.com/cfengine/core/blob/master/misc/cf-support#L116

make_temp_dir()
{
  if command -v mktemp >/dev/null && [ "$OS" != "hpux" ]; then
    mktemp -d
  else
    # shellcheck disable=SC2021
    # ^^ legacy/POSIX requires square brackets
    _tmp="/tmp/`LC_CTYPE=C tr -dc "[A-Z][a-z][0-9]" </dev/urandom | dd count=1 bs=8 2>/dev/null`"
    mkdir "$_tmp"
    echo "$_tmp"
  fi
}

Probably though, the minimal and recommended change would be to add 2>/dev/null in your existing code.

Suggested change
if command mktemp; then
if command -v mktemp 2>/dev/null; then

You want -v so it doesn't run the command and probably 2>/dev/null to keep things quiet. :)

…tion

Having the basename printed along side the error message will aid in
debugging by giving you a clue as to where the fatal error happened.

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Ticket: ENT-13158
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
@larsewi larsewi merged commit 0ed3846 into cfengine:master Aug 12, 2025
11 of 12 checks passed
@larsewi larsewi deleted the mktemp branch October 2, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants