launch: use dup2 to reset daemon stdio over close+open

This commit is contained in:
outfoxxed 2026-04-09 00:10:49 -07:00
parent 7208f68bb7
commit 7f7ab6bc8a
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
2 changed files with 19 additions and 10 deletions

View file

@ -73,6 +73,7 @@ set shell id.
- Fixed JsonAdapter sending unnecessary property changes for primitive values.
- Fixed JsonAdapter serialization for lists.
- Fixed pipewire crashes after hotplugging devices and changing default outputs.
- Fixed launches failing for `--daemonize` on some systems.
## Packaging Changes

View file

@ -84,21 +84,29 @@ void exitDaemon(int code) {
close(DAEMON_PIPE);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
if (open("/dev/null", O_RDONLY) != STDIN_FILENO) { // NOLINT
qFatal() << "Failed to open /dev/null on stdin";
auto fd = open("/dev/null", O_RDWR);
if (fd == -1) {
qCritical().nospace() << "Failed to open /dev/null for daemon stdio" << errno << ": "
<< qt_error_string();
return;
}
if (open("/dev/null", O_WRONLY) != STDOUT_FILENO) { // NOLINT
qFatal() << "Failed to open /dev/null on stdout";
if (dup2(fd, STDIN_FILENO) != STDIN_FILENO) { // NOLINT
qCritical().nospace() << "Failed to set daemon stdin to /dev/null" << errno << ": "
<< qt_error_string();
}
if (open("/dev/null", O_WRONLY) != STDERR_FILENO) { // NOLINT
qFatal() << "Failed to open /dev/null on stderr";
if (dup2(fd, STDOUT_FILENO) != STDOUT_FILENO) { // NOLINT
qCritical().nospace() << "Failed to set daemon stdout to /dev/null" << errno << ": "
<< qt_error_string();
}
if (dup2(fd, STDERR_FILENO) != STDERR_FILENO) { // NOLINT
qCritical().nospace() << "Failed to set daemon stderr to /dev/null" << errno << ": "
<< qt_error_string();
}
close(fd);
}
int main(int argc, char** argv) {