blob: 063b8c35294cbd5503d1fc72583c2fc178b9f0a7 [file] [log] [blame]
Juan Pablo Conde64f59be2024-01-12 16:56:58 -06001#!/usr/bin/env bash
2#
3# Copyright (c) 2024, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Launch a program. Have its PID saved in a file with given name with .pid
9# suffix. When the program exits, create a file with .success suffix, or one
10# with .fail if it fails. This function blocks, so the caller must '&' this if
11# they want to continue. Call must wait for $pid_dir/$name.pid to be created
12# should it want to read it.
13launch() {
14 local pid
15
16 "$@" &
17 pid="$!"
18 echo "$pid" > "$pid_dir/${name:?}.pid"
19 if wait "$pid"; then
20 touch "$pid_dir/$name.success"
21 else
22 touch "$pid_dir/$name.fail"
23 fi
24}
25
26# Provide signal as an argument to the trap function.
27trap_with_sig() {
28 local func
29
30 func="$1" ; shift
31 for sig ; do
32 trap "$func $sig" "$sig"
33 done
34}