| #!/bin/sh |
| |
| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Script that turns on useful logging for flimflam |
| |
| FLIMFLAM="org.chromium.flimflam" |
| MANAGER="${FLIMFLAM}.Manager" |
| send_ff_cmd() { |
| local cmd="$1" |
| shift 1 |
| dbus-send --system "--dest=${FLIMFLAM}" --print-reply / "${MANAGER}.${cmd}" \ |
| "$@" 2>/dev/null |
| } |
| |
| FF_TAGLIST="$(send_ff_cmd ListDebugTags | sed -e \ |
| '/string/!d; s/[[:space:]]\+/ /g' | cut -d "\"" -f 2 | tr "+" " ")" |
| |
| usage(){ |
| cat <<EOF |
| Usage: ff_debug [<tag_expression>]|[--reset]|[--help]|[--list_valid_tags]|[--level <level>] |
| |
| ff_debug adds and removes debug tags for flimflam. |
| Current debug settings are displayed if no parameters are provided |
| |
| <tag_expression> is defined in boolean notation using <debug_tag> separated |
| by an operator [+-], where + and - imply adding and removing of the tag immediately |
| following the operator. An expression beginning with either operators [+-] |
| takes the existing tags and modifies them appropriately. Otherwise, the existing tags |
| are replaced by those specified in the command. |
| |
| <debug_tag> can be listed using the --list_valid_tags |
| |
| e.g.: ff_debug network+wifi |
| Sets debug tags to network and wifi |
| e.g.: ff_debug +network-service |
| Adds network and removes service tags from the existing debug settings |
| |
| --list_valid_tags : Displays all valid tags |
| |
| --level: Displays or sets current debug level for logging |
| All messages at, or above, the current log level are logged. Normal log |
| levels range from 4 (LOG_FATAL) to 0 (LOG_INFO). In addition VERBOSE log |
| levels are available starting at -1. |
| |
| e.g.: ff_debug --level 4 |
| Logs only FATAL messages. |
| e.g.: ff_debug --level 0 |
| Logs INFO, WARNING, ERROR, ERROR_REPORT, and FATAL messages. |
| e.g.: ff_debug --level -4 |
| Logs everything that "--level 0" does, plus SLOG(<tag>, <n>) messages, |
| where <tag> has been enabled for logging, and <n> <= 4. (NOTE: you must |
| negate SLOG levels for use with ff_debug. In this example, SLOG(<tag>, 4) |
| maps to "--level -4".) |
| |
| --reset : Removes all tagging |
| |
| --help : Displays this output |
| EOF |
| } |
| |
| get_ff_debug_tags() { |
| send_ff_cmd GetDebugTags | sed -e '/string/!d; s/[[:space:]]\+/ /g' | \ |
| cut -d "\"" -f 2 |
| } |
| |
| set_ff_debug_tags() { |
| send_ff_cmd SetDebugTags string:"$1" > /dev/null |
| } |
| |
| get_ff_debug_level() { |
| send_ff_cmd GetDebugLevel | sed -e '/int32/!d; s/[[:space:]]\+/ /g' | \ |
| cut -d " " -f 3 |
| } |
| |
| set_ff_debug_level() { |
| send_ff_cmd SetDebugLevel int32:"$1" > /dev/null |
| } |
| |
| starting_ff_tags="$(get_ff_debug_tags)" |
| |
| get_or_set_debug_level() { |
| local ff_debug_level |
| ff_debug_level="$(get_ff_debug_level)" |
| if [ -z "${ff_debug_level}" ]; then |
| # flimflam does not implement GetDebugLevel / SetDebugLevel, simply return |
| return |
| fi |
| |
| if [ $# -gt 0 ]; then |
| echo "Old flimflam debug level: ${ff_debug_level}" |
| set_ff_debug_level "$1" |
| ff_debug_level="$(get_ff_debug_level)" |
| fi |
| echo "Current flimflam debug level: ${ff_debug_level}" |
| } |
| |
| if [ $# -gt 0 ]; then |
| while [ $# -gt 0 ]; do |
| case "$1" in |
| --reset) |
| set_ff_debug_tags '' |
| break |
| ;; |
| --level) |
| shift # move forward to the <level> argument if specified |
| get_or_set_debug_level "$@" |
| exit 0 |
| ;; |
| --list*) |
| echo "Valid Tags: [$(echo "${FF_TAGLIST}" | sed 's/ /, /g')]" |
| exit 0 |
| ;; |
| --help|--*) |
| usage |
| exit 0 |
| ;; |
| *) |
| set_ff_debug_tags "$1" |
| ;; |
| esac |
| shift |
| done |
| |
| echo "Old flimflam tags: [${starting_ff_tags}]" |
| fi |
| echo "Current flimflam tags: [$(get_ff_debug_tags)]" |