Bug 1003695 - dhcpd dispatcher script for NetworkManager incorrect logic
dhcpd dispatcher script for NetworkManager incorrect logic
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: dhcp (Show other bugs)
19
All Linux
unspecified Severity high
: ---
: ---
Assigned To: Jiri Popelka
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-09-02 15:24 EDT by Dave Booth
Modified: 2013-11-27 14:32 EST (History)
3 users (show)

See Also:
Fixed In Version: dhcp-4.2.5-23.fc19
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-11-27 14:19:35 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Dave Booth 2013-09-02 15:24:13 EDT
Description of problem:
/etc/NetworkManager/dispatcher.d/12-dhcpd from package dhcp.4.2.5-15.fc19.i686 is supposed to restart dhcpd services if they are enabled when an interface comes up. However, the logic in the test for an enabled service within that script is incorrect.

==========
#!/bin/bash

INTERFACE=$1 # The interface which is brought up or down
STATUS=$2 # The new state of the interface

# whenever interface is brought up by NM (rhbz #565921)
if [ "$STATUS" = "up" ]; then
    # restart the services
    systemctl -q is-enabled dhcpd.service && systemctl restart dhcpd.service
    systemctl -q is-enabled dhcpd6.service && systemctl restart dhcpd6.service
fi
===========

"systemctl -q is-enabled..." returns 0 if the service is enabled, but this logic is looking for a non-zero return status to trigger the restart.

Maybe use an OR pipeline instead?
Comment 1 Dave Booth 2013-09-02 15:56:14 EDT
Second issue: Apparent race condition between calling the dispatcher script and interface startup completing. Correct the logic to an OR pipeline and the service still fails to correctly restart, particularly at boot time.

This script works
===========
#!/bin/bash

INTERFACE=$1 # The interface which is brought up or down
STATUS=$2 # The new state of the interface

# whenever interface is brought up by NM (rhbz #565921)
if [ "$STATUS" = "up" ]; then
    # wait a few seconds to allow interface startup to complete
    # (important at boot time without this the service still fails
    # 2 seconds is too short, 5 seconds works - davebooth)
    sleep 5
    # restart the services
    systemctl -q is-enabled dhcpd.service || systemctl restart dhcpd.service
    systemctl -q is-enabled dhcpd6.service || systemctl restart dhcpd6.service
fi
===========
Comment 2 Jiri Popelka 2013-09-03 06:03:38 EDT
(In reply to Dave Booth from comment #0)
> "systemctl -q is-enabled..." returns 0 if the service is enabled, but this
> logic is looking for a non-zero return status to trigger the restart.

Strange, I've been always thinking that 
in 'command1 && command2' the command2 will be started in case command1 exits with 0 (because 0 return code means success).

Trying
systemctl is-enabled dhcpd.service && echo "it's enabled, restarting"
and
systemctl is-enabled dhcpd.service || echo "it's enabled, restarting"
seems to confirm my belief. Can you check it once more ?


(In reply to Dave Booth from comment #1)
> if [ "$STATUS" = "up" ]; then
>     # wait a few seconds to allow interface startup to complete
>     # (important at boot time without this the service still fails
>     # 2 seconds is too short, 5 seconds works - davebooth)
>     sleep 5

This should be ok. Thanks.
Comment 3 Fedora Update System 2013-09-17 11:37:09 EDT
dhcp-4.2.5-21.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/dhcp-4.2.5-21.fc20
Comment 4 Fedora Update System 2013-09-17 11:38:06 EDT
dhcp-4.2.5-21.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/FEDORA-2013-16621/dhcp-4.2.5-21.fc19
Comment 5 Fedora Update System 2013-09-17 14:15:40 EDT
Package dhcp-4.2.5-21.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing dhcp-4.2.5-21.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2013-16955/dhcp-4.2.5-21.fc20
then log in and leave karma (feedback).
Comment 6 Fedora Update System 2013-09-18 03:11:54 EDT
dhcp-4.2.5-22.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/dhcp-4.2.5-22.fc20
Comment 7 Fedora Update System 2013-09-22 19:51:33 EDT
dhcp-4.2.5-22.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 8 Jiri Popelka 2013-09-24 07:43:43 EDT
(In reply to Dave Booth from comment #1)
> if [ "$STATUS" = "up" ]; then
>     # wait a few seconds to allow interface startup to complete
>     # (important at boot time without this the service still fails
>     # 2 seconds is too short, 5 seconds works - davebooth)
>     sleep 5

Now I see in /var/log/messages:

nm-dispatcher.action: Script '/etc/NetworkManager/dispatcher.d/12-dhcpd' took too long; killing it.
NetworkManager[616]: <warn> Dispatcher script timed out: Script '/etc/NetworkManager/dispatcher.d/12-dhcpd' timed out.

Looking at the NM code [1] I see that the time-out for dispatcher script is 3 seconds. So I tend to decrease the sleep to 2 or remove it at all, what do you think ?

[1] http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/callouts/nm-dispatcher-action.c#n353
Comment 9 Fedora Update System 2013-09-27 07:17:39 EDT
dhcp-4.2.5-23.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/dhcp-4.2.5-23.fc20
Comment 10 Fedora Update System 2013-09-27 20:20:34 EDT
Package dhcp-4.2.5-23.fc19:
* should fix your issue,
* was pushed to the Fedora 19 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing dhcp-4.2.5-23.fc19'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2013-16621/dhcp-4.2.5-23.fc19
then log in and leave karma (feedback).
Comment 11 Fedora Update System 2013-09-29 20:28:29 EDT
dhcp-4.2.5-23.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 12 Fedora Update System 2013-10-02 02:46:46 EDT
dhcp-4.2.5-23.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 13 Vlad 2013-11-27 13:43:22 EST
Fedora 20, dhcp-4.2.5-26.fc20.i686

dhcpd won't start, I'm getting:
Dispatcher script timed out: Script '/etc/NetworkManager/dispatcher.d/12-dhcpd

I've tried to manually start it with systemctl start dhcpd.service and it just hangs there... 
ps ax does show systemctl restart dhcpd.service command running, but doesn't show dhcpd itself is being started. nothing useful in /var/log/*
Comment 14 Jiri Popelka 2013-11-27 14:19:35 EST
(In reply to Vlad from comment #13)
> I've tried to manually start it with systemctl start dhcpd.service and it
> just hangs there... 

Actually, it looks like the dispatcher script timed out because there's some problem with dhcpd.

> ps ax does show systemctl restart dhcpd.service command running, but doesn't
> show dhcpd itself is being started. nothing useful in /var/log/*

Could you run it by hand with 'dhcpd -d' and post the output in a new bug, to not mess this one. Does 'setenforce 0' make any change ?
Comment 15 Vlad 2013-11-27 14:32:39 EST
Jiri - submitted new bug (#1035445), see dhcpd output there. selinux is disabled at startup.

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