Util-Linux package development
 help / color / mirror / Atom feed
From: Ruediger Meier <sweet_f_a@gmx.de>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: failed exec() exit codes
Date: Thu, 1 Feb 2018 17:01:19 +0100	[thread overview]
Message-ID: <201802011701.19780.sweet_f_a@gmx.de> (raw)
In-Reply-To: <20180201145809.jjtadzla22wlw7rv@ws.net.home>

On Thursday 01 February 2018, Karel Zak wrote:
> Now we use on many places where commands executing another command:
>
>     execvp(argv[optind], argv + optind);
>     err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);
>
> the problem is that EXIT_FAILURE is too generic and it does not
> provide any way how to detect failed exec()s.

I think you did a bit too much. I assume that these exec codes are only 
useful for the programs which get a "command" from the user's command 
line. So that the user can expect the original exit code of his 
wanted "command" if and only if it's not 126 or 127.

So for taskset(1) these exit codes are good but maybe not needed for 
swapon(1) or eject(1).


> I have added a new macro errexec() to replace err(EXIT_FAILURE, ...).
>
> The new macro is compatible with coreutils way:
>
>     #define EX_EXEC_FAILED          126     /* Program located, but
> not usable. */ #define EX_EXEC_ENOENT          127     /* Could not
> find program to exec.  */


coreutils has even 2 more in "src/system.h" and each of these kind of
exec programs are *only* using these ones.

/* Exit statuses for programs like 'env' that exec other programs.  */
enum
{
  EXIT_TIMEDOUT = 124, /* Time expired before child completed.  */
  EXIT_CANCELED = 125, /* Internal error prior to exec attempt.  */
  EXIT_CANNOT_INVOKE = 126, /* Program located, but not usable.  */
  EXIT_ENOENT = 127 /* Could not find program to exec.  */
};

like
$ chroot   --helpdassdf; echo $?
chroot: unrecognized option '--helpdassdf'
Try 'chroot --help' for more information.
125

Other projects like bash only support 126 and 127, like we do now

$ exec bla ; echo $?
bash: exec: bla: not found
127

$ exec --bla ; echo $?
bash: exec: --: invalid option
exec: usage: exec [-cl] [-a name] [command [arguments ...]] 
[redirection ...]
2

cu,
Rudi

  reply	other threads:[~2018-02-01 16:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-01 14:58 failed exec() exit codes Karel Zak
2018-02-01 16:01 ` Ruediger Meier [this message]
2018-02-01 20:22   ` Karel Zak
2018-02-01 21:31     ` Rüdiger Meier
2018-02-02  8:37       ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201802011701.19780.sweet_f_a@gmx.de \
    --to=sweet_f_a@gmx.de \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox