From 6bc6beb3e847eed6750535a0241d9ed4a1460e08 Mon Sep 17 00:00:00 2001 From: Michael Nottebrock Date: Tue, 9 Mar 2004 12:51:06 +0000 Subject: Add artswrapper, a suid wrapper for aRts. --- audio/artswrapper/Makefile | 32 ++++++++++ audio/artswrapper/files/artswrapper.c | 114 ++++++++++++++++++++++++++++++++++ audio/artswrapper/pkg-descr | 3 + 3 files changed, 149 insertions(+) create mode 100644 audio/artswrapper/Makefile create mode 100644 audio/artswrapper/files/artswrapper.c create mode 100644 audio/artswrapper/pkg-descr (limited to 'audio/artswrapper') diff --git a/audio/artswrapper/Makefile b/audio/artswrapper/Makefile new file mode 100644 index 000000000000..86eb284cb9e9 --- /dev/null +++ b/audio/artswrapper/Makefile @@ -0,0 +1,32 @@ +# New ports collection makefile for: artsrapper +# Date created: 2004-03-04 +# Whom: Michael Nottebrock +# +# $FreeBSD$ +# + +PORTNAME= artswrapper +PORTVERSION= 1.2.1 +CATEGORIES= audio +DISTNAME= # none +EXTRACT_SUFX= # none + +MAINTAINER= kde@freebsd.org +COMMENT= Setuid wrapper for arts + +IGNORE= This port is part of KDE 3.2.1 and is not yet ready + +NO_WRKSUBDIR= yes +PLIST_FILES= bin/artswrapper + +do-fetch: + +.include + +do-build: + ${CC} ${CFLAGS} -DHAVE_REALTIME_SCHED -DEXECUTE=\"${LOCALBASE}/bin/artsd\" -o ${WRKSRC}/artswrapper ${FILESDIR}/artswrapper.c + +do-install: + ${INSTALL} ${COPY} ${STRIP} ${_BINOWNGRP} -m 4555 ${WRKSRC}/artswrapper ${PREFIX}/bin + +.include diff --git a/audio/artswrapper/files/artswrapper.c b/audio/artswrapper/files/artswrapper.c new file mode 100644 index 000000000000..eb86fd23417c --- /dev/null +++ b/audio/artswrapper/files/artswrapper.c @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include +#include + +/* + * adjust_priority + * + * sets realtime priority + */ + +#ifdef HAVE_REALTIME_SCHED +#include + +void adjust_priority() +{ + int sched = sched_getscheduler(0); + if(sched == SCHED_FIFO || sched == SCHED_RR) + { + printf(">> since the scheduling policy is not standard, I assume\n"); + printf(" it has been adjusted to fit the needs of realtime audio\n"); + } + else + { + struct sched_param sp; + long priority = (sched_get_priority_max(SCHED_FIFO) + + sched_get_priority_min(SCHED_FIFO))/2; + + sp.sched_priority = priority; + + if(sched_setscheduler(0, SCHED_FIFO, &sp) != -1) + { + printf(">> running as realtime process now (priority %ld)\n", + priority); + putenv("STARTED_THROUGH_ARTSWRAPPER=1"); + } + else + { + /* can't set realtime priority */ + putenv("STARTED_THROUGH_ARTSWRAPPER=2"); + } + } +} +#else +void adjust_priority() +{ + int prio; + + prio = getpriority(PRIO_PROCESS,getpid()); + if(prio > -10) + { + setpriority(PRIO_PROCESS,getpid(),-17); + prio = getpriority(PRIO_PROCESS,getpid()); + } + + /* no system support for realtime priority */ + putenv("STARTED_THROUGH_ARTSWRAPPER=3"); + + if(prio > -10) { + printf(">> synthesizer priority is %d (which is unacceptable,",prio); + printf(" try running as root)\n"); + } + else { + printf(">> synthesizer priority is %d (which is the best\n",prio); + printf(" we can get out of a non realtime system)\n"); + } +} +#endif + +int main(int argc, char **argv) +{ + if(argc == 2) + { + if(strcmp(argv[1],"check") == 0) + { + /* backward compatibility with old artswrapper */ + printf("okay\n"); + return 0; + } + } + + adjust_priority(); + + /* drop root privileges if running setuid root + (due to realtime priority stuff) */ + if (geteuid() != getuid()) + { +#if defined (HAVE_SETEUID) && !defined (HAVE_SETEUID_FAKE) + seteuid(getuid()); +#else + setreuid(-1, getuid()); +#endif + } + + if(argc == 0) + return 1; + +/* + * Real-time status is passed to artsd via the environment variable + * STARTED_THROUGH_ARTSWRAPPER. It has one of the following values: + * + * unset - not running as real-time + * 1 - running as real-time + * 2 - no privileges to set real-time scheduling + * 3 - no support for real-time scheduling + */ + argv[0] = EXECUTE; + execv(EXECUTE,argv); + perror(EXECUTE); + return 1; +} diff --git a/audio/artswrapper/pkg-descr b/audio/artswrapper/pkg-descr new file mode 100644 index 000000000000..fd9aade6ef58 --- /dev/null +++ b/audio/artswrapper/pkg-descr @@ -0,0 +1,3 @@ +This program launches artsd (from the audio/arts port), optionally with +elevated priority. To do this, it needs superuser priviliges and is installed +setuid root. -- cgit v1.2.3