Skip to content

Commit

Permalink
Add __set_errno_and_perror() macro
Browse files Browse the repository at this point in the history
This adds the macro __set_errno_and_perror() to perror the EIO internal
error.
  • Loading branch information
gportay committed May 13, 2024
1 parent fe9361d commit 5d193c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
30 changes: 15 additions & 15 deletions dso.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ static int __elf32_phdr(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr,
if (siz == -1)
return -1;
else if ((size_t)siz < sizeof(*phdr))
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

if (!__elf32_swap(ehdr))
return 0;
Expand All @@ -981,7 +981,7 @@ static int __elf32_shdr(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr,
if (siz == -1)
return -1;
else if ((size_t)siz < sizeof(*shdr))
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

if (!__elf32_swap(ehdr))
return 0;
Expand All @@ -1008,7 +1008,7 @@ static int __elf32_dyn(int fd, Elf32_Ehdr *ehdr, Elf32_Dyn *dyn, size_t dynsiz,
if (siz == -1)
return -1;
else if ((size_t)siz < dynsiz)
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

if (!__elf32_swap(ehdr))
return 0;
Expand Down Expand Up @@ -1070,7 +1070,7 @@ static int __elf64_phdr(int fd, Elf64_Ehdr *ehdr, Elf64_Phdr *phdr,
if (siz == -1)
return -1;
else if ((size_t)siz < sizeof(*phdr))
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

if (!__elf64_swap(ehdr))
return 0;
Expand All @@ -1096,7 +1096,7 @@ static int __elf64_shdr(int fd, Elf64_Ehdr *ehdr, Elf64_Shdr *shdr,
if (siz == -1)
return -1;
else if ((size_t)siz < sizeof(*shdr))
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

if (!__elf64_swap(ehdr))
return 0;
Expand Down Expand Up @@ -1124,7 +1124,7 @@ static int __elf64_dyn(int fd, Elf64_Ehdr *ehdr, Elf64_Dyn *dyn, size_t dynsiz,
if (siz == -1)
return -1;
else if ((size_t)siz < dynsiz)
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

if (!__elf64_swap(ehdr))
return 0;
Expand All @@ -1147,7 +1147,7 @@ static int __elf_ehdr(int fd, Elf64_Ehdr *ehdr)
if (siz == -1)
return -1;
else if ((size_t)siz < sizeof(*ehdr))
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

/* Not an ELF */
if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ static ssize_t __elf_interp32(int fd, Elf32_Ehdr *ehdr, char *buf,
continue;

if (bufsiz < phdr.p_filesz) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand All @@ -1247,7 +1247,7 @@ static ssize_t __elf_interp32(int fd, Elf32_Ehdr *ehdr, char *buf,
if (ret == -1) {
goto exit;
} else if ((size_t)ret < phdr.p_filesz) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand Down Expand Up @@ -1286,7 +1286,7 @@ static ssize_t __elf_interp64(int fd, Elf64_Ehdr *ehdr, char *buf,
continue;

if (bufsiz < phdr.p_filesz) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand All @@ -1295,7 +1295,7 @@ static ssize_t __elf_interp64(int fd, Elf64_Ehdr *ehdr, char *buf,
if (ret == -1) {
goto exit;
} else if ((size_t)ret < phdr.p_filesz) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand Down Expand Up @@ -1371,7 +1371,7 @@ static int __elf_iterate_ehdr32(int fd, Elf32_Ehdr *ehdr, int d_tag,
continue;

if (sizeof(dyn) < phdr.p_filesz) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand Down Expand Up @@ -1415,7 +1415,7 @@ static int __elf_iterate_ehdr32(int fd, Elf32_Ehdr *ehdr, int d_tag,
if (siz == -1) {
goto exit;
} else if ((size_t)siz < size) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand Down Expand Up @@ -1496,7 +1496,7 @@ static int __elf_iterate_ehdr64(int fd, Elf64_Ehdr *ehdr, int d_tag,
continue;

if (sizeof(dyn) < phdr.p_filesz) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand Down Expand Up @@ -1540,7 +1540,7 @@ static int __elf_iterate_ehdr64(int fd, Elf64_Ehdr *ehdr, int d_tag,
if (siz == -1) {
goto exit;
} else if ((size_t)siz < size) {
ret = __set_errno(EIO, -1);
ret = __set_errno_and_perror(EIO, -1);
goto exit;
}

Expand Down
2 changes: 1 addition & 1 deletion iamroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static int __fcan_exec(int fd)
if (siz == -1)
return -1;
else if ((size_t)siz < sizeof(magic))
return __set_errno(EIO, -1);
return __set_errno_and_perror(EIO, -1);

/* It is an interpreter-script */
if (memcmp(magic, SCRIPTMAG, SSCRIPTMAG) == 0)
Expand Down
5 changes: 5 additions & 0 deletions iamroot.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ extern "C" {
({ errno = (e); \
(r); })

#define __set_errno_and_perror(e, r) \
({ errno = (e); \
perror(__func__); \
(r); })

#define _strncpy(s1, s2, n1) \
({ const int l = (n1)-1; \
strncpy((s1), (s2), l); \
Expand Down
15 changes: 10 additions & 5 deletions support/amd64-devuan-jessie-rootfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,8 @@ Setting up libnettle4 ...
Setting up debian-archive-keyring ...
Setting up vim-common ...
Setting up devuan-baseconf ...
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Input/output error
__fcan_exec: Input/output error
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument
dpkg: error processing package devuan-baseconf (--configure):
subprocess installed post-installation script returned error exit status 2
Setting up libnfnetlink0 ...
Expand Down Expand Up @@ -1779,25 +1780,29 @@ Setting up tasksel-data ...
Errors were encountered while processing:
devuan-baseconf
Setting up devuan-baseconf ...
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Input/output error
__fcan_exec: Input/output error
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument
dpkg: error processing package devuan-baseconf (--configure):
subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
devuan-baseconf
Setting up devuan-baseconf ...
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Input/output error
__fcan_exec: Input/output error
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument
dpkg: error processing package devuan-baseconf (--configure):
subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
devuan-baseconf
Setting up devuan-baseconf ...
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Input/output error
__fcan_exec: Input/output error
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument
dpkg: error processing package devuan-baseconf (--configure):
subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
devuan-baseconf
Setting up devuan-baseconf ...
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Input/output error
__fcan_exec: Input/output error
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument
dpkg: error processing package devuan-baseconf (--configure):
subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
Expand Down

0 comments on commit 5d193c9

Please sign in to comment.