From: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Subject: dsprpcd: fix daemon restart behavior for SIGTERM and ENOMEM
Description: dsprpcd: fix daemon restart behavior for SIGTERM and ENOMEM
 Exit the internal restart loop on AEE_ENOMEMORY so the daemon does not
 spin indefinitely when the kernel reports OOM; it is pointless to retry
 in that condition.
 .
 Add RestartForceExitStatus=SIGTERM to all service files so that an
 unintended SIGTERM (e.g. pkill) is treated as a failure and triggers a
 restart, consistent with SIGKILL behavior.
 .
 Add RestartPreventExitStatus=2 (AEE_ENOMEMORY) to the audiopd service
 only, since the kernel returns ENOMEM when the remote heap DMA region is
 not configured, which is a permanent condition that restarting cannot
 recover from.
 .
 Without this, adsprpcd_audiopd.service is restarted endlessly on boards
 whose device tree lacks the audio remote heap DMA region, which was
 observed to send RB1 (Agatti) into a reboot loop with mainline kernels.
 .
 Debian delta relative to the upstream commit: upstream writes the
 audiopd setting as
 .
   RestartPreventExitStatus=2  # AEE_ENOMEMORY
 .
 but systemd unit files do not support trailing comments, so systemd
 fails to parse the value and ignores the setting; the comment is moved
 to a line of its own here. To be reported upstream.
Author: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Origin: upstream, https://github.com/qualcomm/fastrpc/commit/cd0c0dbbfef8ae950f9ebb4483a9b0192d8fb6a6
Bug: https://github.com/qualcomm/fastrpc/issues/370
Applied-Upstream: cd0c0dbbfef8ae950f9ebb4483a9b0192d8fb6a6
Last-Update: 2026-08-13

--- a/files/adsprpcd.service.in
+++ b/files/adsprpcd.service.in
@@ -9,3 +9,4 @@ Type=exec
 ExecStart=@sbindir@/adsprpcd
 Restart=on-failure
 RestartSec=5
+RestartForceExitStatus=SIGTERM
--- a/files/adsprpcd_audiopd.service.in
+++ b/files/adsprpcd_audiopd.service.in
@@ -9,3 +9,6 @@ Type=exec
 ExecStart=@sbindir@/adsprpcd audiopd
 Restart=on-failure
 RestartSec=5
+# AEE_ENOMEMORY
+RestartPreventExitStatus=2
+RestartForceExitStatus=SIGTERM
--- a/files/cdsp1rpcd.service.in
+++ b/files/cdsp1rpcd.service.in
@@ -9,3 +9,4 @@ Type=exec
 ExecStart=@sbindir@/cdsprpcd rootpd cdsp1
 Restart=on-failure
 RestartSec=5
+RestartForceExitStatus=SIGTERM
--- a/files/cdsprpcd.service.in
+++ b/files/cdsprpcd.service.in
@@ -9,3 +9,4 @@ Type=exec
 ExecStart=@sbindir@/cdsprpcd
 Restart=on-failure
 RestartSec=5
+RestartForceExitStatus=SIGTERM
--- a/files/gdsp0rpcd.service.in
+++ b/files/gdsp0rpcd.service.in
@@ -9,3 +9,4 @@ Type=exec
 ExecStart=@sbindir@/gdsprpcd rootpd gdsp0
 Restart=on-failure
 RestartSec=5
+RestartForceExitStatus=SIGTERM
--- a/files/gdsp1rpcd.service.in
+++ b/files/gdsp1rpcd.service.in
@@ -9,3 +9,4 @@ Type=exec
 ExecStart=@sbindir@/gdsprpcd rootpd gdsp1
 Restart=on-failure
 RestartSec=5
+RestartForceExitStatus=SIGTERM
--- a/files/sdsprpcd.service.in
+++ b/files/sdsprpcd.service.in
@@ -9,3 +9,4 @@ Type=exec
 ExecStart=@sbindir@/sdsprpcd
 Restart=on-failure
 RestartSec=5
+RestartForceExitStatus=SIGTERM
--- a/src/dsprpcd.c
+++ b/src/dsprpcd.c
@@ -194,6 +194,10 @@ int main(int argc, char *argv[]) {
             VERIFY_EPRINTF("fastRPC device is not accessible, daemon exiting...");
             break;
         }
+        if (nErr == AEE_ENOMEMORY) {
+            VERIFY_EPRINTF("out of memory, daemon exiting without restart...");
+            break;
+        }
 
         VERIFY_EPRINTF("%s daemon will restart after 100ms...", dsp_name);
         usleep(100000);
