diff options
author | David Oberhollenzer <goliath@infraroot.at> | 2019-03-28 16:33:01 +0100 |
---|---|---|
committer | David Oberhollenzer <goliath@infraroot.at> | 2019-03-29 21:00:53 +0100 |
commit | 7cfe6e845878d67f578fa846e784c064a178d9c5 (patch) | |
tree | 660c8e3a3ff987762f69ff7198457f75b7fdc6bf /lib/init/init_socket_send_status.c | |
parent | f844c4e2c22ea212bf8c0538443878f7586688be (diff) |
cleanup: move init specific stuff of init socket to initd
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'lib/init/init_socket_send_status.c')
-rw-r--r-- | lib/init/init_socket_send_status.c | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/lib/init/init_socket_send_status.c b/lib/init/init_socket_send_status.c deleted file mode 100644 index 8cd5d8a..0000000 --- a/lib/init/init_socket_send_status.c +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: ISC */ -#include <sys/types.h> -#include <sys/socket.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#include "initsock.h" - - -static int send_retry(int fd, const void *dst, size_t addrlen, - const void *buffer, size_t size) -{ - ssize_t ret; -retry: - ret = sendto(fd, buffer, size, MSG_NOSIGNAL, dst, addrlen); - if (ret < 0 && errno == EINTR) - goto retry; - - if (ret < 0 || (size_t)ret < size) - return -1; - - return 0; -} - -static int send_string(int fd, const void *dst, size_t addrlen, - const char *str) -{ - size_t len = strlen(str); - uint8_t raw_len[2]; - - raw_len[0] = (len >> 8) & 0xFF; - raw_len[1] = len & 0xFF; - - if (send_retry(fd, dst, addrlen, raw_len, 2)) - return -1; - - return len > 0 ? send_retry(fd, dst, addrlen, str, len) : 0; -} - -int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen, - E_SERVICE_STATE state, service_t *svc) -{ - uint8_t info[8]; - - if (svc == NULL || state == ESS_NONE) { - info[0] = ESS_NONE; - info[1] = 0; - info[2] = info[3] = 0; - info[4] = info[5] = info[6] = info[7] = 0xFF; - } else { - info[0] = state; - info[1] = svc->status & 0xFF; - info[2] = info[3] = 0; - info[4] = (svc->id >> 24) & 0xFF; - info[5] = (svc->id >> 16) & 0xFF; - info[6] = (svc->id >> 8) & 0xFF; - info[7] = svc->id & 0xFF; - } - - if (send_retry(fd, dest_addr, addrlen, info, sizeof(info))) - return -1; - - if (svc != NULL && state != ESS_NONE) { - if (send_string(fd, dest_addr, addrlen, svc->fname)) - return -1; - if (send_string(fd, dest_addr, addrlen, svc->name)) - return -1; - } - return 0; -} |