File: include-pstore

package info (click to toggle)
linux 4.19.194-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 967,940 kB
  • sloc: ansic: 16,799,826; asm: 272,028; makefile: 38,421; sh: 33,838; perl: 27,701; python: 21,148; cpp: 5,066; yacc: 4,650; lex: 2,584; awk: 1,385; ruby: 25; sed: 5
file content (77 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download | duplicates (62)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
_add_pstore_log() {
  if [ $# -le 3 ]; then
    return
  fi

  local backend="$1"
  local event="$2"
  local date="$3"

  yesno "Include log of $event at $(date -d @$date +%c) stored by $backend?" yep
  if [ $REPLY != yep ]; then
    return
  fi

  echo >&3
  echo "*** Log of $event at $(date -d @$date -Iseconds) from $backend" >&3

  shift 3
  for file in "$@"; do
    tail -n +2 "$file" | sed 's/^<.>//' >&3
  done
}

add_pstore() {
  local backend
  local i
  local j
  local file
  local date
  local head
  local event
  local log_files

  if ! mountpoint -q /sys/fs/pstore; then
    return 0
  fi

  set -- /sys/fs/pstore/dmesg-*-1
  backend=${1#*/dmesg-}
  backend=${backend%-1}
  if [ "$backend" = '*' ]; then
    return 0
  fi

  i=1
  while [ -f /sys/fs/pstore/dmesg-$backend-$i ]; do
    file=/sys/fs/pstore/dmesg-$backend-$i
    head="$(head -1 "$file")"

    # Is this the first part of a log?
    if [ "x${head% Part1}" != "x$head" ]; then
      # Flush previous log, if any
      _add_pstore_log "$backend" "$event" "$date" $log_files

      event="${head% Part1}"
      date=$(stat -c %Y $file)
      log_files=
      j=1
    fi

    if [ "x$head" = "x$event Part$j" ]; then
      # Each part is prepended to the list, because they're numbered
      # backward in log history
      log_files="$file $log_files"
      j=$((j + 1))
    fi

    i=$((i + 1))
  done

  # Flush last log, if any
  _add_pstore_log "$backend" "$event" "$date" $log_files
}

ask_pstore() {
  add_pstore
}