if BUILD_SCHEDUTILS
+srcs_common = schedutils.c schedutils.h
+
usrbin_exec_PROGRAMS = chrt
dist_man_MANS = chrt.1
+chrt_SOURCES = chrt.c $(srcs_common)
+
if HAVE_IOPRIO_GET
if HAVE_IOPRIO_SET
usrbin_exec_PROGRAMS += ionice
+ionice_SOURCES = ionice.c $(srcs_common)
dist_man_MANS += ionice.1
endif
endif
if HAVE_SCHED_GETAFFINITY
usrbin_exec_PROGRAMS += taskset
-taskset_SOURCES = taskset.c $(top_srcdir)/lib/cpuset.c
+taskset_SOURCES = taskset.c $(top_srcdir)/lib/cpuset.c $(srcs_common)
dist_man_MANS += taskset.1
endif
#include "c.h"
#include "nls.h"
+#include "schedutils.h"
+
/* the SCHED_BATCH is supported since Linux 2.6.16
* -- temporary workaround for people with old glibc headers
*/
break;
case 'p':
errno = 0;
- pid = strtol(argv[argc - 1], NULL, 10);
- if (errno)
- err(EXIT_FAILURE, _("failed to parse pid"));
+ pid = getnum(argv[argc - 1], _("failed to parse pid"));
break;
case 'r':
policy = SCHED_RR;
}
errno = 0;
- priority = strtol(argv[optind], NULL, 10);
- if (errno)
- err(EXIT_FAILURE, _("failed to parse priority"));
+ priority = getnum(argv[optind], _("failed to parse priority"));
#ifdef SCHED_RESET_ON_FORK
/* sanity check */
#include "nls.h"
+#include "schedutils.h"
+
static int tolerant;
static inline int ioprio_set(int which, int who, int ioprio)
exit(rc);
}
-static long getnum(const char *str)
-{
- long num;
- char *end = NULL;
-
- if (str == NULL || *str == '\0')
- goto err;
- errno = 0;
- num = strtol(str, &end, 10);
-
- if (errno || (end && *end))
- goto err;
-
- return num;
-err:
- if (errno)
- err(EXIT_SUCCESS, _("cannot parse number '%s'"), str);
- else
- errx(EXIT_SUCCESS, _("cannot parse number '%s'"), str);
- return 0;
-}
-
int main(int argc, char *argv[])
{
int ioprio = 4, set = 0, ioclass = IOPRIO_CLASS_BE, c;
while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
switch (c) {
case 'n':
- ioprio = getnum(optarg);
+ ioprio = getnum(optarg, _("failed to parse class data"));
set |= 1;
break;
case 'c':
- ioclass = getnum(optarg);
+ ioclass = getnum(optarg, _("failed to parse class"));
set |= 2;
break;
case 'p':
- pid = getnum(optarg);
+ pid = getnum(optarg, _("failed to parse pid"));
break;
case 't':
tolerant = 1;
ioprio_print(pid);
for(; argv[optind]; ++optind) {
- pid = getnum(argv[optind]);
+ pid = getnum(argv[optind], _("failed to parse pid"));
ioprio_print(pid);
}
} else {
for(; argv[optind]; ++optind)
{
- pid = getnum(argv[optind]);
+ pid = getnum(argv[optind], _("failed to parse pid"));
ioprio_setpid(pid, ioprio, ioclass);
}
}
--- /dev/null
+/*
+ * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
+ *
+ * Released under the terms of the GNU General Public License version 2
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <err.h>
+
+#include "nls.h"
+
+long getnum(const char *str, const char *errmesg)
+{
+ long num;
+ char *end = NULL;
+
+ if (str == NULL || *str == '\0')
+ goto err;
+ errno = 0;
+ num = strtol(str, &end, 10);
+
+ if (errno || (end && *end))
+ goto err;
+
+ return num;
+err:
+ if (errno)
+ err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+ else
+ errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+ return 0;
+}
--- /dev/null
+#ifndef UTIL_LINUX_SCHED_UTILS
+#define UTIL_LINUX_SCHED_UTILS
+
+extern long getnum(const char *str, const char *errmesg);
+
+#endif
+
#include "cpuset.h"
#include "nls.h"
+#include "schedutils.h"
+
static void __attribute__((__noreturn__)) usage(FILE *out)
{
fprintf(out,
while ((opt = getopt_long(argc, argv, "+pchV", longopts, NULL)) != -1) {
switch (opt) {
case 'p':
- pid = atoi(argv[argc - 1]);
+ pid = getnum(argv[argc - 1], _("failed to parse pid"));
break;
case 'c':
c_opt = 1;