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