mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-15 12:45:09 +02:00
Simplify systemd notify socket handling
This commit is contained in:
parent
4518f1d2c7
commit
2c32259d53
2 changed files with 10 additions and 21 deletions
29
src/fastd.c
29
src/fastd.c
|
@ -420,11 +420,15 @@ static int daemonize(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_SYSTEMD
|
|
||||||
/** Sends a readiness notification on a notify socket */
|
/** Sends a readiness notification on a notify socket */
|
||||||
static void notify_systemd(const char *notify_socket) {
|
static inline void notify_systemd(void) {
|
||||||
|
#ifdef ENABLE_SYSTEMD
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_un sa = {};
|
struct sockaddr_un sa = {};
|
||||||
|
const char *notify_socket = getenv("NOTIFY_SOCKET");
|
||||||
|
|
||||||
|
if (!notify_socket)
|
||||||
|
return;
|
||||||
|
|
||||||
if ((notify_socket[0] != '@' && notify_socket[0] != '/') || notify_socket[1] == 0)
|
if ((notify_socket[0] != '@' && notify_socket[0] != '/') || notify_socket[1] == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -449,9 +453,8 @@ static void notify_systemd(const char *notify_socket) {
|
||||||
pr_debug("sent startup notification to systemd");
|
pr_debug("sent startup notification to systemd");
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/** Early initialization before reading the config */
|
/** Early initialization before reading the config */
|
||||||
static inline void init_early(void) {
|
static inline void init_early(void) {
|
||||||
|
@ -519,17 +522,6 @@ static inline void init_config(int *status_fd) {
|
||||||
static inline void init(int argc, char *argv[]) {
|
static inline void init(int argc, char *argv[]) {
|
||||||
int status_fd = -1;
|
int status_fd = -1;
|
||||||
|
|
||||||
#ifdef ENABLE_SYSTEMD
|
|
||||||
char *notify_socket = getenv("NOTIFY_SOCKET");
|
|
||||||
|
|
||||||
if (notify_socket) {
|
|
||||||
notify_socket = strdup(notify_socket);
|
|
||||||
|
|
||||||
/* unset the socket to allow calling on_pre_up safely */
|
|
||||||
unsetenv("NOTIFY_SOCKET");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
init_early();
|
init_early();
|
||||||
fastd_configure(argc, argv);
|
fastd_configure(argc, argv);
|
||||||
init_config(&status_fd);
|
init_config(&status_fd);
|
||||||
|
@ -568,12 +560,7 @@ static inline void init(int argc, char *argv[]) {
|
||||||
|
|
||||||
fastd_peer_hashtable_init();
|
fastd_peer_hashtable_init();
|
||||||
|
|
||||||
#ifdef ENABLE_SYSTEMD
|
notify_systemd();
|
||||||
if (notify_socket) {
|
|
||||||
notify_systemd(notify_socket);
|
|
||||||
free(notify_socket);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (status_fd >= 0) {
|
if (status_fd >= 0) {
|
||||||
static const uint8_t STATUS = 0;
|
static const uint8_t STATUS = 0;
|
||||||
|
|
|
@ -81,6 +81,8 @@ void fastd_shell_env_free(fastd_shell_env_t *env) {
|
||||||
static void shell_command_setenv(pid_t pid, const fastd_shell_env_t *env) {
|
static void shell_command_setenv(pid_t pid, const fastd_shell_env_t *env) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
|
|
||||||
|
unsetenv("NOTIFY_SOCKET");
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%u", (unsigned)pid);
|
snprintf(buf, sizeof(buf), "%u", (unsigned)pid);
|
||||||
setenv("FASTD_PID", buf, 1);
|
setenv("FASTD_PID", buf, 1);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue