Merge "Remove liblogcat."
This commit is contained in:
commit
28a3160c07
13 changed files with 108 additions and 1065 deletions
|
|
@ -1,11 +0,0 @@
|
||||||
BasedOnStyle: Google
|
|
||||||
AllowShortFunctionsOnASingleLine: false
|
|
||||||
|
|
||||||
CommentPragmas: NOLINT:.*
|
|
||||||
DerivePointerAlignment: false
|
|
||||||
IndentWidth: 4
|
|
||||||
PointerAlignment: Left
|
|
||||||
TabWidth: 4
|
|
||||||
PenaltyExcessCharacter: 32
|
|
||||||
|
|
||||||
Cpp11BracedListStyle: false
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// Copyright (C) 2006-2017 The Android Open Source Project
|
// Copyright (C) 2006 The Android Open Source Project
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,25 +31,13 @@ cc_defaults {
|
||||||
logtags: ["event.logtags"],
|
logtags: ["event.logtags"],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_library {
|
|
||||||
name: "liblogcat",
|
|
||||||
|
|
||||||
defaults: ["logcat_defaults"],
|
|
||||||
srcs: [
|
|
||||||
"logcat.cpp",
|
|
||||||
"getopt_long.cpp",
|
|
||||||
"logcat_system.cpp",
|
|
||||||
],
|
|
||||||
export_include_dirs: ["include"],
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_binary {
|
cc_binary {
|
||||||
name: "logcat",
|
name: "logcat",
|
||||||
|
|
||||||
defaults: ["logcat_defaults"],
|
defaults: ["logcat_defaults"],
|
||||||
shared_libs: ["liblogcat"],
|
|
||||||
srcs: [
|
srcs: [
|
||||||
"logcat_main.cpp",
|
"logcat_main.cpp",
|
||||||
|
"logcat.cpp",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,9 +45,9 @@ cc_binary {
|
||||||
name: "logcatd",
|
name: "logcatd",
|
||||||
|
|
||||||
defaults: ["logcat_defaults"],
|
defaults: ["logcat_defaults"],
|
||||||
shared_libs: ["liblogcat"],
|
|
||||||
srcs: [
|
srcs: [
|
||||||
"logcatd_main.cpp",
|
"logcatd_main.cpp",
|
||||||
|
"logcat.cpp",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,401 +0,0 @@
|
||||||
/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
|
|
||||||
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* Sponsored in part by the Defense Advanced Research Projects
|
|
||||||
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
|
||||||
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
|
||||||
*/
|
|
||||||
/*-
|
|
||||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
|
||||||
* by Dieter Baron and Thomas Klausner.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
#include <log/getopt.h>
|
|
||||||
|
|
||||||
#define PRINT_ERROR ((context->opterr) && (*options != ':'))
|
|
||||||
|
|
||||||
#define FLAG_PERMUTE 0x01 // permute non-options to the end of argv
|
|
||||||
#define FLAG_ALLARGS 0x02 // treat non-options as args to option "-1"
|
|
||||||
|
|
||||||
// return values
|
|
||||||
#define BADCH (int)'?'
|
|
||||||
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
|
|
||||||
#define INORDER (int)1
|
|
||||||
|
|
||||||
#define D_PREFIX 0
|
|
||||||
#define DD_PREFIX 1
|
|
||||||
#define W_PREFIX 2
|
|
||||||
|
|
||||||
// Compute the greatest common divisor of a and b.
|
|
||||||
static int gcd(int a, int b) {
|
|
||||||
int c = a % b;
|
|
||||||
while (c) {
|
|
||||||
a = b;
|
|
||||||
b = c;
|
|
||||||
c = a % b;
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exchange the block from nonopt_start to nonopt_end with the block from
|
|
||||||
// nonopt_end to opt_end (keeping the same order of arguments in each block).
|
|
||||||
// Returns optind - (nonopt_end - nonopt_start) for convenience.
|
|
||||||
static int permute_args(getopt_context* context, char* const* nargv) {
|
|
||||||
// compute lengths of blocks and number and size of cycles
|
|
||||||
int nnonopts = context->nonopt_end - context->nonopt_start;
|
|
||||||
int nopts = context->optind - context->nonopt_end;
|
|
||||||
int ncycle = gcd(nnonopts, nopts);
|
|
||||||
int cyclelen = (context->optind - context->nonopt_start) / ncycle;
|
|
||||||
|
|
||||||
for (int i = 0; i < ncycle; i++) {
|
|
||||||
int cstart = context->nonopt_end + i;
|
|
||||||
int pos = cstart;
|
|
||||||
for (int j = 0; j < cyclelen; j++) {
|
|
||||||
if (pos >= context->nonopt_end) {
|
|
||||||
pos -= nnonopts;
|
|
||||||
} else {
|
|
||||||
pos += nopts;
|
|
||||||
}
|
|
||||||
char* swap = nargv[pos];
|
|
||||||
const_cast<char**>(nargv)[pos] = nargv[cstart];
|
|
||||||
const_cast<char**>(nargv)[cstart] = swap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return context->optind - (context->nonopt_end - context->nonopt_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse_long_options_r --
|
|
||||||
// Parse long options in argc/argv argument vector.
|
|
||||||
// Returns -1 if short_too is set and the option does not match long_options.
|
|
||||||
static int parse_long_options_r(char* const* nargv, const char* options,
|
|
||||||
const struct option* long_options, int* idx,
|
|
||||||
bool short_too, struct getopt_context* context) {
|
|
||||||
const char* current_argv = context->place;
|
|
||||||
const char* current_dash;
|
|
||||||
switch (context->dash_prefix) {
|
|
||||||
case D_PREFIX:
|
|
||||||
current_dash = "-";
|
|
||||||
break;
|
|
||||||
case DD_PREFIX:
|
|
||||||
current_dash = "--";
|
|
||||||
break;
|
|
||||||
case W_PREFIX:
|
|
||||||
current_dash = "-W ";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
current_dash = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
context->optind++;
|
|
||||||
|
|
||||||
const char* has_equal;
|
|
||||||
size_t current_argv_len;
|
|
||||||
if (!!(has_equal = strchr(current_argv, '='))) {
|
|
||||||
// argument found (--option=arg)
|
|
||||||
current_argv_len = has_equal - current_argv;
|
|
||||||
has_equal++;
|
|
||||||
} else {
|
|
||||||
current_argv_len = strlen(current_argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
int match = -1;
|
|
||||||
bool exact_match = false;
|
|
||||||
bool second_partial_match = false;
|
|
||||||
for (int i = 0; long_options[i].name; i++) {
|
|
||||||
// find matching long option
|
|
||||||
if (strncmp(current_argv, long_options[i].name, current_argv_len)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(long_options[i].name) == current_argv_len) {
|
|
||||||
// exact match
|
|
||||||
match = i;
|
|
||||||
exact_match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If this is a known short option, don't allow
|
|
||||||
// a partial match of a single character.
|
|
||||||
if (short_too && current_argv_len == 1) continue;
|
|
||||||
|
|
||||||
if (match == -1) { // first partial match
|
|
||||||
match = i;
|
|
||||||
} else if (long_options[i].has_arg != long_options[match].has_arg ||
|
|
||||||
long_options[i].flag != long_options[match].flag ||
|
|
||||||
long_options[i].val != long_options[match].val) {
|
|
||||||
second_partial_match = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!exact_match && second_partial_match) {
|
|
||||||
// ambiguous abbreviation
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr,
|
|
||||||
"option `%s%.*s' is ambiguous", current_dash,
|
|
||||||
(int)current_argv_len, current_argv);
|
|
||||||
}
|
|
||||||
context->optopt = 0;
|
|
||||||
return BADCH;
|
|
||||||
}
|
|
||||||
if (match != -1) { // option found
|
|
||||||
if (long_options[match].has_arg == no_argument && has_equal) {
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr,
|
|
||||||
"option `%s%.*s' doesn't allow an argument",
|
|
||||||
current_dash, (int)current_argv_len, current_argv);
|
|
||||||
}
|
|
||||||
// XXX: GNU sets optopt to val regardless of flag
|
|
||||||
context->optopt =
|
|
||||||
long_options[match].flag ? 0 : long_options[match].val;
|
|
||||||
return BADCH;
|
|
||||||
}
|
|
||||||
if (long_options[match].has_arg == required_argument ||
|
|
||||||
long_options[match].has_arg == optional_argument) {
|
|
||||||
if (has_equal) {
|
|
||||||
context->optarg = has_equal;
|
|
||||||
} else if (long_options[match].has_arg == required_argument) {
|
|
||||||
// optional argument doesn't use next nargv
|
|
||||||
context->optarg = nargv[context->optind++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((long_options[match].has_arg == required_argument) &&
|
|
||||||
!context->optarg) {
|
|
||||||
// Missing argument; leading ':' indicates no error
|
|
||||||
// should be generated.
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr,
|
|
||||||
"option `%s%s' requires an argument", current_dash,
|
|
||||||
current_argv);
|
|
||||||
}
|
|
||||||
// XXX: GNU sets optopt to val regardless of flag
|
|
||||||
context->optopt =
|
|
||||||
long_options[match].flag ? 0 : long_options[match].val;
|
|
||||||
context->optind--;
|
|
||||||
return BADARG;
|
|
||||||
}
|
|
||||||
} else { // unknown option
|
|
||||||
if (short_too) {
|
|
||||||
context->optind--;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr, "unrecognized option `%s%s'",
|
|
||||||
current_dash, current_argv);
|
|
||||||
}
|
|
||||||
context->optopt = 0;
|
|
||||||
return BADCH;
|
|
||||||
}
|
|
||||||
if (idx) *idx = match;
|
|
||||||
if (long_options[match].flag) {
|
|
||||||
*long_options[match].flag = long_options[match].val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return long_options[match].val;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getopt_long_r --
|
|
||||||
// Parse argc/argv argument vector.
|
|
||||||
int getopt_long_r(int nargc, char* const* nargv, const char* options,
|
|
||||||
const struct option* long_options, int* idx,
|
|
||||||
struct getopt_context* context) {
|
|
||||||
if (!options) return -1;
|
|
||||||
|
|
||||||
// XXX Some GNU programs (like cvs) set optind to 0 instead of
|
|
||||||
// XXX using optreset. Work around this braindamage.
|
|
||||||
if (!context->optind) context->optind = context->optreset = 1;
|
|
||||||
|
|
||||||
// Disable GNU extensions if options string begins with a '+'.
|
|
||||||
int flags = FLAG_PERMUTE;
|
|
||||||
if (*options == '-') {
|
|
||||||
flags |= FLAG_ALLARGS;
|
|
||||||
} else if (*options == '+') {
|
|
||||||
flags &= ~FLAG_PERMUTE;
|
|
||||||
}
|
|
||||||
if (*options == '+' || *options == '-') options++;
|
|
||||||
|
|
||||||
context->optarg = nullptr;
|
|
||||||
if (context->optreset) context->nonopt_start = context->nonopt_end = -1;
|
|
||||||
start:
|
|
||||||
if (context->optreset || !*context->place) { // update scanning pointer
|
|
||||||
context->optreset = 0;
|
|
||||||
if (context->optind >= nargc) { // end of argument vector
|
|
||||||
context->place = EMSG;
|
|
||||||
if (context->nonopt_end != -1) {
|
|
||||||
// do permutation, if we have to
|
|
||||||
context->optind = permute_args(context, nargv);
|
|
||||||
} else if (context->nonopt_start != -1) {
|
|
||||||
// If we skipped non-options, set optind to the first of them.
|
|
||||||
context->optind = context->nonopt_start;
|
|
||||||
}
|
|
||||||
context->nonopt_start = context->nonopt_end = -1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (*(context->place = nargv[context->optind]) != '-' ||
|
|
||||||
context->place[1] == '\0') {
|
|
||||||
context->place = EMSG; // found non-option
|
|
||||||
if (flags & FLAG_ALLARGS) {
|
|
||||||
// GNU extension: return non-option as argument to option 1
|
|
||||||
context->optarg = nargv[context->optind++];
|
|
||||||
return INORDER;
|
|
||||||
}
|
|
||||||
if (!(flags & FLAG_PERMUTE)) {
|
|
||||||
// If no permutation wanted, stop parsing at first non-option.
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// do permutation
|
|
||||||
if (context->nonopt_start == -1) {
|
|
||||||
context->nonopt_start = context->optind;
|
|
||||||
} else if (context->nonopt_end != -1) {
|
|
||||||
context->nonopt_start = permute_args(context, nargv);
|
|
||||||
context->nonopt_end = -1;
|
|
||||||
}
|
|
||||||
context->optind++;
|
|
||||||
// process next argument
|
|
||||||
goto start;
|
|
||||||
}
|
|
||||||
if (context->nonopt_start != -1 && context->nonopt_end == -1) {
|
|
||||||
context->nonopt_end = context->optind;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have "-" do nothing, if "--" we are done.
|
|
||||||
if (context->place[1] != '\0' && *++(context->place) == '-' &&
|
|
||||||
context->place[1] == '\0') {
|
|
||||||
context->optind++;
|
|
||||||
context->place = EMSG;
|
|
||||||
// We found an option (--), so if we skipped
|
|
||||||
// non-options, we have to permute.
|
|
||||||
if (context->nonopt_end != -1) {
|
|
||||||
context->optind = permute_args(context, nargv);
|
|
||||||
}
|
|
||||||
context->nonopt_start = context->nonopt_end = -1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int optchar;
|
|
||||||
// Check long options if:
|
|
||||||
// 1) we were passed some
|
|
||||||
// 2) the arg is not just "-"
|
|
||||||
// 3) either the arg starts with -- we are getopt_long_only()
|
|
||||||
if (long_options && context->place != nargv[context->optind] &&
|
|
||||||
(*context->place == '-')) {
|
|
||||||
bool short_too = false;
|
|
||||||
context->dash_prefix = D_PREFIX;
|
|
||||||
if (*context->place == '-') {
|
|
||||||
context->place++; // --foo long option
|
|
||||||
context->dash_prefix = DD_PREFIX;
|
|
||||||
} else if (*context->place != ':' && strchr(options, *context->place)) {
|
|
||||||
short_too = true; // could be short option too
|
|
||||||
}
|
|
||||||
|
|
||||||
optchar = parse_long_options_r(nargv, options, long_options, idx,
|
|
||||||
short_too, context);
|
|
||||||
if (optchar != -1) {
|
|
||||||
context->place = EMSG;
|
|
||||||
return optchar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* oli; // option letter list index
|
|
||||||
if ((optchar = (int)*(context->place)++) == (int)':' ||
|
|
||||||
(optchar == (int)'-' && *context->place != '\0') ||
|
|
||||||
!(oli = strchr(options, optchar))) {
|
|
||||||
// If the user specified "-" and '-' isn't listed in
|
|
||||||
// options, return -1 (non-option) as per POSIX.
|
|
||||||
// Otherwise, it is an unknown option character (or ':').
|
|
||||||
if (optchar == (int)'-' && *context->place == '\0') return -1;
|
|
||||||
if (!*context->place) context->optind++;
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr, "invalid option -- %c",
|
|
||||||
optchar);
|
|
||||||
}
|
|
||||||
context->optopt = optchar;
|
|
||||||
return BADCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char recargchar[] = "option requires an argument -- %c";
|
|
||||||
if (long_options && optchar == 'W' && oli[1] == ';') {
|
|
||||||
// -W long-option
|
|
||||||
if (*context->place) { // no space
|
|
||||||
; // NOTHING
|
|
||||||
} else if (++(context->optind) >= nargc) { // no arg
|
|
||||||
context->place = EMSG;
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr, recargchar, optchar);
|
|
||||||
}
|
|
||||||
context->optopt = optchar;
|
|
||||||
return BADARG;
|
|
||||||
} else { // white space
|
|
||||||
context->place = nargv[context->optind];
|
|
||||||
}
|
|
||||||
context->dash_prefix = W_PREFIX;
|
|
||||||
optchar = parse_long_options_r(nargv, options, long_options, idx, false,
|
|
||||||
context);
|
|
||||||
context->place = EMSG;
|
|
||||||
return optchar;
|
|
||||||
}
|
|
||||||
if (*++oli != ':') { // doesn't take argument
|
|
||||||
if (!*context->place) context->optind++;
|
|
||||||
} else { // takes (optional) argument
|
|
||||||
context->optarg = nullptr;
|
|
||||||
if (*context->place) { // no white space
|
|
||||||
context->optarg = context->place;
|
|
||||||
} else if (oli[1] != ':') { // arg not optional
|
|
||||||
if (++(context->optind) >= nargc) { // no arg
|
|
||||||
context->place = EMSG;
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
fprintf(context->optstderr ?: stderr, recargchar, optchar);
|
|
||||||
}
|
|
||||||
context->optopt = optchar;
|
|
||||||
return BADARG;
|
|
||||||
}
|
|
||||||
context->optarg = nargv[context->optind];
|
|
||||||
}
|
|
||||||
context->place = EMSG;
|
|
||||||
context->optind++;
|
|
||||||
}
|
|
||||||
// dump back option letter
|
|
||||||
return optchar;
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _LOG_GETOPT_H_
|
|
||||||
#define _LOG_GETOPT_H_
|
|
||||||
|
|
||||||
#ifndef __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE
|
|
||||||
#ifndef __ANDROID_API__
|
|
||||||
#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1
|
|
||||||
#elif __ANDROID_API__ > 24 /* > Nougat */
|
|
||||||
#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 1
|
|
||||||
#else
|
|
||||||
#define __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE 0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE
|
|
||||||
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
struct getopt_context {
|
|
||||||
int opterr;
|
|
||||||
int optind;
|
|
||||||
int optopt;
|
|
||||||
int optreset;
|
|
||||||
const char* optarg;
|
|
||||||
FILE* optstderr; /* NULL defaults to stderr */
|
|
||||||
/* private */
|
|
||||||
const char* place;
|
|
||||||
int nonopt_start;
|
|
||||||
int nonopt_end;
|
|
||||||
int dash_prefix;
|
|
||||||
/* expansion space */
|
|
||||||
int __extra__;
|
|
||||||
void* __stuff__;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define EMSG ""
|
|
||||||
#define NO_PREFIX (-1)
|
|
||||||
|
|
||||||
#define INIT_GETOPT_CONTEXT(context) \
|
|
||||||
context = { 1, 1, '?', 0, NULL, NULL, EMSG, -1, -1, NO_PREFIX, 0, NULL }
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
|
||||||
int getopt_long_r(int nargc, char* const* nargv, const char* options,
|
|
||||||
const struct option* long_options, int* idx,
|
|
||||||
struct getopt_context* context);
|
|
||||||
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif /* __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE */
|
|
||||||
|
|
||||||
#endif /* !_LOG_GETOPT_H_ */
|
|
||||||
|
|
@ -14,12 +14,15 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "logcat.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
|
@ -47,8 +50,6 @@
|
||||||
#include <cutils/sched_policy.h>
|
#include <cutils/sched_policy.h>
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
#include <log/event_tag_map.h>
|
#include <log/event_tag_map.h>
|
||||||
#include <log/getopt.h>
|
|
||||||
#include <log/logcat.h>
|
|
||||||
#include <log/logprint.h>
|
#include <log/logprint.h>
|
||||||
#include <private/android_logger.h>
|
#include <private/android_logger.h>
|
||||||
#include <system/thread_defs.h>
|
#include <system/thread_defs.h>
|
||||||
|
|
@ -854,14 +855,8 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
// net for stability dealing with possible mistaken inputs.
|
// net for stability dealing with possible mistaken inputs.
|
||||||
static const char delimiters[] = ",:; \t\n\r\f";
|
static const char delimiters[] = ",:; \t\n\r\f";
|
||||||
|
|
||||||
struct getopt_context optctx;
|
optind = 0;
|
||||||
INIT_GETOPT_CONTEXT(optctx);
|
while (true) {
|
||||||
optctx.opterr = !!context->error;
|
|
||||||
optctx.optstderr = context->error;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
// list of long-argument only strings for later comparison
|
// list of long-argument only strings for later comparison
|
||||||
static const char pid_str[] = "pid";
|
static const char pid_str[] = "pid";
|
||||||
|
|
@ -902,19 +897,18 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
ret = getopt_long_r(argc, argv, ":cdDhLt:T:gG:sQf:r:n:v:b:BSpP:m:e:",
|
int c = getopt_long(argc, argv, ":cdDhLt:T:gG:sQf:r:n:v:b:BSpP:m:e:", long_options,
|
||||||
long_options, &option_index, &optctx);
|
&option_index);
|
||||||
if (ret < 0) break;
|
if (c == -1) break;
|
||||||
|
|
||||||
switch (ret) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
// only long options
|
// only long options
|
||||||
if (long_options[option_index].name == pid_str) {
|
if (long_options[option_index].name == pid_str) {
|
||||||
// ToDo: determine runtime PID_MAX?
|
// ToDo: determine runtime PID_MAX?
|
||||||
if (!getSizeTArg(optctx.optarg, &pid, 1)) {
|
if (!getSizeTArg(optarg, &pid, 1)) {
|
||||||
logcat_panic(context, HELP_TRUE, "%s %s out of range\n",
|
logcat_panic(context, HELP_TRUE, "%s %s out of range\n",
|
||||||
long_options[option_index].name,
|
long_options[option_index].name, optarg);
|
||||||
optctx.optarg);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -924,11 +918,9 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
ANDROID_LOG_NONBLOCK;
|
ANDROID_LOG_NONBLOCK;
|
||||||
// ToDo: implement API that supports setting a wrap timeout
|
// ToDo: implement API that supports setting a wrap timeout
|
||||||
size_t dummy = ANDROID_LOG_WRAP_DEFAULT_TIMEOUT;
|
size_t dummy = ANDROID_LOG_WRAP_DEFAULT_TIMEOUT;
|
||||||
if (optctx.optarg &&
|
if (optarg && !getSizeTArg(optarg, &dummy, 1)) {
|
||||||
!getSizeTArg(optctx.optarg, &dummy, 1)) {
|
|
||||||
logcat_panic(context, HELP_TRUE, "%s %s out of range\n",
|
logcat_panic(context, HELP_TRUE, "%s %s out of range\n",
|
||||||
long_options[option_index].name,
|
long_options[option_index].name, optarg);
|
||||||
optctx.optarg);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if ((dummy != ANDROID_LOG_WRAP_DEFAULT_TIMEOUT) &&
|
if ((dummy != ANDROID_LOG_WRAP_DEFAULT_TIMEOUT) &&
|
||||||
|
|
@ -949,8 +941,7 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (long_options[option_index].name == id_str) {
|
if (long_options[option_index].name == id_str) {
|
||||||
setId = (optctx.optarg && optctx.optarg[0]) ? optctx.optarg
|
setId = (optarg && optarg[0]) ? optarg : nullptr;
|
||||||
: nullptr;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -978,32 +969,27 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
|
mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK;
|
||||||
// FALLTHRU
|
// FALLTHRU
|
||||||
case 'T':
|
case 'T':
|
||||||
if (strspn(optctx.optarg, "0123456789") !=
|
if (strspn(optarg, "0123456789") != strlen(optarg)) {
|
||||||
strlen(optctx.optarg)) {
|
char* cp = parseTime(tail_time, optarg);
|
||||||
char* cp = parseTime(tail_time, optctx.optarg);
|
|
||||||
if (!cp) {
|
if (!cp) {
|
||||||
logcat_panic(context, HELP_FALSE,
|
logcat_panic(context, HELP_FALSE, "-%c \"%s\" not in time format\n", c,
|
||||||
"-%c \"%s\" not in time format\n", ret,
|
optarg);
|
||||||
optctx.optarg);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (*cp) {
|
if (*cp) {
|
||||||
char c = *cp;
|
char ch = *cp;
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
if (context->error) {
|
if (context->error) {
|
||||||
fprintf(
|
fprintf(context->error, "WARNING: -%c \"%s\"\"%c%s\" time truncated\n",
|
||||||
context->error,
|
c, optarg, ch, cp + 1);
|
||||||
"WARNING: -%c \"%s\"\"%c%s\" time truncated\n",
|
|
||||||
ret, optctx.optarg, c, cp + 1);
|
|
||||||
}
|
}
|
||||||
*cp = c;
|
*cp = ch;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!getSizeTArg(optctx.optarg, &tail_lines, 1)) {
|
if (!getSizeTArg(optarg, &tail_lines, 1)) {
|
||||||
if (context->error) {
|
if (context->error) {
|
||||||
fprintf(context->error,
|
fprintf(context->error, "WARNING: -%c %s invalid, setting to 1\n", c,
|
||||||
"WARNING: -%c %s invalid, setting to 1\n",
|
optarg);
|
||||||
ret, optctx.optarg);
|
|
||||||
}
|
}
|
||||||
tail_lines = 1;
|
tail_lines = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1015,21 +1001,19 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
context->regex = new pcrecpp::RE(optctx.optarg);
|
context->regex = new pcrecpp::RE(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm': {
|
case 'm': {
|
||||||
if (!getSizeTArg(optctx.optarg, &context->maxCount)) {
|
if (!getSizeTArg(optarg, &context->maxCount)) {
|
||||||
logcat_panic(context, HELP_FALSE,
|
logcat_panic(context, HELP_FALSE,
|
||||||
"-%c \"%s\" isn't an "
|
"-%c \"%s\" isn't an integer greater than zero\n", c, optarg);
|
||||||
"integer greater than zero\n",
|
|
||||||
ret, optctx.optarg);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
if (!optctx.optarg) {
|
if (!optarg) {
|
||||||
getLogSize = true;
|
getLogSize = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1037,8 +1021,8 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
|
|
||||||
case 'G': {
|
case 'G': {
|
||||||
char* cp;
|
char* cp;
|
||||||
if (strtoll(optctx.optarg, &cp, 0) > 0) {
|
if (strtoll(optarg, &cp, 0) > 0) {
|
||||||
setLogSize = strtoll(optctx.optarg, &cp, 0);
|
setLogSize = strtoll(optarg, &cp, 0);
|
||||||
} else {
|
} else {
|
||||||
setLogSize = 0;
|
setLogSize = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1071,19 +1055,18 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (!optctx.optarg) {
|
if (!optarg) {
|
||||||
getPruneList = true;
|
getPruneList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// FALLTHRU
|
// FALLTHRU
|
||||||
|
|
||||||
case 'P':
|
case 'P':
|
||||||
setPruneList = optctx.optarg;
|
setPruneList = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b': {
|
case 'b': {
|
||||||
std::unique_ptr<char, void (*)(void*)> buffers(
|
std::unique_ptr<char, void (*)(void*)> buffers(strdup(optarg), free);
|
||||||
strdup(optctx.optarg), free);
|
|
||||||
char* arg = buffers.get();
|
char* arg = buffers.get();
|
||||||
unsigned idMask = 0;
|
unsigned idMask = 0;
|
||||||
char* sv = nullptr; // protect against -ENOMEM above
|
char* sv = nullptr; // protect against -ENOMEM above
|
||||||
|
|
@ -1147,40 +1130,33 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
if ((tail_time == log_time::EPOCH) && !tail_lines) {
|
if ((tail_time == log_time::EPOCH) && !tail_lines) {
|
||||||
tail_time = lastLogTime(optctx.optarg);
|
tail_time = lastLogTime(optarg);
|
||||||
}
|
}
|
||||||
// redirect output to a file
|
// redirect output to a file
|
||||||
context->outputFileName = optctx.optarg;
|
context->outputFileName = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
if (!getSizeTArg(optctx.optarg, &context->logRotateSizeKBytes,
|
if (!getSizeTArg(optarg, &context->logRotateSizeKBytes, 1)) {
|
||||||
1)) {
|
logcat_panic(context, HELP_TRUE, "Invalid parameter \"%s\" to -r\n", optarg);
|
||||||
logcat_panic(context, HELP_TRUE,
|
|
||||||
"Invalid parameter \"%s\" to -r\n",
|
|
||||||
optctx.optarg);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
if (!getSizeTArg(optctx.optarg, &context->maxRotatedLogs, 1)) {
|
if (!getSizeTArg(optarg, &context->maxRotatedLogs, 1)) {
|
||||||
logcat_panic(context, HELP_TRUE,
|
logcat_panic(context, HELP_TRUE, "Invalid parameter \"%s\" to -n\n", optarg);
|
||||||
"Invalid parameter \"%s\" to -n\n",
|
|
||||||
optctx.optarg);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v': {
|
case 'v': {
|
||||||
if (!strcmp(optctx.optarg, "help") ||
|
if (!strcmp(optarg, "help") || !strcmp(optarg, "--help")) {
|
||||||
!strcmp(optctx.optarg, "--help")) {
|
|
||||||
show_format_help(context);
|
show_format_help(context);
|
||||||
context->retval = EXIT_SUCCESS;
|
context->retval = EXIT_SUCCESS;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
std::unique_ptr<char, void (*)(void*)> formats(
|
std::unique_ptr<char, void (*)(void*)> formats(strdup(optarg), free);
|
||||||
strdup(optctx.optarg), free);
|
|
||||||
char* arg = formats.get();
|
char* arg = formats.get();
|
||||||
char* sv = nullptr; // protect against -ENOMEM above
|
char* sv = nullptr; // protect against -ENOMEM above
|
||||||
while (!!(arg = strtok_r(arg, delimiters, &sv))) {
|
while (!!(arg = strtok_r(arg, delimiters, &sv))) {
|
||||||
|
|
@ -1300,8 +1276,7 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
logcat_panic(context, HELP_TRUE,
|
logcat_panic(context, HELP_TRUE, "Option -%c needs an argument\n", optopt);
|
||||||
"Option -%c needs an argument\n", optctx.optopt);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
@ -1310,8 +1285,7 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logcat_panic(context, HELP_TRUE, "Unrecognized Option %c\n",
|
logcat_panic(context, HELP_TRUE, "Unrecognized Option %c\n", optopt);
|
||||||
optctx.optopt);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1400,7 +1374,7 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
"Invalid filter expression in logcat args\n");
|
"Invalid filter expression in logcat args\n");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
} else if (argc == optctx.optind) {
|
} else if (argc == optind) {
|
||||||
// Add from environment variable
|
// Add from environment variable
|
||||||
const char* env_tags_orig = android::getenv(context, "ANDROID_LOG_TAGS");
|
const char* env_tags_orig = android::getenv(context, "ANDROID_LOG_TAGS");
|
||||||
|
|
||||||
|
|
@ -1416,7 +1390,7 @@ static int __logcat(android_logcat_context_internal* context) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Add from commandline
|
// Add from commandline
|
||||||
for (int i = optctx.optind ; i < argc ; i++) {
|
for (int i = optind ; i < argc ; i++) {
|
||||||
// skip stderr redirections of _all_ kinds
|
// skip stderr redirections of _all_ kinds
|
||||||
if ((argv[i][0] == '2') && (argv[i][1] == '>')) continue;
|
if ((argv[i][0] == '2') && (argv[i][1] == '>')) continue;
|
||||||
// skip stdout redirections of _all_ kinds
|
// skip stdout redirections of _all_ kinds
|
||||||
|
|
@ -1707,105 +1681,6 @@ int android_logcat_run_command(android_logcat_context ctx,
|
||||||
return __logcat(context);
|
return __logcat(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// starts a thread, opens a pipe, returns reading end.
|
|
||||||
int android_logcat_run_command_thread(android_logcat_context ctx,
|
|
||||||
int argc, char* const* argv,
|
|
||||||
char* const* envp) {
|
|
||||||
android_logcat_context_internal* context = ctx;
|
|
||||||
|
|
||||||
int save_errno = EBUSY;
|
|
||||||
if ((context->fds[0] >= 0) || (context->fds[1] >= 0)) goto exit;
|
|
||||||
|
|
||||||
if (pipe(context->fds) < 0) {
|
|
||||||
save_errno = errno;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_attr_t attr;
|
|
||||||
if (pthread_attr_init(&attr)) {
|
|
||||||
save_errno = errno;
|
|
||||||
goto close_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sched_param param;
|
|
||||||
memset(¶m, 0, sizeof(param));
|
|
||||||
pthread_attr_setschedparam(&attr, ¶m);
|
|
||||||
pthread_attr_setschedpolicy(&attr, SCHED_BATCH);
|
|
||||||
if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) {
|
|
||||||
save_errno = errno;
|
|
||||||
goto pthread_attr_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
context->stop = false;
|
|
||||||
context->thread_stopped = false;
|
|
||||||
context->output_fd = context->fds[1];
|
|
||||||
// save off arguments so they remain while thread is active.
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
|
||||||
context->args.push_back(std::string(argv[i]));
|
|
||||||
}
|
|
||||||
// save off environment so they remain while thread is active.
|
|
||||||
if (envp) for (size_t i = 0; envp[i]; ++i) {
|
|
||||||
context->envs.push_back(std::string(envp[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& str : context->args) {
|
|
||||||
context->argv_hold.push_back(str.c_str());
|
|
||||||
}
|
|
||||||
context->argv_hold.push_back(nullptr);
|
|
||||||
for (auto& str : context->envs) {
|
|
||||||
context->envp_hold.push_back(str.c_str());
|
|
||||||
}
|
|
||||||
context->envp_hold.push_back(nullptr);
|
|
||||||
|
|
||||||
context->argc = context->argv_hold.size() - 1;
|
|
||||||
context->argv = (char* const*)&context->argv_hold[0];
|
|
||||||
context->envp = (char* const*)&context->envp_hold[0];
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stderr, "argv[%d] = {", context->argc);
|
|
||||||
for (auto str : context->argv_hold) {
|
|
||||||
fprintf(stderr, " \"%s\"", str ?: "nullptr");
|
|
||||||
}
|
|
||||||
fprintf(stderr, " }\n");
|
|
||||||
fflush(stderr);
|
|
||||||
#endif
|
|
||||||
context->retval = EXIT_SUCCESS;
|
|
||||||
if (pthread_create(&context->thr, &attr,
|
|
||||||
(void*(*)(void*))__logcat, context)) {
|
|
||||||
save_errno = errno;
|
|
||||||
goto argv_exit;
|
|
||||||
}
|
|
||||||
pthread_attr_destroy(&attr);
|
|
||||||
|
|
||||||
return context->fds[0];
|
|
||||||
|
|
||||||
argv_exit:
|
|
||||||
context->argv_hold.clear();
|
|
||||||
context->args.clear();
|
|
||||||
context->envp_hold.clear();
|
|
||||||
context->envs.clear();
|
|
||||||
pthread_attr_exit:
|
|
||||||
pthread_attr_destroy(&attr);
|
|
||||||
close_exit:
|
|
||||||
close(context->fds[0]);
|
|
||||||
context->fds[0] = -1;
|
|
||||||
close(context->fds[1]);
|
|
||||||
context->fds[1] = -1;
|
|
||||||
exit:
|
|
||||||
errno = save_errno;
|
|
||||||
context->stop = true;
|
|
||||||
context->thread_stopped = true;
|
|
||||||
context->retval = EXIT_FAILURE;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// test if the thread is still doing 'stuff'
|
|
||||||
int android_logcat_run_command_thread_running(android_logcat_context ctx) {
|
|
||||||
android_logcat_context_internal* context = ctx;
|
|
||||||
|
|
||||||
return context->thread_stopped == false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finished with context
|
// Finished with context
|
||||||
int android_logcat_destroy(android_logcat_context* ctx) {
|
int android_logcat_destroy(android_logcat_context* ctx) {
|
||||||
android_logcat_context_internal* context = *ctx;
|
android_logcat_context_internal* context = *ctx;
|
||||||
|
|
|
||||||
|
|
@ -75,18 +75,8 @@ android_logcat_context create_android_logcat();
|
||||||
*
|
*
|
||||||
* Return value is 0 for success, non-zero for errors.
|
* Return value is 0 for success, non-zero for errors.
|
||||||
*/
|
*/
|
||||||
int android_logcat_run_command(android_logcat_context ctx, int output, int error,
|
int android_logcat_run_command(android_logcat_context ctx, int output, int error, int argc,
|
||||||
int argc, char* const* argv, char* const* envp);
|
char* const* argv, char* const* envp);
|
||||||
|
|
||||||
/* Will not block, performed in-process
|
|
||||||
*
|
|
||||||
* Starts a thread, opens a pipe, returns reading end fd, saves off argv.
|
|
||||||
* The command supports 2>&1 (mix content) and 2>/dev/null (drop content) for
|
|
||||||
* scripted error (stderr) redirection.
|
|
||||||
*/
|
|
||||||
int android_logcat_run_command_thread(android_logcat_context ctx, int argc,
|
|
||||||
char* const* argv, char* const* envp);
|
|
||||||
int android_logcat_run_command_thread_running(android_logcat_context ctx);
|
|
||||||
|
|
||||||
/* Finished with context
|
/* Finished with context
|
||||||
*
|
*
|
||||||
|
|
@ -97,22 +87,6 @@ int android_logcat_run_command_thread_running(android_logcat_context ctx);
|
||||||
*/
|
*/
|
||||||
int android_logcat_destroy(android_logcat_context* ctx);
|
int android_logcat_destroy(android_logcat_context* ctx);
|
||||||
|
|
||||||
/* derived helpers */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* In-process thread that acts like somewhat like libc-like system and popen
|
|
||||||
* respectively. Can not handle shell scripting, only pure calls to the
|
|
||||||
* logcat operations. The android_logcat_system is a wrapper for the
|
|
||||||
* create_android_logcat, android_logcat_run_command and android_logcat_destroy
|
|
||||||
* API above. The android_logcat_popen is a wrapper for the
|
|
||||||
* android_logcat_run_command_thread API above. The android_logcat_pclose is
|
|
||||||
* a wrapper for a reasonable wait until output has subsided for command
|
|
||||||
* completion, fclose on the FILE pointer and the android_logcat_destroy API.
|
|
||||||
*/
|
|
||||||
int android_logcat_system(const char* command);
|
|
||||||
FILE* android_logcat_popen(android_logcat_context* ctx, const char* command);
|
|
||||||
int android_logcat_pclose(android_logcat_context* ctx, FILE* output);
|
|
||||||
|
|
||||||
#endif /* __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE */
|
#endif /* __ANDROID_USE_LIBLOG_LOGCAT_INTERFACE */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <log/logcat.h>
|
#include "logcat.h"
|
||||||
|
|
||||||
int main(int argc, char** argv, char** envp) {
|
int main(int argc, char** argv, char** envp) {
|
||||||
android_logcat_context ctx = create_android_logcat();
|
android_logcat_context ctx = create_android_logcat();
|
||||||
|
|
|
||||||
|
|
@ -1,153 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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 <ctype.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <log/logcat.h>
|
|
||||||
|
|
||||||
static std::string unquote(const char*& cp, const char*& delim) {
|
|
||||||
if ((*cp == '\'') || (*cp == '"')) {
|
|
||||||
// KISS: Simple quotes. Do not handle the case
|
|
||||||
// of concatenation like "blah"foo'bar'
|
|
||||||
char quote = *cp++;
|
|
||||||
delim = strchr(cp, quote);
|
|
||||||
if (!delim) delim = cp + strlen(cp);
|
|
||||||
std::string str(cp, delim);
|
|
||||||
if (*delim) ++delim;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
delim = strpbrk(cp, " \t\f\r\n");
|
|
||||||
if (!delim) delim = cp + strlen(cp);
|
|
||||||
return std::string(cp, delim);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool __android_logcat_parse(const char* command,
|
|
||||||
std::vector<std::string>& args,
|
|
||||||
std::vector<std::string>& envs) {
|
|
||||||
for (const char *delim, *cp = command; cp && *cp; cp = delim) {
|
|
||||||
while (isspace(*cp)) ++cp;
|
|
||||||
if ((args.size() == 0) && (*cp != '=') && !isdigit(*cp)) {
|
|
||||||
const char* env = cp;
|
|
||||||
while (isalnum(*cp) || (*cp == '_')) ++cp;
|
|
||||||
if (cp && (*cp == '=')) {
|
|
||||||
std::string str(env, ++cp);
|
|
||||||
str += unquote(cp, delim);
|
|
||||||
envs.push_back(str);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cp = env;
|
|
||||||
}
|
|
||||||
args.push_back(unquote(cp, delim));
|
|
||||||
if ((args.size() == 1) && (args[0] != "logcat") &&
|
|
||||||
(args[0] != "/system/bin/logcat")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return args.size() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* android_logcat_popen(android_logcat_context* ctx, const char* command) {
|
|
||||||
*ctx = NULL;
|
|
||||||
|
|
||||||
std::vector<std::string> args;
|
|
||||||
std::vector<std::string> envs;
|
|
||||||
if (!__android_logcat_parse(command, args, envs)) return NULL;
|
|
||||||
|
|
||||||
std::vector<const char*> argv;
|
|
||||||
for (auto& str : args) {
|
|
||||||
argv.push_back(str.c_str());
|
|
||||||
}
|
|
||||||
argv.push_back(NULL);
|
|
||||||
|
|
||||||
std::vector<const char*> envp;
|
|
||||||
for (auto& str : envs) {
|
|
||||||
envp.push_back(str.c_str());
|
|
||||||
}
|
|
||||||
envp.push_back(NULL);
|
|
||||||
|
|
||||||
*ctx = create_android_logcat();
|
|
||||||
if (!*ctx) return NULL;
|
|
||||||
|
|
||||||
int fd = android_logcat_run_command_thread(
|
|
||||||
*ctx, argv.size() - 1, (char* const*)&argv[0], (char* const*)&envp[0]);
|
|
||||||
argv.clear();
|
|
||||||
args.clear();
|
|
||||||
envp.clear();
|
|
||||||
envs.clear();
|
|
||||||
if (fd < 0) {
|
|
||||||
android_logcat_destroy(ctx);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int duped = dup(fd);
|
|
||||||
FILE* retval = fdopen(duped, "reb");
|
|
||||||
if (!retval) {
|
|
||||||
close(duped);
|
|
||||||
android_logcat_destroy(ctx);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
int android_logcat_pclose(android_logcat_context* ctx, FILE* output) {
|
|
||||||
if (*ctx) {
|
|
||||||
static const useconds_t wait_sample = 20000;
|
|
||||||
// Wait two seconds maximum
|
|
||||||
for (size_t retry = ((2 * 1000000) + wait_sample - 1) / wait_sample;
|
|
||||||
android_logcat_run_command_thread_running(*ctx) && retry; --retry) {
|
|
||||||
usleep(wait_sample);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output) fclose(output);
|
|
||||||
return android_logcat_destroy(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int android_logcat_system(const char* command) {
|
|
||||||
std::vector<std::string> args;
|
|
||||||
std::vector<std::string> envs;
|
|
||||||
if (!__android_logcat_parse(command, args, envs)) return -1;
|
|
||||||
|
|
||||||
std::vector<const char*> argv;
|
|
||||||
for (auto& str : args) {
|
|
||||||
argv.push_back(str.c_str());
|
|
||||||
}
|
|
||||||
argv.push_back(NULL);
|
|
||||||
|
|
||||||
std::vector<const char*> envp;
|
|
||||||
for (auto& str : envs) {
|
|
||||||
envp.push_back(str.c_str());
|
|
||||||
}
|
|
||||||
envp.push_back(NULL);
|
|
||||||
|
|
||||||
android_logcat_context ctx = create_android_logcat();
|
|
||||||
if (!ctx) return -1;
|
|
||||||
/* Command return value */
|
|
||||||
int retval = android_logcat_run_command(ctx, -1, -1, argv.size() - 1,
|
|
||||||
(char* const*)&argv[0],
|
|
||||||
(char* const*)&envp[0]);
|
|
||||||
/* destroy return value */
|
|
||||||
int ret = android_logcat_destroy(&ctx);
|
|
||||||
/* Paranoia merging any discrepancies between the two return values */
|
|
||||||
if (!ret) ret = retval;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <log/logcat.h>
|
#include "logcat.h"
|
||||||
|
|
||||||
int main(int argc, char** argv, char** envp) {
|
int main(int argc, char** argv, char** envp) {
|
||||||
android_logcat_context ctx = create_android_logcat();
|
android_logcat_context ctx = create_android_logcat();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ test_c_flags := \
|
||||||
|
|
||||||
benchmark_src_files := \
|
benchmark_src_files := \
|
||||||
logcat_benchmark.cpp \
|
logcat_benchmark.cpp \
|
||||||
exec_benchmark.cpp \
|
|
||||||
|
|
||||||
# Build benchmarks for the device. Run with:
|
# Build benchmarks for the device. Run with:
|
||||||
# adb shell /data/nativetest/logcat-benchmarks/logcat-benchmarks
|
# adb shell /data/nativetest/logcat-benchmarks/logcat-benchmarks
|
||||||
|
|
@ -41,7 +40,7 @@ LOCAL_MODULE := $(test_module_prefix)benchmarks
|
||||||
LOCAL_MODULE_TAGS := $(test_tags)
|
LOCAL_MODULE_TAGS := $(test_tags)
|
||||||
LOCAL_CFLAGS += $(test_c_flags)
|
LOCAL_CFLAGS += $(test_c_flags)
|
||||||
LOCAL_SRC_FILES := $(benchmark_src_files)
|
LOCAL_SRC_FILES := $(benchmark_src_files)
|
||||||
LOCAL_SHARED_LIBRARIES := libbase liblogcat
|
LOCAL_SHARED_LIBRARIES := libbase
|
||||||
include $(BUILD_NATIVE_BENCHMARK)
|
include $(BUILD_NATIVE_BENCHMARK)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
@ -51,7 +50,6 @@ include $(BUILD_NATIVE_BENCHMARK)
|
||||||
test_src_files := \
|
test_src_files := \
|
||||||
logcat_test.cpp \
|
logcat_test.cpp \
|
||||||
logcatd_test.cpp \
|
logcatd_test.cpp \
|
||||||
liblogcat_test.cpp \
|
|
||||||
|
|
||||||
# Build tests for the device (with .so). Run with:
|
# Build tests for the device (with .so). Run with:
|
||||||
# adb shell /data/nativetest/logcat-unit-tests/logcat-unit-tests
|
# adb shell /data/nativetest/logcat-unit-tests/logcat-unit-tests
|
||||||
|
|
@ -59,6 +57,6 @@ include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := $(test_module_prefix)unit-tests
|
LOCAL_MODULE := $(test_module_prefix)unit-tests
|
||||||
LOCAL_MODULE_TAGS := $(test_tags)
|
LOCAL_MODULE_TAGS := $(test_tags)
|
||||||
LOCAL_CFLAGS += $(test_c_flags)
|
LOCAL_CFLAGS += $(test_c_flags)
|
||||||
LOCAL_SHARED_LIBRARIES := liblog libbase liblogcat
|
LOCAL_SHARED_LIBRARIES := liblog libbase
|
||||||
LOCAL_SRC_FILES := $(test_src_files)
|
LOCAL_SRC_FILES := $(test_src_files)
|
||||||
include $(BUILD_NATIVE_TEST)
|
include $(BUILD_NATIVE_TEST)
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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 <android-base/file.h>
|
|
||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <log/logcat.h>
|
|
||||||
|
|
||||||
// Dump the statistics and report results
|
|
||||||
|
|
||||||
static void logcat_popen_libc(benchmark::State& state, const char* cmd) {
|
|
||||||
while (state.KeepRunning()) {
|
|
||||||
FILE* fp = popen(cmd, "r");
|
|
||||||
std::string ret;
|
|
||||||
android::base::ReadFdToString(fileno(fp), &ret);
|
|
||||||
pclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void BM_logcat_stat_popen_libc(benchmark::State& state) {
|
|
||||||
logcat_popen_libc(state, "logcat -b all -S");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_stat_popen_libc);
|
|
||||||
|
|
||||||
static void logcat_popen_liblogcat(benchmark::State& state, const char* cmd) {
|
|
||||||
while (state.KeepRunning()) {
|
|
||||||
android_logcat_context ctx;
|
|
||||||
FILE* fp = android_logcat_popen(&ctx, cmd);
|
|
||||||
std::string ret;
|
|
||||||
android::base::ReadFdToString(fileno(fp), &ret);
|
|
||||||
android_logcat_pclose(&ctx, fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void BM_logcat_stat_popen_liblogcat(benchmark::State& state) {
|
|
||||||
logcat_popen_liblogcat(state, "logcat -b all -S");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_stat_popen_liblogcat);
|
|
||||||
|
|
||||||
static void logcat_system_libc(benchmark::State& state, const char* cmd) {
|
|
||||||
while (state.KeepRunning()) {
|
|
||||||
system(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void BM_logcat_stat_system_libc(benchmark::State& state) {
|
|
||||||
logcat_system_libc(state, "logcat -b all -S >/dev/null 2>/dev/null");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_stat_system_libc);
|
|
||||||
|
|
||||||
static void logcat_system_liblogcat(benchmark::State& state, const char* cmd) {
|
|
||||||
while (state.KeepRunning()) {
|
|
||||||
android_logcat_system(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void BM_logcat_stat_system_liblogcat(benchmark::State& state) {
|
|
||||||
logcat_system_liblogcat(state, "logcat -b all -S >/dev/null 2>/dev/null");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_stat_system_liblogcat);
|
|
||||||
|
|
||||||
// Dump the logs and report results
|
|
||||||
|
|
||||||
static void BM_logcat_dump_popen_libc(benchmark::State& state) {
|
|
||||||
logcat_popen_libc(state, "logcat -b all -d");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_dump_popen_libc);
|
|
||||||
|
|
||||||
static void BM_logcat_dump_popen_liblogcat(benchmark::State& state) {
|
|
||||||
logcat_popen_liblogcat(state, "logcat -b all -d");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_dump_popen_liblogcat);
|
|
||||||
|
|
||||||
static void BM_logcat_dump_system_libc(benchmark::State& state) {
|
|
||||||
logcat_system_libc(state, "logcat -b all -d >/dev/null 2>/dev/null");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_dump_system_libc);
|
|
||||||
|
|
||||||
static void BM_logcat_dump_system_liblogcat(benchmark::State& state) {
|
|
||||||
logcat_system_liblogcat(state, "logcat -b all -d >/dev/null 2>/dev/null");
|
|
||||||
}
|
|
||||||
BENCHMARK(BM_logcat_dump_system_liblogcat);
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* 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 <log/logcat.h>
|
|
||||||
|
|
||||||
#define logcat_define(context) android_logcat_context context
|
|
||||||
#define logcat_popen(context, command) android_logcat_popen(&(context), command)
|
|
||||||
#define logcat_pclose(context, fp) android_logcat_pclose(&(context), fp)
|
|
||||||
#define logcat_system(command) android_logcat_system(command)
|
|
||||||
#define logcat liblogcat
|
|
||||||
|
|
||||||
#include "logcat_test.cpp"
|
|
||||||
|
|
@ -37,12 +37,6 @@
|
||||||
#include <log/log.h>
|
#include <log/log.h>
|
||||||
#include <log/log_event_list.h>
|
#include <log/log_event_list.h>
|
||||||
|
|
||||||
#ifndef logcat_popen
|
|
||||||
#define logcat_define(context)
|
|
||||||
#define logcat_popen(context, command) popen((command), "r")
|
|
||||||
#define logcat_pclose(context, fp) pclose(fp)
|
|
||||||
#define logcat_system(command) system(command)
|
|
||||||
#endif
|
|
||||||
#ifndef logcat_executable
|
#ifndef logcat_executable
|
||||||
#define USING_LOGCAT_EXECUTABLE_DEFAULT
|
#define USING_LOGCAT_EXECUTABLE_DEFAULT
|
||||||
#define logcat_executable "logcat"
|
#define logcat_executable "logcat"
|
||||||
|
|
@ -78,7 +72,6 @@ static const char begin[] = "--------- beginning of ";
|
||||||
|
|
||||||
TEST(logcat, buckets) {
|
TEST(logcat, buckets) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
#undef LOG_TAG
|
#undef LOG_TAG
|
||||||
#define LOG_TAG "inject.buckets"
|
#define LOG_TAG "inject.buckets"
|
||||||
|
|
@ -90,10 +83,9 @@ TEST(logcat, buckets) {
|
||||||
__android_log_bswrite(0, logcat_executable ".inject.buckets");
|
__android_log_bswrite(0, logcat_executable ".inject.buckets");
|
||||||
rest();
|
rest();
|
||||||
|
|
||||||
ASSERT_TRUE(NULL !=
|
ASSERT_TRUE(NULL != (fp = popen(logcat_executable
|
||||||
(fp = logcat_popen(
|
" -b radio -b events -b system -b main -d 2>/dev/null",
|
||||||
ctx, logcat_executable
|
"r")));
|
||||||
" -b radio -b events -b system -b main -d 2>/dev/null")));
|
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
|
|
@ -111,7 +103,7 @@ TEST(logcat, buckets) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
EXPECT_EQ(ids, 15);
|
EXPECT_EQ(ids, 15);
|
||||||
|
|
||||||
|
|
@ -120,7 +112,6 @@ TEST(logcat, buckets) {
|
||||||
|
|
||||||
TEST(logcat, event_tag_filter) {
|
TEST(logcat, event_tag_filter) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
#undef LOG_TAG
|
#undef LOG_TAG
|
||||||
#define LOG_TAG "inject.filter"
|
#define LOG_TAG "inject.filter"
|
||||||
|
|
@ -135,7 +126,7 @@ TEST(logcat, event_tag_filter) {
|
||||||
logcat_executable
|
logcat_executable
|
||||||
" -b radio -b system -b main --pid=%d -d -s inject.filter 2>/dev/null",
|
" -b radio -b system -b main --pid=%d -d -s inject.filter 2>/dev/null",
|
||||||
getpid());
|
getpid());
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, command.c_str())));
|
ASSERT_TRUE(NULL != (fp = popen(command.c_str(), "r")));
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
|
|
@ -145,7 +136,7 @@ TEST(logcat, event_tag_filter) {
|
||||||
if (strncmp(begin, buffer, sizeof(begin) - 1)) ++count;
|
if (strncmp(begin, buffer, sizeof(begin) - 1)) ++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
// logcat, liblogcat and logcatd test instances result in the progression
|
// logcat, liblogcat and logcatd test instances result in the progression
|
||||||
// of 3, 6 and 9 for our counts as each round is performed.
|
// of 3, 6 and 9 for our counts as each round is performed.
|
||||||
|
|
@ -191,7 +182,6 @@ TEST(logcat, year) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
char needle[32];
|
char needle[32];
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
@ -205,9 +195,8 @@ TEST(logcat, year) {
|
||||||
#endif
|
#endif
|
||||||
strftime(needle, sizeof(needle), "[ %Y-", ptm);
|
strftime(needle, sizeof(needle), "[ %Y-", ptm);
|
||||||
|
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(
|
ASSERT_TRUE(NULL !=
|
||||||
ctx, logcat_executable
|
(fp = popen(logcat_executable " -v long -v year -b all -t 3 2>/dev/null", "r")));
|
||||||
" -v long -v year -b all -t 3 2>/dev/null")));
|
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
|
|
@ -218,7 +207,7 @@ TEST(logcat, year) {
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
} while ((count < 3) && --tries && inject(3 - count));
|
} while ((count < 3) && --tries && inject(3 - count));
|
||||||
|
|
||||||
|
|
@ -268,12 +257,10 @@ TEST(logcat, tz) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
ASSERT_TRUE(NULL !=
|
ASSERT_TRUE(NULL != (fp = popen(logcat_executable
|
||||||
(fp = logcat_popen(ctx, logcat_executable
|
" -v long -v America/Los_Angeles -b all -t 3 2>/dev/null",
|
||||||
" -v long -v America/Los_Angeles "
|
"r")));
|
||||||
"-b all -t 3 2>/dev/null")));
|
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
|
|
@ -287,7 +274,7 @@ TEST(logcat, tz) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
} while ((count < 3) && --tries && inject(3 - count));
|
} while ((count < 3) && --tries && inject(3 - count));
|
||||||
|
|
||||||
|
|
@ -296,11 +283,11 @@ TEST(logcat, tz) {
|
||||||
|
|
||||||
TEST(logcat, ntz) {
|
TEST(logcat, ntz) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, logcat_executable
|
ASSERT_TRUE(NULL !=
|
||||||
" -v long -v America/Los_Angeles -v "
|
(fp = popen(logcat_executable
|
||||||
"zone -b all -t 3 2>/dev/null")));
|
" -v long -v America/Los_Angeles -v zone -b all -t 3 2>/dev/null",
|
||||||
|
"r")));
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
|
|
@ -312,7 +299,7 @@ TEST(logcat, ntz) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
ASSERT_EQ(0, count);
|
ASSERT_EQ(0, count);
|
||||||
}
|
}
|
||||||
|
|
@ -330,8 +317,7 @@ static void do_tail(int num) {
|
||||||
"ANDROID_PRINTF_LOG=long logcat -b all -t %d 2>/dev/null", num);
|
"ANDROID_PRINTF_LOG=long logcat -b all -t %d 2>/dev/null", num);
|
||||||
|
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
|
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
|
|
@ -339,7 +325,7 @@ static void do_tail(int num) {
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
} while ((count < num) && --tries && inject(num - count));
|
} while ((count < num) && --tries && inject(num - count));
|
||||||
|
|
||||||
|
|
@ -377,8 +363,7 @@ static void do_tail_time(const char* cmd) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
snprintf(buffer, sizeof(buffer), "%s -t 10 2>&1", cmd);
|
snprintf(buffer, sizeof(buffer), "%s -t 10 2>&1", cmd);
|
||||||
logcat_define(ctx);
|
ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
while ((input = fgetLongTime(buffer, sizeof(buffer), fp))) {
|
while ((input = fgetLongTime(buffer, sizeof(buffer), fp))) {
|
||||||
|
|
@ -391,7 +376,7 @@ static void do_tail_time(const char* cmd) {
|
||||||
free(last_timestamp);
|
free(last_timestamp);
|
||||||
last_timestamp = strdup(input);
|
last_timestamp = strdup(input);
|
||||||
}
|
}
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
} while ((count < 10) && --tries && inject(10 - count));
|
} while ((count < 10) && --tries && inject(10 - count));
|
||||||
|
|
||||||
|
|
@ -401,8 +386,7 @@ static void do_tail_time(const char* cmd) {
|
||||||
EXPECT_TRUE(second_timestamp != NULL);
|
EXPECT_TRUE(second_timestamp != NULL);
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s -t '%s' 2>&1", cmd, first_timestamp);
|
snprintf(buffer, sizeof(buffer), "%s -t '%s' 2>&1", cmd, first_timestamp);
|
||||||
logcat_define(ctx);
|
ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
|
|
||||||
|
|
||||||
int second_count = 0;
|
int second_count = 0;
|
||||||
int last_timestamp_count = -1;
|
int last_timestamp_count = -1;
|
||||||
|
|
@ -442,7 +426,7 @@ static void do_tail_time(const char* cmd) {
|
||||||
last_timestamp_count = second_count;
|
last_timestamp_count = second_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
EXPECT_TRUE(found);
|
EXPECT_TRUE(found);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|
@ -483,10 +467,8 @@ TEST(logcat, End_to_End) {
|
||||||
ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
|
ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
|
||||||
|
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
ASSERT_TRUE(NULL !=
|
ASSERT_TRUE(NULL !=
|
||||||
(fp = logcat_popen(ctx, logcat_executable
|
(fp = popen(logcat_executable " -v brief -b events -t 100 2>/dev/null", "r")));
|
||||||
" -v brief -b events -t 100 2>/dev/null")));
|
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
|
|
@ -507,7 +489,7 @@ TEST(logcat, End_to_End) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
ASSERT_EQ(1, count);
|
ASSERT_EQ(1, count);
|
||||||
}
|
}
|
||||||
|
|
@ -521,12 +503,9 @@ TEST(logcat, End_to_End_multitude) {
|
||||||
|
|
||||||
FILE* fp[256]; // does this count as a multitude!
|
FILE* fp[256]; // does this count as a multitude!
|
||||||
memset(fp, 0, sizeof(fp));
|
memset(fp, 0, sizeof(fp));
|
||||||
logcat_define(ctx[sizeof(fp) / sizeof(fp[0])]);
|
|
||||||
size_t num = 0;
|
size_t num = 0;
|
||||||
do {
|
do {
|
||||||
EXPECT_TRUE(NULL !=
|
EXPECT_TRUE(NULL != (fp[num] = popen(logcat_executable " -v brief -b events -t 100", "r")));
|
||||||
(fp[num] = logcat_popen(ctx[num], logcat_executable
|
|
||||||
" -v brief -b events -t 100")));
|
|
||||||
if (!fp[num]) {
|
if (!fp[num]) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"WARNING: limiting to %zu simultaneous logcat operations\n",
|
"WARNING: limiting to %zu simultaneous logcat operations\n",
|
||||||
|
|
@ -556,7 +535,7 @@ TEST(logcat, End_to_End_multitude) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx[idx], fp[idx]);
|
pclose(fp[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EQ(num, count);
|
ASSERT_EQ(num, count);
|
||||||
|
|
@ -564,10 +543,9 @@ TEST(logcat, End_to_End_multitude) {
|
||||||
|
|
||||||
static int get_groups(const char* cmd) {
|
static int get_groups(const char* cmd) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
// NB: crash log only available in user space
|
// NB: crash log only available in user space
|
||||||
EXPECT_TRUE(NULL != (fp = logcat_popen(ctx, cmd)));
|
EXPECT_TRUE(NULL != (fp = popen(cmd, "r")));
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -631,7 +609,7 @@ static int get_groups(const char* cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
@ -815,7 +793,7 @@ TEST(logcat, logrotate) {
|
||||||
snprintf(command, sizeof(command), comm, buf);
|
snprintf(command, sizeof(command), comm, buf);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(ret = system(command), command));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
snprintf(command, sizeof(command), "ls -s %s 2>/dev/null", buf);
|
snprintf(command, sizeof(command), "ls -s %s 2>/dev/null", buf);
|
||||||
|
|
||||||
|
|
@ -861,7 +839,7 @@ TEST(logcat, logrotate_suffix) {
|
||||||
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir);
|
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(ret = system(command), command));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
snprintf(command, sizeof(command), "ls %s 2>/dev/null", tmp_out_dir);
|
snprintf(command, sizeof(command), "ls %s 2>/dev/null", tmp_out_dir);
|
||||||
|
|
||||||
|
|
@ -920,7 +898,7 @@ TEST(logcat, logrotate_continue) {
|
||||||
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
|
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(ret = system(command), command));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
||||||
EXPECT_FALSE(IsFalse(system(command), command));
|
EXPECT_FALSE(IsFalse(system(command), command));
|
||||||
|
|
@ -969,7 +947,7 @@ TEST(logcat, logrotate_continue) {
|
||||||
// re-run the command, it should only add a few lines more content if it
|
// re-run the command, it should only add a few lines more content if it
|
||||||
// continues where it left off.
|
// continues where it left off.
|
||||||
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
|
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
|
||||||
EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(ret = system(command), command));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
||||||
EXPECT_FALSE(IsFalse(system(command), command));
|
EXPECT_FALSE(IsFalse(system(command), command));
|
||||||
|
|
@ -1052,7 +1030,7 @@ TEST(logcat, logrotate_clear) {
|
||||||
tmp_out_dir, log_filename, num_val);
|
tmp_out_dir, log_filename, num_val);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(ret = system(command), command));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
||||||
EXPECT_FALSE(IsFalse(system(command), command));
|
EXPECT_FALSE(IsFalse(system(command), command));
|
||||||
|
|
@ -1082,7 +1060,7 @@ TEST(logcat, logrotate_clear) {
|
||||||
strcat(command, clear_cmd);
|
strcat(command, clear_cmd);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
EXPECT_FALSE(IsFalse(ret = logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(ret = system(command), command));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
|
||||||
EXPECT_FALSE(system(command));
|
EXPECT_FALSE(system(command));
|
||||||
|
|
@ -1120,7 +1098,7 @@ static int logrotate_count_id(const char* logcat_cmd, const char* tmp_out_dir) {
|
||||||
|
|
||||||
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
|
snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
|
||||||
|
|
||||||
int ret = logcat_system(command);
|
int ret = system(command);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "system(\"%s\")=%d", command, ret);
|
fprintf(stderr, "system(\"%s\")=%d", command, ret);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -1194,7 +1172,7 @@ TEST(logcat, logrotate_nodir) {
|
||||||
" -b all -d"
|
" -b all -d"
|
||||||
" -f /das/nein/gerfingerpoken/logcat/log.txt"
|
" -f /das/nein/gerfingerpoken/logcat/log.txt"
|
||||||
" -n 256 -r 1024";
|
" -n 256 -r 1024";
|
||||||
EXPECT_FALSE(IsFalse(0 == logcat_system(command), command));
|
EXPECT_FALSE(IsFalse(0 == system(command), command));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef logcat
|
#ifndef logcat
|
||||||
|
|
@ -1329,10 +1307,7 @@ TEST(logcat, blocking_clear) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool get_white_black(char** list) {
|
static bool get_white_black(char** list) {
|
||||||
FILE* fp;
|
FILE* fp = popen(logcat_executable " -p 2>/dev/null", "r");
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
fp = logcat_popen(ctx, logcat_executable " -p 2>/dev/null");
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "ERROR: logcat -p 2>/dev/null\n");
|
fprintf(stderr, "ERROR: logcat -p 2>/dev/null\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1360,19 +1335,15 @@ static bool get_white_black(char** list) {
|
||||||
asprintf(list, "%s", buf);
|
asprintf(list, "%s", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
return *list != NULL;
|
return *list != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool set_white_black(const char* list) {
|
static bool set_white_black(const char* list) {
|
||||||
FILE* fp;
|
|
||||||
logcat_define(ctx);
|
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), logcat_executable " -P '%s' 2>&1",
|
snprintf(buffer, sizeof(buffer), logcat_executable " -P '%s' 2>&1",
|
||||||
list ? list : "");
|
list ? list : "");
|
||||||
fp = logcat_popen(ctx, buffer);
|
FILE* fp = popen(buffer, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "ERROR: %s\n", buffer);
|
fprintf(stderr, "ERROR: %s\n", buffer);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1391,10 +1362,10 @@ static bool set_white_black(const char* list) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s\n", buf);
|
fprintf(stderr, "%s\n", buf);
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return logcat_pclose(ctx, fp) == 0;
|
return pclose(fp) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(logcat, white_black_adjust) {
|
TEST(logcat, white_black_adjust) {
|
||||||
|
|
@ -1429,7 +1400,6 @@ TEST(logcat, white_black_adjust) {
|
||||||
|
|
||||||
TEST(logcat, regex) {
|
TEST(logcat, regex) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
@ -1450,7 +1420,7 @@ TEST(logcat, regex) {
|
||||||
// Let the logs settle
|
// Let the logs settle
|
||||||
rest();
|
rest();
|
||||||
|
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
|
ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
if (!strncmp(begin, buffer, sizeof(begin) - 1)) {
|
if (!strncmp(begin, buffer, sizeof(begin) - 1)) {
|
||||||
|
|
@ -1462,14 +1432,13 @@ TEST(logcat, regex) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
ASSERT_EQ(2, count);
|
ASSERT_EQ(2, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(logcat, maxcount) {
|
TEST(logcat, maxcount) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
logcat_define(ctx);
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
char buffer[BIG_BUFFER];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
@ -1488,7 +1457,7 @@ TEST(logcat, maxcount) {
|
||||||
|
|
||||||
rest();
|
rest();
|
||||||
|
|
||||||
ASSERT_TRUE(NULL != (fp = logcat_popen(ctx, buffer)));
|
ASSERT_TRUE(NULL != (fp = popen(buffer, "r")));
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
if (!strncmp(begin, buffer, sizeof(begin) - 1)) {
|
if (!strncmp(begin, buffer, sizeof(begin) - 1)) {
|
||||||
|
|
@ -1498,7 +1467,7 @@ TEST(logcat, maxcount) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
ASSERT_EQ(3, count);
|
ASSERT_EQ(3, count);
|
||||||
}
|
}
|
||||||
|
|
@ -1510,13 +1479,7 @@ static bool End_to_End(const char* tag, const char* fmt, ...)
|
||||||
;
|
;
|
||||||
|
|
||||||
static bool End_to_End(const char* tag, const char* fmt, ...) {
|
static bool End_to_End(const char* tag, const char* fmt, ...) {
|
||||||
logcat_define(ctx);
|
FILE* fp = popen(logcat_executable " -v brief -b events -v descriptive -t 100 2>/dev/null", "r");
|
||||||
FILE* fp = logcat_popen(ctx, logcat_executable
|
|
||||||
" -v brief"
|
|
||||||
" -b events"
|
|
||||||
" -v descriptive"
|
|
||||||
" -t 100"
|
|
||||||
" 2>/dev/null");
|
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "End_to_End: popen failed");
|
fprintf(stderr, "End_to_End: popen failed");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1551,7 +1514,7 @@ static bool End_to_End(const char* tag, const char* fmt, ...) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
if ((count == 0) && (lastMatch.length() > 0)) {
|
if ((count == 0) && (lastMatch.length() > 0)) {
|
||||||
// Help us pinpoint where things went wrong ...
|
// Help us pinpoint where things went wrong ...
|
||||||
|
|
@ -1741,13 +1704,12 @@ TEST(logcat, descriptive) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool reportedSecurity(const char* command) {
|
static bool reportedSecurity(const char* command) {
|
||||||
logcat_define(ctx);
|
FILE* fp = popen(command, "r");
|
||||||
FILE* fp = logcat_popen(ctx, command);
|
|
||||||
if (!fp) return true;
|
if (!fp) return true;
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
bool val = android::base::ReadFdToString(fileno(fp), &ret);
|
bool val = android::base::ReadFdToString(fileno(fp), &ret);
|
||||||
logcat_pclose(ctx, fp);
|
pclose(fp);
|
||||||
|
|
||||||
if (!val) return true;
|
if (!val) return true;
|
||||||
return std::string::npos != ret.find("'security'");
|
return std::string::npos != ret.find("'security'");
|
||||||
|
|
@ -1762,13 +1724,12 @@ TEST(logcat, security) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t commandOutputSize(const char* command) {
|
static size_t commandOutputSize(const char* command) {
|
||||||
logcat_define(ctx);
|
FILE* fp = popen(command, "r");
|
||||||
FILE* fp = logcat_popen(ctx, command);
|
|
||||||
if (!fp) return 0;
|
if (!fp) return 0;
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
if (!android::base::ReadFdToString(fileno(fp), &ret)) return 0;
|
if (!android::base::ReadFdToString(fileno(fp), &ret)) return 0;
|
||||||
if (logcat_pclose(ctx, fp) != 0) return 0;
|
if (pclose(fp) != 0) return 0;
|
||||||
|
|
||||||
return ret.size();
|
return ret.size();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue