diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/socket.c | 21 | ||||
-rw-r--r-- | src/utils.c | 18 | ||||
-rw-r--r-- | src/utils.h | 2 |
3 files changed, 33 insertions, 8 deletions
diff --git a/src/socket.c b/src/socket.c index 917ade1..644d49f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -11,6 +11,7 @@ #include "utils.h" static int socket_setopts(int sockfd); +static inline void socket_freeaddr(struct addrinfo **results); static int socket_setopts(int sockfd) @@ -31,6 +32,14 @@ static int socket_setopts(int sockfd) return 0; } +static inline void socket_freeaddr(struct addrinfo **results) +{ + if (*results) { + freeaddrinfo(*results); + *results = NULL; + } +} + int socket_nonblock(const psocket *psock) { return set_fd_nonblock(psock->fd); @@ -50,10 +59,8 @@ int socket_init_in(const char *addr, hints.ai_flags = AI_PASSIVE; /* all interfaces */ s = getaddrinfo(addr, port, &hints, results); - if (s) { - freeaddrinfo(*results); - *results = NULL; - } + if (s) + socket_freeaddr(results); return s; } @@ -92,8 +99,7 @@ int socket_bind_in(psocket *psock, struct addrinfo **results) s = socket_nonblock(psock); finalise: - freeaddrinfo(*results); - *results = NULL; + socket_freeaddr(results); return s; } @@ -160,8 +166,7 @@ int socket_connect_in(psocket *psock, struct addrinfo **results) s = socket_nonblock(psock); finalise: - freeaddrinfo(*results); - *results = NULL; + socket_freeaddr(results); return s; } diff --git a/src/utils.c b/src/utils.c index bcca9c3..69fcb0e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -386,3 +386,21 @@ int create_device_files(const char *mount_path) return s; } + +int update_uid_map(pid_t pid, unsigned int uid_map[3]) +{ + int s; + const char *const path_pid = "/proc/%d/uid_map"; + const char *const path_self = "/proc/self/uid_map"; + char path[32]; + + if (pid < 0) { + s = snprintf(path, sizeof path, "%s", path_self); + } else { + s = snprintf(path, sizeof path, path_pid, pid); + } + if (s <= 0) + return 1; + + return 0; +} diff --git a/src/utils.h b/src/utils.h index 3b075e5..825f621 100644 --- a/src/utils.h +++ b/src/utils.h @@ -41,4 +41,6 @@ int create_device_file_checked(const char *mount_path, const char *device_file, int create_device_files(const char *mount_path); +int update_uid_map(pid_t pid, unsigned int uid_map[3]); + #endif |