summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2019-03-29 10:40:59 +0100
committerDavid Oberhollenzer <goliath@infraroot.at>2019-03-29 21:00:53 +0100
commitc3d14cbfa863ea3af8aaa253f1d7d3909adf1547 (patch)
tree5b057f5fbdd0a28a6c5a9061c5907eb58f8e817f /cmd
parent7cfe6e845878d67f578fa846e784c064a178d9c5 (diff)
cleanup: init status response
- rename init_status_response_t to init_status_t - merge code for handling it - fix memory leak in status command Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/service/startstop.c14
-rw-r--r--cmd/service/status.c18
2 files changed, 11 insertions, 21 deletions
diff --git a/cmd/service/startstop.c b/cmd/service/startstop.c
index ffc33de..8c30efa 100644
--- a/cmd/service/startstop.c
+++ b/cmd/service/startstop.c
@@ -8,17 +8,11 @@
#include <getopt.h>
#include <unistd.h>
-static void free_resp(init_status_response_t *resp)
-{
- free(resp->filename);
- free(resp->service_name);
-}
-
static int cmd_startstop(int argc, char **argv,
E_SERVICE_STATE filter, E_INIT_REQUEST action)
{
int i, fd, ret = EXIT_FAILURE;
- init_status_response_t resp;
+ init_status_t resp;
char tmppath[256];
bool found;
@@ -41,12 +35,12 @@ static int cmd_startstop(int argc, char **argv,
if (init_socket_recv_status(fd, &resp)) {
perror("reading from initd socket");
- free_resp(&resp);
+ free_init_status(&resp);
goto out;
}
if (resp.state == ESS_NONE) {
- free_resp(&resp);
+ free_init_status(&resp);
break;
}
@@ -68,7 +62,7 @@ static int cmd_startstop(int argc, char **argv,
goto out;
}
- free_resp(&resp);
+ free_init_status(&resp);
}
ret = EXIT_SUCCESS;
diff --git a/cmd/service/status.c b/cmd/service/status.c
index abeeb15..752b0c7 100644
--- a/cmd/service/status.c
+++ b/cmd/service/status.c
@@ -15,17 +15,11 @@ static const struct option long_opts[] = {
static const char *short_opts = "d";
-static void free_resp(init_status_response_t *resp)
-{
- free(resp->filename);
- free(resp->service_name);
-}
-
static int cmd_status(int argc, char **argv)
{
bool is_tty, found, show_details = false;
int i, fd, ret = EXIT_FAILURE;
- init_status_response_t resp;
+ init_status_t resp;
char tmppath[256];
const char *state;
service_t *svc;
@@ -63,12 +57,12 @@ static int cmd_status(int argc, char **argv)
if (init_socket_recv_status(fd, &resp)) {
perror("reading from initd socket");
- free_resp(&resp);
+ free_init_status(&resp);
goto out;
}
if (resp.state == ESS_NONE) {
- free_resp(&resp);
+ free_init_status(&resp);
break;
}
@@ -87,8 +81,10 @@ static int cmd_status(int argc, char **argv)
}
}
- if (!found)
+ if (!found) {
+ free_init_status(&resp);
continue;
+ }
}
switch (resp.state) {
@@ -150,7 +146,7 @@ static int cmd_status(int argc, char **argv)
printf("[%s] %s\n", state, resp.filename);
}
- free_resp(&resp);
+ free_init_status(&resp);
}
ret = EXIT_SUCCESS;