ps.c (244154) | ps.c (245610) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 33 unchanged lines hidden (view full) --- 42 43#if 0 44#ifndef lint 45static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; 46#endif /* not lint */ 47#endif 48 49#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 33 unchanged lines hidden (view full) --- 42 43#if 0 44#ifndef lint 45static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; 46#endif /* not lint */ 47#endif 48 49#include <sys/cdefs.h> |
50__FBSDID("$FreeBSD: head/bin/ps/ps.c 244154 2012-12-12 15:45:03Z pjd $"); | 50__FBSDID("$FreeBSD: head/bin/ps/ps.c 245610 2013-01-18 18:24:40Z jhb $"); |
51 52#include <sys/param.h> 53#include <sys/proc.h> 54#include <sys/user.h> 55#include <sys/stat.h> 56#include <sys/ioctl.h> 57#include <sys/sysctl.h> 58#include <sys/mount.h> --- 77 unchanged lines hidden (view full) --- 136static int addelem_tty(struct listinfo *, const char *); 137static int addelem_uid(struct listinfo *, const char *); 138static void add_list(struct listinfo *, const char *); 139static void descendant_sort(KINFO *, int); 140static void format_output(KINFO *); 141static void *expand_list(struct listinfo *); 142static const char * 143 fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int), | 51 52#include <sys/param.h> 53#include <sys/proc.h> 54#include <sys/user.h> 55#include <sys/stat.h> 56#include <sys/ioctl.h> 57#include <sys/sysctl.h> 58#include <sys/mount.h> --- 77 unchanged lines hidden (view full) --- 136static int addelem_tty(struct listinfo *, const char *); 137static int addelem_uid(struct listinfo *, const char *); 138static void add_list(struct listinfo *, const char *); 139static void descendant_sort(KINFO *, int); 140static void format_output(KINFO *); 141static void *expand_list(struct listinfo *); 142static const char * 143 fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int), |
144 KINFO *, char *, int); | 144 KINFO *, char *, char *, int); |
145static void free_list(struct listinfo *); 146static void init_list(struct listinfo *, addelem_rtn, int, const char *); 147static char *kludge_oldps_options(const char *, char *, const char *); 148static int pscomp(const void *, const void *); 149static void saveuser(KINFO *); 150static void scanvars(void); 151static void sizevars(void); 152static void pidmax_init(void); --- 1005 unchanged lines hidden (view full) --- 1158 i = strlen(vent->header); 1159 if (v->width < i) 1160 v->width = i; 1161 } 1162} 1163 1164static const char * 1165fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki, | 145static void free_list(struct listinfo *); 146static void init_list(struct listinfo *, addelem_rtn, int, const char *); 147static char *kludge_oldps_options(const char *, char *, const char *); 148static int pscomp(const void *, const void *); 149static void saveuser(KINFO *); 150static void scanvars(void); 151static void sizevars(void); 152static void pidmax_init(void); --- 1005 unchanged lines hidden (view full) --- 1158 i = strlen(vent->header); 1159 if (v->width < i) 1160 v->width = i; 1161 } 1162} 1163 1164static const char * 1165fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki, |
1166 char *comm, int maxlen) | 1166 char *comm, char *thread, int maxlen) |
1167{ 1168 const char *s; 1169 | 1167{ 1168 const char *s; 1169 |
1170 s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen); | 1170 s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, 1171 ki->ki_p->ki_numthreads > 1 ? thread : NULL, maxlen); |
1171 return (s); 1172} 1173 1174#define UREADOK(ki) (forceuread || (ki->ki_p->ki_flag & P_INMEM)) 1175 1176static void 1177saveuser(KINFO *ki) 1178{ --- 11 unchanged lines hidden (view full) --- 1190 /* 1191 * save arguments if needed 1192 */ 1193 if (needcomm) { 1194 if (ki->ki_p->ki_stat == SZOMB) 1195 ki->ki_args = strdup("<defunct>"); 1196 else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) 1197 ki->ki_args = strdup(fmt(kvm_getargv, ki, | 1172 return (s); 1173} 1174 1175#define UREADOK(ki) (forceuread || (ki->ki_p->ki_flag & P_INMEM)) 1176 1177static void 1178saveuser(KINFO *ki) 1179{ --- 11 unchanged lines hidden (view full) --- 1191 /* 1192 * save arguments if needed 1193 */ 1194 if (needcomm) { 1195 if (ki->ki_p->ki_stat == SZOMB) 1196 ki->ki_args = strdup("<defunct>"); 1197 else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) 1198 ki->ki_args = strdup(fmt(kvm_getargv, ki, |
1198 ki->ki_p->ki_comm, MAXCOMLEN)); | 1199 ki->ki_p->ki_comm, ki->ki_p->ki_tdname, MAXCOMLEN)); |
1199 else 1200 asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); 1201 if (ki->ki_args == NULL) 1202 errx(1, "malloc failed"); 1203 } else { 1204 ki->ki_args = NULL; 1205 } 1206 if (needenv) { 1207 if (UREADOK(ki)) 1208 ki->ki_env = strdup(fmt(kvm_getenvv, ki, | 1200 else 1201 asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); 1202 if (ki->ki_args == NULL) 1203 errx(1, "malloc failed"); 1204 } else { 1205 ki->ki_args = NULL; 1206 } 1207 if (needenv) { 1208 if (UREADOK(ki)) 1209 ki->ki_env = strdup(fmt(kvm_getenvv, ki, |
1209 (char *)NULL, 0)); | 1210 (char *)NULL, (char *)NULL, 0)); |
1210 else 1211 ki->ki_env = strdup("()"); 1212 if (ki->ki_env == NULL) 1213 errx(1, "malloc failed"); 1214 } else { 1215 ki->ki_env = NULL; 1216 } 1217} --- 162 unchanged lines hidden --- | 1211 else 1212 ki->ki_env = strdup("()"); 1213 if (ki->ki_env == NULL) 1214 errx(1, "malloc failed"); 1215 } else { 1216 ki->ki_env = NULL; 1217 } 1218} --- 162 unchanged lines hidden --- |