Skip to content

Commit

Permalink
[swss.sh/syncd.sh] Trap only on EXIT (#11590)
Browse files Browse the repository at this point in the history
When using trap on SIGTERM the script will not react to the SIGTERM signal sent while a child is executing.
I.e, the following script does not react on SIGTERM sent to it if it is
waiting for sleep to finish:

```

trap "echo Handled SIGTERM" 0 2 3 15

echo "Before sleep"
sleep inf
echo "After sleep"
```

Instead, trap only on EXIT which covers also a scenario with exit on
SIGINT, SIGTERM.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored and qiluo-msft committed Aug 11, 2022
1 parent cd48081 commit 8ab448a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function lock_service_state_change()

exec {LOCKFD}>${LOCKFILE}
/usr/bin/flock -x ${LOCKFD}
trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15
trap "/usr/bin/flock -u ${LOCKFD}" EXIT

debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service"
}
Expand Down
6 changes: 3 additions & 3 deletions files/scripts/syncd_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#
# common functions used by "syncd" scipts (syncd.sh, gbsyncd.sh, etc..)
# scripts using this must provide implementations of the following functions:
#
#
# startplatform
# waitplatform
# stopplatform1 and stopplatform2
#
#
# For examples of these, see gbsyncd.sh and syncd.sh.
#

Expand All @@ -23,7 +23,7 @@ function lock_service_state_change()

exec {LOCKFD}>${LOCKFILE}
/usr/bin/flock -x ${LOCKFD}
trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15
trap "/usr/bin/flock -u ${LOCKFD}" EXIT

debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service"
}
Expand Down

0 comments on commit 8ab448a

Please sign in to comment.