Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 374899 - sys-apps/openrc: service_get_value strips \n and returns only one line
Summary: sys-apps/openrc: service_get_value strips \n and returns only one line
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: OpenRC Team
Keywords: InVCS
Depends on:
Blocks: 374183
  Show dependency tree
Reported: 2011-07-12 01:21 UTC by Christian Ruppert (idl0r)
Modified: 2011-07-29 15:48 UTC (History)
1 user (show)

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

rc_getline-rc_service_get_value.patch (DRAFT) (rc_getline-rc_service_get_value.patch,1.23 KB, patch)
2011-07-12 01:21 UTC, Christian Ruppert (idl0r)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Ruppert (idl0r) gentoo-dev 2011-07-12 01:21:47 UTC
Created attachment 279819 [details, diff]
rc_getline-rc_service_get_value.patch (DRAFT)

service_get_value strips \n for no reason IMHO.

Lets take bug 372547 as example.
snipped from
in iproute2_post_start() it'll do:
service_set_value "ip_rule" "${rules}"

This is to save the current ip rules for net.ethN.
So in this case the user added more than one rule which means there must be a \n per line.
That works fine so far, it will be saved as expected but now, when trying to get the value again it will be stripped:
from iproute2_post_stop():
local rules="$(service_get_value "ip_rule")"
_ip_rule_runner del "${rules}"

So here we get only the first rule because a) we only read max. one line and b) even if we loop through the file, \n will be stripped in each line.

Thus we can't do it that way (not yet) to remove the rules.
Well we could do something else in but robbat2 did it on purpose. He argues that the rules could have been changed, so we need to store the same ones  as used in post_start().

This makes sense to me so I played a bit with our rc_getline() function as well as rc_service_get_value.
It now does a) not strip the newline in rc_getline() and b) it reads and returns more than one line if available. It still returns a char *.

It requires some testing/research if we're going to apply it because it *may* break other uses of esp. rc_getline().
Comment 1 SpanKY gentoo-dev 2011-07-12 03:22:50 UTC
i dont think we should be changing rc_getline() semantics.  since you basically want the contents of the file, add a new helper like "rc_getfile()" and use that.

also, side notes:
 - xrealloc(NULL, 10) is the same as xmalloc(10), so you dont need two diff code paths there based on "value"
 - dont cast the return value of alloc funcs as they return (void*)
Comment 2 Christian Ruppert (idl0r) gentoo-dev 2011-07-13 19:43:18 UTC
This has been fixed by the new rc_getfile() function in commit fdaf1c65cdcba2d9b83e02cc0d08fb6dbbd80a80;a=commit;h=fdaf1c65
Comment 3 William Hubbs gentoo-dev 2011-07-29 15:48:43 UTC
I am closing this since it was resolved a while back and it is listed on
the tracker.