As of 6.1.0, running pacman with stdin closed (`pacman <&-`) causes problems for hooks that `NeedTargets`. Perhaps running with stdin closed is user-error, so feel free to close this if that's your position; but it worked fine in 6.0.2, and now fails in fairly cryptic ways.
If run with stdin closed, then hooks that `NeedTargets` will get EBADF when they try to read the list of targets:
```
(11/14) Updating module dependencies...
/usr/share/libalpm/scripts/depmod: line 3: read: read error: 0: Bad file descriptor
(12/14) Updating linux initcpios...
/usr/share/libalpm/scripts/mkinitcpio: line 168: read: read error: 0: Bad file descriptor
```
While the `pacman` command will end up exiting successfully, (in the above example, from running `pacstrap`) the initramfs won't have been generated.
What is happening is that in `util.c` in the child process it does
```c
while(dup2(parent2child_pipefd[TAIL], 0) == -1 && errno == EINTR);
...
_alpm_handle_free(handle);
execv(cmd, argv);
```
and `handle.c:_alpm_handle_free(handle)` calls `curl_multi_cleanup(handle->curlm)`, which closes stdin.
I suspect what is happening is that early on in the parent PID's lifetime libcurl allocates an FD, and because stdin is closed it ends up on stdin. So then once we dup2 the pipe to stdin, libcurl and libalpm are stomping over eachother wrt that FD.
↧