Bug 1938223 - no $HOSTNAME in containers
Summary: no $HOSTNAME in containers
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: setup
Version: 33
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Pavel Zhukov
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1952331
TreeView+ depends on / blocked
 
Reported: 2021-03-12 14:07 UTC by Enrico Scholz
Modified: 2021-07-15 08:18 UTC (History)
4 users (show)

Fixed In Version: setup-2.13.9-1.fc35
Clone Of:
: 1952331 (view as bug list)
Environment:
Last Closed: 2021-07-15 08:18:39 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Enrico Scholz 2021-03-12 14:07:36 UTC
Description of problem:

A login shell within containers does not set $HOSTNAME which is bad because e.g. $PS1 requires this variable.

This is caused by

| HOSTNAME=`/usr/bin/hostnamectl --transient  2>/dev/null`

in /etc/profile.

'hostnamectl' might not be installed in containers and when, it is not working there

| $ /usr/bin/hostnamectl --transient
| System has not been booted with systemd as init system (PID 1). Can't operate.
| Failed to connect to bus: Host is down

or

| Failed to create bus connection: No such file or directory


Previous fedora versions used 'HOSTNAME=/bin/hostname' which is better.  But due to missing 'hostname' package in default containers it is not working there either.

Non-login shells are working fine because they do not execute /etc/profile at all and keep $HOSTNAME untouched (it is set by bash internally).

I suggest:

- remove HOSTNAME setting completely when the shell is bash

- use 'uname -n' instead of hostname or hostnamectl, or  
  check the return value and set HOSTNAME only on success

  | if i=`/bin/hostname 2>/dev/null`; then
  |    HOSTNAME=$i
  | fi


Version-Release number of selected component (if applicable):

setup-2.13.7-2.fc33.noarch



How reproducible:

100%


Steps to Reproduce:
1. podman run -it fedora:33 sh -l -c 'echo $HOSTNAME'
2. podman run -it centos:8 sh -l -c 'echo $HOSTNAME'


Actual results:

1. empty output (bad)

2. hostname (container id)


Note You need to log in before you can comment on or make changes to this bug.