unable to quit() daemon with multiple forks
When running multiple forks, e.g. kresd -f 2
, calling quit()
function on one of the the control sockets leads to infinite loop:
tty1$ kresd -f 2
tty2$ echo 'quit()' | socat - unix-client:tty/21894
tty1$ kresd -f 2
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
[system] ipc: File exists
...
One of the processes terminates sucessfully but the other one ends up in infinite loop.
Backtrace from the cycling process:
#0 0x00007f7073b78c30 in __write_nocancel () at ../sysdeps/unix/syscall-template.S:84
#1 0x00007f7073afba57 in _IO_new_file_write (f=0x7f7073e42500 <_IO_2_1_stderr_>, data=0x7ffccc738460, n=26) at fileops.c:1271
#2 0x00007f7073afc368 in new_do_write (to_do=<optimized out>, data=0x7ffccc738460 "[system] ipc: File exists\n", fp=0x7f7073e42500 <_IO_2_1_stderr_>) at fileops.c:526
#3 _IO_new_file_xsputn (f=0x7f7073e42500 <_IO_2_1_stderr_>, data=<optimized out>, n=26) at fileops.c:1350
#4 0x00007f7073ad1a45 in buffered_vfprintf (s=0x7f7073e42500 <_IO_2_1_stderr_>, format=<optimized out>, args=<optimized out>) at vfprintf.c:2346
#5 0x00007f7073acebf5 in _IO_vfprintf_internal (s=0x7f7073e42500 <_IO_2_1_stderr_>, format=0x558653b144fa "[system] ipc: %s\n", ap=ap@entry=0x7ffccc73a9f8)
at vfprintf.c:1293
#6 0x00007f7073ad7677 in __fprintf (stream=<optimized out>, format=<optimized out>) at fprintf.c:32
#7 0x0000558653b0bf9c in ipc_activity (handle=0x55865560d1e0, status=0, events=1) at daemon/main.c:221
#8 0x00007f7074f84938 in uv.io_poll () from /lib64/libuv.so.1
#9 0x00007f7074f762d4 in uv_run () from /lib64/libuv.so.1
#10 0x0000558653b0c621 in run_worker (loop=0x7f707518f220, engine=0x7ffccc73dfa0, ipc_set=0x7ffccc73e1a0, leader=false, control_fd=-1) at daemon/main.c:367
#11 0x0000558653b0da83 in main (argc=3, argv=0x7ffccc73e568) at daemon/main.c:692
The problem apparently comes from ipc_readall()
:
#0 ipc_readall (fd=10, dst=0x7ffccc73aaf4 "", len=4) at daemon/main.c:169
#1 0x0000558653b0bda4 in ipc_activity (handle=0x55865560d1e0, status=0, events=1) at daemon/main.c:189
#2 0x00007f7074f84938 in uv__io_poll (loop=loop@entry=0x7f707518f220 <default_loop_struct>, timeout=17425) at src/unix/linux-core.c:382
#3 0x00007f7074f762d4 in uv_run (loop=0x7f707518f220 <default_loop_struct>, mode=UV_RUN_DEFAULT) at src/unix/core.c:352
#4 0x0000558653b0c621 in run_worker (loop=0x7f707518f220 <default_loop_struct>, engine=0x7ffccc73dfa0, ipc_set=0x7ffccc73e1a0, leader=false, control_fd=-1)
at daemon/main.c:367
#5 0x0000558653b0da83 in main (argc=3, argv=0x7ffccc73e568) at daemon/main.c:692
In function static bool ipc_readall(int fd, char *dst, size_t len)
the read()
returns 0
but len
parameter is 4:
(gdb) frame
#0 ipc_readall (fd=10, dst=0x7ffccc73aaf4 "", len=4) at daemon/main.c:169
(gdb) bt full
#0 ipc_readall (fd=10, dst=0x7ffccc73aaf4 "", len=4) at daemon/main.c:169
rb = 0
#1 0x0000558653b0bda4 in ipc_activity (handle=0x55865560d1e0, status=0, events=1) at daemon/main.c:189
engine = 0x7ffccc73dfa0
fd = 10
len = 0
Affected version: 1.2.1, c664f007