diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2017-07-24 23:36:51 +0200 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2017-07-24 23:40:24 +0200 |
commit | 52535beec1fe85682094b625d3f2e19520a803a8 (patch) | |
tree | e215bcb0d93b34cdf2d9c51fb79a83e02b03c941 /lib/imsg.c | |
parent | *: fix git-reindent-branch.py reversing order (diff) | |
download | frr-52535beec1fe85682094b625d3f2e19520a803a8.tar.xz frr-52535beec1fe85682094b625d3f2e19520a803a8.zip |
lib: revert reindent of files imported from OpenBSD
We should preserve the original indentation to make it easier to keep
these files in sync with the upstream.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/imsg.c')
-rw-r--r-- | lib/imsg.c | 117 |
1 files changed, 64 insertions, 53 deletions
diff --git a/lib/imsg.c b/lib/imsg.c index 10650f648..fc62c1373 100644 --- a/lib/imsg.c +++ b/lib/imsg.c @@ -21,21 +21,22 @@ #include "openbsd-queue.h" #include "imsg.h" -int imsg_fd_overhead = 0; +int imsg_fd_overhead = 0; -int imsg_get_fd(struct imsgbuf *); +int imsg_get_fd(struct imsgbuf *); #ifndef __OpenBSD__ /* * The original code calls getdtablecount() which is OpenBSD specific. Use * available_fds() from OpenSMTPD instead. */ -static int available_fds(unsigned int n) +static int +available_fds(unsigned int n) { - unsigned int i; - int ret, fds[256]; + unsigned int i; + int ret, fds[256]; - if (n > (sizeof(fds) / sizeof(fds[0]))) + if (n > (sizeof(fds)/sizeof(fds[0]))) return (1); ret = 0; @@ -58,7 +59,8 @@ static int available_fds(unsigned int n) } #endif -void imsg_init(struct imsgbuf *ibuf, int fd) +void +imsg_init(struct imsgbuf *ibuf, int fd) { msgbuf_init(&ibuf->w); memset(&ibuf->r, 0, sizeof(ibuf->r)); @@ -68,18 +70,19 @@ void imsg_init(struct imsgbuf *ibuf, int fd) TAILQ_INIT(&ibuf->fds); } -ssize_t imsg_read(struct imsgbuf *ibuf) +ssize_t +imsg_read(struct imsgbuf *ibuf) { - struct msghdr msg; - struct cmsghdr *cmsg; + struct msghdr msg; + struct cmsghdr *cmsg; union { struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int) * 1)]; + char buf[CMSG_SPACE(sizeof(int) * 1)]; } cmsgbuf; - struct iovec iov; - ssize_t n = -1; - int fd; - struct imsg_fd *ifd; + struct iovec iov; + ssize_t n = -1; + int fd; + struct imsg_fd *ifd; memset(&msg, 0, sizeof(msg)); memset(&cmsgbuf, 0, sizeof(cmsgbuf)); @@ -96,14 +99,12 @@ ssize_t imsg_read(struct imsgbuf *ibuf) again: #ifdef __OpenBSD__ - if (getdtablecount() + imsg_fd_overhead - + (int)((CMSG_SPACE(sizeof(int)) - CMSG_SPACE(0)) - / sizeof(int)) + if (getdtablecount() + imsg_fd_overhead + + (int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int)) >= getdtablesize()) { #else - if (available_fds(imsg_fd_overhead - + (CMSG_SPACE(sizeof(int)) - CMSG_SPACE(0)) - / sizeof(int))) { + if (available_fds(imsg_fd_overhead + + (CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))) { #endif errno = EAGAIN; free(ifd); @@ -119,9 +120,9 @@ again: ibuf->r.wpos += n; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET - && cmsg->cmsg_type == SCM_RIGHTS) { + cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_RIGHTS) { int i; int j; @@ -130,15 +131,14 @@ again: * padding rules, our control buffer might contain * more than one fd, and we must close them. */ - j = ((char *)cmsg + cmsg->cmsg_len - - (char *)CMSG_DATA(cmsg)) - / sizeof(int); + j = ((char *)cmsg + cmsg->cmsg_len - + (char *)CMSG_DATA(cmsg)) / sizeof(int); for (i = 0; i < j; i++) { fd = ((int *)CMSG_DATA(cmsg))[i]; if (ifd != NULL) { ifd->fd = fd; TAILQ_INSERT_TAIL(&ibuf->fds, ifd, - entry); + entry); ifd = NULL; } else close(fd); @@ -152,9 +152,10 @@ fail: return (n); } -ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) +ssize_t +imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) { - size_t av, left, datalen; + size_t av, left, datalen; av = ibuf->r.wpos; @@ -162,7 +163,8 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) return (0); memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr)); - if (imsg->hdr.len < IMSG_HEADER_SIZE || imsg->hdr.len > MAX_IMSGSIZE) { + if (imsg->hdr.len < IMSG_HEADER_SIZE || + imsg->hdr.len > MAX_IMSGSIZE) { errno = ERANGE; return (-1); } @@ -181,7 +183,7 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) imsg->fd = -1; if (imsg->data) - memcpy(imsg->data, ibuf->r.rptr, datalen); + memcpy(imsg->data, ibuf->r.rptr, datalen); if (imsg->hdr.len < av) { left = av - imsg->hdr.len; @@ -193,10 +195,11 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) return (datalen + IMSG_HEADER_SIZE); } -int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, int fd, const void *data, u_int16_t datalen) +int +imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, + pid_t pid, int fd, const void *data, u_int16_t datalen) { - struct ibuf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -211,11 +214,12 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, return (1); } -int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, int fd, const struct iovec *iov, int iovcnt) +int +imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, + pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct ibuf *wbuf; - int i, datalen = 0; + struct ibuf *wbuf; + int i, datalen = 0; for (i = 0; i < iovcnt; i++) datalen += iov[i].iov_len; @@ -235,11 +239,12 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, u_int16_t datalen) +struct ibuf * +imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, + pid_t pid, u_int16_t datalen) { - struct ibuf *wbuf; - struct imsg_hdr hdr; + struct ibuf *wbuf; + struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; if (datalen > MAX_IMSGSIZE) { @@ -261,7 +266,8 @@ struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, return (wbuf); } -int imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) +int +imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) { if (datalen) if (ibuf_add(msg, data, datalen) == -1) { @@ -271,9 +277,10 @@ int imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) return (datalen); } -void imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) +void +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { - struct imsg_hdr *hdr; + struct imsg_hdr *hdr; hdr = (struct imsg_hdr *)msg->buf; @@ -286,15 +293,17 @@ void imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) ibuf_close(&ibuf->w, msg); } -void imsg_free(struct imsg *imsg) +void +imsg_free(struct imsg *imsg) { free(imsg->data); } -int imsg_get_fd(struct imsgbuf *ibuf) +int +imsg_get_fd(struct imsgbuf *ibuf) { - int fd; - struct imsg_fd *ifd; + int fd; + struct imsg_fd *ifd; if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL) return (-1); @@ -306,7 +315,8 @@ int imsg_get_fd(struct imsgbuf *ibuf) return (fd); } -int imsg_flush(struct imsgbuf *ibuf) +int +imsg_flush(struct imsgbuf *ibuf) { while (ibuf->w.queued) if (msgbuf_write(&ibuf->w) <= 0) @@ -314,9 +324,10 @@ int imsg_flush(struct imsgbuf *ibuf) return (0); } -void imsg_clear(struct imsgbuf *ibuf) +void +imsg_clear(struct imsgbuf *ibuf) { - int fd; + int fd; msgbuf_clear(&ibuf->w); while ((fd = imsg_get_fd(ibuf)) != -1) |