Merge remote-tracking branch 'sami/to-craig' into sami-merge

Conflicts:
	pgrep.c
	w.c
This commit is contained in:
Craig Small 2012-03-03 13:56:32 +11:00
commit 502a79e02f
10 changed files with 83 additions and 17 deletions

View File

@ -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 <argp.h>],
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])

View File

@ -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) {

2
pmap.c
View File

@ -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;

View File

@ -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);
}

View File

@ -2,3 +2,4 @@
*.sum
site.bak
site.exp
test-schedbatch

View File

@ -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 \

View File

@ -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"

View File

@ -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 [ <NICE> ]
*
* Author: Mike Fleetwood
* https://bugzilla.redhat.com/show_bug.cgi?id=741090
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
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();
}
}

View File

@ -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)

2
w.c
View File

@ -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;
}