]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc/attach: Detect EACCES from execvp and convert to 126 exit status
authorThomas Parrott <thomas.parrott@canonical.com>
Thu, 13 Oct 2022 14:33:30 +0000 (15:33 +0100)
committerThomas Parrott <thomas.parrott@canonical.com>
Thu, 13 Oct 2022 14:33:30 +0000 (15:33 +0100)
Before:

  sudo lxc-attach -n test /etc/passwd ; echo $?
  lxc-attach: test: ../src/lxc/attach.c: lxc_attach_run_command: 1841 Permission denied - Failed to exec "/etc/passwd"
  255

After:

  sudo lxc-attach -n test /etc/passwd ; echo $?
  lxc-attach: test: ../src/lxc/attach.c: lxc_attach_run_command: 1841 Permission denied - Failed to exec "/etc/passwd"
  126

Which better aligns with bash:

  /etc/passwd; echo $?
  bash: /etc/passwd: Permission denied
  126

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
src/lxc/attach.c

index 769613d6db4bf3e066b2ef0c0b634b8cb1d813fd..f086e96c463ed46e3a617a4dfe8171b553d6d94e 100644 (file)
@@ -1828,6 +1828,7 @@ int lxc_attach_run_command(void *payload)
        ret = execvp(cmd->program, cmd->argv);
        if (ret < 0) {
                switch (errno) {
+               case EACCES:
                case ENOEXEC:
                        ret = 126;
                        break;