~ubuntu-branches/ubuntu/quantal/psmisc/quantal

« back to all changes in this revision

Viewing changes to src/pstree.c

  • Committer: Bazaar Package Importer
  • Author(s): Craig Small
  • Date: 2009-07-25 09:40:01 UTC
  • mfrom: (1.1.10 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090725094001-fpzmko29db07jrp4
Tags: 22.8-1
* New upstream release
 - fuser will print mounts,nfs exports and swaps with -v Closes: #356655
 - pstree and fuser have long options Closes: #517412
 - Fixed pstree -a off-by-one error in buffer, Closes: #536243

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * pstree.c - display process tree
3
3
 *
4
4
 * Copyright (C) 1993-2002 Werner Almesberger
5
 
 * Copyright (C) 2002-2008 Craig Small
 
5
 * Copyright (C) 2002-2009 Craig Small
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
749
749
                        exit (1);
750
750
                      }
751
751
                    (void) close (fd);
 
752
                        /* If we have read the maximum screen length of args, bring it back by one to stop overflow */
 
753
                        if (size >= buffer_size)
 
754
                          size--;
752
755
                    if (size)
753
756
                      buffer[size++] = 0;
754
757
#ifdef WITH_SELINUX
813
816
    "              [ -A | -G | -U ] [ PID | USER ]\n"
814
817
    "       pstree -V\n"
815
818
    "Display a tree of processes.\n\n"
816
 
    "    -a     show command line arguments\n"
817
 
    "    -A     use ASCII line drawing characters\n"
818
 
    "    -c     don't compact identical subtrees\n"
819
 
    "    -h     highlight current process and its ancestors\n"
820
 
    "    -H PID highlight this process and its ancestors\n"
821
 
    "    -G     use VT100 line drawing characters\n"
822
 
    "    -l     don't truncate long lines\n"
823
 
    "    -n     sort output by PID\n"
824
 
    "    -p     show PIDs; implies -c\n"
825
 
    "    -u     show uid transitions\n"
826
 
    "    -U     use UTF-8 (Unicode) line drawing characters\n"
827
 
    "    -V     display version information\n"));
 
819
    "  -a, --arguments     show command line arguments\n"
 
820
    "  -A, --ascii         use ASCII line drawing characters\n"
 
821
    "  -c, --compact       don't compact identical subtrees\n"
 
822
    "  -h, --highlight-all highlight current process and its ancestors\n"
 
823
    "  -H PID,\n"
 
824
    "  --highlight-pid=PID highlight this process and its ancestors\n"
 
825
    "  -G, --vt100         use VT100 line drawing characters\n"
 
826
    "  -l, --long          don't truncate long lines\n"
 
827
    "  -n, --numeric-sort  sort output by PID\n"
 
828
    "  -p, --show-pids     show PIDs; implies -c\n"
 
829
    "  -u, --uid-changes   show uid transitions\n"
 
830
    "  -U, --unicode       use UTF-8 (Unicode) line drawing characters\n"
 
831
    "  -V, --version       display version information\n"));
828
832
#ifdef WITH_SELINUX
829
833
  fprintf (stderr, _(
830
 
    "    -Z     show SELinux security contexts\n"));
 
834
    "  -Z     show         SELinux security contexts\n"));
831
835
#endif /*WITH_SELINUX*/
832
836
  fprintf (stderr, _(
833
 
    "    PID    start at this PID; default is 1 (init)\n"
834
 
    "    USER   show only trees rooted at processes of this user\n\n"));
 
837
    "  PID    start at this PID; default is 1 (init)\n"
 
838
    "  USER   show only trees rooted at processes of this user\n\n"));
835
839
  exit (1);
836
840
}
837
841
 
839
843
{
840
844
  fprintf(stderr, _("pstree (PSmisc) %s\n"), VERSION);
841
845
  fprintf(stderr, _(
842
 
    "Copyright (C) 1993-2005 Werner Almesberger and Craig Small\n\n"));
 
846
    "Copyright (C) 1993-2009 Werner Almesberger and Craig Small\n\n"));
843
847
  fprintf(stderr, _(
844
848
    "PSmisc comes with ABSOLUTELY NO WARRANTY.\n"
845
849
    "This is free software, and you are welcome to redistribute it under\n"
859
863
  char *termname;
860
864
  int c;
861
865
 
 
866
  struct option options[] = {
 
867
        {"arguments", 0, NULL, 'a'},
 
868
        {"ascii", 0, NULL, 'A'},
 
869
        {"compact", 0, NULL, 'c'},
 
870
        {"vt100", 0, NULL, 'G'},
 
871
        {"highlight-all", 0, NULL, 'h'},
 
872
        {"highlight-pid", 1, NULL, 'H'},
 
873
        {"numeric-sort", 0, NULL, 'n'},
 
874
        {"show-pids", 0, NULL, 'p'},
 
875
        {"long", 0, NULL, 'l'},
 
876
        {"uid-changes", 0, NULL, 'u'},
 
877
        {"unicode", 0, NULL, 'U'},
 
878
        {"version", 0, NULL, 'V'},
 
879
#ifdef WITH_SELINUX
 
880
        {"security-context", 0, NULL, 'Z'},
 
881
#endif /*WITH_SELINUX*/
 
882
  };
 
883
 
862
884
  if (ioctl (1, TIOCGWINSZ, &winsz) >= 0)
863
885
    if (winsz.ws_col)
864
886
      output_width = winsz.ws_col;
901
923
  }
902
924
 
903
925
#ifdef WITH_SELINUX
904
 
  while ((c = getopt (argc, argv, "aAcGhH:npluUVZ")) != EOF)
 
926
  while ((c = getopt_long (argc, argv, "aAcGhH:npluUVZ", options, NULL)) != -1)
905
927
#else  /*WITH_SELINUX*/
906
 
  while ((c = getopt (argc, argv, "aAcGhH:npluUV")) != EOF)
 
928
  while ((c = getopt_long (argc, argv, "aAcGhH:npluUV", options, NULL)) != -1)
907
929
#endif /*WITH_SELINUX*/
908
930
    switch (c)
909
931
      {