Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jun 2006 13:12:06 +0400
From:      Yar Tikhiy <yar@comp.chem.msu.su>
To:        mal content <artifact.one@googlemail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Real time privileges for non-root users
Message-ID:  <20060627091206.GB36941@comp.chem.msu.su>
In-Reply-To: <8e96a0b90606220747vf80e805k650518981bde754@mail.gmail.com>
References:  <8e96a0b90606220747vf80e805k650518981bde754@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060627091206.GB36941>