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) module for open[at](2) [or similar] entry $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7#
8############################################################ DESCRIPTION
9#
10# Print path being passed to open(2), openat(2), or similar
11#
12############################################################ PROBE
13
14case "$PROFILE" in
15open) : ${PROBE:=syscall::open:entry, syscall::openat:entry} ;;
16   *) : ${PROBE:=syscall::$PROFILE:entry}
17esac
18
19############################################################ ACTIONS
20
21exec 9<<EOF
22this string path;
23this u_char at;
24
25$PROBE /* probe ID $ID */
26{${TRACE:+
27	printf("<$ID>");
28}
29	/*
30	 * Should we expect the first argument to be a file descriptor?
31	 * NB: Based on probefunc ending in "at" (e.g., openat(2))
32	 */
33	this->at = strstr(probefunc, "at") ==
34		(probefunc + strlen(probefunc) - 2) ? 1 : 0;
35
36	this->path = copyinstr(this->at ? arg1 : arg0);
37}
38EOF
39ACTIONS=$( cat <&9 )
40ID=$(( $ID + 1 ))
41
42############################################################ EVENT DETAILS
43
44if [ ! "$CUSTOM_DETAILS" ]; then
45exec 9<<EOF
46	/*
47	 * Print path details
48	 */
49	printf("%s", this->path);
50EOF
51EVENT_DETAILS=$( cat <&9 )
52fi
53
54################################################################################
55# END
56################################################################################
57