sway: Problems with git master versions of json-c
Short version: It won’t compile out of the box. If do you change the code in order to compile it, it will crash whenever you use any key binding. I eventually decided to see if there were earlier tags of json-c that wouldn’t have this problem and it seems that even with the latest one, version 0.12.1, sway compiles and runs just fine. Maybe the maximum version of json-c with which sway will work should be indicated in README.
Long version:
When compiling, you get type mismatch errors in five files, all involving json_object_array_length in for loops:
sway/ipc-server.c: In function ‘ipc_client_handle_command’: sway/ipc-server.c:449:21: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] for (int i = 0; i < json_object_array_length(request); i++) {
The five files are:
- sway/ipc-server.c
- swaybar/status_line.c
- swaybar/tray/tray.c
- swaygrab/json.c
- swaylock/main.c
The solution for that is very simple. Merely change the type of the counter variables from int to size_t.
On pressing keys, I’ve traced the problem to the line in ipc-server.c:
json_object_object_add(obj, "binding", sb_obj);
My guess is that the call to json_object_put(obj); later in the function frees the objects recursively and then sb_obj is used (or more likely freed, as the stdout error I get from glibc is *** Error in 'sway': corrupted double-linked list: ) later, causing an Earth-shattering kaboom.
Here’s the log file. I used Lynx because I couldn’t figure out how to upload a file with my usual browser (though, I know, Lynx should be be usual browser; with Lynx, all I had to do was ^Xe:e ~/.sway.log<Return>VGy:e #1<Return>p:wq) and I seem not to have been logged into to github, so it’s anonymous gist. Hmm. https://gist.github.com/anonymous/fe18bb44c7d40d5d63fbf15427e70fdc
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (12 by maintainers)
@cauebs Use sway v0.15.1 release, which has all needed fixes.
The problem was in Sway actually… The current patch Fedora ships was a cludge to restore the faulty behaviour when double free’ing a json_object… (see: https://github.com/swaywm/sway/pull/1517/commits/f325e5e2c54228682c2fe919c5d143b16139194f)
The fixes needed for Sway are in #1517.
Just to clarify this a bit more: The real problem has been in Sway since https://github.com/swaywm/sway/commit/6392abe35b32c66c642c25a7c6911021862d3413. There was a bug in json_object_put() (which is the dtor function with ref-counting for a json_object) in all versions of json-c prior to v0.13, which camouflaged any invalid call of the dtor with an already destroyed json_object.
I will apply this set of patches to Sway in Fedora and update json-c to the correct patch, which prevents segfaults on double free and fails an assert instead.