all: make procd "ctrld stop" blocks until process exited

Since procd does not block when init scripts execute stop operation, it
causes ctrld command callers (the installer, users ...) thought that
ctrld process was exited, while it does not.

See: https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2024-05-16 14:35:42 +07:00
1 parent 486096416f
commit f3dd344026
3 files changed
+23

No files matched your search

+17
View File
@@ -449,6 +449,23 @@ func initCLI() {
if doTasks([]task{{s.Stop, true}}) {
p.router.Cleanup()
p.resetDNS()
if router.WaitProcessExited() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
for {
select {
case <-ctx.Done():
mainLog.Load().Error().Msg("timeout while waiting for service to stop")
return
default:
}
time.Sleep(time.Second)
if status, _ := s.Status(); status == service.StatusStopped {
break
}
}
}
mainLog.Load().Notice().Msg("Service stopped")
}
},