dup2(2) could return ENOMEM under extreme condition. For example, when
sysctl fs.nr_open=
2147483584, and RLIMIT_NOFILE is also
2147483584.
The following program fails with ENOMEM:
int
main(void)
{
if (dup2(0,
2000000000) == -1)
err(1, "dup2");
return 0;
}
This ENOMEM comes from an allocation error here:
<https://elixir.bootlin.com/linux/v6.1/source/mm/util.c#L596>
ENOMEM is already documented for open(2).
Signed-off-by: Levi Zim <rsworktech@outlook.com>
[alx: tweak commit message]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
.B RLIMIT_NOFILE
in
.BR getrlimit (2)).
+.TP
+.B ENOMEM
+Insufficient kernel memory was available.
.SH STANDARDS
.TP
.BR dup ()