0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-09-19 20:05:21 +00:00

Flock: shutdown command sends a reply

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

View File

@ -1,4 +1,5 @@
#include "lib/birdlib.h"
#include "lib/cbor.h"
#include "lib/string.h"
#include "lib/io-loop.h"
@ -19,6 +20,7 @@
struct cbor_parser_context {
linpool *lp;
sock *sock;
PACKED enum {
CPE_TYPE = 0,
@ -58,12 +60,13 @@ struct cbor_parser_context {
} while (0)
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);
ctx->lp = lp;
ctx->sock = s;
ctx->type = 0xff;
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");
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;
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);
log(L_INFO "Requested telnet open");
ctx->major_state = 1;
break;

View File

@ -6,6 +6,7 @@
#include "lib/event.h"
#include "lib/obstacle.h"
#include "lib/resource.h"
#include "lib/socket.h"
void hypervisor_exposed_fork(void);
void hypervisor_control_socket(void);
@ -18,7 +19,7 @@ struct 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);
void hcs_parser_cleanup(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 */
hcs_parser_cleanup(s->data);
s->data = hcs_parser_init(s->pool);
s->data = hcs_parser_init(s);
if (sz == size)
return 1;
@ -63,7 +63,7 @@ hcs_connect(sock *s, uint size UNUSED)
s->rx_hook = hcs_rx;
s->err_hook = hcs_err;
s->data = hcs_parser_init(s->pool);
s->data = hcs_parser_init(s);
return 1;
}
@ -103,6 +103,7 @@ hypervisor_control_socket(void)
s->rx_hook = hcs_connect;
s->err_hook = hcs_connect_err;
s->rbsize = 1024;
s->tbsize = 1024;
unlink(flock_config.control_socket_path);
if (sk_open_unix(s, loop, flock_config.control_socket_path) < 0)