0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 18:08:45 +00:00

Flock: shutdown command sends a reply

This commit is contained in:
Maria Matejka 2024-09-10 12:04:44 +02:00
parent cafd775a41
commit 2fcffc544e
3 changed files with 20 additions and 6 deletions

View File

@ -1,4 +1,5 @@
#include "lib/birdlib.h" #include "lib/birdlib.h"
#include "lib/cbor.h"
#include "lib/string.h" #include "lib/string.h"
#include "lib/io-loop.h" #include "lib/io-loop.h"
@ -19,6 +20,7 @@
struct cbor_parser_context { struct cbor_parser_context {
linpool *lp; linpool *lp;
sock *sock;
PACKED enum { PACKED enum {
CPE_TYPE = 0, CPE_TYPE = 0,
@ -58,12 +60,13 @@ struct cbor_parser_context {
} while (0) } while (0)
struct cbor_parser_context * struct cbor_parser_context *
hcs_parser_init(pool *p) hcs_parser_init(sock *s)
{ {
linpool *lp = lp_new(p); linpool *lp = lp_new(s->pool);
struct cbor_parser_context *ctx = lp_allocz(lp, sizeof *ctx); struct cbor_parser_context *ctx = lp_allocz(lp, sizeof *ctx);
ctx->lp = lp; ctx->lp = lp;
ctx->sock = s;
ctx->type = 0xff; ctx->type = 0xff;
ctx->stack_countdown[0] = 1; ctx->stack_countdown[0] = 1;
@ -167,6 +170,14 @@ hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size)
log(L_INFO "Requested shutdown via CLI"); log(L_INFO "Requested shutdown via CLI");
ev_send_loop(&main_birdloop, &poweroff_event); ev_send_loop(&main_birdloop, &poweroff_event);
{
struct cbor_writer *cw = cbor_init(ctx->sock->tbuf, ctx->sock->tbsize, ctx->lp);
cbor_open_block_with_length(cw, 1);
cbor_add_int(cw, -1);
cbor_add_string(cw, "OK");
sk_send(ctx->sock, cw->pt);
}
ctx->major_state = 1; ctx->major_state = 1;
break; break;
@ -175,6 +186,7 @@ hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size)
CBOR_PARSER_ERROR("Expected null, got %u-%u", ctx->type, ctx->value); CBOR_PARSER_ERROR("Expected null, got %u-%u", ctx->type, ctx->value);
log(L_INFO "Requested telnet open"); log(L_INFO "Requested telnet open");
ctx->major_state = 1; ctx->major_state = 1;
break; break;

View File

@ -6,6 +6,7 @@
#include "lib/event.h" #include "lib/event.h"
#include "lib/obstacle.h" #include "lib/obstacle.h"
#include "lib/resource.h" #include "lib/resource.h"
#include "lib/socket.h"
void hypervisor_exposed_fork(void); void hypervisor_exposed_fork(void);
void hypervisor_control_socket(void); void hypervisor_control_socket(void);
@ -18,7 +19,7 @@ struct flock_config {
extern struct flock_config flock_config; extern struct flock_config flock_config;
struct cbor_parser_context *hcs_parser_init(pool *p); struct cbor_parser_context *hcs_parser_init(sock *s);
s64 hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size); s64 hcs_parse(struct cbor_parser_context *ctx, const byte *buf, s64 size);
void hcs_parser_cleanup(struct cbor_parser_context *ctx); void hcs_parser_cleanup(struct cbor_parser_context *ctx);
const char *hcs_error(struct cbor_parser_context *ctx); const char *hcs_error(struct cbor_parser_context *ctx);

View File

@ -39,7 +39,7 @@ hcs_rx(sock *s, uint size)
/* TODO do something more */ /* TODO do something more */
hcs_parser_cleanup(s->data); hcs_parser_cleanup(s->data);
s->data = hcs_parser_init(s->pool); s->data = hcs_parser_init(s);
if (sz == size) if (sz == size)
return 1; return 1;
@ -63,7 +63,7 @@ hcs_connect(sock *s, uint size UNUSED)
s->rx_hook = hcs_rx; s->rx_hook = hcs_rx;
s->err_hook = hcs_err; s->err_hook = hcs_err;
s->data = hcs_parser_init(s->pool); s->data = hcs_parser_init(s);
return 1; return 1;
} }
@ -103,6 +103,7 @@ hypervisor_control_socket(void)
s->rx_hook = hcs_connect; s->rx_hook = hcs_connect;
s->err_hook = hcs_connect_err; s->err_hook = hcs_connect_err;
s->rbsize = 1024; s->rbsize = 1024;
s->tbsize = 1024;
unlink(flock_config.control_socket_path); unlink(flock_config.control_socket_path);
if (sk_open_unix(s, loop, flock_config.control_socket_path) < 0) if (sk_open_unix(s, loop, flock_config.control_socket_path) < 0)