mirror of
https://github.com/pygos/init.git
synced 2024-11-21 18:59:46 +01:00
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>
This commit is contained in:
parent
7cfe6e8458
commit
c3d14cbfa8
6 changed files with 27 additions and 25 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
libinit_a_SOURCES = lib/init/delsvc.c lib/init/svcmap.c lib/init/rdsvc.c
|
||||
libinit_a_SOURCES += lib/init/svcscan.c lib/init/del_svc_list.c
|
||||
libinit_a_SOURCES += lib/init/svc_tsort.c lib/include/service.h
|
||||
libinit_a_SOURCES += lib/init/init_socket_open.c
|
||||
libinit_a_SOURCES += lib/init/init_socket_open.c lib/init/free_init_status.c
|
||||
libinit_a_SOURCES += lib/include/initsock.h lib/init/init_socket_send_request.c
|
||||
libinit_a_SOURCES += lib/init/init_socket_recv_status.c
|
||||
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
|
|
|
@ -45,12 +45,14 @@ typedef struct {
|
|||
int id;
|
||||
char *filename;
|
||||
char *service_name;
|
||||
} init_status_response_t;
|
||||
} init_status_t;
|
||||
|
||||
int init_socket_open(const char *tmppath);
|
||||
|
||||
int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...);
|
||||
|
||||
int init_socket_recv_status(int fd, init_status_response_t *resp);
|
||||
int init_socket_recv_status(int fd, init_status_t *resp);
|
||||
|
||||
void free_init_status(init_status_t *resp);
|
||||
|
||||
#endif /* INITSOCK_H */
|
||||
|
|
10
lib/init/free_init_status.c
Normal file
10
lib/init/free_init_status.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "initsock.h"
|
||||
|
||||
void free_init_status(init_status_t *resp)
|
||||
{
|
||||
free(resp->filename);
|
||||
free(resp->service_name);
|
||||
}
|
|
@ -61,7 +61,7 @@ static char *read_string(int fd)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
int init_socket_recv_status(int fd, init_status_response_t *resp)
|
||||
int init_socket_recv_status(int fd, init_status_t *resp)
|
||||
{
|
||||
uint8_t info[8];
|
||||
|
||||
|
|
Loading…
Reference in a new issue