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