Skip to content

Instantly share code, notes, and snippets.

@ammgws
Last active February 29, 2020 17:27
Show Gist options
  • Save ammgws/354ae23e74ae8ad8935f35509939b3c6 to your computer and use it in GitHub Desktop.
Save ammgws/354ae23e74ae8ad8935f35509939b3c6 to your computer and use it in GitHub Desktop.

OK sudo strace -- swaymsg --socket $SWAYSOCK -t get_inputs 2> swaymsg_getinputs_withswaysock.log

 44 socket(AF_UNIX, SOCK_STREAM, 0)         = 3
 45 connect(3, {sa_family=AF_UNIX, sun_path="/run/user/1000/sway-ipc.1000.1324.sock"}, 110) = 0
 46 setsockopt(3, SOL_SOCKET, SO_RCVTIMEO_OLD, "\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
 47 write(3, "i3-ipc\0\0\0\0d\0\0\0", 14)   = 14
 48 write(3, "", 0)                         = 0
 49 recvfrom(3, "i3-ipc\31\26\0\0d\0\0\0", 14, 0, NULL, NULL) = 14
 50 recvfrom(3, "[ { \"identifier\": \"0:0:Eee_PC_WM"..., 5657, 0, NULL, NULL) = 5657
 51 stat("/dev/urandom", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x9), ...}) = 0
 52 openat(AT_FDCWD, "/dev/urandom", O_RDONLY) = 4
 53 read(4, "\364\304\275\237", 4)          = 4
 54 close(4)                                = 0
 55 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
 56 write(1, "Input device: Eee PC WMI hotkeys"..., 33) = 33
 57 write(1, "  Type: Keyboard\n", 17)      = 17
 58 write(1, "  Identifier: 0:0:Eee_PC_WMI_hot"..., 37) = 37
 59 write(1, "  Product ID: 0\n", 16)       = 16
 60 write(1, "  Vendor ID: 0\n", 15)        = 15
 61 write(1, "  Active Keyboard Layout: Englis"..., 39) = 39

FAIL sudo strace -- swaymsg --socket $SWAYSOCK -t get_outputs 2> swaymsg_getout_withswaysock.log

44 socket(AF_UNIX, SOCK_STREAM, 0)         = 3
45 connect(3, {sa_family=AF_UNIX, sun_path="/run/user/1000/sway-ipc.1000.1324.sock"}, 110) = 0
46 setsockopt(3, SOL_SOCKET, SO_RCVTIMEO_OLD, "\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
47 write(3, "i3-ipc\0\0\0\0\3\0\0\0", 14)  = 14
48 write(3, "", 0)                         = 0
49 recvfrom(3, "", 14, 0, NULL, NULL)      = 0
50 openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
51 fstat(4, {st_mode=S_IFREG|0644, st_size=309, ...}) = 0
52 fstat(4, {st_mode=S_IFREG|0644, st_size=309, ...}) = 0
53 read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0\0\0\0"..., 4096) = 309
54 lseek(4, -176, SEEK_CUR)                = 133
55 read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0\0\0\0"..., 4096) = 176
56 close(4)                                = 0
57 write(2, "2020-03-01 00:58:40 - ", 222020-03-01 00:58:40 - )  = 22
58 ioctl(2, TCGETS, 0x7ffd60e8fcf0)        = -1 ENOTTY (Inappropriate ioctl for device)
59 write(2, "[common/ipc-client.c:88] Unable "..., 55[common/ipc-client.c:88] Unable to receive IPC response) = 55
60 ioctl(2, TCGETS, 0x7ffd60e8fcf0)        = -1 ENOTTY (Inappropriate ioctl for device)
61 write(2, "\n", 1
62 )                       = 1
63 exit_group(1)                           = ?
64 +++ exited with 1 +++

FAIL sudo strace -- swaymsg --socket $SWAYSOCK -t get_tree 2> swaymsg_gettree_withswaysock.log

44 socket(AF_UNIX, SOCK_STREAM, 0)         = 3
45 connect(3, {sa_family=AF_UNIX, sun_path="/run/user/1000/sway-ipc.1000.1324.sock"}, 110) = 0
46 setsockopt(3, SOL_SOCKET, SO_RCVTIMEO_OLD, "\3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
47 write(3, "i3-ipc\0\0\0\0\4\0\0\0", 14)  = 14
48 write(3, "", 0)                         = 0
49 recvfrom(3, "", 14, 0, NULL, NULL)      = 0
50 openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
51 fstat(4, {st_mode=S_IFREG|0644, st_size=309, ...}) = 0
52 fstat(4, {st_mode=S_IFREG|0644, st_size=309, ...}) = 0
53 read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0\0\0\0"..., 4096) = 309
54 lseek(4, -176, SEEK_CUR)                = 133
55 read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0\0\0\0"..., 4096) = 176
56 close(4)                                = 0
57 write(2, "2020-03-01 01:04:33 - ", 222020-03-01 01:04:33 - )  = 22
58 ioctl(2, TCGETS, 0x7ffcee4e47b0)        = -1 ENOTTY (Inappropriate ioctl for device)
59 write(2, "[common/ipc-client.c:88] Unable "..., 55[common/ipc-client.c:88] Unable to receive IPC response) = 55
60 ioctl(2, TCGETS, 0x7ffcee4e47b0)        = -1 ENOTTY (Inappropriate ioctl for device)
61 write(2, "\n", 1
62 )                       = 1
63 exit_group(1)                           = ?
64 +++ exited with 1 +++
@ammgws
Copy link
Author

ammgws commented Feb 29, 2020

ipc server

	case IPC_GET_OUTPUTS:
	{
		json_object *outputs = json_object_new_array();
		for (int i = 0; i < root->outputs->length; ++i) {
			struct sway_output *output = root->outputs->items[i];
			json_object *output_json = ipc_json_describe_node(&output->node);

			// override the default focused indicator because it's set
			// differently for the get_outputs reply
			struct sway_seat *seat = input_manager_get_default_seat();
			struct sway_workspace *focused_ws =
				seat_get_focused_workspace(seat);
			bool focused = focused_ws && output == focused_ws->output;
			json_object_object_del(output_json, "focused");
			json_object_object_add(output_json, "focused",
				json_object_new_boolean(focused));

			const char *subpixel = sway_wl_output_subpixel_to_string(output->wlr_output->subpixel);
			json_object_object_add(output_json, "subpixel_hinting", json_object_new_string(subpixel));
			json_object_array_add(outputs, output_json);
		}
		struct sway_output *output;
		wl_list_for_each(output, &root->all_outputs, link) {
			if (!output->enabled && output != root->noop_output) {
				json_object_array_add(outputs,
						ipc_json_describe_disabled_output(output));
			}
		}
		const char *json_string = json_object_to_json_string(outputs);
		ipc_send_reply(client, payload_type, json_string,
			(uint32_t)strlen(json_string));
		json_object_put(outputs); // free
		goto exit_cleanup;
	}


	case IPC_GET_TREE:
	{
		json_object *tree = ipc_json_describe_node_recursive(&root->node);
		const char *json_string = json_object_to_json_string(tree);
		ipc_send_reply(client, payload_type, json_string,
			(uint32_t)strlen(json_string));
		json_object_put(tree);
		goto exit_cleanup;
	}

@ammgws
Copy link
Author

ammgws commented Feb 29, 2020

failing here
https://github.com/swaywm/sway/blob/813e1209795f7016fd1223c5ce96b2185eed5a9a/sway/ipc-server.c#L912

bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_type,
		const char *payload, uint32_t payload_length) {
	assert(payload);

	char data[IPC_HEADER_SIZE];
	uint32_t *data32 = (uint32_t*)(data + sizeof(ipc_magic));

	memcpy(data, ipc_magic, sizeof(ipc_magic));
	memcpy(&data32[0], &payload_length, sizeof(payload_length));
	memcpy(&data32[1], &payload_type, sizeof(payload_type));

	while (client->write_buffer_len + IPC_HEADER_SIZE + payload_length >=
				 client->write_buffer_size) {
		client->write_buffer_size *= 2;
	}

	if (client->write_buffer_size > 4e6) { // 4 MB
		sway_log(SWAY_ERROR, "Client write buffer too big, disconnecting client");
		ipc_client_disconnect(client);
		return false;
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment