bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug while calling dlcose


From: marco
Subject: Re: Bug while calling dlcose
Date: Sun, 18 May 2003 19:45:33 +0200 (CEST)

> So the conditions are: GDB + Thread + dlclose from within that thread to
> close itself. That is exactly what the console-client does.

So it does work when exiting from the main thread. I included a little
patch for the console-client as a workaround. I used cthread conditions.
Could someone please have a look if I understood conditions correctly?
(And apply it if fixing that whatever is broken will take a long while? I
won't fix it)

Thanks,
Marco

2003-05-18  Marco Gerards  <metgerards@student.han.nl>
        * console.c (should_exit): New variable used to signal the main
        thread for console exit.
        (exit_cond): Likewise.
        (exit_lock): Likewise.
        (_console_exit): New function.
        (console_exit): Signal the main thread to exit the console-client.
        (server_loop_thread): New function.
        (main): Wait for exit_cons and exit.
        * ncursesw.c (input_loop): Use console_exit instead of exit.



diff -up /home/marco/console-client/console.c console-client/console.c
--- /home/marco/console-client/console.c        2003-05-11 23:13:00.000000000 
+0200
+++ console-client/console.c    2003-05-18 21:36:07.000000000 +0200
@@ -1,5 +1,5 @@
 /* console.c -- A pluggable console client.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This program is free software; you can redistribute it and/or
@@ -47,6 +47,11 @@ static struct mutex global_lock;
    displayed.  */
 static vcons_t active_vcons = NULL;

+/* Used for waiting for an exit condition in the main loop (Workaround
+   for a bug in the GDB, cthreads or dlclose).  */
+static int should_exit;
+static struct condition exit_cond;
+static struct mutex exit_lock;
 
 /* Callbacks for input source drivers.  */

@@ -149,13 +154,24 @@ console_scrollback (cons_scroll_t type,


 /* Exit the console client.  Does not return.  */
-void
-console_exit (void)
+static void
+_console_exit (void)
 {
   driver_fini ();
   exit (0);
 }

+/* XXX: The console_exit function cannot be called directly. Signal
+   the main thread to call it.  */
+void
+console_exit (void)
+{
+  mutex_lock (&exit_lock);
+  should_exit = 1;
+  condition_signal (&exit_cond);
+  mutex_unlock (&exit_lock);
+}
+
 /* Signal an error to the user.  */
 void console_error (const wchar_t *const err_msg)
 {
@@ -429,6 +445,15 @@ static const struct argp_child startup_c
 static struct argp startup_argp = {options, parse_opt, 0,
                                   0, startup_children};

+/* Run cons_server_loop in a thread because the main thread must wait
+   for the exit signal.  */
+static any_t
+server_loop_thread (any_t unused)
+{
+  cons_server_loop ();
+  return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -445,6 +470,8 @@ main (int argc, char *argv[])
     error (1, err, "Starting driver %s failed", errname);

   mutex_init (&global_lock);
+  mutex_init (&exit_lock);
+  condition_init (&exit_cond);

   err = cons_init ();
   if (err)
@@ -460,7 +487,14 @@ main (int argc, char *argv[])
       error (1, err, "Timer thread initialization failed");
     }

-  cons_server_loop ();
+  cthread_detach (cthread_fork (server_loop_thread, 0));
+
+  /* Wait until _console_exit send a signal to exit the console.  */
+  mutex_lock (&exit_lock);
+  while (!should_exit)
+    condition_wait (&exit_cond, &exit_lock);
+  mutex_unlock (&exit_lock);
+  _console_exit ();

   /* Never reached.  */
   driver_fini ();
diff -up /home/marco/console-client/ncursesw.c console-client/ncursesw.c
--- /home/marco/console-client/ncursesw.c       2003-05-11 23:13:01.000000000 
+0200
+++ console-client/ncursesw.c   2003-05-18 21:35:55.000000000 +0200
@@ -1,5 +1,5 @@
 /* ncursesw.c - The ncursesw console driver.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This program is free software; you can redistribute it and/or
@@ -293,7 +293,7 @@ input_loop (any_t unused)
                    {
                    case 'x':
                      endwin ();
-                     exit (0);
+                     console_exit ();
                      break;
                    case 23:    /* ^W */
                      assert (size < 100);







reply via email to

[Prev in Thread] Current Thread [Next in Thread]