Bug 1264080

Summary: sysctl returns exit code 0 even on failure
Product: Red Hat Enterprise Linux 7 Reporter: Tereza Cerna <tcerna>
Component: procps-ngAssignee: Jan Rybar <jrybar>
Status: CLOSED WONTFIX QA Contact: qe-baseos-daemons
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: bnater, fedoraproject, jeder, jishi, jskarvad, kdudka
Target Milestone: rcKeywords: MoveUpstream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-12-15 07:36:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tereza Cerna 2015-09-17 13:00:02 UTC
Sysctl does not work in tuned-2.5.1-3.el7.noarch. It is working in fedora, but not in RHEL.

Value is not set up:

1] Try to set up value directly with sysctl:

  $ sysctl -n kernel.sched_rt_runtime_us
  950000
  $ sysctl kernel.sched_rt_runtime_us=11
  sysctl: setting key "kernel.sched_rt_runtime_us": Nepřípustný argument
  kernel.sched_rt_runtime_us = 111
  $ echo $?
  0
  $ sysctl -n kernel.sched_rt_runtime_us
  950000
  $

  sysctl should return error exit code.

2] Try to set up indirectly with tuned profile activation

  $ cat new-profile/tuned.conf 
  [sysctl]
  kernel.sched_rt_runtime_us = 111
  $ systemctl restart tuned
  $ tuned-adm profile new-profile
  $ sysctl -n kernel.sched_rt_runtime_us
  950000
  $

  There are no error in /var/log/tuned/tuned.conf after profile activation.

  $ tuned-adm verify
Verification failed, current system settings differ from the preset profile.
See tuned.log for details. You can mostly fix this by Tuned restart, e.g.:
  service tuned restart
  $ cat /var/log/tuned/tuned.log | grep ERROR
2015-09-17 08:59:01,076 ERROR    tuned.plugins.base: verify: failed: kernel.sched_rt_runtime_us = 950000, expected 111
  $

Comment 1 Jaroslav Škarvada 2015-09-17 13:23:00 UTC
Reassigning to sysctl, tuned cannot detect that the sysctl command failed because sysctl is returning exit code 0, even if the kernel setting failed.

Reproducer:
# sysctl kernel.sched_rt_runtime_us=111111
sysctl: setting key "kernel.sched_rt_runtime_us": Invalid argument
kernel.sched_rt_runtime_us = 111111
# echo $?
0
# sysctl kernel.sched_rt_runtime_us
kernel.sched_rt_runtime_us = 950000

Expected result:
Exit code<>0 if the sysctl settings failed.

Comment 3 Jaroslav Škarvada 2015-09-17 13:47:06 UTC
Regarding the error itself, I don't know why the setting itself is rejected by kernel on RHEL-7:

# echo 111111 > /proc/sys/kernel/sched_rt_runtime_us 
-bash: echo: write error: Invalid argument

but:
# echo 950001  > /proc/sys/kernel/sched_rt_runtime_us
# echo $?
0

I think it should work and it works on Fedora 22. Filled kernel bug 1264091.

By using 950001 in tuned profile, it works correctly for me, so there is probably no tuned bug.

Comment 4 Jaromír Cápík 2015-10-05 14:23:10 UTC
Ahoj.

The sysctl command is often used for writing multiple kernel variables at once and in such case it simply ignores the failed ones. It was always like that. We can't stop processing the variables somewhere in the middle, otherwise we would end up with unfinished kernel configuration during the startup. And since multiple variables can be configured with one sysctl call, we would have to define some rules for the return codes in order to satisfy the particular scenarios (all variables correctly set, some of the variable settings failed, all variable settings failed). Or shall we rather return the number of failures? This needs to be discussed upstream first.

Regards,
Jaromir.

Comment 5 Jaroslav Škarvada 2015-10-05 14:40:23 UTC
(In reply to Jaromír Cápík from comment #4)
> Ahoj.
> 
> The sysctl command is often used for writing multiple kernel variables at
> once and in such case it simply ignores the failed ones. It was always like
> that. We can't stop processing the variables somewhere in the middle,
> otherwise we would end up with unfinished kernel configuration during the
> startup. And since multiple variables can be configured with one sysctl
> call, we would have to define some rules for the return codes in order to
> satisfy the particular scenarios (all variables correctly set, some of the
> variable settings failed, all variable settings failed). Or shall we rather
> return the number of failures? This needs to be discussed upstream first.
> 
> Regards,
> Jaromir.

I have no problem with multiple return codes for failure, but there definitely need to be mechanism how to detect that something failed, i.e. return code != 0.

Comment 7 Jan Rybar 2016-11-29 14:28:05 UTC
*** Bug 1395050 has been marked as a duplicate of this bug. ***

Comment 9 Jan Rybar 2018-11-06 10:57:28 UTC
Relevant bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1621940

The problem is that procps-ng/fileutils.c::close_stream() ignores ERRNO values. I sent fix to upstream a while ago. They seem to be kind of busy lately, so no response yet.

Comment 11 RHEL Program Management 2020-12-15 07:36:53 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.

Comment 12 Jan Rybar 2021-09-15 12:08:52 UTC
FYI, merged into upstream today: https://gitlab.com/procps-ng/procps/-/merge_requests/76/diffs