From 9403bed73ddb60cb3e2d8a101e00793325b4735f Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Tue, 11 Apr 1995 00:20:04 +0000 Subject: Tweak things so that the -t flag works correctly for processes whose tty we can't figure out. --- utils/ps.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'utils/ps.c') 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) -- cgit v1.2.3