]> granicus.if.org Git - procps-ng/commitdiff
Merge branch 'master' into nls
authorCraig Small <csmall@enc.com.au>
Sun, 25 Dec 2011 22:11:27 +0000 (09:11 +1100)
committerCraig Small <csmall@enc.com.au>
Sun, 25 Dec 2011 22:11:27 +0000 (09:11 +1100)
Conflicts:
configure.ac
pmap.c
ps/Makefile.am

1  2 
.gitignore
Makefile.am
configure.ac
pmap.c
proc/libprocps.sym
ps/Makefile.am
top/Makefile.am

diff --cc .gitignore
Simple merge
diff --cc Makefile.am
index 185e0e53d565ccd7c84ef53bb4bb739b52eb6149,e246d026fd39fd06084cec2d6d51f26da4a61575..8fb59cfc5eef0c87e003fae2001c9d6652876133
@@@ -1,17 -1,10 +1,17 @@@
 -AM_CPPFLAGS = -include $(top_builddir)/config.h
 +AM_CPPFLAGS = -include $(top_builddir)/config.h -I$(top_srcdir)/include
  
  ACLOCAL_AMFLAGS = -I m4
 -SUBDIRS = proc ps testsuite
 +SUBDIRS = \
 +      include \
 +      lib \
 +      po \
 +      proc \
 +      ps \
 +      testsuite \
 +      top
  
  AM_CFLAGS = -Iproc
- AM_LDFLAGS = ./proc/libprocfs.la
+ AM_LDFLAGS = ./proc/libprocps.la
  
  sbin_PROGRAMS = \
        sysctl
diff --cc configure.ac
index 51285dda7c31d3d5fc1fbbacd1cc8bad8b3048e3,85afd0e1157b890b37afe1e9e5030ceffa19fd22..7c99fb33acb01c11b2ff0f33d3d437bacda864b6
@@@ -181,22 -160,17 +181,22 @@@ if test "x$enable_whining" = xyes; the
    AC_DEFINE(BUILD_WITH_WHINE, 1, [should extra warnings be printed (slackware-ism)])
  fi
  
 -if test x"$DEJAGNU" = x                                                        
 -then                                                                           
 -  DEJAGNU="\$(top_srcdir)/testsuite/global-conf.exp"                         
 -fi                                                                             
 -AC_SUBST(DEJAGNU)   
 +if test x"$DEJAGNU" = x
 +then
 +  DEJAGNU="\$(top_srcdir)/testsuite/global-conf.exp"
 +fi
 +AC_SUBST(DEJAGNU)
  
  AC_CONFIG_FILES([
 -Makefile
 -proc/Makefile
 -proc/libprocps.pc
 -ps/Makefile
 -testsuite/Makefile
 +      Makefile
 +      include/Makefile
 +      lib/Makefile
 +      po/Makefile.in
 +      proc/Makefile
-       proc/libprocfs.pc
++      proc/libprocps.pc
 +      ps/Makefile
 +      testsuite/Makefile
 +      top/Makefile
  ])
 +
  AC_OUTPUT
diff --cc pmap.c
index 116dc9c98b2bea6a2c91489dbc5217cb96f4dc69,6555b841145b257919f6f0c3ca064c6bf14805b4..998080e840fe4e357b6d3b5bfb7472c98f0fec5e
--- 1/pmap.c
--- 2/pmap.c
+++ b/pmap.c
@@@ -57,445 -50,376 +57,447 @@@ static int x_option
  
  static unsigned shm_minor = ~0u;
  
 -static void discover_shm_minor(void){
 -  void *addr;
 -  int shmid;
 -  char mapbuf[256];
 -
 -  if(!freopen("/proc/self/maps", "r", stdin)) return;
 -
 -  // create
 -  shmid = shmget(IPC_PRIVATE, 42, IPC_CREAT | 0666);
 -  if(shmid==-1) return; // failed; oh well
 -  // attach
 -  addr = shmat(shmid, NULL, SHM_RDONLY);
 -  if(addr==(void*)-1) goto out_destroy;
 -
 -  while(fgets(mapbuf, sizeof mapbuf, stdin)){
 -    char flags[32];
 -    char *tmp; // to clean up unprintables
 -    unsigned KLONG start, end;
 -    unsigned long long file_offset, inode;
 -    unsigned dev_major, dev_minor;
 -    sscanf(mapbuf,"%"KLF"x-%"KLF"x %31s %Lx %x:%x %Lu", &start, &end, flags, &file_offset, &dev_major, &dev_minor, &inode);
 -    tmp = strchr(mapbuf,'\n');
 -    if(tmp) *tmp='\0';
 -    tmp = mapbuf;
 -    while(*tmp){
 -      if(!isprint(*tmp)) *tmp='?';
 -      tmp++;
 -    }
 -    if(start > (unsigned long)addr) continue;
 -    if(dev_major) continue;
 -    if(flags[3] != 's') continue;
 -    if(strstr(mapbuf,"/SYSV")){
 -      shm_minor = dev_minor;
 -      break;
 -    }
 -  }
 -
 -  if(shmdt(addr)) perror("shmdt");
 -
 -out_destroy:
 -  if(shmctl(shmid, IPC_RMID, NULL)) perror("IPC_RMID");
 -
 -  return;
 +static void discover_shm_minor(void)
 +{
 +      void *addr;
 +      int shmid;
 +      char mapbuf[256];
 +
 +      if (!freopen("/proc/self/maps", "r", stdin))
 +              return;
 +
 +      /* create */
 +      shmid = shmget(IPC_PRIVATE, 42, IPC_CREAT | 0666);
 +      if (shmid == -1)
 +              /* failed; oh well */
 +              return;
 +      /* attach */
 +      addr = shmat(shmid, NULL, SHM_RDONLY);
 +      if (addr == (void *)-1)
 +              goto out_destroy;
 +
 +      while (fgets(mapbuf, sizeof mapbuf, stdin)) {
 +              char flags[32];
 +              /* to clean up unprintables */
 +              char *tmp;
 +              unsigned KLONG start, end;
 +              unsigned long long file_offset, inode;
 +              unsigned dev_major, dev_minor;
 +              sscanf(mapbuf, "%" KLF "x-%" KLF "x %31s %Lx %x:%x %Lu", &start,
 +                     &end, flags, &file_offset, &dev_major, &dev_minor,
 +                     &inode);
 +              tmp = strchr(mapbuf, '\n');
 +              if (tmp)
 +                      *tmp = '\0';
 +              tmp = mapbuf;
 +              while (*tmp) {
 +                      if (!isprint(*tmp))
 +                              *tmp = '?';
 +                      tmp++;
 +              }
 +              if (start > (unsigned long)addr)
 +                      continue;
 +              if (dev_major)
 +                      continue;
 +              if (flags[3] != 's')
 +                      continue;
 +              if (strstr(mapbuf, "/SYSV")) {
 +                      shm_minor = dev_minor;
 +                      break;
 +              }
 +      }
 +
 +      if (shmdt(addr))
 +              perror(_("shared memory detach"));
 +
 + out_destroy:
 +      if (shmctl(shmid, IPC_RMID, NULL))
 +              perror(_("shared memory remove"));
 +
 +      return;
  }
  
 -
 -static const char *mapping_name(proc_t *p, unsigned KLONG addr, unsigned KLONG len, const char *mapbuf, unsigned showpath, unsigned dev_major, unsigned dev_minor, unsigned long long inode){
 -  const char *cp;
 -
 -  if(!dev_major && dev_minor==shm_minor && strstr(mapbuf,"/SYSV")){
 -    static char shmbuf[64];
 -    snprintf(shmbuf, sizeof shmbuf, "  [ shmid=0x%Lx ]", inode);
 -    return shmbuf;
 -  }
 -
 -  cp = strrchr(mapbuf,'/');
 -  if(cp){
 -    if(showpath) return strchr(mapbuf,'/');
 -    return cp[1] ? cp+1 : cp;
 -  }
 -
 -  cp = strchr(mapbuf,'/');
 -  if(cp){
 -    if(showpath) return cp;
 -    return strrchr(cp,'/') + 1;  // it WILL succeed
 -  }
 -
 -  cp = "  [ anon ]";
 -  if( (p->start_stack >= addr) && (p->start_stack <= addr+len) )  cp = "  [ stack ]";
 -  return cp;
 +static const char *mapping_name(proc_t * p, unsigned KLONG addr,
 +                              unsigned KLONG len, const char *mapbuf,
 +                              unsigned showpath, unsigned dev_major,
 +                              unsigned dev_minor, unsigned long long inode)
 +{
 +      const char *cp;
 +
 +      if (!dev_major && dev_minor == shm_minor && strstr(mapbuf, "/SYSV")) {
 +              static char shmbuf[64];
 +              snprintf(shmbuf, sizeof shmbuf, "  [ shmid=0x%Lx ]", inode);
 +              return shmbuf;
 +      }
 +
 +      cp = strrchr(mapbuf, '/');
 +      if (cp) {
 +              if (showpath)
 +                      return strchr(mapbuf, '/');
 +              return cp[1] ? cp + 1 : cp;
 +      }
 +
 +      cp = strchr(mapbuf, '/');
 +      if (cp) {
 +              if (showpath)
 +                      return cp;
 +              /* it WILL succeed */
 +              return strrchr(cp, '/') + 1;
 +      }
 +
 +      cp = _("  [ anon ]");
 +      if ((p->start_stack >= addr) && (p->start_stack <= addr + len))
 +              cp = _("  [ stack ]");
 +      return cp;
  }
  
 -static int one_proc(proc_t *p){
 -  char buf[32];
 -  char mapbuf[9600];
 -  char cmdbuf[512];
 -  FILE *fp;
 -  unsigned long total_shared = 0ul;
 -  unsigned long total_private_readonly = 0ul;
 -  unsigned long total_private_writeable = 0ul;
 -
 -  char *cp2=NULL;
 -  unsigned long long rss = 0ull;
 -  unsigned long long private_dirty = 0ull;
 -  unsigned long long shared_dirty = 0ull;
 -  unsigned long long total_rss = 0ull;
 -  unsigned long long total_private_dirty = 0ull;
 -  unsigned long long total_shared_dirty = 0ull;
 -  unsigned KLONG diff=0;
 -
 -  // Overkill, but who knows what is proper? The "w" prog
 -  // uses the tty width to determine this.
 -  int maxcmd = 0xfffff;
 -
 -  sprintf(buf,"/proc/%u/maps",p->tgid);
 -  if ( (fp = fopen(buf, "r")) == NULL) return 1;
 -  if (x_option) {
 -    sprintf(buf,"/proc/%u/smaps",p->tgid);
 -    if ( (fp = freopen(buf, "r", fp)) == NULL) return 1;
 -  }
 -
 -  escape_command(cmdbuf, p, sizeof cmdbuf, &maxcmd, ESC_ARGS|ESC_BRACKETS);
 -  printf("%u:   %s\n", p->tgid, cmdbuf);
 -
 -  if(!q_option && (x_option|d_option)){
 -    if(x_option){
 -      if(sizeof(KLONG)==4) printf("Address   Kbytes     RSS   Dirty Mode   Mapping\n");
 -      else         printf("Address           Kbytes     RSS   Dirty Mode   Mapping\n");
 -    }
 -    if(d_option){
 -      if(sizeof(KLONG)==4) printf("Address   Kbytes Mode  Offset           Device    Mapping\n");
 -      else         printf("Address           Kbytes Mode  Offset           Device    Mapping\n");
 -    }
 -  }
 -
 -  while(fgets(mapbuf,sizeof mapbuf,fp)){
 -    char flags[32];
 -    char *tmp; // to clean up unprintables
 -    unsigned KLONG start, end;
 -    unsigned long long file_offset, inode;
 -    unsigned dev_major, dev_minor;
 -    unsigned long long smap_value;
 -    char smap_key[20];
 -
 -    /* hex values are lower case or numeric, keys are upper */
 -    if (mapbuf[0] >= 'A' && mapbuf[0] <= 'Z') {
 -      /* Its a key */
 -      if (sscanf(mapbuf,"%20[^:]: %llu", smap_key, &smap_value) == 2) {
 -        if (strncmp("Rss", smap_key, 3) == 0) {
 -          rss = smap_value;
 -          total_rss += smap_value;
 -          continue;
 -        }
 -        if (strncmp("Shared_Dirty", smap_key, 12) == 0) {
 -          shared_dirty = smap_value;
 -          total_shared_dirty += smap_value;
 -          continue;
 -        }
 -        if (strncmp("Private_Dirty", smap_key, 13) == 0) {
 -          private_dirty = smap_value;
 -          total_private_dirty += smap_value;
 -          continue;
 -        }
 -        if (strncmp("Swap", smap_key, 4) == 0) { /*doesnt matter as long as last*/
 -          printf(
 -            (sizeof(KLONG)==8)
 -              ? "%016"KLF"x %7lu %7llu %7llu %s  %s\n"
 -              :      "%08lx %7lu %7llu %7llu %s  %s\n",
 -            start,
 -            (unsigned long)(diff>>10),
 -            rss,
 -            (private_dirty + shared_dirty),
 -            flags,
 -            cp2
 -          );
 -          /* reset some counters */
 -          rss = shared_dirty = private_dirty = 0ull;
 -          diff=0;
 -          continue;
 -        }
 -        /* Other keys */
 -        continue;
 -      }
 -    }
 -    sscanf(mapbuf,"%"KLF"x-%"KLF"x %31s %Lx %x:%x %Lu", &start, &end, flags, &file_offset, &dev_major, &dev_minor, &inode);
 -
 -    if(start > range_high)
 -      break;
 -    if(end < range_low)
 -      continue;
 -
 -    tmp = strchr(mapbuf,'\n');
 -    if(tmp) *tmp='\0';
 -    tmp = mapbuf;
 -    while(*tmp){
 -      if(!isprint(*tmp)) *tmp='?';
 -      tmp++;
 -    }
 -    
 -    diff = end-start;
 -    if(flags[3]=='s') total_shared  += diff;
 -    if(flags[3]=='p'){
 -      flags[3] = '-';
 -      if(flags[1]=='w') total_private_writeable += diff;
 -      else              total_private_readonly  += diff;
 -    }
 -
 -    // format used by Solaris 9 and procps-3.2.0+
 -    // an 'R' if swap not reserved (MAP_NORESERVE, SysV ISM shared mem, etc.)
 -    flags[4] = '-';
 -    flags[5] = '\0';
 -
 -    if(x_option){
 -          cp2 = mapping_name(p, start, diff, mapbuf, 0, dev_major, dev_minor, inode);
 -      /* printed with the keys */
 -      continue;
 -    }
 -    if(d_option){
 -      const char *cp = mapping_name(p, start, diff, mapbuf, 0, dev_major, dev_minor, inode);
 -      printf(
 -        (sizeof(KLONG)==8)
 -          ? "%016"KLF"x %7lu %s %016Lx %03x:%05x %s\n"
 -          :      "%08lx %7lu %s %016Lx %03x:%05x %s\n",
 -        start,
 -        (unsigned long)(diff>>10),
 -        flags,
 -        file_offset,
 -        dev_major, dev_minor,
 -        cp
 -      );
 -    }
 -    if(!x_option && !d_option){
 -      const char *cp = mapping_name(p, start, diff, mapbuf, 1, dev_major, dev_minor, inode);
 -      printf(
 -        (sizeof(KLONG)==8)
 -          ? "%016"KLF"x %6luK %s  %s\n"
 -          :      "%08lx %6luK %s  %s\n",
 -        start,
 -        (unsigned long)(diff>>10),
 -        flags,
 -        cp
 -      );
 -    }
 -    
 -  }
 -
 -
 -
 -
 -  if(!q_option){
 -    if(x_option){
 -      if(sizeof(KLONG)==8){
 -        printf("----------------  ------  ------  ------\n");
 -        printf(
 -          "total kB %15ld %7llu %7llu\n",
 -          (total_shared + total_private_writeable + total_private_readonly) >> 10,
 -          total_rss, (total_shared_dirty+total_private_dirty)
 -
 -        );
 -      }else{
 -        printf("-------- ------- ------- ------- -------\n");
 -        printf(
 -          "total kB %7ld       -       -       -\n",
 -          (total_shared + total_private_writeable + total_private_readonly) >> 10
 -        );
 -      }
 -    }
 -    if(d_option){
 -        printf(
 -          "mapped: %ldK    writeable/private: %ldK    shared: %ldK\n",
 -          (total_shared + total_private_writeable + total_private_readonly) >> 10,
 -          total_private_writeable >> 10,
 -          total_shared >> 10
 -        );
 -    }
 -    if(!x_option && !d_option){
 -      if(sizeof(KLONG)==8) printf(" total %16ldK\n", (total_shared + total_private_writeable + total_private_readonly) >> 10);
 -      else                 printf(" total %8ldK\n",  (total_shared + total_private_writeable + total_private_readonly) >> 10);
 -    }
 -  }
 -
 -  return 0;
 +static int one_proc(proc_t * p)
 +{
 +      char buf[32];
 +      char mapbuf[9600];
 +      char cmdbuf[512];
 +      FILE *fp;
 +      unsigned long total_shared = 0ul;
 +      unsigned long total_private_readonly = 0ul;
 +      unsigned long total_private_writeable = 0ul;
++    KLONG diff = 0;
 +
 +      char *cp2 = NULL;
 +      unsigned long long rss = 0ull;
 +      unsigned long long private_dirty = 0ull;
 +      unsigned long long shared_dirty = 0ull;
 +      unsigned long long total_rss = 0ull;
 +      unsigned long long total_private_dirty = 0ull;
 +      unsigned long long total_shared_dirty = 0ull;
 +
 +      /* Overkill, but who knows what is proper? The "w" prog uses
 +       * the tty width to determine this.
 +       */
 +      int maxcmd = 0xfffff;
 +
 +      sprintf(buf, "/proc/%u/maps", p->tgid);
 +      if ((fp = fopen(buf, "r")) == NULL)
 +              return 1;
 +      if (x_option) {
 +              sprintf(buf, "/proc/%u/smaps", p->tgid);
 +              if ((fp = freopen(buf, "r", fp)) == NULL)
 +                      return 1;
 +      }
 +
 +      escape_command(cmdbuf, p, sizeof cmdbuf, &maxcmd,
 +                     ESC_ARGS | ESC_BRACKETS);
 +      printf("%u:   %s\n", p->tgid, cmdbuf);
 +
 +      if (!q_option && (x_option | d_option)) {
 +              if (x_option) {
 +                      if (sizeof(KLONG) == 4)
 +                              /* Translation Hint: Please keep
 +                               * alignment of the following four
 +                               * headers intact. */
 +                              printf
 +                                  (_("Address   Kbytes     RSS   Dirty Mode   Mapping\n"));
 +                      else
 +                              printf
 +                                  (_("Address           Kbytes     RSS   Dirty Mode   Mapping\n"));
 +              }
 +              if (d_option) {
 +                      if (sizeof(KLONG) == 4)
 +                              printf
 +                                  (_("Address   Kbytes Mode  Offset           Device    Mapping\n"));
 +                      else
 +                              printf
 +                                  (_("Address           Kbytes Mode  Offset           Device    Mapping\n"));
 +              }
 +      }
 +
 +      while (fgets(mapbuf, sizeof mapbuf, fp)) {
 +              char flags[32];
 +              /* to clean up unprintables */
 +              char *tmp;
-               unsigned KLONG start, end, diff = 0;
++              unsigned KLONG start, end;
 +              unsigned long long file_offset, inode;
 +              unsigned dev_major, dev_minor;
 +              unsigned long long smap_value;
 +              char smap_key[20];
 +
 +              /* hex values are lower case or numeric, keys are upper */
 +              if (mapbuf[0] >= 'A' && mapbuf[0] <= 'Z') {
 +                      /* Its a key */
 +                      if (sscanf
 +                          (mapbuf, "%20[^:]: %llu", smap_key,
 +                           &smap_value) == 2) {
 +                              if (strncmp("Rss", smap_key, 3) == 0) {
 +                                      rss = smap_value;
 +                                      total_rss += smap_value;
 +                                      continue;
 +                              }
 +                              if (strncmp("Shared_Dirty", smap_key, 12) == 0) {
 +                                      shared_dirty = smap_value;
 +                                      total_shared_dirty += smap_value;
 +                                      continue;
 +                              }
 +                              if (strncmp("Private_Dirty", smap_key, 13) == 0) {
 +                                      private_dirty = smap_value;
 +                                      total_private_dirty += smap_value;
 +                                      continue;
 +                              }
 +                              if (strncmp("Swap", smap_key, 4) == 0) {
 +                                      /*doesnt matter as long as last */
 +                                      printf((sizeof(KLONG) == 8)
 +                                             ? "%016" KLF
 +                                             "x %7lu %7llu %7llu %s  %s\n" :
 +                                             "%08lx %7lu %7llu %7llu %s  %s\n",
 +                                             start,
 +                                             (unsigned long)(diff >> 10), rss,
 +                                             (private_dirty + shared_dirty),
 +                                             flags, cp2);
 +                                      /* reset some counters */
 +                                      rss = shared_dirty = private_dirty =
 +                                          0ull;
++                    diff = 0;
 +                                      continue;
 +                              }
 +                              /* Other keys */
 +                              continue;
 +                      }
 +              }
 +              sscanf(mapbuf, "%" KLF "x-%" KLF "x %31s %Lx %x:%x %Lu", &start,
 +                     &end, flags, &file_offset, &dev_major, &dev_minor,
 +                     &inode);
 +
 +              if (start > range_high)
 +                      break;
 +              if (end < range_low)
 +                      continue;
 +
 +              tmp = strchr(mapbuf, '\n');
 +              if (tmp)
 +                      *tmp = '\0';
 +              tmp = mapbuf;
 +              while (*tmp) {
 +                      if (!isprint(*tmp))
 +                              *tmp = '?';
 +                      tmp++;
 +              }
 +
 +              diff = end - start;
 +              if (flags[3] == 's')
 +                      total_shared += diff;
 +              if (flags[3] == 'p') {
 +                      flags[3] = '-';
 +                      if (flags[1] == 'w')
 +                              total_private_writeable += diff;
 +                      else
 +                              total_private_readonly += diff;
 +              }
 +              /* format used by Solaris 9 and procps-3.2.0+ an 'R'
 +               * if swap not reserved (MAP_NORESERVE, SysV ISM
 +               * shared mem, etc.)
 +               */
 +              flags[4] = '-';
 +              flags[5] = '\0';
 +
 +              if (x_option) {
 +                      cp2 =
 +                          mapping_name(p, start, diff, mapbuf, 0, dev_major,
 +                                       dev_minor, inode);
 +                      /* printed with the keys */
 +                      continue;
 +              }
 +              if (d_option) {
 +                      const char *cp =
 +                          mapping_name(p, start, diff, mapbuf, 0, dev_major,
 +                                       dev_minor, inode);
 +                      printf((sizeof(KLONG) == 8)
 +                             ? "%016" KLF "x %7lu %s %016Lx %03x:%05x %s\n"
 +                             : "%08lx %7lu %s %016Lx %03x:%05x %s\n",
 +                             start,
 +                             (unsigned long)(diff >> 10),
 +                             flags, file_offset, dev_major, dev_minor, cp);
 +              }
 +              if (!x_option && !d_option) {
 +                      const char *cp =
 +                          mapping_name(p, start, diff, mapbuf, 1, dev_major,
 +                                       dev_minor, inode);
 +                      printf((sizeof(KLONG) == 8)
 +                             ? "%016" KLF "x %6luK %s  %s\n"
 +                             : "%08lx %6luK %s  %s\n",
 +                             start, (unsigned long)(diff >> 10), flags, cp);
 +              }
 +
 +      }
 +
 +      if (!q_option) {
 +              if (x_option) {
 +                      if (sizeof(KLONG) == 8) {
 +                              printf
 +                                  ("----------------  ------  ------  ------\n");
 +                              printf(_("total kB %15ld %7llu %7llu\n"),
 +                                     (total_shared + total_private_writeable +
 +                                      total_private_readonly) >> 10,
 +                                     total_rss,
 +                                     (total_shared_dirty +
 +                                      total_private_dirty)
 +
 +                                  );
 +                      } else {
 +                              printf
 +                                  ("-------- ------- ------- ------- -------\n");
 +                              printf
 +                                  (_("total kB %7ld       -       -       -\n"),
 +                                   (total_shared + total_private_writeable +
 +                                    total_private_readonly) >> 10);
 +                      }
 +              }
 +              if (d_option) {
 +                      printf
 +                          (_("mapped: %ldK    writeable/private: %ldK    shared: %ldK\n"),
 +                           (total_shared + total_private_writeable +
 +                            total_private_readonly) >> 10,
 +                           total_private_writeable >> 10, total_shared >> 10);
 +              }
 +              if (!x_option && !d_option) {
 +                      if (sizeof(KLONG) == 8)
 +                              /* Translation Hint: keep total string length
 +                               * as 24 characters. Adjust %16 if needed*/
 +                              printf(_(" total %16ldK\n"),
 +                                     (total_shared + total_private_writeable +
 +                                      total_private_readonly) >> 10);
 +                      else
 +                              /* Translation Hint: keep total string length
 +                               * as 16 characters. Adjust %8 if needed*/
 +                              printf(_(" total %8ldK\n"),
 +                                     (total_shared + total_private_writeable +
 +                                      total_private_readonly) >> 10);
 +              }
 +      }
 +
 +      return 0;
  }
  
 -
 -int main(int argc, char *argv[]){
 -  unsigned *pidlist;
 -  unsigned count = 0;
 -  PROCTAB* PT;
 -  proc_t p;
 -  int ret = 0;
 -
 -  if(argc<2) usage();
 -  pidlist = malloc(sizeof(unsigned)*argc);  // a bit more than needed perhaps
 -
 -  while(*++argv){
 -    if(!strcmp("--version",*argv)){
 -      V_option++;
 -      continue;
 -    }
 -    if(**argv=='-'){
 -      char *walk = *argv;
 -      if(!walk[1]) usage();
 -      while(*++walk){
 -        switch(*walk){
 -        case 'V':
 -          V_option++;
 -          break;
 -        case 'x':
 -          x_option++;
 -          break;
 -        case 'r':
 -          r_option++;
 -          break;
 -        case 'd':
 -          d_option++;
 -          break;
 -        case 'q':
 -          q_option++;
 -          break;
 -        case 'A':{
 -            char *arg1;
 -            if(walk[1]){
 -              arg1 = walk+1;
 -              walk += strlen(walk)-1;
 -            }else{
 -              arg1 = *++argv;
 -              if(!arg1)
 -                usage();
 -            }
 -            char *arg2 = strchr(arg1,',');
 -            if(arg2)
 -              *arg2 = '\0';
 -            if(arg2) ++arg2;
 -            else arg2 = arg1;
 -            
 -            if(*arg1)
 -              range_low = STRTOUKL(arg1,&arg1,16);
 -            if(*arg2)
 -              range_high = STRTOUKL(arg2,&arg2,16);
 -            if(*arg1 || *arg2)
 -              usage();
 -          }
 -          break;
 -        case 'a': // Sun prints anon/swap reservations
 -        case 'F': // Sun forces hostile ptrace-like grab
 -        case 'l': // Sun shows unresolved dynamic names
 -        case 'L': // Sun shows lgroup info
 -        case 's': // Sun shows page sizes
 -        case 'S': // Sun shows swap reservations
 -        default:
 -          usage();
 -        }
 -      }
 -    }else{
 -      char *walk = *argv;
 -      char *endp;
 -      unsigned long pid;
 -      if(!strncmp("/proc/",walk,6)){
 -        walk += 6;
 -        // user allowed to do: pmap /proc/*
 -        if(*walk<'0' || *walk>'9') continue;
 -      }
 -      if(*walk<'0' || *walk>'9') usage();
 -      pid = strtoul(walk, &endp, 0);
 -      if(pid<1ul || pid>0x7ffffffful || *endp) usage();
 -      pidlist[count++] = pid;
 -    }
 -  }
 -
 -  if( (x_option|V_option|r_option|d_option|q_option) >> 1 ) usage(); // dupes
 -  if(V_option){
 -    if(count|x_option|r_option|d_option|q_option) usage();
 -    fprintf(stdout, "pmap (%s)\n", procps_version);
 -    return 0;
 -  }
 -  if(count<1) usage();   // no processes
 -  if(d_option && x_option) usage();
 -
 -  discover_shm_minor();
 -
 -  memset(&p, '\0', sizeof(p));
 -  pidlist[count] = 0;  // old libproc interface is zero-terminated
 -  PT = openproc(PROC_FILLSTAT|PROC_FILLARG|PROC_PID, pidlist);
 -  while(readproc(PT, &p)){
 -    ret |= one_proc(&p);
 -    count--;
 -  }
 -  closeproc(PT);
 -
 -  if(count) ret |= 42;  // didn't find all processes asked for
 -  return ret;
 +int main(int argc, char **argv)
 +{
 +      unsigned *pidlist;
 +      unsigned count = 0;
 +      PROCTAB *PT;
 +      proc_t p;
 +      int ret = 0, c;
 +
 +      static const struct option longopts[] = {
 +              {"extended", no_argument, NULL, 'x'},
 +              {"device", no_argument, NULL, 'd'},
 +              {"quiet", no_argument, NULL, 'q'},
 +              {"range", required_argument, NULL, 'A'},
 +              {"help", no_argument, NULL, 'h'},
 +              {"version", no_argument, NULL, 'V'},
 +              {NULL, 0, NULL, 0}
 +      };
 +
 +      setlocale (LC_ALL, "");
 +      bindtextdomain(PACKAGE, LOCALEDIR);
 +      textdomain(PACKAGE);
 +
 +      x_option = d_option = q_option = 0;
 +
 +      while ((c = getopt_long(argc, argv, "xrdqA:hV", longopts, NULL)) != -1)
 +              switch (c) {
 +              case 'x':
 +                      x_option = 1;
 +                      break;
 +              case 'r':
 +                      warnx(_("option -r is ignored as SunOS compatibility"));
 +                      break;
 +              case 'd':
 +                      d_option = 1;
 +                      break;
 +              case 'q':
 +                      q_option = 1;
 +                      break;
 +              case 'A':
 +                      {
 +                              /* FIXME: this should be a function. */
 +                              char *walk = optarg;
 +                              char *arg1;
 +                              char *arg2;
 +                              if (walk[1]) {
 +                                      arg1 = walk + 1;
 +                                      walk += strlen(walk) - 1;
 +                              } else {
 +                                      arg1 = *++argv;
 +                                      if (!arg1)
 +                                              usage(stderr);
 +                              }
 +                              arg2 = strchr(arg1, ',');
 +                              if (arg2)
 +                                      *arg2 = '\0';
 +                              if(arg2) ++arg2;
 +                              else arg2 = arg1;
 +
 +                              if (*arg1)
 +                                      range_low = STRTOUKL(arg1, &arg1, 16);
 +                              if (*arg2)
 +                                      range_high = STRTOUKL(arg2, &arg2, 16);
 +                              if (*arg1 || *arg2)
 +                                      usage(stderr);
 +                      }
 +                      break;
 +              case 'h':
 +                      usage(stdout);
 +              case 'V':
 +                      printf(PROCPS_NG_VERSION);
 +                      return EXIT_SUCCESS;
 +              case 'a':       /* Sun prints anon/swap reservations */
 +              case 'F':       /* Sun forces hostile ptrace-like grab */
 +              case 'l':       /* Sun shows unresolved dynamic names */
 +              case 'L':       /* Sun shows lgroup info */
 +              case 's':       /* Sun shows page sizes */
 +              case 'S':       /* Sun shows swap reservations */
 +              default:
 +                      usage(stderr);
 +              }
 +
 +      argc -= optind;
 +      argv += optind;
 +
 +      if (argc < 1)
 +              errx(EXIT_FAILURE, _("argument missing"));
 +      if (d_option && x_option)
 +              errx(EXIT_FAILURE, _("options -d and -x cannot coexist"));
 +
 +      pidlist = xmalloc(sizeof(unsigned) * argc);
 +
 +      while (*argv) {
 +              char *walk = *argv++;
 +              char *endp;
 +              unsigned long pid;
 +              if (!strncmp("/proc/", walk, 6)) {
 +                      walk += 6;
 +                      /*  user allowed to do: pmap /proc/PID */
 +                      if (*walk < '0' || *walk > '9')
 +                              continue;
 +              }
 +              if (*walk < '0' || *walk > '9')
 +                      usage(stderr);
 +              pid = strtoul(walk, &endp, 0);
 +              if (pid < 1ul || pid > 0x7ffffffful || *endp)
 +                      usage(stderr);
 +              pidlist[count++] = pid;
 +      }
 +
 +      discover_shm_minor();
 +
 +      memset(&p, '\0', sizeof(p));
 +      /* old libproc interface is zero-terminated */
 +      pidlist[count] = 0;
 +      PT = openproc(PROC_FILLSTAT | PROC_FILLARG | PROC_PID, pidlist);
 +      while (readproc(PT, &p)) {
 +              ret |= one_proc(&p);
 +              count--;
 +      }
 +      closeproc(PT);
 +
 +      if (count)
 +              /* didn't find all processes asked for */
 +              ret |= 42;
 +      return ret;
  }
Simple merge
diff --cc ps/Makefile.am
index 92815a3404b85339aa68b93588c5df77441c6441,b3bd9874d42604270eb69a55048fe1e477c55077..8634fe2af9256b0ba082dee377f06d84fe17ece4
@@@ -1,7 -1,7 +1,7 @@@
  AM_CPPFLAGS = -include $(top_builddir)/config.h
  
 -AM_CFLAGS = -I../proc
 +AM_CFLAGS = -I../proc -I../include
- AM_LDFLAGS = ../proc/libprocfs.la
+ AM_LDFLAGS = ../proc/libprocps.la
  
  dist_man_MANS = ps.1
  
diff --cc top/Makefile.am
index 61ae5e93c6fb9e3170dffddd2be3bf239c6ff8dc,0000000000000000000000000000000000000000..714a04e708ff82d03b2816461cc99504fe3e2a25
mode 100644,000000..100644
--- /dev/null
@@@ -1,26 -1,0 +1,26 @@@
- AM_LDFLAGS = ../proc/libprocfs.la
 +AM_CPPFLAGS = -include $(top_builddir)/config.h
 +
 +AM_CFLAGS = -I../proc -I../include
++AM_LDFLAGS = ../proc/libprocps.la
 +
 +if WITH_NCURSES
 +usrbin_exec_PROGRAMS = \
 +      top
 +
 +top_SOURCES =  \
 +      top.h \
 +      top.c \
 +      top_nls.h \
 +      top_nls.c
 +
 +dist_man_MANS = \
 +      top.1
 +
 +top_LDADD = @NCURSES_LIBS@
 +endif
 +
 +EXTRA_DIST =
 +
 +procpsngdir = $(docdir)
 +dist_procpsng_DATA = \
 +      README.top