diff --git a/configure.ac b/configure.ac index d33eb39c..4f343c26 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,7 @@ AC_PROG_CC AM_PROG_CC_C_O AC_PROG_INSTALL AC_PROG_LN_S +PKG_PROG_PKG_CONFIG AC_SUBST([WITH_WATCH8BIT]) AC_ARG_ENABLE([watch8bit], @@ -127,25 +128,29 @@ AC_TRY_COMPILE([#include ], AC_ARG_WITH([ncurses], AS_HELP_STRING([--without-ncurses], [build only applications not needing ncurses]), - [with_ncurses=no], [with_ncurses=yes] + [with_ncurses=$withval], [with_ncurses=yes] ) if test "x$with_ncurses" = xno; then AM_CONDITIONAL(WITH_NCURSES, false) else - AC_CHECK_LIB(ncursesw, initscr, [have_ncurses=yes], [have_ncurses=no]) - AC_CHECK_HEADERS(curses.h ncurses.h term.h, [], [have_ncurses=no], AC_INCLUDES_DEFAULT) - if test "x$have_ncurses" = xno; then - AC_MSG_ERROR([ncurses support missing/incomplete (for partial build use --without-ncurses)]) - fi + PKG_CHECK_MODULES([NCURSES], [ncurses], [], [ + AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no]) + AC_CHECK_HEADERS(curses.h ncurses.h term.h, [], [have_ncurses=no], AC_INCLUDES_DEFAULT) + if test "x$have_ncurses" = xno; then + AC_MSG_ERROR([ncurses support missing/incomplete (for partial build use --without-ncurses)]) + fi + NCURSES_LIBS="-lncurses" + ]) AM_CONDITIONAL(WITH_NCURSES, true) if test "$enable_watch8bit" = yes; then - AC_CHECK_LIB([ncursesw], [addwstr], [WATCH_NCURSES_LIBS=-lncursesw], - [AC_MSG_ERROR([Cannot find ncurses wide library ncursesw with --enable-watch8bit])]) + PKG_CHECK_MODULES([NCURSESW], [ncursesw], [WATCH_NCURSES_LIBS="$NCURSESW_LIBS"], [ + AC_CHECK_LIB([ncursesw], [addwstr], [WATCH_NCURSES_LIBS=-lncursesw], + [AC_MSG_ERROR([Cannot find ncurses wide library ncursesw with --enable-watch8bit])]) + ]) else - WATCH_NCURSES_LIBS="-lncurses" + WATCH_NCURSES_LIBS="$NCURSES_LIBS" fi - NCURSES_LIBS="-lncurses" fi AC_SUBST([NCURSES_LIBS]) AC_SUBST([WATCH_NCURSES_LIBS]) diff --git a/pgrep.c b/pgrep.c index 6c6d2618..b1d4ace4 100644 --- a/pgrep.c +++ b/pgrep.c @@ -798,9 +798,9 @@ int main (int argc, char **argv) continue; } if (errno==ESRCH) - /* gone now, which is OK */ - continue; - xwarn(_("killing pid %d failed"), procs[i].num); + // gone now, which is OK + continue; + xwarn(_("killing pid %ld failed"), procs[i].num); } } else { if (opt_count) { diff --git a/pmap.c b/pmap.c index e0801eff..df052e92 100644 --- a/pmap.c +++ b/pmap.c @@ -161,7 +161,7 @@ static int one_proc(proc_t * p) unsigned long total_private_writeable = 0ul; KLONG diff = 0; - char *cp2 = NULL; + const char *cp2 = NULL; unsigned long long rss = 0ull; unsigned long long private_dirty = 0ull; unsigned long long shared_dirty = 0ull; diff --git a/ps/output.c b/ps/output.c index e617469d..104d0342 100644 --- a/ps/output.c +++ b/ps/output.c @@ -624,8 +624,12 @@ static int pr_pri_api(char *restrict const outbuf, const proc_t *restrict const return snprintf(outbuf, COLWID, "%ld", -1 - pp->priority); } +// Linux applies nice value in the scheduling policies (classes) +// SCHED_OTHER(0) and SCHED_BATCH(3). Ref: sched_setscheduler(2). +// Also print nice value for old kernels which didn't use scheduling +// policies (-1). static int pr_nice(char *restrict const outbuf, const proc_t *restrict const pp){ - if(pp->sched!=0 && pp->sched!=(unsigned long)-1) return snprintf(outbuf, COLWID, "-"); + if(pp->sched!=0 && pp->sched!=3 && pp->sched!=-1) return snprintf(outbuf, COLWID, "-"); return snprintf(outbuf, COLWID, "%ld", pp->nice); } diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 96ef0306..b14d968d 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -2,3 +2,4 @@ *.sum site.bak site.exp +test-schedbatch diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index d1682ac1..3f795323 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -4,6 +4,10 @@ export DEJAGNU # Programs that are expected across the board. DEJATOOL = +noinst_PROGRAMS = test-schedbatch + +test_schedbatch_SOURCES = ps.test/test-schedbatch.c + if LINUX # These should be in defined in 'across the board' scope, but are # temporarily disabled on other than linux systems, see commit @@ -35,6 +39,7 @@ EXTRA_DIST = \ pmap.test/pmap.exp \ ps.test/ps_output.exp \ ps.test/ps_personality.exp \ + ps.test/ps_sched_batch.exp \ pwdx.test/pwdx.exp \ slabtop.test/slabtop.exp \ sysctl.test/sysctl_read.exp \ diff --git a/testsuite/ps.test/ps_sched_batch.exp b/testsuite/ps.test/ps_sched_batch.exp new file mode 100644 index 00000000..e0c31ffd --- /dev/null +++ b/testsuite/ps.test/ps_sched_batch.exp @@ -0,0 +1,12 @@ +# +# check the ps SCHED_BATCH scheduler policy output +# +set ps "${topdir}ps/pscommand" +set schedbatch "${topdir}testsuite/test-schedbatch" + +spawn $schedbatch 18 + +set test "ps SCHED_BATCH scheduler" +spawn $ps --no-header -o comm,cls,nice -a +expect_pass "$test" "\\s+test-schedbatch\\s+B\\s+18" +untested "$test" diff --git a/testsuite/ps.test/test-schedbatch.c b/testsuite/ps.test/test-schedbatch.c new file mode 100644 index 00000000..13cd6f33 --- /dev/null +++ b/testsuite/ps.test/test-schedbatch.c @@ -0,0 +1,39 @@ +/* test-schedbatch.c - Create a process using SCHED_BATCH scheduler + * policy and nice value. + * Compile: gcc -o test-schedbatch -Wall test-schedbatch.c + * Usage: ./test-schedbatch [ ] + * + * Author: Mike Fleetwood + * https://bugzilla.redhat.com/show_bug.cgi?id=741090 + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +int main(int argc, const char *argv[]) +{ + int nice = 19; + struct sched_param sp; + char msg[50]; + + if (argc >= 2) { + nice = atoi(argv[1]); + } + sp.sched_priority = 0; + if (sched_setscheduler(0, SCHED_BATCH, &sp)) { + perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}"); + } + if (setpriority(PRIO_PROCESS, 0, nice) || errno) { + (void)snprintf(msg, sizeof(msg), + "setpriority(PRIO_PROCESS, 0, %d)", nice); + perror(msg); + } + while (1) { + getchar(); + } +} diff --git a/vmstat.c b/vmstat.c index 814b528d..1f310317 100644 --- a/vmstat.c +++ b/vmstat.c @@ -356,7 +356,7 @@ static int diskpartition_format(const char *partition_name) struct disk_stat *disks; struct partition_stat *partitions, *current_partition = NULL; unsigned long ndisks, j, k, npartitions; - const char format[] = "%20u %10llu %10u %10u\n"; + const char format[] = "%20u %10llu %10u %10llu\n"; fDiskstat = fopen("/proc/diskstats", "rb"); if (!fDiskstat) diff --git a/w.c b/w.c index cded1623..f86f2df1 100644 --- a/w.c +++ b/w.c @@ -392,7 +392,7 @@ int main(int argc, char **argv) userlen = atoi(env_var); if (userlen < 8 || userlen > USERSZ) { xwarnx - (_("user length environment PROCPS_USERLEN must be between 8 and %d, ignoring\n"), + (_("User length environment PROCPS_USERLEN must be between 8 and %zu, ignoring.\n"), USERSZ); userlen = 8; }