mirror of
https://github.com/pygos/init.git
synced 2024-11-22 11:19:45 +01:00
cleanup: move init specific stuff of init socket to initd
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
f844c4e2c2
commit
7cfe6e8458
6 changed files with 37 additions and 52 deletions
|
@ -1,5 +1,5 @@
|
||||||
init_SOURCES = initd/main.c initd/init.h initd/signal_linux.c initd/runsvc.c
|
init_SOURCES = initd/main.c initd/init.h initd/signal_linux.c initd/runsvc.c
|
||||||
init_SOURCES += initd/status.c initd/supervisor.c
|
init_SOURCES += initd/status.c initd/supervisor.c initd/initsock.c
|
||||||
init_CPPFLAGS = $(AM_CPPFLAGS)
|
init_CPPFLAGS = $(AM_CPPFLAGS)
|
||||||
init_CFLAGS = $(AM_CFLAGS)
|
init_CFLAGS = $(AM_CFLAGS)
|
||||||
init_LDFLAGS = $(AM_LDFLAGS)
|
init_LDFLAGS = $(AM_LDFLAGS)
|
||||||
|
|
|
@ -100,4 +100,11 @@ int sigsetup(void);
|
||||||
*/
|
*/
|
||||||
void sigreset(void);
|
void sigreset(void);
|
||||||
|
|
||||||
|
/********** initsock.c **********/
|
||||||
|
|
||||||
|
int init_socket_create(void);
|
||||||
|
|
||||||
|
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
|
||||||
|
E_SERVICE_STATE state, service_t *svc);
|
||||||
|
|
||||||
#endif /* INIT_H */
|
#endif /* INIT_H */
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
/* SPDX-License-Identifier: ISC */
|
/* SPDX-License-Identifier: ISC */
|
||||||
#include <sys/types.h>
|
#include "init.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,
|
static int send_retry(int fd, const void *dst, size_t addrlen,
|
||||||
const void *buffer, size_t size)
|
const void *buffer, size_t size)
|
||||||
|
@ -39,6 +31,33 @@ static int send_string(int fd, const void *dst, size_t addrlen,
|
||||||
return len > 0 ? send_retry(fd, dst, addrlen, str, len) : 0;
|
return len > 0 ? send_retry(fd, dst, addrlen, str, len) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int init_socket_create(void)
|
||||||
|
{
|
||||||
|
struct sockaddr_un un;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror("socket");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&un, 0, sizeof(un));
|
||||||
|
un.sun_family = AF_UNIX;
|
||||||
|
|
||||||
|
strcpy(un.sun_path, INIT_SOCK_PATH);
|
||||||
|
unlink(INIT_SOCK_PATH);
|
||||||
|
|
||||||
|
if (bind(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||||||
|
perror("bind: " INIT_SOCK_PATH);
|
||||||
|
close(fd);
|
||||||
|
unlink(INIT_SOCK_PATH);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
|
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
|
||||||
E_SERVICE_STATE state, service_t *svc)
|
E_SERVICE_STATE state, service_t *svc)
|
||||||
{
|
{
|
|
@ -1,9 +1,8 @@
|
||||||
libinit_a_SOURCES = lib/init/delsvc.c lib/init/svcmap.c lib/init/rdsvc.c
|
libinit_a_SOURCES = lib/init/delsvc.c lib/init/svcmap.c lib/init/rdsvc.c
|
||||||
libinit_a_SOURCES += lib/init/svcscan.c lib/init/del_svc_list.c
|
libinit_a_SOURCES += lib/init/svcscan.c lib/init/del_svc_list.c
|
||||||
libinit_a_SOURCES += lib/init/svc_tsort.c lib/include/service.h
|
libinit_a_SOURCES += lib/init/svc_tsort.c lib/include/service.h
|
||||||
libinit_a_SOURCES += lib/init/init_socket_open.c lib/init/init_socket_create.c
|
libinit_a_SOURCES += lib/init/init_socket_open.c
|
||||||
libinit_a_SOURCES += lib/include/initsock.h lib/init/init_socket_send_request.c
|
libinit_a_SOURCES += lib/include/initsock.h lib/init/init_socket_send_request.c
|
||||||
libinit_a_SOURCES += lib/init/init_socket_send_status.c
|
|
||||||
libinit_a_SOURCES += lib/init/init_socket_recv_status.c
|
libinit_a_SOURCES += lib/init/init_socket_recv_status.c
|
||||||
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
|
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||||
libinit_a_CFLAGS = $(AM_CFLAGS)
|
libinit_a_CFLAGS = $(AM_CFLAGS)
|
||||||
|
|
|
@ -47,15 +47,10 @@ typedef struct {
|
||||||
char *service_name;
|
char *service_name;
|
||||||
} init_status_response_t;
|
} init_status_response_t;
|
||||||
|
|
||||||
int init_socket_create(void);
|
|
||||||
|
|
||||||
int init_socket_open(const char *tmppath);
|
int init_socket_open(const char *tmppath);
|
||||||
|
|
||||||
int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...);
|
int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...);
|
||||||
|
|
||||||
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
|
|
||||||
E_SERVICE_STATE state, service_t *svc);
|
|
||||||
|
|
||||||
int init_socket_recv_status(int fd, init_status_response_t *resp);
|
int init_socket_recv_status(int fd, init_status_response_t *resp);
|
||||||
|
|
||||||
#endif /* INITSOCK_H */
|
#endif /* INITSOCK_H */
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
/* SPDX-License-Identifier: ISC */
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "initsock.h"
|
|
||||||
|
|
||||||
int init_socket_create(void)
|
|
||||||
{
|
|
||||||
struct sockaddr_un un;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
|
||||||
if (fd < 0) {
|
|
||||||
perror("socket");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&un, 0, sizeof(un));
|
|
||||||
un.sun_family = AF_UNIX;
|
|
||||||
|
|
||||||
strcpy(un.sun_path, INIT_SOCK_PATH);
|
|
||||||
unlink(INIT_SOCK_PATH);
|
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr *)&un, sizeof(un))) {
|
|
||||||
perror("bind: " INIT_SOCK_PATH);
|
|
||||||
close(fd);
|
|
||||||
unlink(INIT_SOCK_PATH);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
|
Loading…
Reference in a new issue