banan-os/ports/qemu/patches/0002-implement-daemon.patch

44 lines
858 B
Diff

diff -ru qemu-10.0.2/util/oslib-posix.c qemu-10.0.2-x86_64/util/oslib-posix.c
--- qemu-10.0.2/util/oslib-posix.c 2025-05-29 01:05:47.000000000 +0300
+++ qemu-10.0.2-x86_64/util/oslib-posix.c 2025-08-18 02:38:04.839116456 +0300
@@ -128,7 +128,39 @@
int qemu_daemon(int nochdir, int noclose)
{
+#if defined(__banan_os__)
+ const pid_t pid = fork();
+ if (pid == -1) {
+ return -1;
+ }
+ if (pid > 0) {
+ exit(0);
+ }
+
+ if (setsid() == -1) {
+ return -1;
+ }
+
+ if (nochdir == 0) {
+ if (chdir("/") == -1) {
+ return -1;
+ }
+ }
+
+ if (noclose == 0) {
+ int fd = open("/dev/null", O_RDWR);
+ if (fd == -1) {
+ return -1;
+ }
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ }
+
+ return 0;
+#else
return daemon(nochdir, noclose);
+#endif
}
bool qemu_write_pidfile(const char *path, Error **errp)