diff options
author | Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com> | 2014-02-11 15:28:54 +0100 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2014-02-11 17:31:39 +0100 |
commit | 1b7c044dc4540741b794bd19972763dee2f206b4 (patch) | |
tree | eaffac71a34ad012c19edd4b63268357c9db7b8b /android/bluetoothd-wrapper.c | |
parent | ba4702b2087ab89219b1ca2c0149c591c0343cfc (diff) | |
download | bluez-1b7c044dc4540741b794bd19972763dee2f206b4.tar.gz |
android: Add support for Valgrind in debug variants
This patch allows bluetoothd to be run with Valgrind easily in debug
variants.
For userdebug and eng variants bluetoothd is renamed to bluetoothd-main
and bluetoothd acts a wrapper to launch it either with or without
Valgrind (this is decided by value of persist.sys.bluetooth.valgrind
property).
Diffstat (limited to 'android/bluetoothd-wrapper.c')
-rw-r--r-- | android/bluetoothd-wrapper.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c new file mode 100644 index 000000000..122e6b0a3 --- /dev/null +++ b/android/bluetoothd-wrapper.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2014 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <cutils/properties.h> + +#define PROPERTY_NAME "persist.sys.bluetooth.valgrind" + +#define VALGRIND_BIN "/system/bin/valgrind" + +#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main" + +static void run_valgrind(void) +{ + char *prg_argv[4]; + char *prg_envp[3]; + + prg_argv[0] = VALGRIND_BIN; + prg_argv[1] = "--leak-check=full"; + prg_argv[2] = BLUETOOTHD_BIN; + prg_argv[3] = NULL; + + prg_envp[0] = "G_SLICE=always-malloc"; + prg_envp[1] = "G_DEBUG=gc-friendly"; + prg_envp[2] = NULL; + + execve(prg_argv[0], prg_argv, prg_envp); +} + +static void run_bluetoothd(void) +{ + char *prg_argv[2]; + char *prg_envp[1]; + + prg_argv[0] = BLUETOOTHD_BIN; + prg_argv[1] = NULL; + + prg_envp[0] = NULL; + + execve(prg_argv[0], prg_argv, prg_envp); +} + +int main(int argc, char *argv[]) +{ + char value[PROPERTY_VALUE_MAX]; + + if (property_get(PROPERTY_NAME, value, "") > 0 && + (!strcasecmp(value, "true") || atoi(value) > 0)) + run_valgrind(); + + /* In case we failed to execute Valgrind, try to run bluetoothd + * without it + */ + + run_bluetoothd(); + + return 0; +} |