diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-02-15 21:50:45 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-02-15 21:50:45 +0000 |
| commit | c981cbbd13775bb259623977c23853f3db93c68a (patch) | |
| tree | 709164265de36f1211a3b3f5dc27fba84263aa88 /usr.bin | |
| parent | 640dd76f2cf9e3cb3b180670533e0cb289ea6c74 (diff) | |
| parent | ca62461bc6525f4d25d276714b4b0a2947e183a0 (diff) | |
Notes
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/proccontrol/proccontrol.c | 32 | ||||
| -rw-r--r-- | usr.bin/top/Makefile | 9 | ||||
| -rw-r--r-- | usr.bin/top/display.c | 30 | ||||
| -rw-r--r-- | usr.bin/top/display.h | 2 | ||||
| -rw-r--r-- | usr.bin/top/machine.c | 4 | ||||
| -rw-r--r-- | usr.bin/top/top.c | 4 | ||||
| -rw-r--r-- | usr.bin/top/username.c | 6 | ||||
| -rw-r--r-- | usr.bin/top/utils.c | 8 | ||||
| -rw-r--r-- | usr.bin/top/utils.h | 2 |
9 files changed, 65 insertions, 32 deletions
diff --git a/usr.bin/proccontrol/proccontrol.c b/usr.bin/proccontrol/proccontrol.c index 4cb37018c419..3c0ad53e7526 100644 --- a/usr.bin/proccontrol/proccontrol.c +++ b/usr.bin/proccontrol/proccontrol.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> enum { + MODE_ASLR, MODE_INVALID, MODE_TRACE, MODE_TRAPCAP, @@ -62,7 +63,7 @@ static void __dead2 usage(void) { - fprintf(stderr, "Usage: proccontrol -m (trace|trapcap) [-q] " + fprintf(stderr, "Usage: proccontrol -m (aslr|trace|trapcap) [-q] " "[-s (enable|disable)] [-p pid | command]\n"); exit(1); } @@ -81,7 +82,9 @@ main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "m:qs:p:")) != -1) { switch (ch) { case 'm': - if (strcmp(optarg, "trace") == 0) + if (strcmp(optarg, "aslr") == 0) + mode = MODE_ASLR; + else if (strcmp(optarg, "trace") == 0) mode = MODE_TRACE; else if (strcmp(optarg, "trapcap") == 0) mode = MODE_TRAPCAP; @@ -121,6 +124,9 @@ main(int argc, char *argv[]) if (query) { switch (mode) { + case MODE_ASLR: + error = procctl(P_PID, pid, PROC_ASLR_STATUS, &arg); + break; case MODE_TRACE: error = procctl(P_PID, pid, PROC_TRACE_STATUS, &arg); break; @@ -134,6 +140,23 @@ main(int argc, char *argv[]) if (error != 0) err(1, "procctl status"); switch (mode) { + case MODE_ASLR: + switch (arg & ~PROC_ASLR_ACTIVE) { + case PROC_ASLR_FORCE_ENABLE: + printf("force enabled"); + break; + case PROC_ASLR_FORCE_DISABLE: + printf("force disabled"); + break; + case PROC_ASLR_NOFORCE: + printf("not forced"); + break; + } + if ((arg & PROC_ASLR_ACTIVE) != 0) + printf(", active\n"); + else + printf(", not active\n"); + break; case MODE_TRACE: if (arg == -1) printf("disabled\n"); @@ -155,6 +178,11 @@ main(int argc, char *argv[]) } } else { switch (mode) { + case MODE_ASLR: + arg = enable ? PROC_ASLR_FORCE_ENABLE : + PROC_ASLR_FORCE_DISABLE; + error = procctl(P_PID, pid, PROC_ASLR_CTL, &arg); + break; case MODE_TRACE: arg = enable ? PROC_TRACE_CTL_ENABLE : PROC_TRACE_CTL_DISABLE; diff --git a/usr.bin/top/Makefile b/usr.bin/top/Makefile index d778e07c8c14..d11b91273b50 100644 --- a/usr.bin/top/Makefile +++ b/usr.bin/top/Makefile @@ -7,14 +7,5 @@ SRCS= commands.c display.c machine.c screen.c top.c \ username.c utils.c MAN= top.1 -.if ${COMPILER_TYPE} == "gcc" -.if ${COMPILER_VERSION} >= 50000 -CFLAGS.gcc=-Wno-error=discarded-qualifiers -Wno-error=incompatible-pointer-types -.else #base gcc -NO_WERROR= -.endif -.endif -CFLAGS.clang=-Wno-error=incompatible-pointer-types-discards-qualifiers - LIBADD= ncursesw m kvm jail util sbuf .include <bsd.prog.mk> diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 862d2a944c89..b17be6e83569 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -184,7 +184,7 @@ int display_init(struct statics * statics) { int lines; - char **pp; + const char * const *pp; int *ip; int i; @@ -516,8 +516,8 @@ void z_cpustates(void) { int i = 0; - const char **names; - char *thisname; + const char * const *names; + const char *thisname; int cpu, value; for (cpu = 0; cpu < num_cpus; cpu++) { @@ -751,7 +751,7 @@ static int header_length; * allocated area with the trimmed header. */ -const char * +char * trim_header(const char *text) { char *s; @@ -829,7 +829,11 @@ i_process(int line, char *thisline) } /* truncate the line to conform to our current screen width */ - thisline[screen_width] = '\0'; + int len = strlen(thisline); + if (screen_width < len) + { + thisline[screen_width] = '\0'; + } /* write the line out */ fputs(thisline, stdout); @@ -839,7 +843,10 @@ i_process(int line, char *thisline) p = stpcpy(base, thisline); /* zero fill the rest of it */ - memset(p, 0, screen_width - (p - base)); + if (p - base < screen_width) + { + memset(p, 0, screen_width - (p - base)); + } } void @@ -853,7 +860,11 @@ u_process(int line, char *newline) bufferline = &screenbuf[lineindex(line)]; /* truncate the line to conform to our current screen width */ - newline[screen_width] = '\0'; + int len = strlen(newline); + if (screen_width < len) + { + newline[screen_width] = '\0'; + } /* is line higher than we went on the last display? */ if (line >= last_hi) @@ -878,7 +889,10 @@ u_process(int line, char *newline) optr = stpcpy(bufferline, newline); /* zero fill the rest of it */ - memset(optr, 0, screen_width - (optr - bufferline)); + if (optr - bufferline < screen_width) + { + memset(optr, 0, screen_width - (optr - bufferline)); + } } else { diff --git a/usr.bin/top/display.h b/usr.bin/top/display.h index 5b5aa32fe220..546f21ce34b0 100644 --- a/usr.bin/top/display.h +++ b/usr.bin/top/display.h @@ -27,7 +27,7 @@ void i_timeofday(time_t *tod); void i_uptime(struct timeval *bt, time_t *tod); void new_message(int type, const char *msgfmt, ...); int readline(char *buffer, int size, int numeric); -const char *trim_header(const char *text); +char *trim_header(const char *text); void u_arc(int *stats); void u_carc(int *stats); void u_cpustates(int *states); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 374c9da0edf4..563efc624e24 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -618,7 +618,7 @@ get_old_proc(struct kinfo_proc *pp) pp->ki_udata = NOPROC; return (NULL); } - pp->ki_udata = oldp; + pp->ki_udata = __DECONST(void *, oldp); return (oldp); } @@ -634,7 +634,7 @@ get_io_stats(const struct kinfo_proc *pp, long *inp, long *oup, long *flp, static struct kinfo_proc dummy; long ret; - oldp = get_old_proc(pp); + oldp = get_old_proc(__DECONST(struct kinfo_proc *, pp)); if (oldp == NULL) { memset(&dummy, 0, sizeof(dummy)); oldp = &dummy; diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 80fa446fc7b1..650789689b6b 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -219,7 +219,7 @@ end: } int -main(int argc, char *argv[]) +main(int argc, const char *argv[]) { int i; int active_procs; @@ -306,7 +306,7 @@ main(int argc, char *argv[]) optind = 1; } - while ((i = getopt_long(ac, av, "CSIHPabijJ:nquvzs:d:U:m:o:p:Ttw", longopts, NULL)) != EOF) + while ((i = getopt_long(ac, __DECONST(char * const *, av), "CSIHPabijJ:nquvzs:d:U:m:o:p:Ttw", longopts, NULL)) != EOF) { switch(i) { diff --git a/usr.bin/top/username.c b/usr.bin/top/username.c index 3b15b6a2231e..be2efa8f2135 100644 --- a/usr.bin/top/username.c +++ b/usr.bin/top/username.c @@ -70,7 +70,7 @@ username(int uid) } int -userid(char username[]) +userid(char username_[]) { struct passwd *pwd; @@ -78,13 +78,13 @@ userid(char username[]) but for now we just do it simply and remember just the result. */ - if ((pwd = getpwnam(username)) == NULL) + if ((pwd = getpwnam(username_)) == NULL) { return(-1); } /* enter the result in the hash table */ - enter_user(pwd->pw_uid, username, 1); + enter_user(pwd->pw_uid, username_, 1); /* return our result */ return(pwd->pw_uid); diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c index 93bbcad09dc4..b3d4b15be28b 100644 --- a/usr.bin/top/utils.c +++ b/usr.bin/top/utils.c @@ -146,7 +146,7 @@ string_index(const char *string, const char * const *array) * squat about quotes. */ -const char * const * +const char ** argparse(char *line, int *cntp) { const char **ap; @@ -292,11 +292,11 @@ char * format_k(int64_t amt) { static char retarray[NUM_STRINGS][16]; - static int index = 0; + static int index_ = 0; char *ret; - ret = retarray[index]; - index = (index + 1) % NUM_STRINGS; + ret = retarray[index_]; + index_ = (index_ + 1) % NUM_STRINGS; humanize_number(ret, 6, amt * 1024, "", HN_AUTOSCALE, HN_NOSPACE); return (ret); } diff --git a/usr.bin/top/utils.h b/usr.bin/top/utils.h index 106e1da08963..2688f5518575 100644 --- a/usr.bin/top/utils.h +++ b/usr.bin/top/utils.h @@ -16,7 +16,7 @@ int atoiwi(const char *); char *itoa(unsigned int); char *itoa7(int); int digits(int); -const char * const *argparse(char *, int *); +const char **argparse(char *, int *); long percentages(int, int *, long *, long *, long *); const char *format_time(long); char *format_k(int64_t); |
