~ubuntu-branches/ubuntu/jaunty/pulseaudio/jaunty-updates

« back to all changes in this revision

Viewing changes to src/pulsecore/iochannel.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2007-12-04 00:56:08 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20071204005608-3lzrrrpxi186kgx4
Tags: upstream-0.9.8
ImportĀ upstreamĀ versionĀ 0.9.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: iochannel.c 1971 2007-10-28 19:13:50Z lennart $ */
 
1
/* $Id: iochannel.c 2022 2007-11-04 16:51:26Z lennart $ */
2
2
 
3
3
/***
4
4
  This file is part of PulseAudio.
267
267
    ssize_t r;
268
268
    struct msghdr mh;
269
269
    struct iovec iov;
270
 
    uint8_t cmsg_data[CMSG_SPACE(sizeof(struct ucred))];
 
270
    union {
 
271
        struct cmsghdr hdr;
 
272
        uint8_t data[CMSG_SPACE(sizeof(struct ucred))];
 
273
    } cmsg;
271
274
    struct ucred *u;
272
 
    struct cmsghdr *cmsg;
273
275
 
274
276
    pa_assert(io);
275
277
    pa_assert(data);
280
282
    iov.iov_base = (void*) data;
281
283
    iov.iov_len = l;
282
284
 
283
 
    memset(cmsg_data, 0, sizeof(cmsg_data));
284
 
    cmsg = (struct cmsghdr*)  cmsg_data;
285
 
    cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
286
 
    cmsg->cmsg_level = SOL_SOCKET;
287
 
    cmsg->cmsg_type = SCM_CREDENTIALS;
 
285
    memset(&cmsg, 0, sizeof(cmsg));
 
286
    cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct ucred));
 
287
    cmsg.hdr.cmsg_level = SOL_SOCKET;
 
288
    cmsg.hdr.cmsg_type = SCM_CREDENTIALS;
288
289
 
289
 
    u = (struct ucred*) CMSG_DATA(cmsg);
 
290
    u = (struct ucred*) CMSG_DATA(&cmsg.hdr);
290
291
 
291
292
    u->pid = getpid();
292
293
    if (ucred) {
302
303
    mh.msg_namelen = 0;
303
304
    mh.msg_iov = &iov;
304
305
    mh.msg_iovlen = 1;
305
 
    mh.msg_control = cmsg_data;
306
 
    mh.msg_controllen = sizeof(cmsg_data);
 
306
    mh.msg_control = &cmsg;
 
307
    mh.msg_controllen = sizeof(cmsg);
307
308
    mh.msg_flags = 0;
308
309
 
309
310
    if ((r = sendmsg(io->ofd, &mh, MSG_NOSIGNAL)) >= 0) {
318
319
    ssize_t r;
319
320
    struct msghdr mh;
320
321
    struct iovec iov;
321
 
    uint8_t cmsg_data[CMSG_SPACE(sizeof(struct ucred))];
 
322
    union {
 
323
        struct cmsghdr hdr;
 
324
        uint8_t data[CMSG_SPACE(sizeof(struct ucred))];
 
325
    } cmsg;
322
326
 
323
327
    pa_assert(io);
324
328
    pa_assert(data);
331
335
    iov.iov_base = data;
332
336
    iov.iov_len = l;
333
337
 
334
 
    memset(cmsg_data, 0, sizeof(cmsg_data));
 
338
    memset(&cmsg, 0, sizeof(cmsg));
335
339
 
336
340
    memset(&mh, 0, sizeof(mh));
337
341
    mh.msg_name = NULL;
338
342
    mh.msg_namelen = 0;
339
343
    mh.msg_iov = &iov;
340
344
    mh.msg_iovlen = 1;
341
 
    mh.msg_control = cmsg_data;
342
 
    mh.msg_controllen = sizeof(cmsg_data);
 
345
    mh.msg_control = &cmsg;
 
346
    mh.msg_controllen = sizeof(cmsg);
343
347
    mh.msg_flags = 0;
344
348
 
345
349
    if ((r = recvmsg(io->ifd, &mh, 0)) >= 0) {
346
 
        struct cmsghdr *cmsg;
 
350
        struct cmsghdr *cmh;
347
351
 
348
352
        *creds_valid = 0;
349
353
 
350
 
        for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
 
354
        for (cmh = CMSG_FIRSTHDR(&mh); cmh; cmh = CMSG_NXTHDR(&mh, cmh)) {
351
355
 
352
 
            if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) {
 
356
            if (cmh->cmsg_level == SOL_SOCKET && cmh->cmsg_type == SCM_CREDENTIALS) {
353
357
                struct ucred u;
354
 
                pa_assert(cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred)));
355
 
                memcpy(&u, CMSG_DATA(cmsg), sizeof(struct ucred));
 
358
                pa_assert(cmh->cmsg_len == CMSG_LEN(sizeof(struct ucred)));
 
359
                memcpy(&u, CMSG_DATA(cmh), sizeof(struct ucred));
356
360
 
357
361
                creds->gid = u.gid;
358
362
                creds->uid = u.uid;