[libcamera-devel,v2] utils: ipc: Assign a new gid to proxy worker
diff mbox series

Message ID 20210727042750.13525-1-umang.jain@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,v2] utils: ipc: Assign a new gid to proxy worker
Related show

Commit Message

Umang Jain July 27, 2021, 4:27 a.m. UTC
Isolated IPAs are forked to a new process by the proxy worker, which
shares the same process group. This allows the undesired effect that
the proxy worker will receive signals such as SIGINT and will be closed
by a Ctrl-C event before the pipeline handlers have been able to fully
clean up.

Prevent this signal from being delivered to the proxy worker by moving
the process to a new process group, matching the pid of the isolated
proxy.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=60
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
v1 -> v2:
- Revamp commit message.
- Fix a typo in `if` condition check.
---
 .../module_ipa_proxy_worker.cpp.tmpl                 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch
diff mbox series

diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl
index d993e39e..fa529f2c 100644
--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl
+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl
@@ -207,6 +207,18 @@  int main(int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
+	/*
+	 * Shutdown of proxy worker can be preempt by events like
+	 * SIGINT/SIGTERM, even before the pipeline handler can request
+	 * shutdown. Hence, assign a new gid to prevent signals on the
+	 * application being delivered to the proxy.
+	 */
+	if (setpgid(0, 0) < 0) {
+		int err = errno;
+		LOG({{proxy_worker_name}}, Warning)
+			<< "Failed to set new gid: " << strerror(err);
+	}
+
 	{{proxy_worker_name}} proxyWorker;
 	int ret = proxyWorker.init(ipam, fd);
 	if (ret < 0) {