Skip to content

Commit

Permalink
#714 yabai message receiver could get stuck in *recv* on Big Sur
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Nov 14, 2020
1 parent 686a20e commit 7f8aa4e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Fixed an issue (exposed on Big Sur, maybe didn't exist on prior macOS versions ??) that caused yabai' message receiver to block in *recv* [#714](https://github.com/koekeishiya/yabai/issues/714)

## [3.3.3] - 2020-11-13
### Changed
Expand Down
16 changes: 11 additions & 5 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,17 +1003,23 @@ static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WOKE)

static EVENT_CALLBACK(EVENT_HANDLER_DAEMON_MESSAGE)
{
int length;
char *message = socket_read(param1, &length);
if (!message) goto out;

FILE *rsp = fdopen(param1, "w");
if (!rsp) goto out;
if (!rsp) goto err;

debug_message(__FUNCTION__, message);
handle_message(rsp, message);

debug_message(__FUNCTION__, context);
handle_message(rsp, context);
fflush(rsp);
fclose(rsp);

out:
socket_close(param1);
err:
free(context);

out:
socket_close(param1);
return EVENT_SUCCESS;
}
2 changes: 1 addition & 1 deletion src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -2293,5 +2293,5 @@ void handle_message(FILE *rsp, char *message)

static SOCKET_DAEMON_HANDLER(message_handler)
{
event_loop_post(&g_event_loop, DAEMON_MESSAGE, message, sockfd, NULL);
event_loop_post(&g_event_loop, DAEMON_MESSAGE, NULL, sockfd, NULL);
}
10 changes: 1 addition & 9 deletions src/misc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,7 @@ static void *socket_connection_handler(void *context)

while (daemon->is_running) {
int sockfd = accept(daemon->sockfd, NULL, 0);
if (sockfd == -1) continue;

int length;
char *message = socket_read(sockfd, &length);
if (message) {
daemon->handler(message, length, sockfd);
} else {
socket_close(sockfd);
}
if (sockfd != -1) daemon->handler(sockfd);
}

return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/misc/socket.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOCKET_H
#define SOCKET_H

#define SOCKET_DAEMON_HANDLER(name) void name(char *message, int length, int sockfd)
#define SOCKET_DAEMON_HANDLER(name) void name(int sockfd)
typedef SOCKET_DAEMON_HANDLER(socket_daemon_handler);

#define FAILURE_MESSAGE "\x07"
Expand Down

0 comments on commit 7f8aa4e

Please sign in to comment.