Improve error handling

This commit is contained in:
project-repo 2020-05-25 17:45:19 +02:00
commit 8f9ed72201
2 changed files with 9 additions and 1 deletions

View file

@ -515,7 +515,11 @@ main(int argc, char *argv[]) {
wlr_xwayland_set_seat(xwayland, server.seat->seat);
#endif
ipc_init(&server);
if(ipc_init(&server) != 0) {
wlr_log(WLR_ERROR, "Failed to initialize IPC");
ret = 1;
goto end;
}
{ // config_file should only be visible as long as it is valid
char *config_file = get_config_file();

View file

@ -73,6 +73,7 @@ int ipc_init(struct cg_server *server) {
if (max_path_size <= snprintf(ipc->sockaddr->sun_path, max_path_size,
"%s/cagebreak-ipc.%i.%i.sock", sockdir, getuid(), getpid())) {
wlr_log(WLR_ERROR,"Unable to write socket path to ipc->sockaddr->sun_path. Path too long");
free(ipc->sockaddr);
return -1;
}
@ -80,11 +81,14 @@ int ipc_init(struct cg_server *server) {
if (bind(ipc->socket, (struct sockaddr *)ipc->sockaddr, sizeof(*ipc->sockaddr)) == -1) {
wlr_log(WLR_ERROR, "Unable to bind IPC socket");
free(ipc->sockaddr);
return -1;
}
if (listen(ipc->socket, 3) == -1) {
wlr_log(WLR_ERROR, "Unable to listen on IPC socket");
free(ipc->sockaddr);
return -1;
}
setenv("CAGEBREAK_SOCKET", ipc->sockaddr->sun_path, 1);