]> granicus.if.org Git - strace/commitdiff
more FreeBSD updates
authorWichert Akkerman <wichert@deephackmode.org>
Sun, 3 Sep 2000 23:57:48 +0000 (23:57 +0000)
committerWichert Akkerman <wichert@deephackmode.org>
Sun, 3 Sep 2000 23:57:48 +0000 (23:57 +0000)
CREDITS
ChangeLog
defs.h
net.c
process.c
strace.c
term.c

diff --git a/CREDITS b/CREDITS
index ed03b50094e8fe46a98a1dadb28e41b2261157c8..2c8c22a628d2853d0408952b176ba418e72c1cb7 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -39,4 +39,4 @@ porting to new systems:
        Florian Lohoff <flo@rfc822.org>
        D.J. Barrow <djbarrow@de.ibm.com>
        Topi Miettinen <Topi.Miettinen@nic.fi>
-       Gaël Roualland <gael.roualland@dial.oleane.com>
+       Gaël Roualland <gael.roualland@iname.com>
index 758e584c5248391cb8447aee94c4e2f126cfa0b0..bf4377ce3b276d79a72b7e1a70088527dd5f3d1b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
   *  file.c: rename dirent64 struct to kernel_dirent64 so things compile
      again with newer libcs
   *  test/clone.c: improve our testcase a bit
+  *  Merge another patch from Gäel Roualland with FreeBSD updates
 
 2000-09-01  Wichert Akkerman <wakkerma@debian.org>
 
diff --git a/defs.h b/defs.h
index 4dbed044b225ed27de838e701b6d097f022bfc05..e6f90f101cad7bdcf33db6ce2d735a08d21c9cbb 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -210,9 +210,10 @@ extern int mp_ioctl (int f, int c, void *a, int s);
 #define PIOCWSTOP       PIOCWAIT
 #define PR_WHY         why
 #define PR_WHAT                val
-#define PR_FLAGS       flags
+#define PR_FLAGS       state
 /* from /usr/src/sys/miscfs/procfs/procfs_vnops.c,
    status.state = 0 for running, 1 for stopped */
+#define PR_ASLEEP      1
 #define PR_SYSENTRY     S_SCE
 #define PR_SYSEXIT      S_SCX
 #define PR_SIGNALLED    S_SIG
diff --git a/net.c b/net.c
index da061c87cefc91021a80e398115fd7cc76b27c20..daea7825d0ab8db81cd481488cc20d2858ea63eb 100644 (file)
--- a/net.c
+++ b/net.c
@@ -943,7 +943,7 @@ struct tcb *tcp;
                else
                        tprintf("[%u, %u]", fds[0], fds[1]);
        }
-#elif defined(SPARC) || defined(SVR4)
+#elif defined(SPARC) || defined(SVR4) || defined(FREEBSD)
        if (exiting(tcp))
                tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
 #endif
@@ -990,12 +990,9 @@ struct tcb *tcp;
                else
                        tprintf(", [%u, %u]", fds[0], fds[1]);
 #endif /* LINUX */
-#ifdef SUNOS4
+#if defined(SUNOS4) || defined(SVR4) || defined(FREEBSD)
                tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
-#endif /* SUNOS4 */
-#ifdef SVR4
-               tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
-#endif /* SVR4 */
+#endif /* SUNOS4 || SVR4 || FREEBSD */
        }
        return 0;
 }
index 47fc87d24813fef0e7e50b8b161a82121c327be9..11b9910ee9f3c2f413674543ac97b217f741bd9f 100644 (file)
--- a/process.c
+++ b/process.c
@@ -376,7 +376,7 @@ struct tcb *tcp;
                        fprintf(stderr, "sys_fork: tcb table full\n");
                        return 0;
                }
-               if (proc_open(tcpchild, 1) < 0)
+               if (proc_open(tcpchild, 2) < 0)
                        droptcb(tcpchild);
        }
        return 0;
index 3e4b4a610c3b31851ba37a1151a639d8afbaa84b..0e9242b1bdaa6918e1e6ec46bc4fa03ecf2b10c5 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -684,11 +684,7 @@ int attaching;
                                perror("strace: PIOCSTATUS");
                                return -1;
                        }
-#ifndef FREEBSD                        
                        if (tcp->status.PR_FLAGS & PR_ASLEEP)
-#else
-                       if (tcp->status.state == 1)
-#endif
                            break;
                }
        }
@@ -823,11 +819,31 @@ int attaching;
        }
 #else /* FREEBSD */
        } else {
-              /* little hack to show the current syscall */
-              IOCTL_STATUS(tcp);
-              tcp->flags &= ~TCB_INSYSCALL;
-              tcp->status.why = PR_SYSENTRY;
-              trace_syscall(tcp);
+               if (attaching < 2) { 
+                       /* We are attaching to an already running process.
+                        * Try to figure out the state of the process in syscalls,
+                        * to handle the first event well.
+                        * This is done by having a look at the "wchan" property of the
+                        * process, which tells where it is stopped (if it is). */
+                       FILE * status;
+                       char wchan[20]; /* should be enough */
+                       
+                       sprintf(proc, "/proc/%d/status", tcp->pid);
+                       status = fopen(proc, "r");
+                       if (status &&
+                           (fscanf(status, "%*s %*d %*d %*d %*d %*d,%*d %*s %*d,%*d"
+                                   "%*d,%*d %*d,%*d %19s", wchan) == 1) &&
+                           strcmp(wchan, "nochan") && strcmp(wchan, "spread") &&
+                           strcmp(wchan, "stopevent")) {
+                               /* The process is asleep in the middle of a syscall.
+                                  Fake the syscall entry event */
+                               tcp->flags &= ~(TCB_INSYSCALL|TCB_STARTUP);
+                               tcp->status.PR_WHY = PR_SYSENTRY;
+                               trace_syscall(tcp);
+                       }
+                       if (status)
+                               fclose(status);
+               } /* otherwise it's a fork being followed */
        }
 #endif /* FREEBSD */
 #ifndef HAVE_POLLABLE_PROCFS
@@ -1474,6 +1490,14 @@ trace()
                        }
                }
 
+#ifdef FREEBSD
+               if ((tcp->flags & TCB_STARTUP) && (tcp->status.PR_WHY == PR_SYSEXIT)) {
+                       /* discard first event for a syscall we never entered */
+                       IOCTL (tcp->pfd, PIOCRUN, 0);
+                       continue;
+               }
+#endif         
+               
                /* clear the just started flag */
                tcp->flags &= ~TCB_STARTUP;
 
diff --git a/term.c b/term.c
index db15ef9b112eb8e2658cd01a26b30b0ef95525ec..0a741d54f8e527e842b17fadba4ded20809c3d07 100644 (file)
--- a/term.c
+++ b/term.c
@@ -178,7 +178,10 @@ long code, arg;
 #ifndef FREEBSD
        struct termio tio;
 #else
-       struct termios tio;
+       #define TCGETS  TIOCGETA
+       #define TCSETS  TIOCSETA
+       #define TCSETSW TIOCSETAW
+       #define TCSETSF TIOCSETAF
 #endif 
        struct winsize ws;
 #ifdef TIOCGSIZE
@@ -204,7 +207,16 @@ long code, arg;
                        return 0;
                if (abbrev(tcp)) {
                        tprintf(", {");
+#ifndef FREEBSD                        
                        printxval(baud_options, tios.c_cflag & CBAUD, "B???");
+#else
+                       printxval(baud_options, tios.c_ispeed, "B???");
+                       if (tios.c_ispeed != tios.c_ospeed) {
+                               tprintf(" (in)");
+                               printxval(baud_options, tios.c_ospeed, "B???");
+                               tprintf(" (out)");
+                       }
+#endif                 
                        tprintf(" %sopost %sisig %sicanon %secho ...}",
                                (tios.c_oflag & OPOST) ? "" : "-",
                                (tios.c_lflag & ISIG) ? "" : "-",
@@ -216,7 +228,7 @@ long code, arg;
                        (long) tios.c_iflag, (long) tios.c_oflag);
                tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
                        (long) tios.c_cflag, (long) tios.c_lflag);
-#ifndef SVR4
+#if !defined(SVR4) && !defined(FREEBSD)
                tprintf("c_line=%u, ", tios.c_line);
 #endif
                if (!(tios.c_lflag & ICANON))