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