Skip to contentSkip to conversation

chcpu exit code?

DISCUSSION Bernhard Voelker 4 participants 8 messages Feb 27, 2014 – Mar 5, 2014 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Although the man page does not mention the exit status, I think it's wrong that 'chcpu' exits OK when an action failed or when a bad CPU number was specified:

  $ ./chcpu -d 0 ; echo $?
  CPU 0 is not hot pluggable
  0
  $ ./chcpu -g 3 ; echo $?
  CPU 3 is not configurable
  0
  $ ./chcpu -e 4 ; echo $?
  CPU 4 does not exist
  0

WDYT?

Have a nice day,
Berny

#1 lore raw
Quoted 7 lines

From: Bernhard Voelker <[email protected]>

Although the man page does not mention the exit status, I think it's wrong that 'chcpu' exits OK when an action failed or when a bad CPU number was specified:

WDYT?

I agree that it would be helpful if chcpu used the usual success/failure convention for exit status. The reason is that sometimes one wants to use "set -e" in a script so that any command that fails unexpectedly will cause processing to halt. Similarly, if one hands a command to a program to execute, a program that is set up to execute generic commands supplied by some outside source usually handles non-zero exit status specially by reporting that the command failed, while treating zero exit statuses as not-to-be-remarked-upon.

Dale

#2 lore raw
In reply to Bernhard Voelker
Quoted 12 lines · Bernhard Voelker

Although the man page does not mention the exit status, I think it's wrong that 'chcpu' exits OK when an action failed or when a bad CPU number was specified:

  $ ./chcpu -d 0 ; echo $?
  CPU 0 is not hot pluggable
  0
  $ ./chcpu -g 3 ; echo $?
  CPU 3 is not configurable
  0
Quoted 5 lines
  $ ./chcpu -e 4 ; echo $?
  CPU 4 does not exist
  0

WDYT?

The question is: what should chcpu return if it partially succeeded?

# chcpu -d 3-4
CPU 3 disabled
CPU 4 does not exist

If I remember correctly this was the reason to make it always return 0.

However, it is indeed valid to say if *everything* failed, it should return an error. Hm?

#3 lore raw
Quoted 10 lines · Heiko Carstens

The question is: what should chcpu return if it partially succeeded?

# chcpu -d 3-4
CPU 3 disabled
CPU 4 does not exist

If I remember correctly this was the reason to make it always return 0.

However, it is indeed valid to say if *everything* failed, it should return an error. Hm?

Indeed, e.g. df(1) also fails if only a single mount point cannot be listed. Otherwise, the calling script could not rely on the exit code, and would still have to fall back to parsing the output.

But thanks to your question I was reminded to have a look at *where* chcpu writes messages:

  $ chcpu -d 3-4 > /dev/null
  $ chcpu -d 3-4 2> /dev/null
  CPU 3 is already disabled
  CPU 4 does not exist
  $

I.e. chcpu does not write the error diagnostic to stderr ... humm.

Have a nice day,
Berny

maintainer
#4 lore raw
In reply to Heiko Carstens
Quoted 17 lines · Heiko Carstens
Quoted 16 lines · Bernhard Voelker

Although the man page does not mention the exit status, I think it's wrong that 'chcpu' exits OK when an action failed or when a bad CPU number was specified:

  $ ./chcpu -d 0 ; echo $?
  CPU 0 is not hot pluggable
  0
  $ ./chcpu -g 3 ; echo $?
  CPU 3 is not configurable
  0
  $ ./chcpu -e 4 ; echo $?
  CPU 4 does not exist
  0
Quoted 7 lines
Quoted 1 line

WDYT?

The question is: what should chcpu return if it partially succeeded?

# chcpu -d 3-4
CPU 3 disabled
CPU 4 does not exist

This is not so unusual situation, we have for example the same thing in mount -a where

0 - success
32 - mount failure
64 - some mount succeeded

I think we can do something like this with chcpu, my suggestion is

0 - success
1 - failure
64 - partial success

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw
Quoted 5 lines · Karel Zak

I think we can do something like this with chcpu, my suggestion is

0 - success
1 - failure
64 - partial success

+1

Thanks & have a nice day,
Berny

maintainer
#6 lore raw
Quoted 8 lines · Bernhard Voelker
Quoted 5 lines · Karel Zak

I think we can do something like this with chcpu, my suggestion is

0 - success
1 - failure
64 - partial success

+1

Fixed. Thanks for your report.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#7 lore raw
Quoted 1 line · Karel Zak

Fixed. Thanks for your report.

LGTM, thanks!

Have a nice day,
Berny