iochannel/pstream: Support sending file descriptors

This patch adds support to iochannel, pstream and pstream-util
to send file descriptors over a unix pipe.

Currently we don't support writing both creds and fds in the same
packet, it's either one or the other (or neither).

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This commit is contained in:
David Henningsson 2014-04-15 16:12:25 +02:00
parent 06bc22b220
commit cb484805c1
6 changed files with 102 additions and 22 deletions

View file

@ -28,7 +28,7 @@
#include "pstream-util.h"
void pa_pstream_send_tagstruct_with_creds(pa_pstream *p, pa_tagstruct *t, const pa_creds *creds) {
static void pa_pstream_send_tagstruct_with_ancil(pa_pstream *p, pa_tagstruct *t, const pa_ancil *ancil) {
size_t length;
uint8_t *data;
pa_packet *packet;
@ -38,10 +38,37 @@ void pa_pstream_send_tagstruct_with_creds(pa_pstream *p, pa_tagstruct *t, const
pa_assert_se(data = pa_tagstruct_free_data(t, &length));
pa_assert_se(packet = pa_packet_new_dynamic(data, length));
pa_pstream_send_packet(p, packet, creds);
pa_pstream_send_packet(p, packet, ancil);
pa_packet_unref(packet);
}
void pa_pstream_send_tagstruct_with_creds(pa_pstream *p, pa_tagstruct *t, const pa_creds *creds) {
if (creds) {
pa_ancil a;
a.nfd = 0;
a.creds_valid = true;
a.creds = *creds;
pa_pstream_send_tagstruct_with_ancil(p, t, &a);
}
else
pa_pstream_send_tagstruct_with_ancil(p, t, NULL);
}
void pa_pstream_send_tagstruct_with_fds(pa_pstream *p, pa_tagstruct *t, int nfd, const int *fds) {
if (nfd > 0) {
pa_ancil a;
a.nfd = nfd;
a.creds_valid = false;
pa_assert(nfd <= MAX_ANCIL_FDS);
memcpy(a.fds, fds, sizeof(int) * nfd);
pa_pstream_send_tagstruct_with_ancil(p, t, &a);
}
else
pa_pstream_send_tagstruct_with_ancil(p, t, NULL);
}
void pa_pstream_send_error(pa_pstream *p, uint32_t tag, uint32_t error) {
pa_tagstruct *t;