All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] Allow setting hostname before userspace starts
@ 2022-05-06  6:03 Dan Moulding
  2022-05-06  6:03 ` [PATCH v2 1/1] init: Add "hostname" kernel parameter Dan Moulding
  2022-05-06  7:23 ` [PATCH v2 0/1] Allow setting hostname before userspace starts Pavel Machek
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Moulding @ 2022-05-06  6:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-doc, tglx, akpm, corbet, Dan Moulding

Some userspace processes may rely on gethostname to always return the
correct machine name. However, the only way that the hostname may be
set is by some other userspace process calling sethostname
first. During boot, if a process that depends on gethostname runs
before sethostname has been called, then the process that called
gethostname is going to get an incorrect result.

A real-world case where this comes up is with mdadm, which if
gethostname returns the wrong name, can cause local md-raid arrays to
appear to be foreign arrays. This can alter how mdadm assembles the
array, or can even cause array assembly to fail. I imagine there are
probbaly other real-world cases where undesirable behavior results when
the hostname is not set early enough.

I'm proposing adding the option to set the hostname from a kernel
parameter, so that the correct host name can be guaranteed to be set
before any userspace process can call gethostname.

I can imagine an even better way to do this would be to have the
hostname written to some non-volatile storage (like a firmware NVRAM
variable or such), which the kernel could read out during early
boot. But, alas, such designs require hardware support, standards, and
cooperation. This proposal is an alternative that can provide a simple
and immediate solution.

v2:
* Use strlcpy instead of strncpy to eliminate W=1 compiler warning
  (assuaging it from its string truncation fears). Thanks to kernel
  test robot for finding this.
* Move "hostname" after "hlt" in kernel-parameters.txt (I promise I
  know my ABCs).

Dan Moulding (1):
  init: Add "hostname" kernel parameter

 Documentation/admin-guide/kernel-parameters.txt | 13 +++++++++++++
 init/version.c                                  | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-06 15:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06  6:03 [PATCH v2 0/1] Allow setting hostname before userspace starts Dan Moulding
2022-05-06  6:03 ` [PATCH v2 1/1] init: Add "hostname" kernel parameter Dan Moulding
2022-05-06  7:23 ` [PATCH v2 0/1] Allow setting hostname before userspace starts Pavel Machek
2022-05-06 15:44   ` Dan Moulding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.