ipc: correctly shutdown IPC sockets when exiting/restarting
This commit is contained in:
parent
fca826a6f9
commit
f7a1a9fb20
@ -73,6 +73,8 @@ static void ipc_recv_message(int sockfd, uint32_t message_type,
|
||||
int n = read(sockfd, msg + read_bytes, to_read);
|
||||
if (n == -1)
|
||||
err(EXIT_FAILURE, "read() failed");
|
||||
if (n == 0)
|
||||
errx(EXIT_FAILURE, "received EOF instead of reply");
|
||||
|
||||
read_bytes += n;
|
||||
to_read -= n;
|
||||
|
@ -67,5 +67,11 @@ int ipc_create_socket(const char *filename);
|
||||
*/
|
||||
void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
|
||||
|
||||
/**
|
||||
* Calls shutdown() on each socket and closes it. This function to be called
|
||||
* when exiting or restarting only!
|
||||
*
|
||||
*/
|
||||
void ipc_shutdown();
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "log.h"
|
||||
#include "sighandler.h"
|
||||
#include "manage.h"
|
||||
#include "ipc.h"
|
||||
|
||||
bool focus_window_in_container(xcb_connection_t *conn, Container *container, direction_t direction) {
|
||||
/* If this container is empty, we’re done */
|
||||
@ -1015,6 +1016,7 @@ void parse_command(xcb_connection_t *conn, const char *command) {
|
||||
if (STARTS_WITH(command, "exit")) {
|
||||
LOG("User issued exit-command, exiting without error.\n");
|
||||
restore_geometry(global_conn);
|
||||
ipc_shutdown();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
13
src/ipc.c
13
src/ipc.c
@ -105,6 +105,19 @@ void ipc_send_event(const char *event, uint32_t message_type, const char *payloa
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls shutdown() on each socket and closes it. This function to be called
|
||||
* when exiting or restarting only!
|
||||
*
|
||||
*/
|
||||
void ipc_shutdown() {
|
||||
ipc_client *current;
|
||||
TAILQ_FOREACH(current, &all_clients, clients) {
|
||||
shutdown(current->fd, SHUT_RDWR);
|
||||
close(current->fd);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Executes the command and returns whether it could be successfully parsed
|
||||
* or not (at the moment, always returns true).
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "ewmh.h"
|
||||
#include "manage.h"
|
||||
#include "workspace.h"
|
||||
#include "ipc.h"
|
||||
|
||||
static iconv_t conversion_descriptor = 0;
|
||||
struct keyvalue_table_head by_parent = TAILQ_HEAD_INITIALIZER(by_parent);
|
||||
@ -513,6 +514,8 @@ static char **append_argument(char **original, char *argument) {
|
||||
void i3_restart() {
|
||||
restore_geometry(global_conn);
|
||||
|
||||
ipc_shutdown();
|
||||
|
||||
LOG("restarting \"%s\"...\n", start_argv[0]);
|
||||
/* make sure -a is in the argument list or append it */
|
||||
start_argv = append_argument(start_argv, "-a");
|
||||
|
Loading…
Reference in New Issue
Block a user