[__hostname] Remove incorrectly sent messages (again)

The --onchage sent the message on the target where messaging is not supported.

Now the result is that a "changed" message is only emitted when the running
hostname changes, not when the persistent hostname changes.
This commit is contained in:
Dennis Camera 2019-10-26 17:25:44 +02:00
parent e7279680ed
commit f276813f7f
1 changed files with 8 additions and 14 deletions

View File

@ -20,8 +20,6 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
onchange_cmd="echo changed >>'$__messages_out'"
not_supported() { not_supported() {
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2 echo "Please contribute an implementation for it if you can." >&2
@ -29,7 +27,7 @@ not_supported() {
} }
set_hostname_systemd() { set_hostname_systemd() {
echo "$1" | __file /etc/hostname --source - --onchange "$onchange_cmd" echo "$1" | __file /etc/hostname --source -
} }
os=$(cat "$__global/explorer/os") os=$(cat "$__global/explorer/os")
@ -64,7 +62,7 @@ case $os
in in
alpine|debian|devuan|ubuntu) alpine|debian|devuan|ubuntu)
echo "$name_should" \ echo "$name_should" \
| __file /etc/hostname --source - --onchange "$onchange_cmd" | __file /etc/hostname --source -
;; ;;
macosx) macosx)
# handled in gencode-remote # handled in gencode-remote
@ -81,8 +79,7 @@ in
--file /etc/rc.conf \ --file /etc/rc.conf \
--delimiter '=' --exact_delimiter \ --delimiter '=' --exact_delimiter \
--key 'HOSTNAME' \ --key 'HOSTNAME' \
--value "\"$name_should\"" \ --value "\"$name_should\""
--onchange "$onchange_cmd"
fi fi
;; ;;
centos|fedora|redhat|scientific) centos|fedora|redhat|scientific)
@ -94,8 +91,7 @@ in
--file /etc/sysconfig/network \ --file /etc/sysconfig/network \
--delimiter '=' --exact_delimiter \ --delimiter '=' --exact_delimiter \
--key HOSTNAME \ --key HOSTNAME \
--value "\"$name_should\"" \ --value "\"$name_should\""
--onchange "$onchange_cmd"
else else
set_hostname_systemd "$name_should" set_hostname_systemd "$name_should"
fi fi
@ -119,29 +115,27 @@ in
--file /etc/rc.conf \ --file /etc/rc.conf \
--delimiter '=' --exact_delimiter \ --delimiter '=' --exact_delimiter \
--key 'hostname' \ --key 'hostname' \
--value "\"$name_should\"" \ --value "\"$name_should\""
--onchange "$onchange_cmd"
;; ;;
netbsd) netbsd)
__key_value rcconf-hostname \ __key_value rcconf-hostname \
--file /etc/rc.conf \ --file /etc/rc.conf \
--delimiter '=' --exact_delimiter \ --delimiter '=' --exact_delimiter \
--key 'hostname' \ --key 'hostname' \
--value "\"$name_should\"" \ --value "\"$name_should\""
--onchange "$onchange_cmd"
# To avoid confusion, ensure that the hostname is only stored once # To avoid confusion, ensure that the hostname is only stored once
__file /etc/myname --state absent __file /etc/myname --state absent
;; ;;
openbsd) openbsd)
echo "$name_should" \ echo "$name_should" \
| __file /etc/myname --source - --onchange "$onchange_cmd" | __file /etc/myname --source -
;; ;;
suse) suse)
# We write into /etc/HOSTNAME for backwards-compatibility. Modern SuSE # We write into /etc/HOSTNAME for backwards-compatibility. Modern SuSE
# has hostnamectl anyway and symlinks /etc/HOSTNAME to /etc/hostname. # has hostnamectl anyway and symlinks /etc/HOSTNAME to /etc/hostname.
echo "$name_should" \ echo "$name_should" \
| __file /etc/HOSTNAME --source - --onchange "$onchange_cmd" | __file /etc/HOSTNAME --source -
;; ;;
*) *)
# On other operating systems we fall back to systemd's hostnamectl if available… # On other operating systems we fall back to systemd's hostnamectl if available…