blob: 0d62a7abad3273eadb15b8670acdfc6bb0ec46e6 [file] [log] [blame]
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogerscf7f1912014-10-22 22:06:39 -070017#include <stdio.h>
18#include <stdlib.h>
19
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070020#ifdef HAVE_ANDROID_OS
21#include <android/log.h>
22#else
23#include <stdarg.h>
24#include <iostream>
25#endif
26
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070027#include "sigchain.h"
28
Andreas Gampe9d9cfa82014-11-03 20:25:24 -080029#define ATTRIBUTE_UNUSED __attribute__((__unused__))
30
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070031static void log(const char* format, ...) {
32 char buf[256];
33 va_list ap;
34 va_start(ap, format);
35 vsnprintf(buf, sizeof(buf), format, ap);
36#ifdef HAVE_ANDROID_OS
37 __android_log_write(ANDROID_LOG_ERROR, "libsigchain", buf);
38#else
39 std::cout << buf << "\n";
40#endif
41 va_end(ap);
42}
43
Andreas Gampe9d9cfa82014-11-03 20:25:24 -080044extern "C" void ClaimSignalChain(int signal ATTRIBUTE_UNUSED,
45 struct sigaction* oldaction ATTRIBUTE_UNUSED) {
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070046 log("ClaimSignalChain is not exported by the main executable.");
47 abort();
48}
49
Andreas Gampe9d9cfa82014-11-03 20:25:24 -080050extern "C" void UnclaimSignalChain(int signal ATTRIBUTE_UNUSED) {
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070051 log("UnclaimSignalChain is not exported by the main executable.");
52 abort();
53}
54
Andreas Gampe9d9cfa82014-11-03 20:25:24 -080055extern "C" void InvokeUserSignalHandler(int sig ATTRIBUTE_UNUSED,
56 siginfo_t* info ATTRIBUTE_UNUSED,
57 void* context ATTRIBUTE_UNUSED) {
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070058 log("InvokeUserSignalHandler is not exported by the main executable.");
59 abort();
60}
61
62extern "C" void InitializeSignalChain() {
63 log("InitializeSignalChain is not exported by the main executable.");
64 abort();
65}
Mathieu Chartierd0004802014-10-15 16:59:47 -070066
Andreas Gampe9d9cfa82014-11-03 20:25:24 -080067extern "C" void EnsureFrontOfChain(int signal ATTRIBUTE_UNUSED,
68 struct sigaction* expected_action ATTRIBUTE_UNUSED) {
Mathieu Chartierd0004802014-10-15 16:59:47 -070069 log("EnsureFrontOfChain is not exported by the main executable.");
70 abort();
71}