2016-11-02 03:38:28 +03:00
|
|
|
#ifndef __COMMON_SCM_H__
|
|
|
|
#define __COMMON_SCM_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2016-11-14 23:01:17 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/un.h>
|
2016-11-02 03:38:28 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 pressue 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
|
|
|
|
|
2016-11-14 23:01:17 +03:00
|
|
|
extern int send_fds(int sock, struct sockaddr_un *saddr, int len,
|
2016-11-22 20:03:00 +03:00
|
|
|
int *fds, int nr_fds, void *data, unsigned ch_size);
|
2017-01-25 12:46:28 +03:00
|
|
|
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);
|
|
|
|
}
|
2016-11-14 23:01:17 +03:00
|
|
|
|
2016-11-15 12:42:00 +03:00
|
|
|
static inline int send_fd(int sock, struct sockaddr_un *saddr, int saddr_len, int fd)
|
|
|
|
{
|
2016-11-22 20:03:00 +03:00
|
|
|
return send_fds(sock, saddr, saddr_len, &fd, 1, NULL, 0);
|
2016-11-15 12:42:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int recv_fd(int sock)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
|
2016-11-22 20:03:00 +03:00
|
|
|
ret = recv_fds(sock, &fd, 1, NULL, 0);
|
2016-11-15 12:42:00 +03:00
|
|
|
if (ret)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2016-11-02 03:38:28 +03:00
|
|
|
#endif
|