Bug 1003695 - dhcpd dispatcher script for NetworkManager incorrect logic
Summary: dhcpd dispatcher script for NetworkManager incorrect logic
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: dhcp
Version: 19
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Jiri Popelka
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-09-02 19:24 UTC by Dave Booth
Modified: 2013-11-27 19:32 UTC (History)
3 users (show)

Fixed In Version: dhcp-4.2.5-23.fc19
Clone Of:
Environment:
Last Closed: 2013-11-27 19:19:35 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Dave Booth 2013-09-02 19:24:13 UTC
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 19:56:14 UTC
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 10:03:38 UTC
(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 15:37:09 UTC
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 15:38:06 UTC
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 18:15:40 UTC
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 07:11:54 UTC
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 23:51:33 UTC
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 11:43:43 UTC
(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 11:17:39 UTC
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-28 00:20:34 UTC
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-30 00:28:29 UTC
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 06:46:46 UTC
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 18:43:22 UTC
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 19:19:35 UTC
(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 19:32:39 UTC
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.