From cb08cf4735f9fa4c42af66e16fbb6bb512df59a3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 4 Jun 2009 02:05:47 +0200 Subject: properly set RLIMIT_RTTIME --- rtkit-test.c | 104 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 47 deletions(-) (limited to 'rtkit-test.c') diff --git a/rtkit-test.c b/rtkit-test.c index 59244f8..25ef419 100644 --- a/rtkit-test.c +++ b/rtkit-test.c @@ -13,72 +13,82 @@ #define SCHED_RESET_ON_FORK 0x40000000 #endif +#ifndef RLIMIT_RTTIME +#define RLIMIT_RTTIME 15 +#endif + static void print_status(const char *t) { - int ret; + int ret; - if ((ret = sched_getscheduler(0)) < 0) { - fprintf(stderr, "sched_getscheduler() failed: %s\n", strerror(errno)); - return; - } + if ((ret = sched_getscheduler(0)) < 0) { + fprintf(stderr, "sched_getscheduler() failed: %s\n", strerror(errno)); + return; + } - printf("%s:\n" - "\tSCHED_RESET_ON_FORK: %s\n", - t, - (ret & SCHED_RESET_ON_FORK) ? "yes" : "no"); + printf("%s:\n" + "\tSCHED_RESET_ON_FORK: %s\n", + t, + (ret & SCHED_RESET_ON_FORK) ? "yes" : "no"); - if ((ret & ~SCHED_RESET_ON_FORK) == SCHED_RR) { - struct sched_param param; + if ((ret & ~SCHED_RESET_ON_FORK) == SCHED_RR) { + struct sched_param param; - if (sched_getparam(0, ¶m) < 0) { - fprintf(stderr, "sched_getschedparam() failed: %s\n", strerror(errno)); - return; - } + if (sched_getparam(0, ¶m) < 0) { + fprintf(stderr, "sched_getschedparam() failed: %s\n", strerror(errno)); + return; + } - printf("\tSCHED_RR with priority %i\n", param.sched_priority); + printf("\tSCHED_RR with priority %i\n", param.sched_priority); - } else if ((ret & ~SCHED_RESET_ON_FORK) == SCHED_OTHER) { - errno = 0; - ret = getpriority(PRIO_PROCESS, 0); - if (errno != 0) { - fprintf(stderr, "getpriority() failed: %s\n", strerror(errno)); - return; - } + } else if ((ret & ~SCHED_RESET_ON_FORK) == SCHED_OTHER) { + errno = 0; + ret = getpriority(PRIO_PROCESS, 0); + if (errno != 0) { + fprintf(stderr, "getpriority() failed: %s\n", strerror(errno)); + return; + } - printf("\tSCHED_OTHER with nice level: %i\n", ret); + printf("\tSCHED_OTHER with nice level: %i\n", ret); - } else - fprintf(stderr, "Neither SCHED_RR nor SCHED_OTHER.\n"); + } else + fprintf(stderr, "Neither SCHED_RR nor SCHED_OTHER.\n"); } int main(int argc, char *argv[]) { - DBusError error; - DBusConnection *bus; - int r; + DBusError error; + DBusConnection *bus; + int r; + struct rlimit rlim; + + dbus_error_init(&error); - dbus_error_init(&error); + if (!(bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { + fprintf(stderr, "Failed to connect to system bus: %s\n", error.message); + return 1; + } - if (!(bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { - fprintf(stderr, "Failed to connect to system bus: %s\n", error.message); - return 1; - } + memset(&rlim, 0, sizeof(rlim)); + rlim.rlim_cur = rlim.rlim_max = 100000000ULL; /* 100ms */ + if ((setrlimit(RLIMIT_RTTIME, &rlim) < 0)) + fprintf(stderr, "Failed to set RLIMIT_RTTIME: %s\n", strerror(errno)); - print_status("before"); + print_status("before"); - if ((r = rtkit_make_high_priority(bus, 0, -10)) < 0) - fprintf(stderr, "Failed to become high priority: %s\n", strerror(-r)); - else - printf("Sucessfully became high priority.\n"); + if ((r = rtkit_make_high_priority(bus, 0, -10)) < 0) + fprintf(stderr, "Failed to become high priority: %s\n", strerror(-r)); + else + printf("Sucessfully became high priority.\n"); - print_status("after high priority"); + print_status("after high priority"); - if ((r = rtkit_make_realtime(bus, 0, 10)) < 0) - fprintf(stderr, "Failed to become realtime: %s\n", strerror(-r)); - else - printf("Sucessfully became realtime.\n"); + if ((r = rtkit_make_realtime(bus, 0, 10)) < 0) + fprintf(stderr, "Failed to become realtime: %s\n", strerror(-r)); + else + printf("Sucessfully became realtime.\n"); - print_status("after realtime"); + print_status("after realtime"); - dbus_connection_unref(bus); + dbus_connection_unref(bus); - return 0; + return 0; } -- cgit