#1720 PR merged: Clean termination of descendant processes (issue 1712)

Labels: enhancement, bug, cleanup, fixed / solved / done

jsmeix opened issue at 2018-01-31 16:04:

In lib/_input-output-functions.sh
there is now a new function descendants_pids()
that outputs PIDs of all descendant processes of a parent process PID
where the output lists latest descendants PIDs first and the initial parent PID last
(i.e. great-grandchildren PIDs, grandchildren PIDs, children PIDs, parent PID)
so that the output ordering is already the right ordering to cleanly terminate
a sub-tree of processes below a parent process and finally the parent process
and this termination functionality is used in the DoExitTasks() function
to do a clean termination of descendant processes that should fix
https://github.com/rear/rear/issues/1712

jsmeix commented at 2018-02-01 14:28:

Now the code looks o.k. to me and works well for me,
e.g. for Ctrl+C during archive operation

# usr/sbin/rear -D mkbackup
...
Preparing archive operation
Archived 50 MiB [avg 10278 KiB/sec] 
Archived 72 MiB [avg 9238 KiB/sec] 
^C
Exiting rear mkbackup (PID 24531) and its descendant processes
Terminating descendant process 10440 dd of=/tmp/rear.B23O3b7Z1uz0AJu/outputfs/f48/backup.tar.gz
Running exit tasks
You should also rm -Rf /tmp/rear.B23O3b7Z1uz0AJu
rear mkbackup failed, check /root/rear.master.issue1712/var/log/rear/rear-f48.log for details

versus normal finishing

# usr/sbin/rear -D mkbackup
...
Preparing archive operation
Archived 50 MiB [avg 10249 KiB/sec] 
Archived 72 MiB [avg 8211 KiB/sec] 
...
Archived 877 MiB [avg 7077 KiB/sec] 
OK
Archived 877 MiB in 130 seconds [avg 6914 KiB/sec]
Exiting rear mkbackup (PID 11037) and its descendant processes
Running exit tasks
You should also rm -Rf /tmp/rear.kKD2z4RXQSFznIa

jsmeix commented at 2018-02-06 12:43:

If there are no serious objections I will merge it later today
because I think it is at least a good step in the right direction.

jsmeix commented at 2019-09-27 11:21:

Via
https://github.com/rear/rear/commit/856262d3ddda695bf14f1deb57c436061b739852
I set a fallback value when the shell variable COLUMNS is not defined
(e.g. in noninteractive bash)
cf. https://github.com/rear/rear/pull/1720#discussion_r328686592

@pcahyna
I could not test my change so I would much appreciate it
if you could verify if things behave now more fail safe.

jsmeix commented at 2019-09-27 11:34:

https://github.com/rear/rear/commit/2383d2f77cf4f6819e702a695a7f950cff57a62c
is a fix for my last fix.


[Export of Github issue for rear/rear.]