1# -*- tab-width: 4 -*- ;; Emacs
2# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
3############################################################ IDENT(1)
4#
5# $Title: dwatch(8) gource module for VOP_*(9) activity $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7# $FrauBSD: dwatch-gource/gource-vfs 2018-05-29 21:51:31 +0000 freebsdfrau $
8#
9############################################################ DESCRIPTION
10#
11# Produce gource custom log format for filesystem activity
12#
13############################################################ PROBE
14
15_RAW_PROFILE=gource-vfs-raw
16load_profile $_RAW_PROFILE
17
18############################################################ GLOBALS
19
20: ${_DEBUG=}
21
22############################################################ MAIN
23
24if [ "$DEBUG$EXIT_AFTER_COMPILE" ]; then
25	eval dwatch $ARGV -qFX $_RAW_PROFILE
26	exit
27fi
28
29info "Watching '$PROBE' ..."
30eval dwatch $ARGV -qFX $_RAW_PROFILE | awk -v debug=$_DEBUG '
31	BEGIN {
32		date = "[[:digit:]]+ [A-Z][a-z][a-z] [0-9 ][0-9]"
33		time = "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]"
34		stderr = "/dev/stderr"
35	}
36	debug { printf "DEBUG: %s\n", $0 > stderr; fflush(stderr) }
37	length(datetime = substr($0, 1, 20)) != 20 { next }
38	datetime !~ "^" date " " time "$" { next }
39	(epoch = $9) !~ /^[[:digit:]]+/ { next }
40	(execname = $6) && sub(/\[[[:digit:]]+\]:$/, "", execname) {
41		if ((probe = $8) ~ /remove|rm/) type = "D"
42		else if (probe ~ /lookup/) type = "M"
43		else type = "A"
44		sub(/.*:entry [[:digit:]]+ /, "")
45		printf "%u|%s|%s|%s\n", epoch, execname, type, (path = $0)
46		fflush()
47	}
48' # END-QUOTE
49
50exit $SUCCESS
51
52################################################################################
53# END
54################################################################################
55