|
Packit |
34410b |
/*
|
|
Packit |
34410b |
* Copyright (C) 2014 Intel Corporation
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
34410b |
* you may not use this file except in compliance with the License.
|
|
Packit |
34410b |
* You may obtain a copy of the License at
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
34410b |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
34410b |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
34410b |
* See the License for the specific language governing permissions and
|
|
Packit |
34410b |
* limitations under the License.
|
|
Packit |
34410b |
*
|
|
Packit |
34410b |
*/
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#include <stdio.h>
|
|
Packit |
34410b |
#include <stdlib.h>
|
|
Packit |
34410b |
#include <string.h>
|
|
Packit |
34410b |
#include <unistd.h>
|
|
Packit |
34410b |
#include <stdbool.h>
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#include <cutils/properties.h>
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#include "hal-utils.h"
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#define VALGRIND_BIN "/system/bin/valgrind"
|
|
Packit |
34410b |
|
|
Packit |
34410b |
#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main"
|
|
Packit |
34410b |
|
|
Packit |
34410b |
static void run_valgrind(int debug, int mgmt_dbg)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
char *prg_argv[7];
|
|
Packit |
34410b |
char *prg_envp[3];
|
|
Packit |
34410b |
|
|
Packit |
34410b |
prg_argv[0] = VALGRIND_BIN;
|
|
Packit |
34410b |
prg_argv[1] = "--leak-check=full";
|
|
Packit |
34410b |
prg_argv[2] = "--track-origins=yes";
|
|
Packit |
34410b |
prg_argv[3] = BLUETOOTHD_BIN;
|
|
Packit |
34410b |
prg_argv[4] = debug ? "-d" : NULL;
|
|
Packit |
34410b |
prg_argv[5] = mgmt_dbg ? "--mgmt-debug" : NULL;
|
|
Packit |
34410b |
prg_argv[6] = NULL;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
prg_envp[0] = "G_SLICE=always-malloc";
|
|
Packit |
34410b |
prg_envp[1] = "G_DEBUG=gc-friendly";
|
|
Packit |
34410b |
prg_envp[2] = NULL;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
execve(prg_argv[0], prg_argv, prg_envp);
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
static void run_bluetoothd(int debug, int mgmt_dbg)
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
char *prg_argv[4];
|
|
Packit |
34410b |
char *prg_envp[1];
|
|
Packit |
34410b |
|
|
Packit |
34410b |
prg_argv[0] = BLUETOOTHD_BIN;
|
|
Packit |
34410b |
prg_argv[1] = debug ? "-d" : NULL;
|
|
Packit |
34410b |
prg_argv[2] = mgmt_dbg ? "--mgmt-debug" : NULL;
|
|
Packit |
34410b |
prg_argv[3] = NULL;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
prg_envp[0] = NULL;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
execve(prg_argv[0], prg_argv, prg_envp);
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
int main(int argc, char *argv[])
|
|
Packit |
34410b |
{
|
|
Packit |
34410b |
char value[PROPERTY_VALUE_MAX];
|
|
Packit |
34410b |
int debug = 0;
|
|
Packit |
34410b |
int mgmt_dbg = 0;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (get_config("debug", value, NULL) > 0 &&
|
|
Packit |
34410b |
(!strcasecmp(value, "true") || atoi(value) > 0))
|
|
Packit |
34410b |
debug = 1;
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (get_config("mgmtdbg", value, NULL) > 0 &&
|
|
Packit |
34410b |
(!strcasecmp(value, "true") || atoi(value) > 0)) {
|
|
Packit |
34410b |
debug = 1;
|
|
Packit |
34410b |
mgmt_dbg = 1;
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if (get_config("valgrind", value, NULL) > 0 &&
|
|
Packit |
34410b |
(!strcasecmp(value, "true") || atoi(value) > 0))
|
|
Packit |
34410b |
run_valgrind(debug, mgmt_dbg);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
/*
|
|
Packit |
34410b |
* In case we failed to execute Valgrind, try to run bluetoothd
|
|
Packit |
34410b |
* without it
|
|
Packit |
34410b |
*/
|
|
Packit |
34410b |
run_bluetoothd(debug, mgmt_dbg);
|
|
Packit |
34410b |
|
|
Packit |
34410b |
return 0;
|
|
Packit |
34410b |
}
|