Real time privileges for non-root users

Yar Tikhiy yar at comp.chem.msu.su
Tue Jun 27 09:12:19 UTC 2006


On Thu, Jun 22, 2006 at 03:47:44PM +0100, mal content wrote:
> Hello.
> 
> Is it possible to grant real-time privileges to ordinary
> users (not root) under FreeBSD? I'm doing some audio
> work and I'd like to give real time privileges to my user id.

While I can't think of an existing user-friendly solution, you can
use available tools and interfaces to satisfy your needs.

The easiest, but not the smartest, way is to use rtprio(1).

>From rtprio(2):

    Realtime and idle priority is inherited through fork() and exec().

That is, you can start a shell with higher real-time priority, and
it will hand its priority down to its children:

    $ su
    # rtprio 1 su yourself

A smarter way is to use login.conf(5).  Idle or real-time priority
can be set for a login class, but the feature doesn't seem to be
documented anywhere except in the code itself.  The respective block
from src/lib/libutil/login_class.c is as follows:

    /* Set the process priority */
    if (flags & LOGIN_SETPRIORITY) {
        p = login_getcapnum(lc, "priority", LOGIN_DEFPRI, LOGIN_DEFPRI);

        if(p > PRIO_MAX) {
            rtp.type = RTP_PRIO_IDLE;
            rtp.prio = p - PRIO_MAX - 1;
            p = (rtp.prio > RTP_PRIO_MAX) ? 31 : p;
            if(rtprio(RTP_SET, 0, &rtp))
                syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
                    pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
        } else if(p < PRIO_MIN) {
            rtp.type = RTP_PRIO_REALTIME;
            rtp.prio = abs(p - PRIO_MIN + RTP_PRIO_MAX);
            p = (rtp.prio > RTP_PRIO_MAX) ? 1 : p;
            if(rtprio(RTP_SET, 0, &rtp))
                syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
                    pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
        } else {
            if (setpriority(PRIO_PROCESS, 0, (int)p) != 0)
                syslog(LOG_WARNING, "setpriority '%s' (%s): %m",
                    pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS);
        }
    }

Can you grok it? ;-)

-- 
Yar


More information about the freebsd-hackers mailing list