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