Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 629228 - net-online service not catching errors
Summary: net-online service not catching errors
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-28 18:19 UTC by jon R-B
Modified: 2017-12-13 00:32 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
The solution suggested by jon R-B (net-online.patch,416 bytes, patch)
2017-11-19 14:57 UTC, drserge
Details | Diff
net-online.patch (net-online.patch,748 bytes, patch)
2017-12-11 21:22 UTC, William Hubbs
Details | Diff
net-online.patch (net-online.patch,735 bytes, patch)
2017-12-11 21:29 UTC, William Hubbs
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jon R-B 2017-08-28 18:19:19 UTC
While attempting to make use of rc_need="net-online" in netmount (for cifs) and ntp-client an issue was identified.

/etc/init.d/net-online: line 47: read: read error: 0: Invalid argument
/etc/init.d/net-online: line 48: [: -eq: unary operator expected

/sys/class/net/$dev/carrier is unreadable while an interface is down and the associated lines in /etc/init.d/net-online are not tolerant of this causing timeouts.

Present code:


 	for dev in ${interfaces}; do
		: $((ifcount += 1))
		read x < /sys/class/net/$dev/carrier
		[ $x -eq 1 ] && : $((carriers += 1))
		read x < /sys/class/net/$dev/operstate
		[ "$x" = up ] && : $((configured += 1))


Testing code to work around the issue:

 	for dev in ${interfaces}; do
		: $((ifcount += 1))
		#read x < /sys/class/net/$dev/carrier # jrb comment
		x=0 # jrb added
		read x < /sys/class/net/$dev/carrier 2> /dev/null # jrb added redirect
		[ $x -eq 1 ] && : $((carriers += 1))
		read x < /sys/class/net/$dev/operstate
		[ "$x" = up ] && : $((configured += 1))
Comment 1 William Hubbs gentoo-dev 2017-09-05 17:19:40 UTC
Hi,

pasting changes like this directly into the comments makes it impossible
for me to directly add them to the code. I will take a look at these,
but In the future, please attach patches instead of inlining the
changes.
Comment 2 drserge 2017-11-19 14:57:14 UTC
Created attachment 504960 [details, diff]
The solution suggested by jon R-B

(converted from jon R-B comment)
Comment 3 Marcel Greter 2017-12-09 22:26:20 UTC
Had the same issue and created a PR on the github repo:
https://github.com/OpenRC/openrc/pull/189

Improved the fix from jon R-B a bit, as it is not fixing it fully.
On the first failing try, the variable x would be assigned the
value down from the second check. On a second failing try,
the conditional [ $carrier -eq 1 ] will print an error:
[: down: integer expression expected
Comment 4 William Hubbs gentoo-dev 2017-12-11 21:22:34 UTC
Created attachment 509546 [details, diff]
net-online.patch

I merged the pull request.

However, I would like to know if this works as well. If it does, I would
rather test for existance than suppress the errors.
Comment 5 William Hubbs gentoo-dev 2017-12-11 21:29:08 UTC
Created attachment 509552 [details, diff]
net-online.patch

This is the version of the patch you should test; I missed removing a
redirection.

Thanks,

William
Comment 6 Marcel Greter 2017-12-12 10:51:08 UTC
Unfortunately, checking for existence (or readability) will not be enough, as even though the file is there and readable from a permission standpoint, it can still return EINVAL.

- https://bugzilla.redhat.com/show_bug.cgi?id=1253797
- https://unix.stackexchange.com/questions/252002/help-testing-special-file-in-sys-class-net

Best regards
Comment 7 William Hubbs gentoo-dev 2017-12-13 00:32:13 UTC
This is fixed upstream and will be included in OpenRC 0.35.