1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#ifndef __COMMON_SCM_H__
#define __COMMON_SCM_H__
#include <stdint.h>
#include <stdbool.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/uio.h>
/*
* Because of kernel doing kmalloc for user data passed
* in SCM messages, and there is kernel's SCM_MAX_FD as a limit
* for descriptors passed at once we're trying to reduce
* the pressure on kernel memory manager and use predefined
* known to work well size of the message buffer.
*/
#define CR_SCM_MSG_SIZE (1024)
#define CR_SCM_MAX_FD (252)
struct scm_fdset {
struct msghdr hdr;
struct iovec iov;
char msg_buf[CR_SCM_MSG_SIZE];
};
#ifndef F_GETOWNER_UIDS
#define F_GETOWNER_UIDS 17
#endif
extern int send_fds(int sock, struct sockaddr_un *saddr, int len, int *fds, int nr_fds, void *data, unsigned ch_size);
extern int __recv_fds(int sock, int *fds, int nr_fds, void *data, unsigned ch_size, int flags);
static inline int recv_fds(int sock, int *fds, int nr_fds, void *data, unsigned ch_size)
{
return __recv_fds(sock, fds, nr_fds, data, ch_size, 0);
}
static inline int send_fd(int sock, struct sockaddr_un *saddr, int saddr_len, int fd)
{
return send_fds(sock, saddr, saddr_len, &fd, 1, NULL, 0);
}
static inline int recv_fd(int sock)
{
int fd, ret;
ret = recv_fds(sock, &fd, 1, NULL, 0);
if (ret)
return -1;
return fd;
}
#endif
|