From a210cf6a665916057f8be88e064e0b416f58a063 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Wed, 14 Oct 2020 05:11:12 -0600 Subject: [PATCH] interface: set a default hostname property --- libifupdown/interface.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libifupdown/interface.c b/libifupdown/interface.c index 4f5eafb..73e6a52 100644 --- a/libifupdown/interface.c +++ b/libifupdown/interface.c @@ -16,6 +16,7 @@ #include #include +#include #include "libifupdown/interface.h" #include "libifupdown/config-file.h" @@ -121,6 +122,13 @@ lif_interface_init(struct lif_interface *interface, const char *ifname) /* keep the 'vlan' executor as a config hint for backwards compatibility */ if (strchr(ifname, '.') != NULL) lif_interface_use_executor(interface, "vlan"); + + /* learn a reasonable default hostname */ + struct utsname un; + if (uname(&un) < 0) + return; + + lif_dict_add(&interface->vars, "hostname", strdup(un.nodename)); } bool