summaryrefslogtreecommitdiff
path: root/libps/filters.c
blob: d47a130f88e3186eb06bbbdac159261890611f74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Some ps_filter_t's to restrict proc_stat_list's in various ways.

   Copyright (C) 1995 Free Software Foundation, Inc.

   Written by Miles Bader <miles@gnu.ai.mit.edu>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

#include <hurd.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <pwd.h>
#include <unistd.h>

#include "ps.h"
#include "common.h"

/* ---------------------------------------------------------------- */

static bool 
ps_own_p(proc_stat_t ps)
{
  static int own_uid = -1;
  if (own_uid < 0)
    own_uid = getuid();
  return own_uid == proc_stat_info(ps)->owner;
}
struct ps_filter ps_own_filter =
{"own", PSTAT_INFO, ps_own_p};

static bool 
ps_not_sess_leader_p(proc_stat_t ps)
{
  return !(proc_stat_state(ps) & PSTAT_STATE_P_SESSLDR);
}
struct ps_filter ps_not_sess_leader_filter =
{"not-sess-leader", PSTAT_STATE, ps_not_sess_leader_p};

static bool 
ps_unorphaned_p(proc_stat_t ps)
{
  int state = proc_stat_state(ps);
  return !(state & PSTAT_STATE_P_ORPHAN) || (state & PSTAT_STATE_P_SESSLDR);
}
struct ps_filter ps_unorphaned_filter =
{"unorphaned", PSTAT_STATE, ps_unorphaned_p};

static bool 
ps_ctty_p(proc_stat_t ps)
{
  return proc_stat_cttyid(ps) != MACH_PORT_NULL;
}
struct ps_filter ps_ctty_filter =
{"ctty", PSTAT_CTTYID, ps_ctty_p};

static bool 
ps_parent_p(proc_stat_t ps)
{
  return !(proc_stat_state(ps) & PSTAT_STATE_P_NOPARENT);
}
struct ps_filter ps_parent_filter =
{"parent", PSTAT_STATE, ps_parent_p};