|
|
@ -31,9 +31,7 @@ static const int IPC_SOCKET_BACKLOG = 5; |
|
|
|
* Create IPC socket at specified path and return file descriptor to socket. |
|
|
|
* Create IPC socket at specified path and return file descriptor to socket. |
|
|
|
* This initializes the static variable sockaddr. |
|
|
|
* This initializes the static variable sockaddr. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_create_socket(const char *filename) { |
|
|
|
ipc_create_socket(const char *filename) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char *normal_filename; |
|
|
|
char *normal_filename; |
|
|
|
char *parent; |
|
|
|
char *parent; |
|
|
|
const size_t addr_size = sizeof(struct sockaddr_un); |
|
|
|
const size_t addr_size = sizeof(struct sockaddr_un); |
|
|
@ -44,8 +42,8 @@ ipc_create_socket(const char *filename) |
|
|
|
// In case socket file exists
|
|
|
|
// In case socket file exists
|
|
|
|
unlink(normal_filename); |
|
|
|
unlink(normal_filename); |
|
|
|
|
|
|
|
|
|
|
|
// For portability clear the addr structure, since some implementations have
|
|
|
|
// For portability clear the addr structure, since some implementations
|
|
|
|
// nonstandard fields in the structure
|
|
|
|
// have nonstandard fields in the structure
|
|
|
|
memset(&sockaddr, 0, addr_size); |
|
|
|
memset(&sockaddr, 0, addr_size); |
|
|
|
|
|
|
|
|
|
|
|
parentdir(normal_filename, &parent); |
|
|
|
parentdir(normal_filename, &parent); |
|
|
@ -65,7 +63,7 @@ ipc_create_socket(const char *filename) |
|
|
|
|
|
|
|
|
|
|
|
DEBUG("Created socket at %s\n", sockaddr.sun_path); |
|
|
|
DEBUG("Created socket at %s\n", sockaddr.sun_path); |
|
|
|
|
|
|
|
|
|
|
|
if (bind(sock_fd, (const struct sockaddr *)&sockaddr, addr_size) == -1) { |
|
|
|
if (bind(sock_fd, (const struct sockaddr *) &sockaddr, addr_size) == -1) { |
|
|
|
fputs("Failed to bind socket\n", stderr); |
|
|
|
fputs("Failed to bind socket\n", stderr); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
@ -83,17 +81,16 @@ ipc_create_socket(const char *filename) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Internal function used to receive IPC messages from a given file descriptor. |
|
|
|
* Internal function used to receive IPC messages from a given file |
|
|
|
|
|
|
|
* descriptor. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns -1 on error reading (could be EAGAIN or EINTR) |
|
|
|
* Returns -1 on error reading (could be EAGAIN or EINTR) |
|
|
|
* Returns -2 if EOF before header could be read |
|
|
|
* Returns -2 if EOF before header could be read |
|
|
|
* Returns -3 if invalid IPC header |
|
|
|
* Returns -3 if invalid IPC header |
|
|
|
* Returns -4 if message length exceeds MAX_MESSAGE_SIZE |
|
|
|
* Returns -4 if message length exceeds MAX_MESSAGE_SIZE |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size, |
|
|
|
ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size, |
|
|
|
uint8_t **reply) { |
|
|
|
uint8_t **reply) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint32_t read_bytes = 0; |
|
|
|
uint32_t read_bytes = 0; |
|
|
|
const int32_t to_read = sizeof(dwm_ipc_header_t); |
|
|
|
const int32_t to_read = sizeof(dwm_ipc_header_t); |
|
|
|
char header[to_read]; |
|
|
|
char header[to_read]; |
|
|
@ -105,15 +102,19 @@ ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size, |
|
|
|
|
|
|
|
|
|
|
|
if (n == 0) { |
|
|
|
if (n == 0) { |
|
|
|
if (read_bytes == 0) { |
|
|
|
if (read_bytes == 0) { |
|
|
|
fprintf(stderr, "Unexpectedly reached EOF while reading header."); |
|
|
|
|
|
|
|
fprintf(stderr, |
|
|
|
fprintf(stderr, |
|
|
|
"Read %" PRIu32 " bytes, expected %" PRIu32 " total bytes.\n", |
|
|
|
"Unexpectedly reached EOF while reading header."); |
|
|
|
|
|
|
|
fprintf(stderr, |
|
|
|
|
|
|
|
"Read %" PRIu32 " bytes, expected %" PRIu32 |
|
|
|
|
|
|
|
" total bytes.\n", |
|
|
|
read_bytes, to_read); |
|
|
|
read_bytes, to_read); |
|
|
|
return -2; |
|
|
|
return -2; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fprintf(stderr, "Unexpectedly reached EOF while reading header."); |
|
|
|
|
|
|
|
fprintf(stderr, |
|
|
|
fprintf(stderr, |
|
|
|
"Read %" PRIu32 " bytes, expected %" PRIu32 " total bytes.\n", |
|
|
|
"Unexpectedly reached EOF while reading header."); |
|
|
|
|
|
|
|
fprintf(stderr, |
|
|
|
|
|
|
|
"Read %" PRIu32 " bytes, expected %" PRIu32 |
|
|
|
|
|
|
|
" total bytes.\n", |
|
|
|
read_bytes, to_read); |
|
|
|
read_bytes, to_read); |
|
|
|
return -3; |
|
|
|
return -3; |
|
|
|
} |
|
|
|
} |
|
|
@ -155,18 +156,22 @@ ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size, |
|
|
|
|
|
|
|
|
|
|
|
read_bytes = 0; |
|
|
|
read_bytes = 0; |
|
|
|
while (read_bytes < *reply_size) { |
|
|
|
while (read_bytes < *reply_size) { |
|
|
|
const ssize_t n = read(fd, *reply + read_bytes, *reply_size - read_bytes); |
|
|
|
const ssize_t n = |
|
|
|
|
|
|
|
read(fd, *reply + read_bytes, *reply_size - read_bytes); |
|
|
|
|
|
|
|
|
|
|
|
if (n == 0) { |
|
|
|
if (n == 0) { |
|
|
|
fprintf(stderr, "Unexpectedly reached EOF while reading payload."); |
|
|
|
fprintf(stderr, |
|
|
|
fprintf(stderr, "Read %" PRIu32 " bytes, expected %" PRIu32 " bytes.\n", |
|
|
|
"Unexpectedly reached EOF while reading payload."); |
|
|
|
|
|
|
|
fprintf(stderr, |
|
|
|
|
|
|
|
"Read %" PRIu32 " bytes, expected %" PRIu32 " bytes.\n", |
|
|
|
read_bytes, *reply_size); |
|
|
|
read_bytes, *reply_size); |
|
|
|
free(*reply); |
|
|
|
free(*reply); |
|
|
|
return -2; |
|
|
|
return -2; |
|
|
|
} else if (n == -1) { |
|
|
|
} else if (n == -1) { |
|
|
|
// TODO: Should we return and wait for another epoll event?
|
|
|
|
// TODO: Should we return and wait for another epoll event?
|
|
|
|
// This would require saving the partial read in some way.
|
|
|
|
// This would require saving the partial read in some way.
|
|
|
|
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue; |
|
|
|
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
free(*reply); |
|
|
|
free(*reply); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
@ -186,13 +191,12 @@ ipc_recv_message(int fd, uint8_t *msg_type, uint32_t *reply_size, |
|
|
|
* Returns -1 on unknown error trying to write, errno will carry over from |
|
|
|
* Returns -1 on unknown error trying to write, errno will carry over from |
|
|
|
* write() call |
|
|
|
* write() call |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static ssize_t |
|
|
|
static ssize_t ipc_write_message(int fd, const void *buf, size_t count) { |
|
|
|
ipc_write_message(int fd, const void *buf, size_t count) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
size_t written = 0; |
|
|
|
size_t written = 0; |
|
|
|
|
|
|
|
|
|
|
|
while (written < count) { |
|
|
|
while (written < count) { |
|
|
|
const ssize_t n = write(fd, (uint8_t *)buf + written, count - written); |
|
|
|
const ssize_t n = |
|
|
|
|
|
|
|
write(fd, (uint8_t *) buf + written, count - written); |
|
|
|
|
|
|
|
|
|
|
|
if (n == -1) { |
|
|
|
if (n == -1) { |
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
|
|
@ -215,20 +219,16 @@ ipc_write_message(int fd, const void *buf, size_t count) |
|
|
|
* handle, set yajl options, and in the future any other initialization that |
|
|
|
* handle, set yajl options, and in the future any other initialization that |
|
|
|
* should occur for event messages. |
|
|
|
* should occur for event messages. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_event_init_message(yajl_gen *gen) { |
|
|
|
ipc_event_init_message(yajl_gen *gen) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*gen = yajl_gen_alloc(NULL); |
|
|
|
*gen = yajl_gen_alloc(NULL); |
|
|
|
yajl_gen_config(*gen, yajl_gen_beautify, 1); |
|
|
|
yajl_gen_config(*gen, yajl_gen_beautify, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Prepares buffers of IPC subscribers of specified event using buffer from yajl |
|
|
|
* Prepares buffers of IPC subscribers of specified event using buffer from |
|
|
|
* handle. |
|
|
|
* yajl handle. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_event_prepare_send_message(yajl_gen gen, IPCEvent event) { |
|
|
|
ipc_event_prepare_send_message(yajl_gen gen, IPCEvent event) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const unsigned char *buffer; |
|
|
|
const unsigned char *buffer; |
|
|
|
size_t len = 0; |
|
|
|
size_t len = 0; |
|
|
|
|
|
|
|
|
|
|
@ -238,7 +238,7 @@ ipc_event_prepare_send_message(yajl_gen gen, IPCEvent event) |
|
|
|
for (IPCClient *c = ipc_clients; c; c = c->next) { |
|
|
|
for (IPCClient *c = ipc_clients; c; c = c->next) { |
|
|
|
if (c->subscriptions & event) { |
|
|
|
if (c->subscriptions & event) { |
|
|
|
DEBUG("Sending selected client change event to fd %d\n", c->fd); |
|
|
|
DEBUG("Sending selected client change event to fd %d\n", c->fd); |
|
|
|
ipc_prepare_send_message(c, IPC_TYPE_EVENT, len, (char *)buffer); |
|
|
|
ipc_prepare_send_message(c, IPC_TYPE_EVENT, len, (char *) buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -251,28 +251,24 @@ ipc_event_prepare_send_message(yajl_gen gen, IPCEvent event) |
|
|
|
* handle, set yajl options, and in the future any other initialization that |
|
|
|
* handle, set yajl options, and in the future any other initialization that |
|
|
|
* should occur for reply messages. |
|
|
|
* should occur for reply messages. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_reply_init_message(yajl_gen *gen) { |
|
|
|
ipc_reply_init_message(yajl_gen *gen) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*gen = yajl_gen_alloc(NULL); |
|
|
|
*gen = yajl_gen_alloc(NULL); |
|
|
|
yajl_gen_config(*gen, yajl_gen_beautify, 1); |
|
|
|
yajl_gen_config(*gen, yajl_gen_beautify, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Prepares the IPC client's buffer with a message using the buffer of the yajl |
|
|
|
* Prepares the IPC client's buffer with a message using the buffer of the |
|
|
|
* handle. |
|
|
|
* yajl handle. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_reply_prepare_send_message(yajl_gen gen, IPCClient *c, |
|
|
|
ipc_reply_prepare_send_message(yajl_gen gen, IPCClient *c, |
|
|
|
IPCMessageType msg_type) { |
|
|
|
IPCMessageType msg_type) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const unsigned char *buffer; |
|
|
|
const unsigned char *buffer; |
|
|
|
size_t len = 0; |
|
|
|
size_t len = 0; |
|
|
|
|
|
|
|
|
|
|
|
yajl_gen_get_buf(gen, &buffer, &len); |
|
|
|
yajl_gen_get_buf(gen, &buffer, &len); |
|
|
|
len++; // For null char
|
|
|
|
len++; // For null char
|
|
|
|
|
|
|
|
|
|
|
|
ipc_prepare_send_message(c, msg_type, len, (const char *)buffer); |
|
|
|
ipc_prepare_send_message(c, msg_type, len, (const char *) buffer); |
|
|
|
|
|
|
|
|
|
|
|
// Not documented, but this frees temp_buffer
|
|
|
|
// Not documented, but this frees temp_buffer
|
|
|
|
yajl_gen_free(gen); |
|
|
|
yajl_gen_free(gen); |
|
|
@ -284,9 +280,7 @@ ipc_reply_prepare_send_message(yajl_gen gen, IPCClient *c, |
|
|
|
* Returns 0 if a command with the specified name was found |
|
|
|
* Returns 0 if a command with the specified name was found |
|
|
|
* Returns -1 if a command with the specified name could not be found |
|
|
|
* Returns -1 if a command with the specified name could not be found |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_get_ipc_command(const char *name, IPCCommand *ipc_command) { |
|
|
|
ipc_get_ipc_command(const char *name, IPCCommand *ipc_command) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < ipc_commands_len; i++) { |
|
|
|
for (int i = 0; i < ipc_commands_len; i++) { |
|
|
|
if (strcmp(ipc_commands[i].name, name) == 0) { |
|
|
|
if (strcmp(ipc_commands[i].name, name) == 0) { |
|
|
|
*ipc_command = ipc_commands[i]; |
|
|
|
*ipc_command = ipc_commands[i]; |
|
|
@ -307,9 +301,8 @@ ipc_get_ipc_command(const char *name, IPCCommand *ipc_command) |
|
|
|
* Returns 0 if the message was successfully parsed |
|
|
|
* Returns 0 if the message was successfully parsed |
|
|
|
* Returns -1 otherwise |
|
|
|
* Returns -1 otherwise |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_parse_run_command(char *msg, |
|
|
|
ipc_parse_run_command(char *msg, IPCParsedCommand *parsed_command) |
|
|
|
IPCParsedCommand *parsed_command) { |
|
|
|
{ |
|
|
|
|
|
|
|
char error_buffer[1000]; |
|
|
|
char error_buffer[1000]; |
|
|
|
yajl_val parent = yajl_tree_parse(msg, error_buffer, 1000); |
|
|
|
yajl_val parent = yajl_tree_parse(msg, error_buffer, 1000); |
|
|
|
|
|
|
|
|
|
|
@ -336,7 +329,8 @@ ipc_parse_run_command(char *msg, IPCParsedCommand *parsed_command) |
|
|
|
|
|
|
|
|
|
|
|
const char *command_name = YAJL_GET_STRING(command_val); |
|
|
|
const char *command_name = YAJL_GET_STRING(command_val); |
|
|
|
size_t command_name_len = strlen(command_name); |
|
|
|
size_t command_name_len = strlen(command_name); |
|
|
|
parsed_command->name = (char *)malloc((command_name_len + 1) * sizeof(char)); |
|
|
|
parsed_command->name = |
|
|
|
|
|
|
|
(char *) malloc((command_name_len + 1) * sizeof(char)); |
|
|
|
strcpy(parsed_command->name, command_name); |
|
|
|
strcpy(parsed_command->name, command_name); |
|
|
|
|
|
|
|
|
|
|
|
DEBUG("Received command: %s\n", parsed_command->name); |
|
|
|
DEBUG("Received command: %s\n", parsed_command->name); |
|
|
@ -359,14 +353,14 @@ ipc_parse_run_command(char *msg, IPCParsedCommand *parsed_command) |
|
|
|
// If no arguments are specified, make a dummy argument to pass to the
|
|
|
|
// If no arguments are specified, make a dummy argument to pass to the
|
|
|
|
// function. This is just the way dwm's void(Arg*) functions are setup.
|
|
|
|
// function. This is just the way dwm's void(Arg*) functions are setup.
|
|
|
|
if (*argc == 0) { |
|
|
|
if (*argc == 0) { |
|
|
|
*args = (Arg *)malloc(sizeof(Arg)); |
|
|
|
*args = (Arg *) malloc(sizeof(Arg)); |
|
|
|
*arg_types = (ArgType *)malloc(sizeof(ArgType)); |
|
|
|
*arg_types = (ArgType *) malloc(sizeof(ArgType)); |
|
|
|
(*arg_types)[0] = ARG_TYPE_NONE; |
|
|
|
(*arg_types)[0] = ARG_TYPE_NONE; |
|
|
|
(*args)[0].i = 0; |
|
|
|
(*args)[0].i = 0; |
|
|
|
(*argc)++; |
|
|
|
(*argc)++; |
|
|
|
} else if (*argc > 0) { |
|
|
|
} else if (*argc > 0) { |
|
|
|
*args = (Arg *)calloc(*argc, sizeof(Arg)); |
|
|
|
*args = (Arg *) calloc(*argc, sizeof(Arg)); |
|
|
|
*arg_types = (ArgType *)malloc(*argc * sizeof(ArgType)); |
|
|
|
*arg_types = (ArgType *) malloc(*argc * sizeof(ArgType)); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < *argc; i++) { |
|
|
|
for (int i = 0; i < *argc; i++) { |
|
|
|
yajl_val arg_val = args_val->u.array.values[i]; |
|
|
|
yajl_val arg_val = args_val->u.array.values[i]; |
|
|
@ -386,7 +380,7 @@ ipc_parse_run_command(char *msg, IPCParsedCommand *parsed_command) |
|
|
|
} |
|
|
|
} |
|
|
|
// If the number is not an integer, it must be a float
|
|
|
|
// If the number is not an integer, it must be a float
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
(*args)[i].f = (float)YAJL_GET_DOUBLE(arg_val); |
|
|
|
(*args)[i].f = (float) YAJL_GET_DOUBLE(arg_val); |
|
|
|
(*arg_types)[i] = ARG_TYPE_FLOAT; |
|
|
|
(*arg_types)[i] = ARG_TYPE_FLOAT; |
|
|
|
DEBUG("f=%f\n", (*args)[i].f); |
|
|
|
DEBUG("f=%f\n", (*args)[i].f); |
|
|
|
// If argument is not a number, it must be a string
|
|
|
|
// If argument is not a number, it must be a string
|
|
|
@ -394,9 +388,9 @@ ipc_parse_run_command(char *msg, IPCParsedCommand *parsed_command) |
|
|
|
} else if (YAJL_IS_STRING(arg_val)) { |
|
|
|
} else if (YAJL_IS_STRING(arg_val)) { |
|
|
|
char *arg_s = YAJL_GET_STRING(arg_val); |
|
|
|
char *arg_s = YAJL_GET_STRING(arg_val); |
|
|
|
size_t arg_s_size = (strlen(arg_s) + 1) * sizeof(char); |
|
|
|
size_t arg_s_size = (strlen(arg_s) + 1) * sizeof(char); |
|
|
|
(*args)[i].v = (char *)malloc(arg_s_size); |
|
|
|
(*args)[i].v = (char *) malloc(arg_s_size); |
|
|
|
(*arg_types)[i] = ARG_TYPE_STR; |
|
|
|
(*arg_types)[i] = ARG_TYPE_STR; |
|
|
|
strcpy((char *)(*args)[i].v, arg_s); |
|
|
|
strcpy((char *) (*args)[i].v, arg_s); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -409,11 +403,10 @@ ipc_parse_run_command(char *msg, IPCParsedCommand *parsed_command) |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Free the members of a IPCParsedCommand struct |
|
|
|
* Free the members of a IPCParsedCommand struct |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_free_parsed_command_members(IPCParsedCommand *command) { |
|
|
|
ipc_free_parsed_command_members(IPCParsedCommand *command) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < command->argc; i++) { |
|
|
|
for (int i = 0; i < command->argc; i++) { |
|
|
|
if (command->arg_types[i] == ARG_TYPE_STR) free((void *)command->args[i].v); |
|
|
|
if (command->arg_types[i] == ARG_TYPE_STR) |
|
|
|
|
|
|
|
free((void *) command->args[i].v); |
|
|
|
} |
|
|
|
} |
|
|
|
free(command->args); |
|
|
|
free(command->args); |
|
|
|
free(command->arg_types); |
|
|
|
free(command->arg_types); |
|
|
@ -428,10 +421,10 @@ ipc_free_parsed_command_members(IPCParsedCommand *command) |
|
|
|
* Returns -1 if the argument count doesn't match |
|
|
|
* Returns -1 if the argument count doesn't match |
|
|
|
* Returns -2 if the argument types don't match |
|
|
|
* Returns -2 if the argument types don't match |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_validate_run_command(IPCParsedCommand *parsed, |
|
|
|
ipc_validate_run_command(IPCParsedCommand *parsed, const IPCCommand actual) |
|
|
|
const IPCCommand actual) { |
|
|
|
{ |
|
|
|
if (actual.argc != parsed->argc) |
|
|
|
if (actual.argc != parsed->argc) return -1; |
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < parsed->argc; i++) { |
|
|
|
for (int i = 0; i < parsed->argc; i++) { |
|
|
|
ArgType ptype = parsed->arg_types[i]; |
|
|
|
ArgType ptype = parsed->arg_types[i]; |
|
|
@ -440,7 +433,7 @@ ipc_validate_run_command(IPCParsedCommand *parsed, const IPCCommand actual) |
|
|
|
if (ptype != atype) { |
|
|
|
if (ptype != atype) { |
|
|
|
if (ptype == ARG_TYPE_UINT && atype == ARG_TYPE_PTR) |
|
|
|
if (ptype == ARG_TYPE_UINT && atype == ARG_TYPE_PTR) |
|
|
|
// If this argument is supposed to be a void pointer, cast it
|
|
|
|
// If this argument is supposed to be a void pointer, cast it
|
|
|
|
parsed->args[i].v = (void *)parsed->args[i].ui; |
|
|
|
parsed->args[i].v = (void *) parsed->args[i].ui; |
|
|
|
else if (ptype == ARG_TYPE_UINT && atype == ARG_TYPE_SINT) |
|
|
|
else if (ptype == ARG_TYPE_UINT && atype == ARG_TYPE_SINT) |
|
|
|
// If this argument is supposed to be a signed int, cast it
|
|
|
|
// If this argument is supposed to be a signed int, cast it
|
|
|
|
parsed->args[i].i = parsed->args[i].ui; |
|
|
|
parsed->args[i].i = parsed->args[i].ui; |
|
|
@ -458,9 +451,7 @@ ipc_validate_run_command(IPCParsedCommand *parsed, const IPCCommand actual) |
|
|
|
* Returns 0 if a valid event name was given |
|
|
|
* Returns 0 if a valid event name was given |
|
|
|
* Returns -1 otherwise |
|
|
|
* Returns -1 otherwise |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_event_stoi(const char *subscription, IPCEvent *event) { |
|
|
|
ipc_event_stoi(const char *subscription, IPCEvent *event) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (strcmp(subscription, "tag_change_event") == 0) |
|
|
|
if (strcmp(subscription, "tag_change_event") == 0) |
|
|
|
*event = IPC_EVENT_TAG_CHANGE; |
|
|
|
*event = IPC_EVENT_TAG_CHANGE; |
|
|
|
else if (strcmp(subscription, "client_focus_change_event") == 0) |
|
|
|
else if (strcmp(subscription, "client_focus_change_event") == 0) |
|
|
@ -479,18 +470,17 @@ ipc_event_stoi(const char *subscription, IPCEvent *event) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Parse a IPC_TYPE_SUBSCRIBE message from a client. This function extracts the |
|
|
|
* Parse a IPC_TYPE_SUBSCRIBE message from a client. This function extracts |
|
|
|
* event name and the subscription action from the message. |
|
|
|
* the event name and the subscription action from the message. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns 0 if message was successfully parsed |
|
|
|
* Returns 0 if message was successfully parsed |
|
|
|
* Returns -1 otherwise |
|
|
|
* Returns -1 otherwise |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_parse_subscribe(const char *msg, |
|
|
|
ipc_parse_subscribe(const char *msg, IPCSubscriptionAction *subscribe, |
|
|
|
IPCSubscriptionAction *subscribe, |
|
|
|
IPCEvent *event) |
|
|
|
IPCEvent *event) { |
|
|
|
{ |
|
|
|
|
|
|
|
char error_buffer[100]; |
|
|
|
char error_buffer[100]; |
|
|
|
yajl_val parent = yajl_tree_parse((char *)msg, error_buffer, 100); |
|
|
|
yajl_val parent = yajl_tree_parse((char *) msg, error_buffer, 100); |
|
|
|
|
|
|
|
|
|
|
|
if (parent == NULL) { |
|
|
|
if (parent == NULL) { |
|
|
|
fputs("Failed to parse command from client\n", stderr); |
|
|
|
fputs("Failed to parse command from client\n", stderr); |
|
|
@ -514,7 +504,8 @@ ipc_parse_subscribe(const char *msg, IPCSubscriptionAction *subscribe, |
|
|
|
const char *event_str = YAJL_GET_STRING(event_val); |
|
|
|
const char *event_str = YAJL_GET_STRING(event_val); |
|
|
|
DEBUG("Received event: %s\n", event_str); |
|
|
|
DEBUG("Received event: %s\n", event_str); |
|
|
|
|
|
|
|
|
|
|
|
if (ipc_event_stoi(event_str, event) < 0) return -1; |
|
|
|
if (ipc_event_stoi(event_str, event) < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
const char *action_path[] = {"action", 0}; |
|
|
|
const char *action_path[] = {"action", 0}; |
|
|
|
yajl_val action_val = yajl_tree_get(parent, action_path, yajl_t_string); |
|
|
|
yajl_val action_val = yajl_tree_get(parent, action_path, yajl_t_string); |
|
|
@ -547,9 +538,7 @@ ipc_parse_subscribe(const char *msg, IPCSubscriptionAction *subscribe, |
|
|
|
* Returns 0 if message was successfully parsed |
|
|
|
* Returns 0 if message was successfully parsed |
|
|
|
* Returns -1 otherwise |
|
|
|
* Returns -1 otherwise |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_parse_get_dwm_client(const char *msg, Window *win) { |
|
|
|
ipc_parse_get_dwm_client(const char *msg, Window *win) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char error_buffer[100]; |
|
|
|
char error_buffer[100]; |
|
|
|
|
|
|
|
|
|
|
|
yajl_val parent = yajl_tree_parse(msg, error_buffer, 100); |
|
|
|
yajl_val parent = yajl_tree_parse(msg, error_buffer, 100); |
|
|
@ -581,20 +570,19 @@ ipc_parse_get_dwm_client(const char *msg, Window *win) |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Called when an IPC_TYPE_RUN_COMMAND message is received from a client. This |
|
|
|
* Called when an IPC_TYPE_RUN_COMMAND message is received from a client. This |
|
|
|
* function parses, executes the given command, and prepares a reply message to |
|
|
|
* function parses, executes the given command, and prepares a reply message |
|
|
|
* the client indicating success/failure. |
|
|
|
* to the client indicating success/failure. |
|
|
|
* |
|
|
|
* |
|
|
|
* NOTE: There is currently no check for argument validity beyond the number of |
|
|
|
* NOTE: There is currently no check for argument validity beyond the number |
|
|
|
* arguments given and types of arguments. There is also no way to check if the |
|
|
|
* of arguments given and types of arguments. There is also no way to check if |
|
|
|
* function succeeded based on dwm's void(const Arg*) function types. Pointer |
|
|
|
* the function succeeded based on dwm's void(const Arg*) function types. |
|
|
|
* arguments can cause crashes if they are not validated in the function itself. |
|
|
|
* Pointer arguments can cause crashes if they are not validated in the |
|
|
|
|
|
|
|
* function itself. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns 0 if message was successfully parsed |
|
|
|
* Returns 0 if message was successfully parsed |
|
|
|
* Returns -1 on failure parsing message |
|
|
|
* Returns -1 on failure parsing message |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_run_command(IPCClient *ipc_client, char *msg) { |
|
|
|
ipc_run_command(IPCClient *ipc_client, char *msg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IPCParsedCommand parsed_command; |
|
|
|
IPCParsedCommand parsed_command; |
|
|
|
IPCCommand ipc_command; |
|
|
|
IPCCommand ipc_command; |
|
|
|
|
|
|
|
|
|
|
@ -609,7 +597,8 @@ ipc_run_command(IPCClient *ipc_client, char *msg) |
|
|
|
|
|
|
|
|
|
|
|
if (ipc_get_ipc_command(parsed_command.name, &ipc_command) < 0) { |
|
|
|
if (ipc_get_ipc_command(parsed_command.name, &ipc_command) < 0) { |
|
|
|
ipc_prepare_reply_failure(ipc_client, IPC_TYPE_RUN_COMMAND, |
|
|
|
ipc_prepare_reply_failure(ipc_client, IPC_TYPE_RUN_COMMAND, |
|
|
|
"Command %s not found", parsed_command.name); |
|
|
|
"Command %s not found", |
|
|
|
|
|
|
|
parsed_command.name); |
|
|
|
ipc_free_parsed_command_members(&parsed_command); |
|
|
|
ipc_free_parsed_command_members(&parsed_command); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
@ -630,7 +619,8 @@ ipc_run_command(IPCClient *ipc_client, char *msg) |
|
|
|
if (parsed_command.argc == 1) |
|
|
|
if (parsed_command.argc == 1) |
|
|
|
ipc_command.func.single_param(parsed_command.args); |
|
|
|
ipc_command.func.single_param(parsed_command.args); |
|
|
|
else if (parsed_command.argc > 1) |
|
|
|
else if (parsed_command.argc > 1) |
|
|
|
ipc_command.func.array_param(parsed_command.args, parsed_command.argc); |
|
|
|
ipc_command.func.array_param(parsed_command.args, |
|
|
|
|
|
|
|
parsed_command.argc); |
|
|
|
|
|
|
|
|
|
|
|
DEBUG("Called function for command %s\n", parsed_command.name); |
|
|
|
DEBUG("Called function for command %s\n", parsed_command.name); |
|
|
|
|
|
|
|
|
|
|
@ -644,9 +634,7 @@ ipc_run_command(IPCClient *ipc_client, char *msg) |
|
|
|
* Called when an IPC_TYPE_GET_MONITORS message is received from a client. It |
|
|
|
* Called when an IPC_TYPE_GET_MONITORS message is received from a client. It |
|
|
|
* prepares a reply with the properties of all of the monitors in JSON. |
|
|
|
* prepares a reply with the properties of all of the monitors in JSON. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_get_monitors(IPCClient *c, Monitor *mons, Monitor *selmon) { |
|
|
|
ipc_get_monitors(IPCClient *c, Monitor *mons, Monitor *selmon) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
dump_monitors(gen, mons, selmon); |
|
|
|
dump_monitors(gen, mons, selmon); |
|
|
@ -658,9 +646,8 @@ ipc_get_monitors(IPCClient *c, Monitor *mons, Monitor *selmon) |
|
|
|
* Called when an IPC_TYPE_GET_TAGS message is received from a client. It |
|
|
|
* Called when an IPC_TYPE_GET_TAGS message is received from a client. It |
|
|
|
* prepares a reply with info about all the tags in JSON. |
|
|
|
* prepares a reply with info about all the tags in JSON. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_get_tags(IPCClient *c, const char *tags[], |
|
|
|
ipc_get_tags(IPCClient *c, const char *tags[], const int tags_len) |
|
|
|
const int tags_len) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
|
|
|
|
|
|
|
@ -673,9 +660,8 @@ ipc_get_tags(IPCClient *c, const char *tags[], const int tags_len) |
|
|
|
* Called when an IPC_TYPE_GET_LAYOUTS message is received from a client. It |
|
|
|
* Called when an IPC_TYPE_GET_LAYOUTS message is received from a client. It |
|
|
|
* prepares a reply with a JSON array of available layouts |
|
|
|
* prepares a reply with a JSON array of available layouts |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void |
|
|
|
static void ipc_get_layouts(IPCClient *c, const Layout layouts[], |
|
|
|
ipc_get_layouts(IPCClient *c, const Layout layouts[], const int layouts_len) |
|
|
|
const int layouts_len) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
|
|
|
|
|
|
|
@ -685,20 +671,20 @@ ipc_get_layouts(IPCClient *c, const Layout layouts[], const int layouts_len) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Called when an IPC_TYPE_GET_DWM_CLIENT message is received from a client. It |
|
|
|
* Called when an IPC_TYPE_GET_DWM_CLIENT message is received from a client. |
|
|
|
* prepares a JSON reply with the properties of the client with the specified |
|
|
|
* It prepares a JSON reply with the properties of the client with the |
|
|
|
* window XID. |
|
|
|
* specified window XID. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns 0 if the message was successfully parsed and if the client with the |
|
|
|
* Returns 0 if the message was successfully parsed and if the client with the |
|
|
|
* specified window XID was found |
|
|
|
* specified window XID was found |
|
|
|
* Returns -1 if the message could not be parsed |
|
|
|
* Returns -1 if the message could not be parsed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_get_dwm_client(IPCClient *ipc_client, const char *msg, |
|
|
|
ipc_get_dwm_client(IPCClient *ipc_client, const char *msg, const Monitor *mons) |
|
|
|
const Monitor *mons) { |
|
|
|
{ |
|
|
|
|
|
|
|
Window win; |
|
|
|
Window win; |
|
|
|
|
|
|
|
|
|
|
|
if (ipc_parse_get_dwm_client(msg, &win) < 0) return -1; |
|
|
|
if (ipc_parse_get_dwm_client(msg, &win) < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
// Find client with specified window XID
|
|
|
|
// Find client with specified window XID
|
|
|
|
for (const Monitor *m = mons; m; m = m->next) |
|
|
|
for (const Monitor *m = mons; m; m = m->next) |
|
|
@ -722,20 +708,19 @@ ipc_get_dwm_client(IPCClient *ipc_client, const char *msg, const Monitor *mons) |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Called when an IPC_TYPE_SUBSCRIBE message is received from a client. It |
|
|
|
* Called when an IPC_TYPE_SUBSCRIBE message is received from a client. It |
|
|
|
* subscribes/unsubscribes the client from the specified event and replies with |
|
|
|
* subscribes/unsubscribes the client from the specified event and replies |
|
|
|
* the result. |
|
|
|
* with the result. |
|
|
|
* |
|
|
|
* |
|
|
|
* Returns 0 if the message was successfully parsed. |
|
|
|
* Returns 0 if the message was successfully parsed. |
|
|
|
* Returns -1 if the message could not be parsed |
|
|
|
* Returns -1 if the message could not be parsed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static int |
|
|
|
static int ipc_subscribe(IPCClient *c, const char *msg) { |
|
|
|
ipc_subscribe(IPCClient *c, const char *msg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IPCSubscriptionAction action = IPC_ACTION_SUBSCRIBE; |
|
|
|
IPCSubscriptionAction action = IPC_ACTION_SUBSCRIBE; |
|
|
|
IPCEvent event = 0; |
|
|
|
IPCEvent event = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (ipc_parse_subscribe(msg, &action, &event)) { |
|
|
|
if (ipc_parse_subscribe(msg, &action, &event)) { |
|
|
|
ipc_prepare_reply_failure(c, IPC_TYPE_SUBSCRIBE, "Event does not exist"); |
|
|
|
ipc_prepare_reply_failure(c, IPC_TYPE_SUBSCRIBE, |
|
|
|
|
|
|
|
"Event does not exist"); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -755,15 +740,14 @@ ipc_subscribe(IPCClient *c, const char *msg) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_init(const char *socket_path, const int p_epoll_fd, |
|
|
|
ipc_init(const char *socket_path, const int p_epoll_fd, IPCCommand commands[], |
|
|
|
IPCCommand commands[], const int commands_len) { |
|
|
|
const int commands_len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Initialize struct to 0
|
|
|
|
// Initialize struct to 0
|
|
|
|
memset(&sock_epoll_event, 0, sizeof(sock_epoll_event)); |
|
|
|
memset(&sock_epoll_event, 0, sizeof(sock_epoll_event)); |
|
|
|
|
|
|
|
|
|
|
|
int socket_fd = ipc_create_socket(socket_path); |
|
|
|
int socket_fd = ipc_create_socket(socket_path); |
|
|
|
if (socket_fd < 0) return -1; |
|
|
|
if (socket_fd < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
ipc_commands = commands; |
|
|
|
ipc_commands = commands; |
|
|
|
ipc_commands_len = commands_len; |
|
|
|
ipc_commands_len = commands_len; |
|
|
@ -781,9 +765,7 @@ ipc_init(const char *socket_path, const int p_epoll_fd, IPCCommand commands[], |
|
|
|
return socket_fd; |
|
|
|
return socket_fd; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_cleanup() { |
|
|
|
ipc_cleanup() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IPCClient *c = ipc_clients; |
|
|
|
IPCClient *c = ipc_clients; |
|
|
|
// Free clients and their buffers
|
|
|
|
// Free clients and their buffers
|
|
|
|
while (c) { |
|
|
|
while (c) { |
|
|
@ -809,27 +791,19 @@ ipc_cleanup() |
|
|
|
close(sock_fd); |
|
|
|
close(sock_fd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_get_sock_fd() { |
|
|
|
ipc_get_sock_fd() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return sock_fd; |
|
|
|
return sock_fd; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IPCClient * |
|
|
|
IPCClient *ipc_get_client(int fd) { |
|
|
|
ipc_get_client(int fd) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return ipc_list_get_client(ipc_clients, fd); |
|
|
|
return ipc_list_get_client(ipc_clients, fd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_is_client_registered(int fd) { |
|
|
|
ipc_is_client_registered(int fd) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (ipc_get_client(fd) != NULL); |
|
|
|
return (ipc_get_client(fd) != NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_accept_client() { |
|
|
|
ipc_accept_client() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int fd = -1; |
|
|
|
int fd = -1; |
|
|
|
|
|
|
|
|
|
|
|
struct sockaddr_un client_addr; |
|
|
|
struct sockaddr_un client_addr; |
|
|
@ -839,7 +813,7 @@ ipc_accept_client() |
|
|
|
// have nonstandard fields in the structure
|
|
|
|
// have nonstandard fields in the structure
|
|
|
|
memset(&client_addr, 0, sizeof(struct sockaddr_un)); |
|
|
|
memset(&client_addr, 0, sizeof(struct sockaddr_un)); |
|
|
|
|
|
|
|
|
|
|
|
fd = accept(sock_fd, (struct sockaddr *)&client_addr, &len); |
|
|
|
fd = accept(sock_fd, (struct sockaddr *) &client_addr, &len); |
|
|
|
if (fd < 0 && errno != EINTR) { |
|
|
|
if (fd < 0 && errno != EINTR) { |
|
|
|
fputs("Failed to accept IPC connection from client", stderr); |
|
|
|
fputs("Failed to accept IPC connection from client", stderr); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
@ -852,7 +826,8 @@ ipc_accept_client() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IPCClient *nc = ipc_client_new(fd); |
|
|
|
IPCClient *nc = ipc_client_new(fd); |
|
|
|
if (nc == NULL) return -1; |
|
|
|
if (nc == NULL) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
// Wake up to messages from this client
|
|
|
|
// Wake up to messages from this client
|
|
|
|
nc->event.data.fd = fd; |
|
|
|
nc->event.data.fd = fd; |
|
|
@ -866,9 +841,7 @@ ipc_accept_client() |
|
|
|
return fd; |
|
|
|
return fd; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_drop_client(IPCClient *c) { |
|
|
|
ipc_drop_client(IPCClient *c) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int fd = c->fd; |
|
|
|
int fd = c->fd; |
|
|
|
shutdown(fd, SHUT_RDWR); |
|
|
|
shutdown(fd, SHUT_RDWR); |
|
|
|
int res = close(fd); |
|
|
|
int res = close(fd); |
|
|
@ -891,21 +864,20 @@ ipc_drop_client(IPCClient *c) |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_read_client(IPCClient *c, IPCMessageType *msg_type, |
|
|
|
ipc_read_client(IPCClient *c, IPCMessageType *msg_type, uint32_t *msg_size, |
|
|
|
uint32_t *msg_size, char **msg) { |
|
|
|
char **msg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int fd = c->fd; |
|
|
|
int fd = c->fd; |
|
|
|
int ret = |
|
|
|
int ret = ipc_recv_message(fd, (uint8_t *) msg_type, msg_size, |
|
|
|
ipc_recv_message(fd, (uint8_t *)msg_type, msg_size, (uint8_t **)msg); |
|
|
|
(uint8_t **) msg); |
|
|
|
|
|
|
|
|
|
|
|
if (ret < 0) { |
|
|
|
if (ret < 0) { |
|
|
|
// This will happen if these errors occur while reading header
|
|
|
|
// This will happen if these errors occur while reading header
|
|
|
|
if (ret == -1 && |
|
|
|
if (ret == -1 |
|
|
|
(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) |
|
|
|
&& (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) |
|
|
|
return -2; |
|
|
|
return -2; |
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Error reading message: dropping client at fd %d\n", fd); |
|
|
|
fprintf(stderr, "Error reading message: dropping client at fd %d\n", |
|
|
|
|
|
|
|
fd); |
|
|
|
ipc_drop_client(c); |
|
|
|
ipc_drop_client(c); |
|
|
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
return -1; |
|
|
@ -923,18 +895,17 @@ ipc_read_client(IPCClient *c, IPCMessageType *msg_type, uint32_t *msg_size, |
|
|
|
DEBUG("Received message: '%.*s' ", *msg_size, *msg); |
|
|
|
DEBUG("Received message: '%.*s' ", *msg_size, *msg); |
|
|
|
else |
|
|
|
else |
|
|
|
DEBUG("Received empty message "); |
|
|
|
DEBUG("Received empty message "); |
|
|
|
DEBUG("Message type: %" PRIu8 " ", (uint8_t)*msg_type); |
|
|
|
DEBUG("Message type: %" PRIu8 " ", (uint8_t) *msg_type); |
|
|
|
DEBUG("Message size: %" PRIu32 "\n", *msg_size); |
|
|
|
DEBUG("Message size: %" PRIu32 "\n", *msg_size); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ssize_t |
|
|
|
ssize_t ipc_write_client(IPCClient *c) { |
|
|
|
ipc_write_client(IPCClient *c) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const ssize_t n = ipc_write_message(c->fd, c->buffer, c->buffer_size); |
|
|
|
const ssize_t n = ipc_write_message(c->fd, c->buffer, c->buffer_size); |
|
|
|
|
|
|
|
|
|
|
|
if (n < 0) return n; |
|
|
|
if (n < 0) |
|
|
|
|
|
|
|
return n; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Deal with client timeouts
|
|
|
|
// TODO: Deal with client timeouts
|
|
|
|
|
|
|
|
|
|
|
@ -954,25 +925,24 @@ ipc_write_client(IPCClient *c) |
|
|
|
// Shift unwritten buffer to beginning of buffer and reallocate
|
|
|
|
// Shift unwritten buffer to beginning of buffer and reallocate
|
|
|
|
c->buffer_size -= n; |
|
|
|
c->buffer_size -= n; |
|
|
|
memmove(c->buffer, c->buffer + n, c->buffer_size); |
|
|
|
memmove(c->buffer, c->buffer + n, c->buffer_size); |
|
|
|
c->buffer = (char *)realloc(c->buffer, c->buffer_size); |
|
|
|
c->buffer = (char *) realloc(c->buffer, c->buffer_size); |
|
|
|
|
|
|
|
|
|
|
|
return n; |
|
|
|
return n; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_prepare_send_message(IPCClient *c, const IPCMessageType msg_type, |
|
|
|
ipc_prepare_send_message(IPCClient *c, const IPCMessageType msg_type, |
|
|
|
const uint32_t msg_size, const char *msg) { |
|
|
|
const uint32_t msg_size, const char *msg) |
|
|
|
dwm_ipc_header_t header = {.magic = IPC_MAGIC_ARR, |
|
|
|
{ |
|
|
|
.type = msg_type, |
|
|
|
dwm_ipc_header_t header = { |
|
|
|
.size = msg_size}; |
|
|
|
.magic = IPC_MAGIC_ARR, .type = msg_type, .size = msg_size}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t header_size = sizeof(dwm_ipc_header_t); |
|
|
|
uint32_t header_size = sizeof(dwm_ipc_header_t); |
|
|
|
uint32_t packet_size = header_size + msg_size; |
|
|
|
uint32_t packet_size = header_size + msg_size; |
|
|
|
|
|
|
|
|
|
|
|
if (c->buffer == NULL) |
|
|
|
if (c->buffer == NULL) |
|
|
|
c->buffer = (char *)malloc(c->buffer_size + packet_size); |
|
|
|
c->buffer = (char *) malloc(c->buffer_size + packet_size); |
|
|
|
else |
|
|
|
else |
|
|
|
c->buffer = (char *)realloc(c->buffer, c->buffer_size + packet_size); |
|
|
|
c->buffer = (char *) realloc(c->buffer, c->buffer_size + packet_size); |
|
|
|
|
|
|
|
|
|
|
|
// Copy header to end of client buffer
|
|
|
|
// Copy header to end of client buffer
|
|
|
|
memcpy(c->buffer + c->buffer_size, &header, header_size); |
|
|
|
memcpy(c->buffer + c->buffer_size, &header, header_size); |
|
|
@ -987,10 +957,8 @@ ipc_prepare_send_message(IPCClient *c, const IPCMessageType msg_type, |
|
|
|
epoll_ctl(epoll_fd, EPOLL_CTL_MOD, c->fd, &c->event); |
|
|
|
epoll_ctl(epoll_fd, EPOLL_CTL_MOD, c->fd, &c->event); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_prepare_reply_failure(IPCClient *c, IPCMessageType msg_type, |
|
|
|
ipc_prepare_reply_failure(IPCClient *c, IPCMessageType msg_type, |
|
|
|
const char *format, ...) { |
|
|
|
const char *format, ...) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
va_list args; |
|
|
|
va_list args; |
|
|
|
|
|
|
|
|
|
|
@ -998,7 +966,7 @@ ipc_prepare_reply_failure(IPCClient *c, IPCMessageType msg_type, |
|
|
|
va_start(args, format); |
|
|
|
va_start(args, format); |
|
|
|
size_t len = vsnprintf(NULL, 0, format, args); |
|
|
|
size_t len = vsnprintf(NULL, 0, format, args); |
|
|
|
va_end(args); |
|
|
|
va_end(args); |
|
|
|
char *buffer = (char *)malloc((len + 1) * sizeof(char)); |
|
|
|
char *buffer = (char *) malloc((len + 1) * sizeof(char)); |
|
|
|
|
|
|
|
|
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
ipc_reply_init_message(&gen); |
|
|
|
|
|
|
|
|
|
|
@ -1013,39 +981,32 @@ ipc_prepare_reply_failure(IPCClient *c, IPCMessageType msg_type, |
|
|
|
free(buffer); |
|
|
|
free(buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_prepare_reply_success(IPCClient *c, IPCMessageType msg_type) { |
|
|
|
ipc_prepare_reply_success(IPCClient *c, IPCMessageType msg_type) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const char *success_msg = "{\"result\":\"success\"}"; |
|
|
|
const char *success_msg = "{\"result\":\"success\"}"; |
|
|
|
const size_t msg_len = strlen(success_msg) + 1; // +1 for null char
|
|
|
|
const size_t msg_len = strlen(success_msg) + 1; // +1 for null char
|
|
|
|
|
|
|
|
|
|
|
|
ipc_prepare_send_message(c, msg_type, msg_len, success_msg); |
|
|
|
ipc_prepare_send_message(c, msg_type, msg_len, success_msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_tag_change_event(int mon_num, TagState old_state, |
|
|
|
ipc_tag_change_event(int mon_num, TagState old_state, TagState new_state) |
|
|
|
TagState new_state) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
dump_tag_event(gen, mon_num, old_state, new_state); |
|
|
|
dump_tag_event(gen, mon_num, old_state, new_state); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_TAG_CHANGE); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_TAG_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_client_focus_change_event(int mon_num, Client *old_client, |
|
|
|
ipc_client_focus_change_event(int mon_num, Client *old_client, |
|
|
|
Client *new_client) { |
|
|
|
Client *new_client) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
dump_client_focus_change_event(gen, old_client, new_client, mon_num); |
|
|
|
dump_client_focus_change_event(gen, old_client, new_client, mon_num); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_CLIENT_FOCUS_CHANGE); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_CLIENT_FOCUS_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_layout_change_event(const int mon_num, const char *old_symbol, |
|
|
|
ipc_layout_change_event(const int mon_num, const char *old_symbol, |
|
|
|
|
|
|
|
const Layout *old_layout, const char *new_symbol, |
|
|
|
const Layout *old_layout, const char *new_symbol, |
|
|
|
const Layout *new_layout) |
|
|
|
const Layout *new_layout) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
dump_layout_change_event(gen, mon_num, old_symbol, old_layout, new_symbol, |
|
|
|
dump_layout_change_event(gen, mon_num, old_symbol, old_layout, new_symbol, |
|
|
@ -1053,30 +1014,27 @@ ipc_layout_change_event(const int mon_num, const char *old_symbol, |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_LAYOUT_CHANGE); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_LAYOUT_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_monitor_focus_change_event(const int last_mon_num, |
|
|
|
ipc_monitor_focus_change_event(const int last_mon_num, const int new_mon_num) |
|
|
|
const int new_mon_num) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
dump_monitor_focus_change_event(gen, last_mon_num, new_mon_num); |
|
|
|
dump_monitor_focus_change_event(gen, last_mon_num, new_mon_num); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_MONITOR_FOCUS_CHANGE); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_MONITOR_FOCUS_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_focused_title_change_event(const int mon_num, const Window client_id, |
|
|
|
ipc_focused_title_change_event(const int mon_num, const Window client_id, |
|
|
|
const char *old_name, |
|
|
|
const char *old_name, const char *new_name) |
|
|
|
const char *new_name) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
dump_focused_title_change_event(gen, mon_num, client_id, old_name, new_name); |
|
|
|
dump_focused_title_change_event(gen, mon_num, client_id, old_name, |
|
|
|
|
|
|
|
new_name); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_FOCUSED_TITLE_CHANGE); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_FOCUSED_TITLE_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_focused_state_change_event(const int mon_num, const Window client_id, |
|
|
|
ipc_focused_state_change_event(const int mon_num, const Window client_id, |
|
|
|
|
|
|
|
const ClientState *old_state, |
|
|
|
const ClientState *old_state, |
|
|
|
const ClientState *new_state) |
|
|
|
const ClientState *new_state) { |
|
|
|
{ |
|
|
|
|
|
|
|
yajl_gen gen; |
|
|
|
yajl_gen gen; |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
ipc_event_init_message(&gen); |
|
|
|
dump_focused_state_change_event(gen, mon_num, client_id, old_state, |
|
|
|
dump_focused_state_change_event(gen, mon_num, client_id, old_state, |
|
|
@ -1084,20 +1042,21 @@ ipc_focused_state_change_event(const int mon_num, const Window client_id, |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_FOCUSED_STATE_CHANGE); |
|
|
|
ipc_event_prepare_send_message(gen, IPC_EVENT_FOCUSED_STATE_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void ipc_send_events(Monitor *mons, Monitor **lastselmon, Monitor *selmon) { |
|
|
|
ipc_send_events(Monitor *mons, Monitor **lastselmon, Monitor *selmon) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (Monitor *m = mons; m; m = m->next) { |
|
|
|
for (Monitor *m = mons; m; m = m->next) { |
|
|
|
unsigned int urg = 0, occ = 0, tagset = 0; |
|
|
|
unsigned int urg = 0, occ = 0, tagset = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (Client *c = m->clients; c; c = c->next) { |
|
|
|
for (Client *c = m->clients; c; c = c->next) { |
|
|
|
occ |= c->tags; |
|
|
|
occ |= c->tags; |
|
|
|
|
|
|
|
|
|
|
|
if (c->isurgent) urg |= c->tags; |
|
|
|
if (c->isurgent) |
|
|
|
|
|
|
|
urg |= c->tags; |
|
|
|
} |
|
|
|
} |
|
|
|
tagset = m->tagset[m->seltags]; |
|
|
|
tagset = m->tagset[m->seltags]; |
|
|
|
|
|
|
|
|
|
|
|
TagState new_state = {.selected = tagset, .occupied = occ, .urgent = urg}; |
|
|
|
TagState new_state = {.selected = tagset, |
|
|
|
|
|
|
|
.occupied = occ, |
|
|
|
|
|
|
|
.urgent = urg}; |
|
|
|
|
|
|
|
|
|
|
|
if (memcmp(&m->tagstate, &new_state, sizeof(TagState)) != 0) { |
|
|
|
if (memcmp(&m->tagstate, &new_state, sizeof(TagState)) != 0) { |
|
|
|
ipc_tag_change_event(m->num, m->tagstate, new_state); |
|
|
|
ipc_tag_change_event(m->num, m->tagstate, new_state); |
|
|
@ -1109,22 +1068,24 @@ ipc_send_events(Monitor *mons, Monitor **lastselmon, Monitor *selmon) |
|
|
|
m->lastsel = m->sel; |
|
|
|
m->lastsel = m->sel; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(m->ltsymbol, m->lastltsymbol) != 0 || |
|
|
|
if (strcmp(m->ltsymbol, m->lastltsymbol) != 0 |
|
|
|
m->lastlt != m->lt[m->sellt]) { |
|
|
|
|| m->lastlt != m->lt[m->sellt]) { |
|
|
|
ipc_layout_change_event(m->num, m->lastltsymbol, m->lastlt, m->ltsymbol, |
|
|
|
ipc_layout_change_event(m->num, m->lastltsymbol, m->lastlt, |
|
|
|
m->lt[m->sellt]); |
|
|
|
m->ltsymbol, m->lt[m->sellt]); |
|
|
|
strcpy(m->lastltsymbol, m->ltsymbol); |
|
|
|
strcpy(m->lastltsymbol, m->ltsymbol); |
|
|
|
m->lastlt = m->lt[m->sellt]; |
|
|
|
m->lastlt = m->lt[m->sellt]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (*lastselmon != selmon) { |
|
|
|
if (*lastselmon != selmon) { |
|
|
|
if (*lastselmon != NULL) |
|
|
|
if (*lastselmon != NULL) |
|
|
|
ipc_monitor_focus_change_event((*lastselmon)->num, selmon->num); |
|
|
|
ipc_monitor_focus_change_event((*lastselmon)->num, |
|
|
|
|
|
|
|
selmon->num); |
|
|
|
*lastselmon = selmon; |
|
|
|
*lastselmon = selmon; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Client *sel = m->sel; |
|
|
|
Client *sel = m->sel; |
|
|
|
if (!sel) continue; |
|
|
|
if (!sel) |
|
|
|
|
|
|
|
continue; |
|
|
|
ClientState *o = &m->sel->prevstate; |
|
|
|
ClientState *o = &m->sel->prevstate; |
|
|
|
ClientState n = {.oldstate = sel->oldstate, |
|
|
|
ClientState n = {.oldstate = sel->oldstate, |
|
|
|
.isfixed = sel->isfixed, |
|
|
|
.isfixed = sel->isfixed, |
|
|
@ -1139,12 +1100,11 @@ ipc_send_events(Monitor *mons, Monitor **lastselmon, Monitor *selmon) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_handle_client_epoll_event(struct epoll_event *ev, Monitor *mons, |
|
|
|
ipc_handle_client_epoll_event(struct epoll_event *ev, Monitor *mons, |
|
|
|
|
|
|
|
Monitor **lastselmon, Monitor *selmon, |
|
|
|
Monitor **lastselmon, Monitor *selmon, |
|
|
|
const char *tags[], const int tags_len, |
|
|
|
const char *tags[], const int tags_len, |
|
|
|
const Layout *layouts, const int layouts_len) |
|
|
|
const Layout *layouts, |
|
|
|
{ |
|
|
|
const int layouts_len) { |
|
|
|
int fd = ev->data.fd; |
|
|
|
int fd = ev->data.fd; |
|
|
|
IPCClient *c = ipc_get_client(fd); |
|
|
|
IPCClient *c = ipc_get_client(fd); |
|
|
|
|
|
|
|
|
|
|
@ -1153,14 +1113,16 @@ ipc_handle_client_epoll_event(struct epoll_event *ev, Monitor *mons, |
|
|
|
ipc_drop_client(c); |
|
|
|
ipc_drop_client(c); |
|
|
|
} else if (ev->events & EPOLLOUT) { |
|
|
|
} else if (ev->events & EPOLLOUT) { |
|
|
|
DEBUG("Sending message to client at fd %d...\n", fd); |
|
|
|
DEBUG("Sending message to client at fd %d...\n", fd); |
|
|
|
if (c->buffer_size) ipc_write_client(c); |
|
|
|
if (c->buffer_size) |
|
|
|
|
|
|
|
ipc_write_client(c); |
|
|
|
} else if (ev->events & EPOLLIN) { |
|
|
|
} else if (ev->events & EPOLLIN) { |
|
|
|
IPCMessageType msg_type = 0; |
|
|
|
IPCMessageType msg_type = 0; |
|
|
|
uint32_t msg_size = 0; |
|
|
|
uint32_t msg_size = 0; |
|
|
|
char *msg = NULL; |
|
|
|
char *msg = NULL; |
|
|
|
|
|
|
|
|
|
|
|
DEBUG("Received message from fd %d\n", fd); |
|
|
|
DEBUG("Received message from fd %d\n", fd); |
|
|
|
if (ipc_read_client(c, &msg_type, &msg_size, &msg) < 0) return -1; |
|
|
|
if (ipc_read_client(c, &msg_type, &msg_size, &msg) < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
if (msg_type == IPC_TYPE_GET_MONITORS) |
|
|
|
if (msg_type == IPC_TYPE_GET_MONITORS) |
|
|
|
ipc_get_monitors(c, mons, selmon); |
|
|
|
ipc_get_monitors(c, mons, selmon); |
|
|
@ -1169,12 +1131,15 @@ ipc_handle_client_epoll_event(struct epoll_event *ev, Monitor *mons, |
|
|
|
else if (msg_type == IPC_TYPE_GET_LAYOUTS) |
|
|
|
else if (msg_type == IPC_TYPE_GET_LAYOUTS) |
|
|
|
ipc_get_layouts(c, layouts, layouts_len); |
|
|
|
ipc_get_layouts(c, layouts, layouts_len); |
|
|
|
else if (msg_type == IPC_TYPE_RUN_COMMAND) { |
|
|
|
else if (msg_type == IPC_TYPE_RUN_COMMAND) { |
|
|
|
if (ipc_run_command(c, msg) < 0) return -1; |
|
|
|
if (ipc_run_command(c, msg) < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
ipc_send_events(mons, lastselmon, selmon); |
|
|
|
ipc_send_events(mons, lastselmon, selmon); |
|
|
|
} else if (msg_type == IPC_TYPE_GET_DWM_CLIENT) { |
|
|
|
} else if (msg_type == IPC_TYPE_GET_DWM_CLIENT) { |
|
|
|
if (ipc_get_dwm_client(c, msg, mons) < 0) return -1; |
|
|
|
if (ipc_get_dwm_client(c, msg, mons) < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
} else if (msg_type == IPC_TYPE_SUBSCRIBE) { |
|
|
|
} else if (msg_type == IPC_TYPE_SUBSCRIBE) { |
|
|
|
if (ipc_subscribe(c, msg) < 0) return -1; |
|
|
|
if (ipc_subscribe(c, msg) < 0) |
|
|
|
|
|
|
|
return -1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fprintf(stderr, "Invalid message type received from fd %d", fd); |
|
|
|
fprintf(stderr, "Invalid message type received from fd %d", fd); |
|
|
|
ipc_prepare_reply_failure(c, msg_type, "Invalid message type: %d", |
|
|
|
ipc_prepare_reply_failure(c, msg_type, "Invalid message type: %d", |
|
|
@ -1182,17 +1147,17 @@ ipc_handle_client_epoll_event(struct epoll_event *ev, Monitor *mons, |
|
|
|
} |
|
|
|
} |
|
|
|
free(msg); |
|
|
|
free(msg); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fprintf(stderr, "Epoll event returned %d from fd %d\n", ev->events, fd); |
|
|
|
fprintf(stderr, "Epoll event returned %d from fd %d\n", ev->events, |
|
|
|
|
|
|
|
fd); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int ipc_handle_socket_epoll_event(struct epoll_event *ev) { |
|
|
|
ipc_handle_socket_epoll_event(struct epoll_event *ev) |
|
|
|
if (!(ev->events & EPOLLIN)) |
|
|
|
{ |
|
|
|
return -1; |
|
|
|
if (!(ev->events & EPOLLIN)) return -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// EPOLLIN means incoming client connection request
|
|
|
|
// EPOLLIN means incoming client connection request
|
|
|
|
fputs("Received EPOLLIN event on socket\n", stderr); |
|
|
|
fputs("Received EPOLLIN event on socket\n", stderr); |
|
|
|