On 13/08/15 22:04, Antti Kantee wrote:
> If you think it's a huge benefit for you, we can add your code as an inline 
> function to <rump/rumperr.h>.  But it will still go out-of-date unless the 
> header is somehow autogenerated as part of the build.

Uhm yes, I think it could be useful to me. However based on your replies I 
suspect I may be doing
something strange, or at least unusual.

I'm attaching a patch just to show you what I'm doing. But please don't laugh 
at my kludges, it's just
a quick & dirty unfinished work ;-)

Notice how the rump_errtrans_rump2host() function in this code is being quite 
useful. Also note
the replacement of O_NDELAY and O_CLOEXEC by hardcoded numbers, where a similar 
translation facility
would be useful too.

Am I doing something completely wrong here? Does this look like the right way 
of using
rump_sys_{open,ioctl,etc}?

Many thanks

-- 
Robert Millan
Index: pulseaudio-2.0.new/src/modules/oss/module-oss.c
===================================================================
--- pulseaudio-2.0.new.orig/src/modules/oss/module-oss.c	2012-05-13 15:26:37.000000000 +0200
+++ pulseaudio-2.0.new/src/modules/oss/module-oss.c	2015-08-16 00:10:46.859074183 +0200
@@ -34,6 +34,8 @@
  *
  */
 
+#define RUMP 1
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -72,6 +74,10 @@
 #include <sys/syscall.h>
 #endif
 
+#include <rump/rump.h>
+#include <rump/rumperr.h>
+#include <rump/rump_syscalls.h>
+
 #include "oss-util.h"
 #include "module-oss-symdef.h"
 
@@ -94,11 +100,15 @@
         "fragments=<number of fragments> "
         "fragment_size=<fragment size> "
         "mmap=<enable memory mapping?>");
-#ifdef __linux__
+#if defined(__linux__) && !defined(RUMP)
 PA_MODULE_DEPRECATED("Please use module-alsa-card instead of module-oss!");
 #endif
 
+#ifdef RUMP
+#define DEFAULT_DEVICE "/dev/sound"
+#else
 #define DEFAULT_DEVICE "/dev/dsp"
+#endif
 
 struct userdata {
     pa_core *core;
@@ -179,16 +189,20 @@
     if (u->use_mmap) {
 
         if (!quick)
-            ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &zero);
+					rump_sys_ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &zero);
 
 #ifdef SNDCTL_DSP_HALT
         if (enable_bits == 0)
-            if (ioctl(u->fd, SNDCTL_DSP_HALT, NULL) < 0)
+					if (rump_sys_ioctl(u->fd, SNDCTL_DSP_HALT, NULL) < 0) {
+						errno = rump_errtrans_rump2host(errno);
                 pa_log_warn("SNDCTL_DSP_HALT: %s", pa_cstrerror(errno));
+					}
 #endif
 
-        if (ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) < 0)
+        if (rump_sys_ioctl(u->fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) < 0) {
+					errno = rump_errtrans_rump2host(errno);
             pa_log_warn("SNDCTL_DSP_SETTRIGGER: %s", pa_cstrerror(errno));
+				}
 
         if (u->sink && !(enable_bits & PCM_ENABLE_OUTPUT)) {
             pa_log_debug("clearing playback buffer");
@@ -198,8 +212,10 @@
     } else {
 
         if (enable_bits)
-            if (ioctl(u->fd, SNDCTL_DSP_POST, NULL) < 0)
+					if (rump_sys_ioctl(u->fd, SNDCTL_DSP_POST, NULL) < 0) {
+						errno = rump_errtrans_rump2host(errno);
                 pa_log_warn("SNDCTL_DSP_POST: %s", pa_cstrerror(errno));
+					}
 
         if (!quick) {
             /*
@@ -257,7 +273,8 @@
 
 /*     pa_log("Mmmap writing..."); */
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_GETOPTR: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -333,7 +350,8 @@
 
 /*     pa_log("Mmmap reading..."); */
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_GETIPTR: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -357,7 +375,8 @@
 
     pa_assert(u);
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_GETOPTR: %s", pa_cstrerror(errno));
         return 0;
     }
@@ -382,7 +401,8 @@
 
     pa_assert(u);
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_GETIPTR: %s", pa_cstrerror(errno));
         return 0;
     }
@@ -422,7 +442,8 @@
         u->use_getodelay = 0;
 #endif
 #else
-        if (ioctl(u->fd, SNDCTL_DSP_GETODELAY, &arg) < 0) {
+        if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETODELAY, &arg) < 0) {
+					errno = rump_errtrans_rump2host(errno);
             pa_log_info("Device doesn't support SNDCTL_DSP_GETODELAY: %s", pa_cstrerror(errno));
             u->use_getodelay = 0;
         } else
@@ -433,7 +454,8 @@
     if (!u->use_getodelay && u->use_getospace) {
         struct audio_buf_info info;
 
-        if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
+        if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
+					errno = rump_errtrans_rump2host(errno);
             pa_log_info("Device doesn't support SNDCTL_DSP_GETOSPACE: %s", pa_cstrerror(errno));
             u->use_getospace = 0;
         } else
@@ -454,7 +476,8 @@
     if (u->use_getispace) {
         struct audio_buf_info info;
 
-        if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
+        if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
+					errno = rump_errtrans_rump2host(errno);
             pa_log_info("Device doesn't support SNDCTL_DSP_GETISPACE: %s", pa_cstrerror(errno));
             u->use_getispace = 0;
         } else
@@ -516,8 +539,8 @@
     }
 
     /* Let's suspend */
-    ioctl(u->fd, SNDCTL_DSP_SYNC, NULL);
-    pa_close(u->fd);
+    rump_sys_ioctl(u->fd, SNDCTL_DSP_SYNC, NULL);
+    rump_sys_close(u->fd);
     u->fd = -1;
 
     if (u->rtpoll_item) {
@@ -567,7 +590,8 @@
         goto fail;
     }
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log_warn("SNDCTL_DSP_GETBLKSIZE: %s", pa_cstrerror(errno));
         goto fail;
     }
@@ -575,12 +599,14 @@
     in_frag_size = out_frag_size = frag_size;
     in_nfrags = out_nfrags = u->nfrags;
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
+			errno = rump_errtrans_rump2host(errno);
         in_frag_size = info.fragsize;
         in_nfrags = info.fragstotal;
     }
 
-    if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
+    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
+			errno = rump_errtrans_rump2host(errno);
         out_frag_size = info.fragsize;
         out_nfrags = info.fragstotal;
     }
@@ -631,7 +657,7 @@
     return 0;
 
 fail:
-    pa_close(u->fd);
+    rump_sys_close(u->fd);
     u->fd = -1;
     return -1;
 }
@@ -918,7 +944,8 @@
                 if (u->use_getospace) {
                     audio_buf_info info;
 
-                    if (ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
+                    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
+											errno = rump_errtrans_rump2host(errno);
                         pa_log_info("Device doesn't support SNDCTL_DSP_GETOSPACE: %s", pa_cstrerror(errno));
                         u->use_getospace = FALSE;
                     } else {
@@ -1029,7 +1056,8 @@
                 if (u->use_getispace) {
                     audio_buf_info info;
 
-                    if (ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
+                    if (rump_sys_ioctl(u->fd, SNDCTL_DSP_GETISPACE, &info) < 0) {
+											errno = rump_errtrans_rump2host(errno);
                         pa_log_info("Device doesn't support SNDCTL_DSP_GETISPACE: %s", pa_cstrerror(errno));
                         u->use_getispace = FALSE;
                     } else {
@@ -1239,7 +1267,8 @@
     if (pa_oss_auto_format(fd, &ss) < 0)
         goto fail;
 
-    if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
+    if (rump_sys_ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_GETBLKSIZE: %s", pa_cstrerror(errno));
         goto fail;
     }
@@ -1266,14 +1295,16 @@
     u->rtpoll_item = NULL;
     build_pollfd(u);
 
-    if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
+    if (rump_sys_ioctl(fd, SNDCTL_DSP_GETISPACE, &info) >= 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log_info("Input -- %u fragments of size %u.", info.fragstotal, info.fragsize);
         u->in_fragment_size = (uint32_t) info.fragsize;
         u->in_nfrags = (uint32_t) info.fragstotal;
         u->use_getispace = TRUE;
     }
 
-    if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
+    if (rump_sys_ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) {
+			errno = rump_errtrans_rump2host(errno);
         pa_log_info("Output -- %u fragments of size %u.", info.fragstotal, info.fragsize);
         u->out_fragment_size = (uint32_t) info.fragsize;
         u->out_nfrags = (uint32_t) info.fragstotal;
@@ -1416,8 +1447,10 @@
     if ((u->mixer_fd = pa_oss_open_mixer_for_device(u->device_name)) >= 0) {
         pa_bool_t do_close = TRUE;
 
-        if (ioctl(fd, SOUND_MIXER_READ_DEVMASK, &u->mixer_devmask) < 0)
+        if (rump_sys_ioctl(fd, SOUND_MIXER_READ_DEVMASK, &u->mixer_devmask) < 0){
+					errno = rump_errtrans_rump2host(errno);
             pa_log_warn("SOUND_MIXER_READ_DEVMASK failed: %s", pa_cstrerror(errno));
+				}
         else {
             if (u->sink && (u->mixer_devmask & (SOUND_MASK_VOLUME|SOUND_MASK_PCM))) {
                 pa_log_debug("Found hardware mixer track for playback.");
@@ -1437,7 +1470,7 @@
         }
 
         if (do_close) {
-            pa_close(u->mixer_fd);
+            rump_sys_close(u->mixer_fd);
             u->mixer_fd = -1;
             u->mixer_devmask = 0;
         }
@@ -1489,7 +1522,7 @@
     if (u)
         pa__done(m);
     else if (fd >= 0)
-        pa_close(fd);
+        rump_sys_close(fd);
 
     if (ma)
         pa_modargs_free(ma);
@@ -1556,10 +1589,10 @@
         munmap(u->out_mmap, u->out_hwbuf_size);
 
     if (u->fd >= 0)
-        pa_close(u->fd);
+			rump_sys_close(u->fd);
 
     if (u->mixer_fd >= 0)
-        pa_close(u->mixer_fd);
+			rump_sys_close(u->mixer_fd);
 
     pa_xfree(u->device_name);
 
Index: pulseaudio-2.0.new/src/modules/oss/oss-util.c
===================================================================
--- pulseaudio-2.0.new.orig/src/modules/oss/oss-util.c	2012-05-13 15:26:37.000000000 +0200
+++ pulseaudio-2.0.new/src/modules/oss/oss-util.c	2015-08-15 23:30:10.849747765 +0200
@@ -45,6 +45,7 @@
     int fd = -1;
     int caps;
     char *t;
+		int ret;
 
     pa_assert(device);
     pa_assert(mode);
@@ -54,10 +55,13 @@
         pcaps = &caps;
 
     if (*mode == O_RDWR) {
-        if ((fd = pa_open_cloexec(device, O_RDWR|O_NDELAY, 0)) >= 0) {
-            ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
+        if ((fd = rump_sys_open(device, O_RDWR|0x00000004|0x00400000, 0)) >= 0) {
+					  rump_sys_ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
 
-            if (ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps) < 0) {
+
+            ret = rump_sys_ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps);
+						errno = rump_errtrans_rump2host(errno);
+						if (ret < 0) {
                 pa_log("SNDCTL_DSP_GETCAPS: %s", pa_cstrerror(errno));
                 goto fail;
             }
@@ -67,17 +71,19 @@
 
             pa_log_warn("'%s' doesn't support full duplex", device);
 
-            pa_close(fd);
+            rump_sys_close(fd);
         }
 
-        if ((fd = pa_open_cloexec(device, (*mode = O_WRONLY)|O_NDELAY, 0)) < 0) {
-            if ((fd = pa_open_cloexec(device, (*mode = O_RDONLY)|O_NDELAY, 0)) < 0) {
+        if ((fd = rump_sys_open(device, (*mode = O_WRONLY)|0x00000004|0x00400000, 0)) < 0) {
+            if ((fd = rump_sys_open(device, (*mode = O_RDONLY)|0x00000004|0x00400000, 0)) < 0) {
+							errno = rump_errtrans_rump2host(errno);
                 pa_log("open('%s'): %s", device, pa_cstrerror(errno));
                 goto fail;
             }
         }
     } else {
-        if ((fd = pa_open_cloexec(device, *mode|O_NDELAY, 0)) < 0) {
+        if ((fd = rump_sys_open(device, *mode|0x00000004|0x00400000, 0)) < 0) {
+					errno = rump_errtrans_rump2host(errno);
             pa_log("open('%s'): %s", device, pa_cstrerror(errno));
             goto fail;
         }
@@ -85,7 +91,9 @@
 
     *pcaps = 0;
 
-    if (ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps) < 0) {
+    ret = rump_sys_ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps);
+		errno = rump_errtrans_rump2host(errno);
+		if (ret < 0) {
         pa_log("SNDCTL_DSP_GETCAPS: %s", pa_cstrerror(errno));
         goto fail;
     }
@@ -148,7 +156,7 @@
 
 fail:
     if (fd >= 0)
-        pa_close(fd);
+			rump_sys_close(fd);
     return -1;
 }
 
@@ -178,9 +186,9 @@
     orig_format = ss->format;
 
     reqformat = format = format_trans[ss->format];
-    if (reqformat == AFMT_QUERY || ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != reqformat) {
+    if (reqformat == AFMT_QUERY || rump_sys_ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != reqformat) {
         format = AFMT_S16_NE;
-        if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != AFMT_S16_NE) {
+        if (rump_sys_ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != AFMT_S16_NE) {
             int f = AFMT_S16_NE == AFMT_S16_LE ? AFMT_S16_BE : AFMT_S16_LE;
             format = f;
             if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != f) {
@@ -202,7 +210,8 @@
                pa_sample_format_to_string(ss->format));
 
     channels = ss->channels;
-    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
+    if (rump_sys_ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
+			  errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_CHANNELS: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -214,7 +223,8 @@
     }
 
     speed = (int) ss->rate;
-    if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) < 0) {
+    if (rump_sys_ioctl(fd, SNDCTL_DSP_SPEED, &speed) < 0) {
+			  errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_SPEED: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -240,7 +250,8 @@
 
     pa_log_debug("Asking for %i fragments of size %i (requested %i)", nfrags, 1 << pa_ulog2(frag_size), frag_size);
 
-    if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &arg) < 0) {
+    if (rump_sys_ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &arg) < 0) {
+			  errno = rump_errtrans_rump2host(errno);
         pa_log("SNDCTL_DSP_SETFRAGMENT: %s", pa_cstrerror(errno));
         return -1;
     }
@@ -256,8 +267,10 @@
     pa_assert(ss);
     pa_assert(volume);
 
-    if (ioctl(fd, mixer, &vol) < 0)
+    if (rump_sys_ioctl(fd, mixer, &vol) < 0) {
+			  errno = rump_errtrans_rump2host(errno);
         return -1;
+		}
 
     pa_cvolume_reset(volume, ss->channels);
 
@@ -284,8 +297,10 @@
         vol |= ((r*100)/PA_VOLUME_NORM) << 8;
     }
 
-    if (ioctl(fd, mixer, &vol) < 0)
+    if (rump_sys_ioctl(fd, mixer, &vol) < 0) {
+			  errno = rump_errtrans_rump2host(errno);
         return -1;
+		}
 
     pa_log_debug("Wrote mixer settings: %s", pa_cvolume_snprint(cv, sizeof(cv), volume));
     return 0;
@@ -391,9 +406,11 @@
 static int open_mixer(const char *mixer) {
     int fd;
 
-    if ((fd = pa_open_cloexec(mixer, O_RDWR|O_NDELAY, 0)) >= 0)
+    if ((fd = rump_sys_open(mixer, O_RDWR|0x00000004|0x00400000, 0)) >= 0)
         return fd;
 
+		errno = rump_errtrans_rump2host(errno);
+
     return -1;
 }
 
Index: pulseaudio-2.0.new/src/daemon/main.c
===================================================================
--- pulseaudio-2.0.new.orig/src/daemon/main.c	2015-08-16 00:14:10.024550925 +0200
+++ pulseaudio-2.0.new/src/daemon/main.c	2015-08-16 01:54:44.803834565 +0200
@@ -221,6 +221,7 @@
         return -1;
     }
 
+#if 0
 #if defined(HAVE_SETRESGID)
     r = setresgid(gr->gr_gid, gr->gr_gid, gr->gr_gid);
 #elif defined(HAVE_SETEGID)
@@ -252,6 +253,7 @@
         pa_log(_("Failed to change UID: %s"), pa_cstrerror(errno));
         return -1;
     }
+#endif
 
     pa_set_env("USER", PA_SYSTEM_USER);
     pa_set_env("USERNAME", PA_SYSTEM_USER);
@@ -268,7 +270,7 @@
     if (!getenv("PULSE_STATE_PATH"))
         pa_set_env("PULSE_STATE_PATH", PA_SYSTEM_STATE_PATH);
 
-    pa_log_info(_("Successfully dropped root privileges."));
+//    pa_log_info(_("Successfully dropped root privileges."));
 
     return 0;
 }
Index: pulseaudio-2.0.new/src/Makefile.am
===================================================================
--- pulseaudio-2.0.new.orig/src/Makefile.am	2015-08-16 02:47:03.868560427 +0200
+++ pulseaudio-2.0.new/src/Makefile.am	2015-08-16 02:47:17.947544554 +0200
@@ -145,6 +145,8 @@
 # This is needed because automake doesn't properly expand the foreach below
 pulseaudio_DEPENDENCIES = libpulsecore-@[email protected] libpulsecommon-@[email protected] libpulse.la $(PREOPEN_LIBS)
 
+pulseaudio_LDADD += -lrump -lrumpvfs -lrumpdev -lrumpdev_audio -lrumpdev_pci -lrumpdev_audio_ac97 -lrumpdev_pci_auich -lrumpdev_pci_hdaudio -lrumpdev_hdaudio_hdafg
+
 if HAVE_DBUS
 pulseaudio_CFLAGS += $(DBUS_CFLAGS)
 pulseaudio_SOURCES += daemon/server-lookup.c daemon/server-lookup.h
@@ -1596,7 +1598,7 @@
 
 module_oss_la_SOURCES = modules/oss/module-oss.c
 module_oss_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_oss_la_LIBADD = $(MODULE_LIBADD) liboss-util.la
+module_oss_la_LIBADD = $(MODULE_LIBADD) liboss-util.la -lrump -lrumpvfs -lrumpdev -lrumpdev_audio -lrumpdev_pci -lrumpdev_audio_ac97 -lrumpdev_pci_auich -lrumpdev_pci_hdaudio -lrumpdev_hdaudio_hdafg
 
 # COREAUDIO
 

Reply via email to