* dec-thread.c (dec_thread_wait): Add options parameter. Use it
[deliverable/binutils-gdb.git] / gdb / linux-nat.c
index c3aa94fe3ad848cf7ac76b2f76041ee96cd2ae1a..90574424a32c42c686ccb38201563cd329946ac6 100644 (file)
@@ -53,6 +53,7 @@
 #include <sys/types.h>
 #include "gdb_dirent.h"
 #include "xml-support.h"
+#include "terminal.h"
 
 #ifdef HAVE_PERSONALITY
 # include <sys/personality.h>
@@ -626,6 +627,7 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
 
          parent_inf = find_inferior_pid (GET_PID (last_ptid));
          child_inf->attach_flag = parent_inf->attach_flag;
+         copy_terminal_info (child_inf, parent_inf);
 
          /* Retain child fork in ptrace (stopped) state.  */
          fp = find_fork_pid (child_pid);
@@ -723,6 +725,7 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
 
       parent_inf = find_inferior_pid (GET_PID (last_ptid));
       child_inf->attach_flag = parent_inf->attach_flag;
+      copy_terminal_info (child_inf, parent_inf);
 
       /* If we're vforking, we may want to hold on to the parent until
         the child exits or execs.  At exec time we can remove the old
@@ -1338,7 +1341,6 @@ linux_nat_create_inferior (struct target_ops *ops,
                           char *exec_file, char *allargs, char **env,
                           int from_tty)
 {
-  int saved_async = 0;
 #ifdef HAVE_PERSONALITY
   int personality_orig = 0, personality_set = 0;
 #endif /* HAVE_PERSONALITY */
@@ -1346,11 +1348,6 @@ linux_nat_create_inferior (struct target_ops *ops,
   /* The fork_child mechanism is synchronous and calls target_wait, so
      we have to mask the async mode.  */
 
-  if (target_can_async_p ())
-    /* Mask async mode.  Creating a child requires a loop calling
-       wait_for_inferior currently.  */
-    saved_async = linux_nat_async_mask (0);
-
 #ifdef HAVE_PERSONALITY
   if (disable_randomization)
     {
@@ -1380,9 +1377,6 @@ linux_nat_create_inferior (struct target_ops *ops,
                 safe_strerror (errno));
     }
 #endif /* HAVE_PERSONALITY */
-
-  if (saved_async)
-    linux_nat_async_mask (saved_async);
 }
 
 static void
@@ -2684,7 +2678,8 @@ linux_nat_filter_event (int lwpid, int status, int options)
 
 static ptid_t
 linux_nat_wait_1 (struct target_ops *ops,
-                 ptid_t ptid, struct target_waitstatus *ourstatus)
+                 ptid_t ptid, struct target_waitstatus *ourstatus,
+                 int target_options)
 {
   static sigset_t prev_mask;
   struct lwp_info *lp = NULL;
@@ -2819,8 +2814,9 @@ retry:
       set_sigint_trap ();
     }
 
-  if (target_can_async_p ())
-    options |= WNOHANG; /* In async mode, don't block.  */
+  /* Translate generic target_wait options into waitpid options.  */
+  if (target_options & TARGET_WNOHANG)
+    options |= WNOHANG;
 
   while (lp == NULL)
     {
@@ -2925,7 +2921,7 @@ retry:
             In sync mode, suspend waiting for a SIGCHLD signal.  */
          if (options & __WCLONE)
            {
-             if (target_can_async_p ())
+             if (target_options & TARGET_WNOHANG)
                {
                  /* No interesting event.  */
                  ourstatus->kind = TARGET_WAITKIND_IGNORE;
@@ -3069,7 +3065,8 @@ retry:
 
 static ptid_t
 linux_nat_wait (struct target_ops *ops,
-               ptid_t ptid, struct target_waitstatus *ourstatus)
+               ptid_t ptid, struct target_waitstatus *ourstatus,
+               int target_options)
 {
   ptid_t event_ptid;
 
@@ -3080,7 +3077,7 @@ linux_nat_wait (struct target_ops *ops,
   if (target_can_async_p ())
     async_file_flush ();
 
-  event_ptid = linux_nat_wait_1 (ops, ptid, ourstatus);
+  event_ptid = linux_nat_wait_1 (ops, ptid, ourstatus, target_options);
 
   /* If we requested any event, and something came out, assume there
      may be more.  If we requested a specific lwp or process, also
@@ -4363,14 +4360,9 @@ linux_nat_terminal_inferior (void)
       return;
     }
 
-  /* GDB should never give the terminal to the inferior, if the
-     inferior is running in the background (run&, continue&, etc.).
-     This check can be removed when the common code is fixed.  */
-  if (!sync_execution)
-    return;
-
   terminal_inferior ();
 
+  /* Calls to target_terminal_*() are meant to be idempotent.  */
   if (!async_terminal_is_ours)
     return;
 
@@ -4396,9 +4388,6 @@ linux_nat_terminal_ours (void)
      but claiming it sure should.  */
   terminal_ours ();
 
-  if (!sync_execution)
-    return;
-
   if (async_terminal_is_ours)
     return;
 
This page took 0.024899 seconds and 4 git commands to generate.