mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
cleanups after changes by Denis Vlasenko. Size optimization
This commit is contained in:
parent
63ca3bfe9d
commit
465300ced9
@ -18,16 +18,19 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
|
||||||
static int read_to_buf(char *filename, void *buf, int bufsize)
|
#define PROCPS_BUFSIZE 1024
|
||||||
|
|
||||||
|
static int read_to_buf(const char *filename, void *buf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
bufsize = read(fd, buf, bufsize);
|
ret = read(fd, buf, PROCPS_BUFSIZE);
|
||||||
close(fd);
|
close(fd);
|
||||||
return bufsize;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ extern procps_status_t * procps_scan(int save_user_arg0)
|
|||||||
int n;
|
int n;
|
||||||
char status[32];
|
char status[32];
|
||||||
char *status_tail;
|
char *status_tail;
|
||||||
char buf[1024];
|
char buf[PROCPS_BUFSIZE];
|
||||||
procps_status_t curstatus;
|
procps_status_t curstatus;
|
||||||
int pid;
|
int pid;
|
||||||
long tasknice;
|
long tasknice;
|
||||||
@ -71,7 +74,7 @@ extern procps_status_t * procps_scan(int save_user_arg0)
|
|||||||
bb_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
|
bb_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
|
||||||
|
|
||||||
strcpy(status_tail, "/stat");
|
strcpy(status_tail, "/stat");
|
||||||
n = read_to_buf(status, buf, sizeof(buf));
|
n = read_to_buf(status, buf);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
continue;
|
continue;
|
||||||
name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
|
name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
|
||||||
@ -125,7 +128,7 @@ extern procps_status_t * procps_scan(int save_user_arg0)
|
|||||||
|
|
||||||
if(save_user_arg0) {
|
if(save_user_arg0) {
|
||||||
strcpy(status_tail, "/cmdline");
|
strcpy(status_tail, "/cmdline");
|
||||||
n = read_to_buf(status, buf, sizeof(buf));
|
n = read_to_buf(status, buf);
|
||||||
if(n > 0) {
|
if(n > 0) {
|
||||||
if(buf[n-1]=='\n')
|
if(buf[n-1]=='\n')
|
||||||
buf[--n] = 0;
|
buf[--n] = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user