[BACK]Return to kdump.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / kdump

Diff for /src/usr.bin/kdump/kdump.c between version 1.63 and 1.64

version 1.63, 2011/09/19 22:00:37 version 1.64, 2012/02/20 21:04:35
Line 57 
Line 57 
 #include <ctype.h>  #include <ctype.h>
 #include <err.h>  #include <err.h>
 #include <fcntl.h>  #include <fcntl.h>
   #include <limits.h>
 #include <signal.h>  #include <signal.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 132 
Line 133 
         "PT_TRACE_ME",  "PT_READ_I",    "PT_READ_D",    "PT_READ_U",          "PT_TRACE_ME",  "PT_READ_I",    "PT_READ_D",    "PT_READ_U",
         "PT_WRITE_I",   "PT_WRITE_D",   "PT_WRITE_U",   "PT_CONTINUE",          "PT_WRITE_I",   "PT_WRITE_D",   "PT_WRITE_U",   "PT_CONTINUE",
         "PT_KILL",      "PT_ATTACH",    "PT_DETACH",    "PT_IO",          "PT_KILL",      "PT_ATTACH",    "PT_DETACH",    "PT_IO",
           "PT_SET_EVENT_MASK", "PT_GET_EVENT_MASK", "PT_GET_PROCESS_STATE",
 };  };
   
 static int narg;  static int narg;
Line 232 
Line 234 
                 if (ktrlen > size) {                  if (ktrlen > size) {
                         void *newm;                          void *newm;
   
                           if (ktrlen == SIZE_MAX)
                                   errx(1, "data too long");
                         newm = realloc(m, ktrlen+1);                          newm = realloc(m, ktrlen+1);
                         if (newm == NULL)                          if (newm == NULL)
                                 err(1, NULL);                                  err(1, NULL);
Line 711 
Line 715 
                 pn(NULL);                  pn(NULL);
                 pn(shmctlname);                  pn(shmctlname);
                 break;                  break;
           case SYS_clock_gettime:
           case SYS_clock_settime:
           case SYS_clock_getres:
                   pn(clockname);
                   break;
         case SYS_sigaction:          case SYS_sigaction:
                 pn(signame);                  pn(signame);
                 break;                  break;
         case SYS_sigprocmask:          case SYS_sigprocmask:
                 pn(sigprocmaskhowname);                  pn(sigprocmaskhowname);
                   pn(sigset);
                 break;                  break;
           case SYS_sigsuspend:
                   pn(sigset);
                   break;
         case SYS_socket: {          case SYS_socket: {
                 int sockdomain = *ap;                  int sockdomain = *ap;
   
Line 743 
Line 756 
                 pn(NULL);                  pn(NULL);
                 pn(wait4optname);                  pn(wait4optname);
                 break;                  break;
           case SYS___thrsleep:
                   pn(NULL);
                   pn(clockname);
                   break;
           case SYS___thrsigdivert:
                   pn(sigset);
                   break;
         case SYS_faccessat:          case SYS_faccessat:
                 pn(atfd);                  pn(atfd);
                 pn(NULL);                  pn(NULL);
Line 849 
Line 869 
 static struct ctlname kernmallocname[] = CTL_KERN_MALLOC_NAMES;  static struct ctlname kernmallocname[] = CTL_KERN_MALLOC_NAMES;
 static struct ctlname forkstatname[] = CTL_KERN_FORKSTAT_NAMES;  static struct ctlname forkstatname[] = CTL_KERN_FORKSTAT_NAMES;
 static struct ctlname nchstatsname[] = CTL_KERN_NCHSTATS_NAMES;  static struct ctlname nchstatsname[] = CTL_KERN_NCHSTATS_NAMES;
   static struct ctlname kernprocname[] =
   {
           { NULL },
           { "all" },
           { "pid" },
           { "pgrp" },
           { "session" },
           { "tty" },
           { "uid" },
           { "ruid" },
   };
 static struct ctlname ttysname[] = CTL_KERN_TTY_NAMES;  static struct ctlname ttysname[] = CTL_KERN_TTY_NAMES;
 static struct ctlname semname[] = CTL_KERN_SEMINFO_NAMES;  static struct ctlname semname[] = CTL_KERN_SEMINFO_NAMES;
 static struct ctlname shmname[] = CTL_KERN_SHMINFO_NAMES;  static struct ctlname shmname[] = CTL_KERN_SHMINFO_NAMES;
Line 935 
Line 966 
                         case KERN_WATCHDOG:                          case KERN_WATCHDOG:
                                 SETNAME(watchdogname);                                  SETNAME(watchdogname);
                                 break;                                  break;
                           case KERN_PROC:
                                   idx++;  /* zero is valid at this level */
                                   SETNAME(kernprocname);
                                   break;
                         case KERN_TIMECOUNTER:                          case KERN_TIMECOUNTER:
                                 SETNAME(tcname);                                  SETNAME(tcname);
                                 break;                                  break;
Line 961 
Line 996 
                 if (ret > 0 && (strcmp(current->sysnames[code], "fork") == 0 ||                  if (ret > 0 && (strcmp(current->sysnames[code], "fork") == 0 ||
                     strcmp(current->sysnames[code], "vfork") == 0 ||                      strcmp(current->sysnames[code], "vfork") == 0 ||
                     strcmp(current->sysnames[code], "rfork") == 0 ||                      strcmp(current->sysnames[code], "rfork") == 0 ||
                       strcmp(current->sysnames[code], "__tfork") == 0 ||
                     strcmp(current->sysnames[code], "clone") == 0))                      strcmp(current->sysnames[code], "clone") == 0))
                         mappidtoemul(ret, current);                          mappidtoemul(ret, current);
         }          }
   
         if (error == 0) {          if (error == 0) {
                 if (fancy) {                  if (fancy) {
                         (void)printf("%ld", (long)ret);                          switch (current == &emulations[0] ? code : -1) {
                         if (ret < 0 || ret > 9)                          case SYS_sigprocmask:
                                 (void)printf("/%#lx", (long)ret);                                  sigset(ret);
                                   break;
                           case SYS___thrsigdivert:
                                   signame(ret);
                                   break;
                           case -1:        /* non-default emulation */
                           default:
                                   (void)printf("%ld", (long)ret);
                                   if (ret < 0 || ret > 9)
                                           (void)printf("/%#lx", (long)ret);
                           }
                 } else {                  } else {
                         if (decimal)                          if (decimal)
                                 (void)printf("%ld", (long)ret);                                  (void)printf("%ld", (long)ret);
Line 1123 
Line 1169 
         (void)printf("SIG%s ", sys_signame[psig->signo]);          (void)printf("SIG%s ", sys_signame[psig->signo]);
         if (psig->action == SIG_DFL)          if (psig->action == SIG_DFL)
                 (void)printf("SIG_DFL");                  (void)printf("SIG_DFL");
         else          else {
                 (void)printf("caught handler=0x%lx mask=0x%x",                  (void)printf("caught handler=0x%lx mask=",
                     (u_long)psig->action, psig->mask);                      (u_long)psig->action);
                   sigset(psig->mask);
           }
         if (psig->code) {          if (psig->code) {
                 printf(" code ");                  printf(" code ");
                 if (fancy) {                  if (fancy) {
Line 1179 
Line 1227 
   
   
   
 void  static void
 ktrsockaddr(struct sockaddr *sa)  ktrsockaddr(struct sockaddr *sa)
 {  {
 /*  /*
Line 1256 
Line 1304 
         printf(" }\n");          printf(" }\n");
 }  }
   
 void  static void
 ktrstat(struct stat *statp)  print_time(time_t t, int relative)
 {  {
         char mode[12], timestr[PATH_MAX + 4];          char timestr[PATH_MAX + 4];
           struct tm *tm;
   
           if (resolv == 0 || relative)
                   printf("%jd", (intmax_t)t);
           else {
                   tm = localtime(&t);
                   (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);
                   printf("\"%s\"", timestr);
           }
   }
   
   static void
   print_timespec(const struct timespec *tsp, int relative)
   {
           print_time(tsp->tv_sec, relative);
           if (tsp->tv_nsec != 0)
                   printf(".%09ld", tsp->tv_nsec);
   }
   
   static void
   ktrstat(const struct stat *statp)
   {
           char mode[12];
         struct passwd *pwd;          struct passwd *pwd;
         struct group  *grp;          struct group  *grp;
         struct tm *tm;  
   
         /*          /*
          * note: ktrstruct() has already verified that statp points to a           * note: ktrstruct() has already verified that statp points to a
          * buffer exactly sizeof(struct stat) bytes long.           * buffer exactly sizeof(struct stat) bytes long.
          */           */
         printf("struct stat {");          printf("struct stat { ");
         strmode(statp->st_mode, mode);          strmode(statp->st_mode, mode);
         printf("dev=%d, ino=%u, mode=%s, nlink=%u, ",          printf("dev=%d, ino=%u, mode=%s, nlink=%u, ",
             statp->st_dev, statp->st_ino, mode, statp->st_nlink);              statp->st_dev, statp->st_ino, mode, statp->st_nlink);
Line 1282 
Line 1352 
                 printf("gid=\"%s\", ", grp->gr_name);                  printf("gid=\"%s\", ", grp->gr_name);
         printf("rdev=%d, ", statp->st_rdev);          printf("rdev=%d, ", statp->st_rdev);
         printf("atime=");          printf("atime=");
         if (resolv == 0)          print_timespec(&statp->st_atim, 0);
                 printf("%jd", (intmax_t)statp->st_atim.tv_sec);          printf(", mtime=");
         else {          print_timespec(&statp->st_mtim, 0);
                 tm = localtime(&statp->st_atim.tv_sec);          printf(", ctime=");
                 (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);          print_timespec(&statp->st_ctim, 0);
                 printf("\"%s\"", timestr);          printf(", size=%lld, blocks=%lld, blksize=%u, flags=0x%x, gen=0x%x",
         }  
         if (statp->st_atim.tv_nsec != 0)  
                 printf(".%09ld, ", statp->st_atim.tv_nsec);  
         else  
                 printf(", ");  
         printf("stime=");  
         if (resolv == 0)  
                 printf("%jd", (intmax_t)statp->st_mtim.tv_sec);  
         else {  
                 tm = localtime(&statp->st_mtim.tv_sec);  
                 (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);  
                 printf("\"%s\"", timestr);  
         }  
         if (statp->st_mtim.tv_nsec != 0)  
                 printf(".%09ld, ", statp->st_mtim.tv_nsec);  
         else  
                 printf(", ");  
         printf("ctime=");  
         if (resolv == 0)  
                 printf("%jd", (intmax_t)statp->st_ctim.tv_sec);  
         else {  
                 tm = localtime(&statp->st_ctim.tv_sec);  
                 (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm);  
                 printf("\"%s\"", timestr);  
         }  
         if (statp->st_ctim.tv_nsec != 0)  
                 printf(".%09ld, ", statp->st_ctim.tv_nsec);  
         else  
                 printf(", ");  
         printf("size=%lld, blocks=%lld, blksize=%u, flags=0x%x, gen=0x%x",  
             statp->st_size, statp->st_blocks, statp->st_blksize,              statp->st_size, statp->st_blocks, statp->st_blksize,
             statp->st_flags, statp->st_gen);              statp->st_flags, statp->st_gen);
         printf(" }\n");          printf(" }\n");
 }  }
   
 void  static void
 ktrstruct(char *buf, size_t buflen)  ktrstruct(char *buf, size_t buflen)
 {  {
         char *name, *data;          char *name, *data;
         size_t namelen, datalen;          size_t namelen, datalen;
         int i;          int i;
         struct stat sb;  
         struct sockaddr_storage ss;  
   
         for (name = buf, namelen = 0; namelen < buflen && name[namelen] != '\0';          for (name = buf, namelen = 0; namelen < buflen && name[namelen] != '\0';
              ++namelen)               ++namelen)
Line 1348 
Line 1386 
                 if (!isalpha((unsigned char)name[i]))                  if (!isalpha((unsigned char)name[i]))
                         goto invalid;                          goto invalid;
         if (strcmp(name, "stat") == 0) {          if (strcmp(name, "stat") == 0) {
                   struct stat sb;
   
                 if (datalen != sizeof(struct stat))                  if (datalen != sizeof(struct stat))
                         goto invalid;                          goto invalid;
                 memcpy(&sb, data, datalen);                  memcpy(&sb, data, datalen);
                 ktrstat(&sb);                  ktrstat(&sb);
         } else if (strcmp(name, "sockaddr") == 0) {          } else if (strcmp(name, "sockaddr") == 0) {
                   struct sockaddr_storage ss;
   
                 if (datalen > sizeof(ss))                  if (datalen > sizeof(ss))
                         goto invalid;                          goto invalid;
                 memcpy(&ss, data, datalen);                  memcpy(&ss, data, datalen);

Legend:
Removed from v.1.63  
changed lines
  Added in v.1.64