From 2541f5c057122788041c59366b9a89c7e2566186 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 11 Aug 2022 18:24:39 +0200 Subject: [PATCH] client: make a connection before parsing inputs This shows a clear error message if the socket does not exist and when using privileged commands. Fix #535. --- src/client/lldpcli.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index a7d9be4b..3af19204 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -431,6 +431,7 @@ main(int argc, char *argv[]) const char *fmt = "plain"; lldpctl_conn_t *conn = NULL; const char *options = is_lldpctl(argv[0])?"hdvf:u:":"hdsvf:c:C:u:"; + lldpctl_atom_t *configuration; int gotinputs = 0, version = 0; struct inputs inputs; @@ -503,6 +504,13 @@ main(int argc, char *argv[]) conn = lldpctl_new_name(ctlname, NULL, NULL, NULL); if (conn == NULL) goto end; + /* Check we have a working connection */ + if ((configuration = lldpctl_get_configuration(conn)) == NULL) { + /* ctl.c already outputs an error */ + goto end; + } + lldpctl_atom_dec_ref(configuration); + /* Process file inputs */ while (gotinputs && !TAILQ_EMPTY(&inputs)) { /* coverity[use_after_free] -- 2.39.5