diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-05-20 01:13:43 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-05-20 01:13:43 +0200 |
commit | 7c394faa38de389638e19b19212ed50aca870e3c (patch) | |
tree | 475a9da2fa7d10160705ed9a83bc419a75718b90 /src/logger.c | |
parent | ff876e283a61320b718ec752d93b1fd40a5fdd0c (diff) |
sd-daemon: add API to verify socket types
Diffstat (limited to 'src/logger.c')
-rw-r--r-- | src/logger.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/logger.c b/src/logger.c index e7c2be01e0..c486a8acd1 100644 --- a/src/logger.c +++ b/src/logger.c @@ -424,11 +424,25 @@ static int server_init(Server *s, unsigned n_sockets) { for (i = 0; i < n_sockets; i++) { struct epoll_event ev; + int fd; + + fd = SD_LISTEN_FDS_START+i; + + if ((r = sd_is_socket(fd, SOCK_STREAM, 1)) < 0) { + log_error("Failed to determine file descriptor type: %s", strerror(-r)); + goto fail; + } + + if (!r) { + log_error("Wrong file descriptor type."); + r = -EINVAL; + goto fail; + } zero(ev); ev.events = EPOLLIN; - ev.data.ptr = UINT_TO_PTR(SD_LISTEN_FDS_START+i); - if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, SD_LISTEN_FDS_START+i, &ev) < 0) { + ev.data.ptr = UINT_TO_PTR(fd); + if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) { r = -errno; log_error("Failed to add server fd to epoll object: %s", strerror(errno)); goto fail; |