misc: replace any remaining tab characters in readproc
This commit is contained in:
parent
d5c5051fb3
commit
01beb85f7d
@ -597,8 +597,8 @@ LEAVE(0x160);
|
|||||||
static void statm2proc(const char* s, proc_t *restrict P) {
|
static void statm2proc(const char* s, proc_t *restrict P) {
|
||||||
int num;
|
int num;
|
||||||
num = sscanf(s, "%ld %ld %ld %ld %ld %ld %ld",
|
num = sscanf(s, "%ld %ld %ld %ld %ld %ld %ld",
|
||||||
&P->size, &P->resident, &P->share,
|
&P->size, &P->resident, &P->share,
|
||||||
&P->trs, &P->lrs, &P->drs, &P->dt);
|
&P->trs, &P->lrs, &P->drs, &P->dt);
|
||||||
/* fprintf(stderr, "statm2proc converted %d fields.\n",num); */
|
/* fprintf(stderr, "statm2proc converted %d fields.\n",num); */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,7 +628,7 @@ static int file2str(const char *directory, const char *what, struct utlbuf_s *ub
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char** file2strvec(const char* directory, const char* what) {
|
static char** file2strvec(const char* directory, const char* what) {
|
||||||
char buf[2048]; /* read buf bytes at a time */
|
char buf[2048]; /* read buf bytes at a time */
|
||||||
char *p, *rbuf = 0, *endbuf, **q, **ret;
|
char *p, *rbuf = 0, *endbuf, **q, **ret;
|
||||||
int fd, tot = 0, n, c, end_of_file = 0;
|
int fd, tot = 0, n, c, end_of_file = 0;
|
||||||
int align;
|
int align;
|
||||||
@ -644,13 +644,13 @@ static char** file2strvec(const char* directory, const char* what) {
|
|||||||
end_of_file = 1;
|
end_of_file = 1;
|
||||||
if (n == 0 && rbuf == 0) {
|
if (n == 0 && rbuf == 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL; /* process died between our open and read */
|
return NULL; /* process died between our open and read */
|
||||||
}
|
}
|
||||||
if (end_of_file && (n == 0 || buf[n-1]))/* last read char not null */
|
if (end_of_file && (n == 0 || buf[n-1]))/* last read char not null */
|
||||||
buf[n++] = '\0'; /* so append null-terminator */
|
buf[n++] = '\0'; /* so append null-terminator */
|
||||||
rbuf = xrealloc(rbuf, tot + n); /* allocate more memory */
|
rbuf = xrealloc(rbuf, tot + n); /* allocate more memory */
|
||||||
memcpy(rbuf + tot, buf, n); /* copy buffer into it */
|
memcpy(rbuf + tot, buf, n); /* copy buffer into it */
|
||||||
tot += n; /* increment total byte ctr */
|
tot += n; /* increment total byte ctr */
|
||||||
if (end_of_file)
|
if (end_of_file)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -658,9 +658,9 @@ static char** file2strvec(const char* directory, const char* what) {
|
|||||||
if (n <= 0 && !end_of_file) {
|
if (n <= 0 && !end_of_file) {
|
||||||
if (rbuf)
|
if (rbuf)
|
||||||
free(rbuf);
|
free(rbuf);
|
||||||
return NULL; /* read error */
|
return NULL; /* read error */
|
||||||
}
|
}
|
||||||
endbuf = rbuf + tot; /* count space for pointers */
|
endbuf = rbuf + tot; /* count space for pointers */
|
||||||
align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
|
align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
|
||||||
for (c = 0, p = rbuf; p < endbuf; p++) {
|
for (c = 0, p = rbuf; p < endbuf; p++) {
|
||||||
if (!*p || *p == '\n')
|
if (!*p || *p == '\n')
|
||||||
@ -668,18 +668,18 @@ static char** file2strvec(const char* directory, const char* what) {
|
|||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
*p = 0;
|
*p = 0;
|
||||||
}
|
}
|
||||||
c += sizeof(char*); /* one extra for NULL term */
|
c += sizeof(char*); /* one extra for NULL term */
|
||||||
|
|
||||||
rbuf = xrealloc(rbuf, tot + c + align); /* make room for ptrs AT END */
|
rbuf = xrealloc(rbuf, tot + c + align); /* make room for ptrs AT END */
|
||||||
endbuf = rbuf + tot; /* addr just past data buf */
|
endbuf = rbuf + tot; /* addr just past data buf */
|
||||||
q = ret = (char**) (endbuf+align); /* ==> free(*ret) to dealloc */
|
q = ret = (char**) (endbuf+align); /* ==> free(*ret) to dealloc */
|
||||||
*q++ = p = rbuf; /* point ptrs to the strings */
|
*q++ = p = rbuf; /* point ptrs to the strings */
|
||||||
endbuf--; /* do not traverse final NUL */
|
endbuf--; /* do not traverse final NUL */
|
||||||
while (++p < endbuf)
|
while (++p < endbuf)
|
||||||
if (!*p) /* NUL char implies that */
|
if (!*p) /* NUL char implies that */
|
||||||
*q++ = p+1; /* next string -> next char */
|
*q++ = p+1; /* next string -> next char */
|
||||||
|
|
||||||
*q = 0; /* null ptr list terminator */
|
*q = 0; /* null ptr list terminator */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,19 +839,19 @@ static char *lxc_containers (const char *path) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Test if item X of type T is present in the 0 terminated list L */
|
/* Test if item X of type T is present in the 0 terminated list L */
|
||||||
# define XinL(T, X, L) ( { \
|
# define XinL(T, X, L) ( { \
|
||||||
T x = (X), *l = (L); \
|
T x = (X), *l = (L); \
|
||||||
while (*l && *l != x) l++; \
|
while (*l && *l != x) l++; \
|
||||||
*l == x; \
|
*l == x; \
|
||||||
} )
|
} )
|
||||||
|
|
||||||
/* Test if item X of type T is present in the list L of length N */
|
/* Test if item X of type T is present in the list L of length N */
|
||||||
# define XinLN(T, X, L, N) ( { \
|
# define XinLN(T, X, L, N) ( { \
|
||||||
T x = (X), *l = (L); \
|
T x = (X), *l = (L); \
|
||||||
int i = 0, n = (N); \
|
int i = 0, n = (N); \
|
||||||
while (i < n && l[i] != x) i++; \
|
while (i < n && l[i] != x) i++; \
|
||||||
i < n && l[i] == x; \
|
i < n && l[i] == x; \
|
||||||
} )
|
} )
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
// This reads process info from /proc in the traditional way, for one process.
|
// This reads process info from /proc in the traditional way, for one process.
|
||||||
@ -1109,7 +1109,7 @@ next_task:
|
|||||||
// This finds processes in /proc in the traditional way.
|
// This finds processes in /proc in the traditional way.
|
||||||
// Return non-zero on success.
|
// Return non-zero on success.
|
||||||
static int simple_nextpid(PROCTAB *restrict const PT, proc_t *restrict const p) {
|
static int simple_nextpid(PROCTAB *restrict const PT, proc_t *restrict const p) {
|
||||||
static struct dirent *ent; /* dirent handle */
|
static struct dirent *ent; /* dirent handle */
|
||||||
char *restrict const path = PT->path;
|
char *restrict const path = PT->path;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ent = readdir(PT->procfs);
|
ent = readdir(PT->procfs);
|
||||||
@ -1127,7 +1127,7 @@ static int simple_nextpid(PROCTAB *restrict const PT, proc_t *restrict const p)
|
|||||||
// This finds tasks in /proc/*/task/ in the traditional way.
|
// This finds tasks in /proc/*/task/ in the traditional way.
|
||||||
// Return non-zero on success.
|
// Return non-zero on success.
|
||||||
static int simple_nexttid(PROCTAB *restrict const PT, const proc_t *restrict const p, proc_t *restrict const t, char *restrict const path) {
|
static int simple_nexttid(PROCTAB *restrict const PT, const proc_t *restrict const p, proc_t *restrict const t, char *restrict const path) {
|
||||||
static struct dirent *ent; /* dirent handle */
|
static struct dirent *ent; /* dirent handle */
|
||||||
if(PT->taskdir_user != p->tgid){
|
if(PT->taskdir_user != p->tgid){
|
||||||
if(PT->taskdir){
|
if(PT->taskdir){
|
||||||
closedir(PT->taskdir);
|
closedir(PT->taskdir);
|
||||||
|
164
proc/readproc.h
164
proc/readproc.h
@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
// ld cutime, cstime, priority, nice, timeout, alarm, rss,
|
// ld cutime, cstime, priority, nice, timeout, alarm, rss,
|
||||||
// c state,
|
// c state,
|
||||||
// d ppid, pgrp, session, tty, tpgid,
|
// d ppid, pgrp, session, tty, tpgid,
|
||||||
// s signal, blocked, sigignore, sigcatch,
|
// s signal, blocked, sigignore, sigcatch,
|
||||||
// lu flags, min_flt, cmin_flt, maj_flt, cmaj_flt, utime, stime,
|
// lu flags, min_flt, cmin_flt, maj_flt, cmaj_flt, utime, stime,
|
||||||
// lu rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip,
|
// lu rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip,
|
||||||
// lu start_time, vsize, wchan,
|
// lu start_time, vsize, wchan,
|
||||||
|
|
||||||
// This is to help document a transition from pid to tgid/tid caused
|
// This is to help document a transition from pid to tgid/tid caused
|
||||||
// by the introduction of thread support. It is used in cases where
|
// by the introduction of thread support. It is used in cases where
|
||||||
@ -42,88 +42,88 @@ __BEGIN_DECLS
|
|||||||
typedef struct proc_t {
|
typedef struct proc_t {
|
||||||
// 1st 16 bytes
|
// 1st 16 bytes
|
||||||
int
|
int
|
||||||
tid, // (special) task id, the POSIX thread ID (see also: tgid)
|
tid, // (special) task id, the POSIX thread ID (see also: tgid)
|
||||||
ppid; // stat,status pid of parent process
|
ppid; // stat,status pid of parent process
|
||||||
long // next 2 fields are NOT filled in by readproc
|
long // next 2 fields are NOT filled in by readproc
|
||||||
maj_delta, // stat (special) major page faults since last update
|
maj_delta, // stat (special) major page faults since last update
|
||||||
min_delta; // stat (special) minor page faults since last update
|
min_delta; // stat (special) minor page faults since last update
|
||||||
unsigned
|
unsigned
|
||||||
pcpu; // stat (special) %CPU usage (is not filled in by readproc!!!)
|
pcpu; // stat (special) %CPU usage (is not filled in by readproc!!!)
|
||||||
char
|
char
|
||||||
state, // stat,status single-char code for process state (S=sleeping)
|
state, // stat,status single-char code for process state (S=sleeping)
|
||||||
#ifdef FALSE_THREADS
|
#ifdef FALSE_THREADS
|
||||||
pad_1, // n/a padding (psst, also used if multi-threaded)
|
pad_1, // n/a padding (psst, also used if multi-threaded)
|
||||||
#else
|
#else
|
||||||
pad_1, // n/a padding
|
pad_1, // n/a padding
|
||||||
#endif
|
#endif
|
||||||
pad_2, // n/a padding
|
pad_2, // n/a padding
|
||||||
pad_3; // n/a padding
|
pad_3; // n/a padding
|
||||||
// 2nd 16 bytes
|
// 2nd 16 bytes
|
||||||
unsigned long long
|
unsigned long long
|
||||||
utime, // stat user-mode CPU time accumulated by process
|
utime, // stat user-mode CPU time accumulated by process
|
||||||
stime, // stat kernel-mode CPU time accumulated by process
|
stime, // stat kernel-mode CPU time accumulated by process
|
||||||
// and so on...
|
// and so on...
|
||||||
cutime, // stat cumulative utime of process and reaped children
|
cutime, // stat cumulative utime of process and reaped children
|
||||||
cstime, // stat cumulative stime of process and reaped children
|
cstime, // stat cumulative stime of process and reaped children
|
||||||
start_time; // stat start time of process -- seconds since 1-1-70
|
start_time; // stat start time of process -- seconds since 1-1-70
|
||||||
#ifdef SIGNAL_STRING
|
#ifdef SIGNAL_STRING
|
||||||
char
|
char
|
||||||
// Linux 2.1.7x and up have 64 signals. Allow 64, plus '\0' and padding.
|
// Linux 2.1.7x and up have 64 signals. Allow 64, plus '\0' and padding.
|
||||||
signal[18], // status mask of pending signals, per-task for readtask() but per-proc for readproc()
|
signal[18], // status mask of pending signals, per-task for readtask() but per-proc for readproc()
|
||||||
blocked[18], // status mask of blocked signals
|
blocked[18], // status mask of blocked signals
|
||||||
sigignore[18], // status mask of ignored signals
|
sigignore[18], // status mask of ignored signals
|
||||||
sigcatch[18], // status mask of caught signals
|
sigcatch[18], // status mask of caught signals
|
||||||
_sigpnd[18]; // status mask of PER TASK pending signals
|
_sigpnd[18]; // status mask of PER TASK pending signals
|
||||||
#else
|
#else
|
||||||
long long
|
long long
|
||||||
// Linux 2.1.7x and up have 64 signals.
|
// Linux 2.1.7x and up have 64 signals.
|
||||||
signal, // status mask of pending signals, per-task for readtask() but per-proc for readproc()
|
signal, // status mask of pending signals, per-task for readtask() but per-proc for readproc()
|
||||||
blocked, // status mask of blocked signals
|
blocked, // status mask of blocked signals
|
||||||
sigignore, // status mask of ignored signals
|
sigignore, // status mask of ignored signals
|
||||||
sigcatch, // status mask of caught signals
|
sigcatch, // status mask of caught signals
|
||||||
_sigpnd; // status mask of PER TASK pending signals
|
_sigpnd; // status mask of PER TASK pending signals
|
||||||
#endif
|
#endif
|
||||||
unsigned long
|
unsigned long
|
||||||
start_code, // stat address of beginning of code segment
|
start_code, // stat address of beginning of code segment
|
||||||
end_code, // stat address of end of code segment
|
end_code, // stat address of end of code segment
|
||||||
start_stack, // stat address of the bottom of stack for the process
|
start_stack, // stat address of the bottom of stack for the process
|
||||||
kstk_esp, // stat kernel stack pointer
|
kstk_esp, // stat kernel stack pointer
|
||||||
kstk_eip, // stat kernel instruction pointer
|
kstk_eip, // stat kernel instruction pointer
|
||||||
wchan; // stat (special) address of kernel wait channel proc is sleeping in
|
wchan; // stat (special) address of kernel wait channel proc is sleeping in
|
||||||
long
|
long
|
||||||
priority, // stat kernel scheduling priority
|
priority, // stat kernel scheduling priority
|
||||||
nice, // stat standard unix nice level of process
|
nice, // stat standard unix nice level of process
|
||||||
rss, // stat identical to 'resident'
|
rss, // stat identical to 'resident'
|
||||||
alarm, // stat ?
|
alarm, // stat ?
|
||||||
// the next 7 members come from /proc/#/statm
|
// the next 7 members come from /proc/#/statm
|
||||||
size, // statm total virtual memory (as # pages)
|
size, // statm total virtual memory (as # pages)
|
||||||
resident, // statm resident non-swapped memory (as # pages)
|
resident, // statm resident non-swapped memory (as # pages)
|
||||||
share, // statm shared (mmap'd) memory (as # pages)
|
share, // statm shared (mmap'd) memory (as # pages)
|
||||||
trs, // statm text (exe) resident set (as # pages)
|
trs, // statm text (exe) resident set (as # pages)
|
||||||
lrs, // statm library resident set (always 0 w/ 2.6)
|
lrs, // statm library resident set (always 0 w/ 2.6)
|
||||||
drs, // statm data+stack resident set (as # pages)
|
drs, // statm data+stack resident set (as # pages)
|
||||||
dt; // statm dirty pages (always 0 w/ 2.6)
|
dt; // statm dirty pages (always 0 w/ 2.6)
|
||||||
long
|
long
|
||||||
vm_size, // status equals 'size' (as kb)
|
vm_size, // status equals 'size' (as kb)
|
||||||
vm_lock, // status locked pages (as kb)
|
vm_lock, // status locked pages (as kb)
|
||||||
vm_rss, // status equals 'rss' and/or 'resident' (as kb)
|
vm_rss, // status equals 'rss' and/or 'resident' (as kb)
|
||||||
vm_rss_anon, // status the 'anonymous' portion of vm_rss (as kb)
|
vm_rss_anon, // status the 'anonymous' portion of vm_rss (as kb)
|
||||||
vm_rss_file, // status the 'file-backed' portion of vm_rss (as kb)
|
vm_rss_file, // status the 'file-backed' portion of vm_rss (as kb)
|
||||||
vm_rss_shared, // status the 'shared' portion of vm_rss (as kb)
|
vm_rss_shared, // status the 'shared' portion of vm_rss (as kb)
|
||||||
vm_data, // status data only size (as kb)
|
vm_data, // status data only size (as kb)
|
||||||
vm_stack, // status stack only size (as kb)
|
vm_stack, // status stack only size (as kb)
|
||||||
vm_swap, // status based on linux-2.6.34 "swap ents" (as kb)
|
vm_swap, // status based on linux-2.6.34 "swap ents" (as kb)
|
||||||
vm_exe, // status equals 'trs' (as kb)
|
vm_exe, // status equals 'trs' (as kb)
|
||||||
vm_lib, // status total, not just used, library pages (as kb)
|
vm_lib, // status total, not just used, library pages (as kb)
|
||||||
rtprio, // stat real-time priority
|
rtprio, // stat real-time priority
|
||||||
sched, // stat scheduling class
|
sched, // stat scheduling class
|
||||||
vsize, // stat number of pages of virtual memory ...
|
vsize, // stat number of pages of virtual memory ...
|
||||||
rss_rlim, // stat resident set size limit?
|
rss_rlim, // stat resident set size limit?
|
||||||
flags, // stat kernel flags for the process
|
flags, // stat kernel flags for the process
|
||||||
min_flt, // stat number of minor page faults since process start
|
min_flt, // stat number of minor page faults since process start
|
||||||
maj_flt, // stat number of major page faults since process start
|
maj_flt, // stat number of major page faults since process start
|
||||||
cmin_flt, // stat cumulative min_flt of process and child processes
|
cmin_flt, // stat cumulative min_flt of process and child processes
|
||||||
cmaj_flt; // stat cumulative maj_flt of process and child processes
|
cmaj_flt; // stat cumulative maj_flt of process and child processes
|
||||||
char
|
char
|
||||||
*environ, // (special) environment as string (/proc/#/environ)
|
*environ, // (special) environment as string (/proc/#/environ)
|
||||||
*cmdline, // (special) command line as string (/proc/#/cmdline)
|
*cmdline, // (special) command line as string (/proc/#/cmdline)
|
||||||
@ -145,19 +145,19 @@ typedef struct proc_t {
|
|||||||
*fgroup, // status filesystem group name
|
*fgroup, // status filesystem group name
|
||||||
*cmd; // stat,status basename of executable file in call to exec(2)
|
*cmd; // stat,status basename of executable file in call to exec(2)
|
||||||
int
|
int
|
||||||
pgrp, // stat process group id
|
pgrp, // stat process group id
|
||||||
session, // stat session id
|
session, // stat session id
|
||||||
nlwp, // stat,status number of threads, or 0 if no clue
|
nlwp, // stat,status number of threads, or 0 if no clue
|
||||||
tgid, // (special) thread group ID, the POSIX PID (see also: tid)
|
tgid, // (special) thread group ID, the POSIX PID (see also: tid)
|
||||||
tty, // stat full device number of controlling terminal
|
tty, // stat full device number of controlling terminal
|
||||||
/* FIXME: int uids & gids should be uid_t or gid_t from pwd.h */
|
/* FIXME: int uids & gids should be uid_t or gid_t from pwd.h */
|
||||||
euid, egid, // stat(),status effective
|
euid, egid, // stat(),status effective
|
||||||
ruid, rgid, // status real
|
ruid, rgid, // status real
|
||||||
suid, sgid, // status saved
|
suid, sgid, // status saved
|
||||||
fuid, fgid, // status fs (used for file access only)
|
fuid, fgid, // status fs (used for file access only)
|
||||||
tpgid, // stat terminal process group id
|
tpgid, // stat terminal process group id
|
||||||
exit_signal, // stat might not be SIGCHLD
|
exit_signal, // stat might not be SIGCHLD
|
||||||
processor; // stat current (or most recent?) CPU
|
processor; // stat current (or most recent?) CPU
|
||||||
int
|
int
|
||||||
oom_score, // oom_score (badness for OOM killer)
|
oom_score, // oom_score (badness for OOM killer)
|
||||||
oom_adj; // oom_adj (adjustment to OOM score)
|
oom_adj; // oom_adj (adjustment to OOM score)
|
||||||
@ -181,21 +181,21 @@ typedef struct proc_t {
|
|||||||
#define PROCPATHLEN 64 // must hold /proc/2000222000/task/2000222000/cmdline
|
#define PROCPATHLEN 64 // must hold /proc/2000222000/task/2000222000/cmdline
|
||||||
|
|
||||||
typedef struct PROCTAB {
|
typedef struct PROCTAB {
|
||||||
DIR* procfs;
|
DIR* procfs;
|
||||||
// char deBug0[64];
|
// char deBug0[64];
|
||||||
DIR* taskdir; // for threads
|
DIR* taskdir; // for threads
|
||||||
// char deBug1[64];
|
// char deBug1[64];
|
||||||
pid_t taskdir_user; // for threads
|
pid_t taskdir_user; // for threads
|
||||||
int did_fake; // used when taskdir is missing
|
int did_fake; // used when taskdir is missing
|
||||||
int(*finder)(struct PROCTAB *__restrict const, proc_t *__restrict const);
|
int(*finder)(struct PROCTAB *__restrict const, proc_t *__restrict const);
|
||||||
proc_t*(*reader)(struct PROCTAB *__restrict const, proc_t *__restrict const);
|
proc_t*(*reader)(struct PROCTAB *__restrict const, proc_t *__restrict const);
|
||||||
int(*taskfinder)(struct PROCTAB *__restrict const, const proc_t *__restrict const, proc_t *__restrict const, char *__restrict const);
|
int(*taskfinder)(struct PROCTAB *__restrict const, const proc_t *__restrict const, proc_t *__restrict const, char *__restrict const);
|
||||||
proc_t*(*taskreader)(struct PROCTAB *__restrict const, const proc_t *__restrict const, proc_t *__restrict const, char *__restrict const);
|
proc_t*(*taskreader)(struct PROCTAB *__restrict const, const proc_t *__restrict const, proc_t *__restrict const, char *__restrict const);
|
||||||
pid_t* pids; // pids of the procs
|
pid_t* pids; // pids of the procs
|
||||||
uid_t* uids; // uids of procs
|
uid_t* uids; // uids of procs
|
||||||
int nuid; // cannot really sentinel-terminate unsigned short[]
|
int nuid; // cannot really sentinel-terminate unsigned short[]
|
||||||
int i; // generic
|
int i; // generic
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
unsigned u; // generic
|
unsigned u; // generic
|
||||||
void * vp; // generic
|
void * vp; // generic
|
||||||
char path[PROCPATHLEN]; // must hold /proc/2000222000/task/2000222000/cmdline
|
char path[PROCPATHLEN]; // must hold /proc/2000222000/task/2000222000/cmdline
|
||||||
|
Loading…
Reference in New Issue
Block a user