failed exec() exit codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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 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.  */

    #define errexec(name)   err(errno == ENOENT ? EX_EXEC_ENOENT : EX_EXEC_FAILED, \ 
                        _("failed to execute %s"), name)

Example:

        $ taskset -c 1 ./foo; echo $?
        taskset: failed to execute ./foo: No such file or directory
        127

        $ touch foo

        $ taskset -c 1 ./foo; echo $?
        taskset: failed to execute ./foo: Permission denied
        126


We had discussion about it 2 years ago, but it has never been
implemented and merged. Fixed now ;-)

Objections? 

    Karel


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux