ctdb-locking: Fix lock helper handling when ctdbd is PID 1

Fix bug https://bugzilla.samba.org/show_bug.cgi?id=16292

When ctdbd runs as PID 1, for example in a container, it crashes on the first database freeze, i.e. the first recovery with a database attached. This was reported by @phlogistonjohn in 2021:

https://lists.samba.org/archive/samba-technical/2021-July/136743.html

See the commit messages for details of the issues and fixes.

I used Claude Opus 5.5, via Claude Code, to do most of the heavy lifting. The details are interesting...

While looking at another task related to child process re-parenting, Claude analysed the CTDB code for similar issues. It reported that this code shares a "PPID is 1" check but it is different and should be removed because it is simply wrong! So, I explained that there is a known crash related to this and gave it John's original crash report. It analysed the backtrace, reproduced the crash on master (using ctdbd as PID 1 under unshare, which was cool!) and fixed the initial bug in a similar way to what John suggested back in 2021. Claude was keen to remove the "PPID is 1" check but I wanted something to replace it, so I suggested using a failed write of the the result to know that ctdbd has disappeared early and let Claude construct the relevant stream of bytes. Apart from some minor changes suggested by me, Claude wrote the new tests and then pointed out that there is a cosmetic bug in the lock helper's cleanup() function, so it created a fix, which I tweaked to keep it short. Claude writes surprisingly good, brief commit messages. I tweaked where appropriate, adding detail in some places where I thought subtle things needed more explanation.

It would probably have been a couple more years before I got that far back in my inbox without prompting and thought seriously about fixing this...

Checklist

  • Commits have Signed-off-by: with name/author being identical to the commit author
  • (optional) This MR is just one part towards a larger feature.
  • (optional, if backport required) Bugzilla bug filed and BUG: tag added
  • Test suite updated with functionality tests
  • Test suite updated with negative tests
  • Documentation updated
  • CI timeout is 3h or higher (see Settings/CICD/General pipelines/ Timeout)

Reviewer's checklist:

  • There is a test suite reasonably covering new functionality or modifications
  • Function naming, parameters, return values, types, etc., are consistent and according to README.Coding.md
  • This feature/change has adequate documentation added
  • No obvious mistakes in the code

Merge request reports

Loading
Loading