summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-04-11 00:20:04 +0000
committerMiles Bader <miles@gnu.org>1995-04-11 00:20:04 +0000
commit9403bed73ddb60cb3e2d8a101e00793325b4735f (patch)
treea406ece4e2dc0a41ba05b18bb9231f713839cc19 /utils
parentf2aa7a4e79a741cf8a2506f49dd792e5267d7ea4 (diff)
Tweak things so that the -t flag works correctly for processes whose tty we
can't figure out.
Diffstat (limited to 'utils')
-rw-r--r--utils/ps.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/utils/ps.c b/utils/ps.c
index 03640ff1..652ac878 100644
--- a/utils/ps.c
+++ b/utils/ps.c
@@ -427,17 +427,21 @@ main(int argc, char *argv[])
}
bool proc_stat_has_ctty(struct proc_stat *ps)
{
- ps_tty_t tty = proc_stat_tty(ps);
- if (tty)
+ if (proc_stat_has(ps, PSTAT_TTY))
+ /* Only match processes whose tty we can figure out. */
{
- unsigned i;
- char *name = ps_tty_name(tty);
- char *short_name = ps_tty_short_name(tty);
-
- for (i = 0; i < num_tty_names; i++)
- if ((name && strcmp (tty_names[i], name) == 0)
- || (short_name && strcmp (tty_names[i], short_name) == 0))
- return TRUE;
+ ps_tty_t tty = proc_stat_tty(ps);
+ if (tty)
+ {
+ unsigned i;
+ char *name = ps_tty_name(tty);
+ char *short_name = ps_tty_short_name(tty);
+
+ for (i = 0; i < num_tty_names; i++)
+ if ((name && strcmp (tty_names[i], name) == 0)
+ || (short_name && strcmp (tty_names[i], short_name) == 0))
+ return TRUE;
+ }
}
return FALSE;
}
@@ -581,8 +585,12 @@ main(int argc, char *argv[])
if (num_uids > 0)
proc_stat_list_filter1(procset, proc_stat_has_owner, PSTAT_INFO, FALSE);
if (num_tty_names > 0)
- /* Returns TRUE if PS has for a controlling terminal any in TTY_NAMES. */
- proc_stat_list_filter1(procset, proc_stat_has_ctty, PSTAT_TTY, FALSE);
+ {
+ /* We set the PSTAT_TTY flag separately so that our filter function
+ can look at any procs that fail to set it. */
+ proc_stat_list_set_flags(procset, PSTAT_TTY);
+ proc_stat_list_filter1(procset, proc_stat_has_ctty, 0, FALSE);
+ }
if (filter_mask & FILTER_NSESSLDR)
proc_stat_list_filter(procset, &ps_not_sess_leader_filter, FALSE);
if (filter_mask & FILTER_UNORPHANED)