part 1
This commit is contained in:
parent
3f6928c4fb
commit
1572abd03e
42
sysctl.c
42
sysctl.c
@ -58,7 +58,7 @@ static const char ERR_PRELOAD_FILE[] = "error: unable to open preload file '%s'\
|
||||
static const char WARN_BAD_LINE[] = "warning: %s(%d): invalid syntax, continuing...\n";
|
||||
|
||||
|
||||
static void slashdot(char *p, char old, char new){
|
||||
static void slashdot(char *restrict p, char old, char new){
|
||||
p = strpbrk(p,"/.");
|
||||
if(!p) return; /* nothing -- can't be, but oh well */
|
||||
if(*p==new) return; /* already in desired format */
|
||||
@ -76,7 +76,7 @@ static void slashdot(char *p, char old, char new){
|
||||
* Display the usage format
|
||||
*
|
||||
*/
|
||||
static int Usage(const char *name) {
|
||||
static int Usage(const char *restrict const name) {
|
||||
printf("usage: %s [-n] variable ... \n"
|
||||
" %s [-n] -w variable=value ... \n"
|
||||
" %s [-n] -a \n"
|
||||
@ -116,16 +116,17 @@ static char *StripLeadingAndTrailingSpaces(char *oneline) {
|
||||
* Read a sysctl setting
|
||||
*
|
||||
*/
|
||||
static int ReadSetting(const char *setting) {
|
||||
static int ReadSetting(const char *restrict const name) {
|
||||
int rc = 0;
|
||||
char *tmpname, *outname;
|
||||
char *restrict tmpname;
|
||||
char *restrict outname;
|
||||
char inbuf[1025];
|
||||
const char *name = setting;
|
||||
FILE *fp;
|
||||
FILE *restrict fp;
|
||||
|
||||
if (!setting || !*setting) {
|
||||
fprintf(stderr, ERR_INVALID_KEY, setting);
|
||||
} /* endif */
|
||||
if (!name || !*name) {
|
||||
fprintf(stderr, ERR_INVALID_KEY, name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* used to open the file */
|
||||
tmpname = malloc(strlen(name)+strlen(PROC_PATH)+1);
|
||||
@ -179,12 +180,12 @@ static int ReadSetting(const char *setting) {
|
||||
* Display all the sysctl settings
|
||||
*
|
||||
*/
|
||||
static int DisplayAll(const char *path, bool ShowTableUtil) {
|
||||
static int DisplayAll(const char *restrict const path, bool ShowTableUtil) {
|
||||
int rc = 0;
|
||||
int rc2;
|
||||
DIR *dp;
|
||||
struct dirent *de;
|
||||
char *tmpdir;
|
||||
DIR *restrict dp;
|
||||
struct dirent *restrict de;
|
||||
char *restrict tmpdir;
|
||||
struct stat ts;
|
||||
|
||||
dp = opendir(path);
|
||||
@ -195,7 +196,7 @@ static int DisplayAll(const char *path, bool ShowTableUtil) {
|
||||
} else {
|
||||
readdir(dp); readdir(dp); /* skip . and .. */
|
||||
while (( de = readdir(dp) )) {
|
||||
tmpdir = (char *)malloc(strlen(path)+strlen(de->d_name)+2);
|
||||
tmpdir = (char *restrict)malloc(strlen(path)+strlen(de->d_name)+2);
|
||||
sprintf(tmpdir, "%s%s", path, de->d_name);
|
||||
rc2 = stat(tmpdir, &ts); /* should check this return code */
|
||||
if (rc2 != 0) {
|
||||
@ -206,15 +207,14 @@ static int DisplayAll(const char *path, bool ShowTableUtil) {
|
||||
DisplayAll(tmpdir, ShowTableUtil);
|
||||
} else {
|
||||
rc |= ReadSetting(tmpdir+strlen(PROC_PATH));
|
||||
} /* endif */
|
||||
} /* endif */
|
||||
}
|
||||
}
|
||||
free(tmpdir);
|
||||
} /* end while */
|
||||
}
|
||||
closedir(dp);
|
||||
} /* endif */
|
||||
|
||||
}
|
||||
return rc;
|
||||
} /* end DisplayAll() */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@ -302,7 +302,7 @@ static int WriteSetting(const char *setting) {
|
||||
* - we parse the file and then reform it (strip out whitespace)
|
||||
*
|
||||
*/
|
||||
static void Preload(const char *filename) {
|
||||
static void Preload(const char *restrict const filename) {
|
||||
FILE *fp;
|
||||
char oneline[257];
|
||||
char buffer[257];
|
||||
|
20
w.c
20
w.c
@ -44,7 +44,7 @@ typedef struct utmp utmp_t;
|
||||
* unprintable. Always outputs at least 16 chars padded with spaces
|
||||
* on the right if necessary.
|
||||
*/
|
||||
static void print_host(char* host, int len) {
|
||||
static void print_host(const char *restrict host, int len) {
|
||||
char *last;
|
||||
int width = 0;
|
||||
|
||||
@ -62,15 +62,8 @@ static void print_host(char* host, int len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!width){ /* blank fields screw up parsers */
|
||||
fputc('-', stdout);
|
||||
++width;
|
||||
}
|
||||
/* if *any* unprintables(or blanks), replace rest of line with spaces */
|
||||
while (width < 16) {
|
||||
fputc(' ', stdout);
|
||||
++width;
|
||||
}
|
||||
// space-fill, and a '-' too if needed to ensure the column exists
|
||||
if(width < 16) fputs("- "+width, stderr);
|
||||
}
|
||||
|
||||
/***** compact 7 char format for time intervals (belongs in libproc?) */
|
||||
@ -90,7 +83,7 @@ static void print_time_ival7(time_t t, int centi_sec, FILE* fout) {
|
||||
}
|
||||
|
||||
/**** stat the device file to get an idle time */
|
||||
static time_t idletime(char *tty) {
|
||||
static time_t idletime(const char *restrict const tty) {
|
||||
struct stat sbuf;
|
||||
if (stat(tty, &sbuf) != 0)
|
||||
return 0;
|
||||
@ -128,7 +121,7 @@ static void print_logintime(time_t logt, FILE* fout) {
|
||||
* for the "best" process to report as "(w)hat" the user for that login
|
||||
* session is doing currently. This the essential core of 'w'.
|
||||
*/
|
||||
static proc_t *getproc(utmp_t *u, char *tty, unsigned long long *jcpu, int *found_utpid) {
|
||||
static proc_t *getproc(const utmp_t *restrict const u, const char *restrict const tty, const unsigned long long *restrict jcpu, const int *restrict found_utpid) {
|
||||
int line;
|
||||
proc_t **p, *best = NULL, *secondbest = NULL;
|
||||
unsigned uid = ~0U;
|
||||
@ -144,7 +137,8 @@ static proc_t *getproc(utmp_t *u, char *tty, unsigned long long *jcpu, int *foun
|
||||
/* OK to have passwd_data go out of scope here */
|
||||
}
|
||||
line = tty_to_dev(tty);
|
||||
*jcpu = *found_utpid = 0;
|
||||
*jcpu = 0;
|
||||
*found_utpid = 0;
|
||||
for(p = procs; *p; p++) {
|
||||
if((**p).pid == u->ut_pid) {
|
||||
*found_utpid = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user