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 dtrace_proc(4) activity $ 6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $ 7# $FreeBSD$ 8# 9############################################################ DESCRIPTION 10# 11# Display process activity 12# 13############################################################ PROBE 14 15case "$PROFILE" in 16proc) 17 : ${PROBE:=$( echo \ 18 proc:::create, \ 19 proc:::exec, \ 20 proc:::exec-failure, \ 21 proc:::exec-success, \ 22 proc:::exit, \ 23 proc:::signal-clear, \ 24 proc:::signal-discard, \ 25 proc:::signal-send )} 26 ;; 27proc-signal) 28 : ${PROBE:=$( echo \ 29 proc:::signal-clear, \ 30 proc:::signal-discard, \ 31 proc:::signal-send )} 32 ;; 33proc-status) 34 : ${PROBE:=$( echo \ 35 proc:::create, \ 36 proc:::exec, \ 37 proc:::exec-failure, \ 38 proc:::exec-success, \ 39 proc:::exit )} 40 ;; 41*) 42 : ${PROBE:=proc:::${PROFILE#proc-}} 43esac 44 45############################################################ ACTIONS 46 47exec 9<<EOF 48this int sig; 49this pid_t pid; 50this string details; 51this string exec_arg0; 52 53inline string probealias[string name] = 54 name == "create" ? "FORK" : 55 name == "exec" ? "EXEC" : 56 name == "exec-failure" ? "FAIL" : 57 name == "exec-success" ? "INIT" : 58 name == "exit" ? "EXIT" : 59 name == "signal-clear" ? "CLEAR" : 60 name == "signal-discard" ? "DISCARD" : 61 name == "signal-send" ? "SEND" : 62 name; 63 64$PROBE /* probe ID $ID */ 65{${TRACE:+ 66 printf("<$ID>");} 67 this->details = ""; 68} 69 70proc:::create /* probe ID $(( $ID + 1 )) */ 71{${TRACE:+ 72 printf("<$(( $ID + 1 ))>"); 73} 74 $( pproc -P _create "(struct proc *)args[0]" ) 75 76 /* details = "pid <pid of args[0]> -- <proc args of args[0]>" */ 77 this->details = strjoin( 78 strjoin("pid ", lltostr(this->pid_create)), 79 strjoin(" -- ", this->args_create)); 80} 81 82proc:::exec /* probe ID $(( $ID + 2 )) */ 83{${TRACE:+ 84 printf("<$(( $ID + 2 ))");} 85 this->details = this->exec_arg0 = stringof(arg0); 86} 87 88proc:::exec-failure /* probe ID $(( $ID + 3 )) */ 89{${TRACE:+ 90 printf("<$(( $ID + 3 ))>"); 91} 92 /* details = "<arg0 from proc:::exec>: <strerror of arg0> (<arg0>)" */ 93 this->details = strjoin( 94 strjoin(this->exec_arg0, ": "), 95 strjoin(strerror[(int)arg0], 96 strjoin(" (", strjoin(lltostr((int)arg0), ")")))); 97} 98 99proc:::exec-success /* probe ID $(( $ID + 4 )) */ 100{${TRACE:+ 101 printf("<$(( $ID + 4 ))>");} 102 this->details = this->args0; 103} 104 105proc:::exit /* probe ID $(( $ID + 5 )) */ 106{${TRACE:+ 107 printf("<$(( $ID + 5 ))>");} 108 this->details = child_signal_string[(int)arg0]; 109} 110 111proc:::signal-clear /* probe ID $(( $ID + 6 )) */ 112{${TRACE:+ 113 printf("<$(( $ID + 6 ))>");} 114 this->pid = (pid_t)((ksiginfo_t *)args[1])->ksi_info.si_pid; 115 this->sig = (int)arg0; 116} 117 118proc:::signal-discard, proc:::signal-send /* probe ID $(( $ID + 7 )) */ 119{${TRACE:+ 120 printf("<$(( $ID + 7 ))>");} 121 this->pid = (pid_t)((struct proc *)args[1])->p_pid; 122 this->sig = (int)arg2; 123} 124 125proc:::signal-clear, 126proc:::signal-discard, 127proc:::signal-send /* probe ID $(( $ID + 8 )) */ 128{${TRACE:+ 129 printf("<$(( $ID + 8 ))>"); 130} 131 /* details = "<signal>[<num>] pid <pid>" */ 132 this->details = strjoin(strjoin(signal_string[this->sig], "["), 133 strjoin(strjoin(lltostr(this->sig), "] pid "), 134 lltostr(this->pid))); 135} 136 137proc:::signal-send, proc:::signal-discard /* probe ID $(( $ID + 9 )) */ 138{${TRACE:+ 139 printf("<$(( $ID + 9 ))>"); 140} 141 $( pproc -P _signal "(struct proc *)args[1]" ) 142 143 this->details = strjoin(this->details, 144 strjoin(" -- ", this->args_signal)); 145} 146EOF 147ACTIONS=$( cat <&9 ) 148ID=$(( $ID + 10 )) 149 150############################################################ EVENT DETAILS 151 152exec 9<<EOF 153 /* 154 * Print details 155 */ 156 printf("%s %s", probealias[probename], this->details); 157EOF 158EVENT_DETAILS=$( cat <&9 ) 159 160################################################################################ 161# END 162################################################################################ 163