Projects STRLCPY dismember Commits 69c32ddd
🤬
  • ■ ■ ■ ■ ■ ■
    internal/cmd/tree.go
    skipped 4 lines
    5 5   "github.com/liamg/dismember/pkg/proc"
    6 6   "github.com/spf13/cobra"
    7 7   "io"
     8 + "os"
    8 9  )
    9 10   
    10 11  func init() {
    skipped 43 lines
    54 55   })
    55 56   }
    56 57   
    57  - drawBranch(cmd.OutOrStdout(), rootWithStatus, nil, all)
     58 + uid := os.Getuid()
     59 + drawBranch(cmd.OutOrStdout(), rootWithStatus, "", true, all, uid)
    58 60   return nil
    59 61  }
    60 62   
    61  -func drawBranch(w io.Writer, parent procWithStatus, lasts []bool, all []procWithStatus) {
     63 +func drawBranch(w io.Writer, parent procWithStatus, prefix string, last bool, all []procWithStatus, uid int) {
    62 64   
    63 65   var children []procWithStatus
    64 66   for _, process := range all {
    skipped 3 lines
    68 70   children = append(children, process)
    69 71   }
    70 72   
    71  - var done bool
    72  - _, _ = fmt.Fprint(w, ansiDim)
    73  - if len(lasts) > 1 {
    74  - for _, last := range lasts[1:] {
    75  - if !last {
    76  - _, _ = fmt.Fprint(w, " │ ")
    77  - } else if !done {
    78  - done = true
    79  - _, _ = fmt.Fprint(w, " │ ")
    80  - } else {
    81  - _, _ = fmt.Fprint(w, " ")
    82  - }
    83  - }
    84  - }
    85  - 
    86  - if len(lasts) > 0 {
     73 + _, _ = fmt.Print(ansiDim + prefix)
     74 + if prefix != "" {
    87 75   symbol := '├'
    88  - if lasts[len(lasts)-1] {
     76 + if last {
    89 77   symbol = '└'
    90 78   }
    91 79   _, _ = fmt.Fprintf(w, " %c─ ", symbol)
    92 80   }
    93 81   
    94 82   _, _ = fmt.Fprint(w, ansiReset)
     83 + //owner, err := parent.process.Ownership()
     84 + //if err != nil {
     85 + //
     86 + //}
    95 87   _, _ = fmt.Fprintf(w, "%s %s(%s%d%s)%s\n", parent.status.Name, ansiDim, ansiReset, parent.process, ansiDim, ansiReset)
     88 + _, _ = fmt.Fprint(w, ansiReset)
     89 + 
     90 + if last {
     91 + prefix += " "
     92 + } else {
     93 + prefix += " │ "
     94 + }
    96 95   
    97 96   for i, child := range children {
    98  - drawBranch(w, child, append(lasts, i == len(children)-1), all)
     97 + drawBranch(w, child, prefix, i == len(children)-1, all)
    99 98   }
    100 99  }
    101 100   
  • ■ ■ ■ ■ ■ ■
    pkg/proc/process.go
    skipped 5 lines
    6 6   "path/filepath"
    7 7   "regexp"
    8 8   "strconv"
     9 + "syscall"
    9 10  )
    10 11   
    11 12  type Process uint64
    skipped 8 lines
    20 21   
    21 22  func Self() Process {
    22 23   return Process(os.Getpid())
     24 +}
     25 + 
     26 +type Ownership struct {
     27 + UID uint32
     28 + GID uint32
     29 +}
     30 + 
     31 +func (p *Process) Ownership() (*Ownership, error) {
     32 + info, err := os.Stat(fmt.Sprintf("/proc/%d", *p))
     33 + if err != nil {
     34 + return nil, err
     35 + }
     36 + stat, ok := info.Sys().(*syscall.Stat_t)
     37 + if !ok {
     38 + return nil, fmt.Errorf("stat syscall returned unexpected data: %#v", info.Sys())
     39 + }
     40 + return &Ownership{
     41 + UID: stat.Uid,
     42 + GID: stat.Gid,
     43 + }, nil
    23 44  }
    24 45   
    25 46  func (p *Process) Name() string {
    skipped 48 lines
Please wait...
Page is in error, reload to recover