3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2013-2018 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file sets up signalling for all POSIX CHIP Inet layer library test
22 * applications and tools.
24 * NOTE: These do not comprise a public part of the CHIP API and
25 * are subject to change without notice.
29 #include "TestSetupSignalling.h"
36 static void ExitOnSIGUSR1Handler(int signum)
38 // exit() allows us a slightly better clean up (gcov data) than SIGINT's exit
42 // We set a hook to exit when we receive SIGUSR1, SIGTERM or SIGHUP
43 void SetSIGUSR1Handler()
45 SetSignalHandler(ExitOnSIGUSR1Handler);
48 void SetSignalHandler(SignalHandler handler)
51 int signals[] = { SIGUSR1 };
54 memset(&sa, 0, sizeof(sa));
55 sa.sa_handler = handler;
57 for (i = 0; i < sizeof(signals) / sizeof(signals[0]); i++)
59 if (sigaction(signals[i], &sa, nullptr) == -1)
61 perror("Can't catch signal");