Author: jhb
Date: Tue Dec 24 18:41:17 2013
New Revision: 259829
URL: http://svnweb.freebsd.org/changeset/base/259829

Log:
  MFC 255493:
  - Decode the idtype argument passed to wait6() in kdump and truss.
  - Don't treat an options argument of 0 to wait4() as an error in
    kdump.
  - Decode the wait options passed to wait4() and wait6() in truss
    and decode the returned rusage and exit status.

Modified:
  stable/9/usr.bin/kdump/kdump.c
  stable/9/usr.bin/kdump/mksubr
  stable/9/usr.bin/truss/syscall.h
  stable/9/usr.bin/truss/syscalls.c
Directory Properties:
  stable/9/usr.bin/kdump/   (props changed)
  stable/9/usr.bin/truss/   (props changed)

Modified: stable/9/usr.bin/kdump/kdump.c
==============================================================================
--- stable/9/usr.bin/kdump/kdump.c      Tue Dec 24 17:28:27 2013        
(r259828)
+++ stable/9/usr.bin/kdump/kdump.c      Tue Dec 24 18:41:17 2013        
(r259829)
@@ -58,6 +58,7 @@ extern int errno;
 #include <sys/sysent.h>
 #include <sys/un.h>
 #include <sys/queue.h>
+#include <sys/wait.h>
 #ifdef IPX
 #include <sys/types.h>
 #include <netipx/ipx.h>
@@ -556,8 +557,30 @@ ktrsyscall(struct ktr_syscall *ktr, u_in
                        case SYS_wait4:
                                print_number(ip, narg, c);
                                print_number(ip, narg, c);
+                               /*
+                                * A flags value of zero is valid for
+                                * wait4() but not for wait6(), so
+                                * handle zero special here.
+                                */
+                               if (*ip == 0) {
+                                       print_number(ip, narg, c);
+                               } else {
+                                       putchar(',');
+                                       wait6optname(*ip);
+                                       ip++;
+                                       narg--;
+                               }
+                               break;
+                       case SYS_wait6:
+                               putchar('(');
+                               idtypename(*ip, decimal);
+                               c = ',';
+                               ip++;
+                               narg--;
+                               print_number(ip, narg, c);
+                               print_number(ip, narg, c);
                                putchar(',');
-                               wait4optname(*ip);
+                               wait6optname(*ip);
                                ip++;
                                narg--;
                                break;

Modified: stable/9/usr.bin/kdump/mksubr
==============================================================================
--- stable/9/usr.bin/kdump/mksubr       Tue Dec 24 17:28:27 2013        
(r259828)
+++ stable/9/usr.bin/kdump/mksubr       Tue Dec 24 18:41:17 2013        
(r259829)
@@ -314,6 +314,68 @@ flagsandmodename(int flags, int mode, in
        }
 }
 
+/* MANUAL */
+void
+idtypename(idtype_t idtype, int decimal)
+{
+       switch(idtype) {
+       case P_PID:
+               printf("P_PID");
+               break;
+       case P_PPID:
+               printf("P_PPID");
+               break;
+       case P_PGID:
+               printf("P_PGID");
+               break;
+       case P_SID:
+               printf("P_SID");
+               break;
+       case P_CID:
+               printf("P_CID");
+               break;
+       case P_UID:
+               printf("P_UID");
+               break;
+       case P_GID:
+               printf("P_GID");
+               break;
+       case P_ALL:
+               printf("P_ALL");
+               break;
+       case P_LWPID:
+               printf("P_LWPID");
+               break;
+       case P_TASKID:
+               printf("P_TASKID");
+               break;
+       case P_PROJID:
+               printf("P_PROJID");
+               break;
+       case P_POOLID:
+               printf("P_POOLID");
+               break;
+       case P_JAILID:
+               printf("P_JAILID");
+               break;
+       case P_CTID:
+               printf("P_CTID");
+               break;
+       case P_CPUID:
+               printf("P_CPUID");
+               break;
+       case P_PSETID:
+               printf("P_PSETID");
+               break;
+       default:
+               if (decimal) {
+                       printf("%d", idtype);
+               } else {
+                       printf("%#x", idtype);
+               }
+       }
+}
+
 /*
  * MANUAL
  *
@@ -393,7 +455,7 @@ auto_switch_type "sockoptname"         "
 auto_switch_type "socktypename"        "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*"   
       "sys/socket.h"
 auto_or_type     "thrcreateflagsname"  "THR_[A-Z]+[[:space:]]+0x[0-9]+"        
       "sys/thr.h"
 auto_switch_type "vmresultname"        "KERN_[A-Z]+[[:space:]]+[0-9]+"         
       "vm/vm_param.h"
-auto_or_type     "wait4optname"        "W[A-Z]+[[:space:]]+[0-9]+"             
       "sys/wait.h"
+auto_or_type     "wait6optname"        "W[A-Z]+[[:space:]]+[0-9]+"             
       "sys/wait.h"
 auto_switch_type "whencename"          "SEEK_[A-Z]+[[:space:]]+[0-9]+"         
       "sys/unistd.h"
 
 cat <<_EOF_

Modified: stable/9/usr.bin/truss/syscall.h
==============================================================================
--- stable/9/usr.bin/truss/syscall.h    Tue Dec 24 17:28:27 2013        
(r259828)
+++ stable/9/usr.bin/truss/syscall.h    Tue Dec 24 18:41:17 2013        
(r259829)
@@ -40,7 +40,7 @@ enum Argtype { None = 1, Hex, Octal, Int
        Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres,
        Umtx, Sigset, Sigprocmask, Kevent, Sockdomain, Socktype, Open,
        Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2,
-       Pathconf, Rforkflags };
+       Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype };
 
 #define        ARG_MASK        0xff
 #define        OUT     0x100

Modified: stable/9/usr.bin/truss/syscalls.c
==============================================================================
--- stable/9/usr.bin/truss/syscalls.c   Tue Dec 24 17:28:27 2013        
(r259828)
+++ stable/9/usr.bin/truss/syscalls.c   Tue Dec 24 18:41:17 2013        
(r259829)
@@ -39,12 +39,13 @@ static const char rcsid[] =
  * arguments.
  */
 
-#include <sys/mman.h>
 #include <sys/types.h>
+#include <sys/mman.h>
 #include <sys/ptrace.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/un.h>
+#include <sys/wait.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/ioccom.h>
@@ -263,6 +264,12 @@ struct syscall syscalls[] = {
          .args = { { Name , 0 } , { Name, 1 } } },
        { .name = "posix_openpt", .ret_type = 1, .nargs = 1,
          .args = { { Open, 0 } } },
+       { .name = "wait4", .ret_type = 1, .nargs = 4,
+         .args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 },
+                   { Rusage | OUT, 3 } } },
+       { .name = "wait6", .ret_type = 1, .nargs = 6,
+         .args = { { Idtype, 0 }, { Int, 1 }, { ExitStatus | OUT, 2 },
+                   { Waitoptions, 3 }, { Rusage | OUT, 4 }, { Ptr, 5 } } },
        { .name = 0 },
 };
 
@@ -377,6 +384,17 @@ static struct xlat rfork_flags[] = {
        X(RFSIGSHARE) X(RFTSIGZMB) X(RFLINUXTHPN) XEND
 };
 
+static struct xlat wait_options[] = {
+       X(WNOHANG) X(WUNTRACED) X(WCONTINUED) X(WNOWAIT) X(WEXITED)
+       X(WTRAPPED) XEND
+};
+
+static struct xlat idtype_arg[] = {
+       X(P_PID) X(P_PPID) X(P_PGID) X(P_SID) X(P_CID) X(P_UID) X(P_GID)
+       X(P_ALL) X(P_LWPID) X(P_TASKID) X(P_PROJID) X(P_POOLID) X(P_JAILID)
+       X(P_CTID) X(P_CPUID) X(P_PSETID) XEND
+};
+
 #undef X
 #undef XEND
 
@@ -533,6 +551,16 @@ get_string(pid_t pid, void *offset, int 
        }
 }
 
+static char *
+strsig2(int sig)
+{
+       char *tmp;
+
+       tmp = strsig(sig);
+       if (tmp == NULL)
+               asprintf(&tmp, "%d", sig);
+       return (tmp);
+}
 
 /*
  * print_arg
@@ -818,19 +846,14 @@ print_arg(struct syscall_args *sc, unsig
                free(fds);
                break;
        }
-       case Signal: {
-               long sig;
-
-               sig = args[sc->offset];
-               tmp = strsig(sig);
-               if (tmp == NULL)
-                       asprintf(&tmp, "%ld", sig);
+       case Signal:
+               tmp = strsig2(args[sc->offset]);
                break;
-       }
        case Sigset: {
                long sig;
                sigset_t ss;
                int i, used;
+               char *signame;
 
                sig = args[sc->offset];
                if (get_struct(pid, (void *)args[sc->offset], (void *)&ss,
@@ -841,8 +864,11 @@ print_arg(struct syscall_args *sc, unsig
                tmp = malloc(sys_nsig * 8); /* 7 bytes avg per signal name */
                used = 0;
                for (i = 1; i < sys_nsig; i++) {
-                       if (sigismember(&ss, i))
-                               used += sprintf(tmp + used, "%s|", strsig(i));
+                       if (sigismember(&ss, i)) {
+                               signame = strsig(i);
+                               used += sprintf(tmp + used, "%s|", signame);
+                               free(signame);
+                       }
                }
                if (used)
                        tmp[used-1] = 0;
@@ -1139,6 +1165,35 @@ print_arg(struct syscall_args *sc, unsig
                        asprintf(&tmp, "0x%lx", args[sc->offset]);
                break;
        }
+       case ExitStatus: {
+               char *signame;
+               int status;
+               signame = NULL;
+               if (get_struct(pid, (void *)args[sc->offset], &status,
+                   sizeof(status)) != -1) {
+                       if (WIFCONTINUED(status))
+                               tmp = strdup("{ CONTINUED }");
+                       else if (WIFEXITED(status))
+                               asprintf(&tmp, "{ EXITED,val=%d }",
+                                   WEXITSTATUS(status));
+                       else if (WIFSIGNALED(status))
+                               asprintf(&tmp, "{ SIGNALED,sig=%s%s }",
+                                   signame = strsig2(WTERMSIG(status)),
+                                   WCOREDUMP(status) ? ",cored" : "");
+                       else
+                               asprintf(&tmp, "{ STOPPED,sig=%s }",
+                                   signame = strsig2(WTERMSIG(status)));
+               } else
+                       asprintf(&tmp, "0x%lx", args[sc->offset]);
+               free(signame);
+               break;
+       }
+       case Waitoptions:
+               tmp = strdup(xlookup_bits(wait_options, args[sc->offset]));
+               break;
+       case Idtype:
+               tmp = strdup(xlookup(idtype_arg, args[sc->offset]));
+               break;
        default:
                errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK);
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to