cli: don't use unsafe functions in pager_fallback()

The pager_fallback() runs in the forked child process.
As such, it can only use functions from `man signal-safety`
or that are explicitly allowed.

We are mostly good, but g_printerr() is not allowed. It can deadlock.
Just avoid it. It's not very to print those error messages anyway.
This commit is contained in:
Thomas Haller 2022-10-11 08:36:21 +02:00
parent a35d8ff769
commit e843a7caa2
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1423,20 +1423,18 @@ pager_fallback(void)
{
char buf[64];
int rb;
int errsv;
/* We are still in the child process (after fork() and before exec()).
* We must only used functions listed in `man signal-safety`. */
do {
rb = read(STDIN_FILENO, buf, sizeof(buf));
if (rb == -1) {
errsv = errno;
if (errsv == EINTR)
if (errno == EINTR)
continue;
g_printerr(_("Error reading nmcli output: %s\n"), nm_strerror_native(errsv));
_exit(EXIT_FAILURE);
}
if (write(STDOUT_FILENO, buf, rb) == -1) {
errsv = errno;
g_printerr(_("Error writing nmcli output: %s\n"), nm_strerror_native(errsv));
_exit(EXIT_FAILURE);
}
} while (rb > 0);