Skip to contentSkip to conversation

gdbstub: fix gdbserver_fork

Qemu-devel Laurent Desnogues 1 participant 1 message Jan 6, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

as reported by Martin Mohring fork doesn't work with NPTL. A fix is attached that makes the also attached test run (tested with ARM CodeSourcery 2008q3 on an x86_64 Fedora Core with kernel 2.6.23).

Laurent

gdbstub.c +1 -1
Index: gdbstub.c
===================================================================
@@ -2225,7 +2225,7 @@
 void gdbserver_fork(CPUState *env)
 {
     GDBState *s = gdbserver_state;
-    if (s->fd < 0)
+    if (gdbserver_fd < 0 || s->fd < 0)
       return;
     close(s->fd);
     s->fd = -1;

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <wait.h>

static void test_fork(void)

{
    pid_t id;

    id = fork();
    if (id == 0) {
        printf("child\n");
        exit(0);
    } else if (id == -1) {
        perror("Fork fail");
        exit(-1);
    } else {
        int status;
        waitpid(id, &status, 0);
        printf("Parent:  done %d\n", status);
        exit(0);
    }
}

int main(int argc, char **argv)

{
    test_fork();
    return 0;
}