* use setresuid() instead of setruid() if available
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Nov 2004 00:07:24 +0000 (00:07 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Nov 2004 00:07:24 +0000 (00:07 +0000)
* if fix for the non-fp resampler

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@314 fefdeb5f-60dc-0310-8127-8f9354f1896f

configure.ac
polyp/caps.c
polyp/resampler.c

index 4db6b5b..3ab9491 100644 (file)
@@ -96,6 +96,9 @@ AC_SUBST(CAP_LIBS)
 
 AC_CHECK_HEADERS(sys/capability.h)
 
+AC_CHECK_FUNCS(setresuid)
+AC_CHECK_FUNCS(setreuid)
+
 PKG_CHECK_MODULES(LIBSAMPLERATE, [ samplerate >= 0.1.0 ])
 AC_SUBST(LIBSAMPLERATE_CFLAGS)
 AC_SUBST(LIBSAMPLERATE_LIBS)
index 34d97eb..93fca89 100644 (file)
@@ -23,6 +23,9 @@
 #include <config.h>
 #endif
 
+/* setresuid() is only available on GNU */
+#define _GNU_SOURCE
+
 #include <assert.h>
 #include <unistd.h>
 #include <errno.h>
@@ -41,13 +44,17 @@ void pa_drop_root(void) {
     
     if (uid == 0 || geteuid() != 0)
         return;
-    
-/*     pa_log(__FILE__": dropping root rights.\n"); */
-    
-    setreuid(uid, uid);
 
-/*    setuid(uid);
-    seteuid(uid);*/
+    /*     pa_log(__FILE__": dropping root rights.\n"); */
+
+#if defined(HAVE_SETRESUID)
+    setresuid(uid, uid, uid);
+#elif defined(HAVE_SETREUID)
+    setreuid(uid, uid);
+#else
+    setuid(uid);
+    seteuid(uid);
+#endif
 }
 
 #ifdef HAVE_SYS_CAPABILITY_H
index 377aa79..68c0129 100644 (file)
@@ -342,8 +342,8 @@ static void trivial_run(struct pa_resampler *r, const struct pa_memchunk *in, st
             unsigned j;
             
             j = (i->o_counter * r->i_ss.rate / r->o_ss.rate);
-            assert(j >= i->i_counter);
-            j = j - i->i_counter;
+            
+            j = j > i->i_counter ? j - i->i_counter : 0;
             
             if (j >= nframes)
                 break;