This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Added new functions in tapset/signal.stp


Hi,

I have written numerous new functions for the signal tapset. These
functions are used in my psig scripts (see my next post), and can be
reused in other scripts.

Kindly accept and commit the patch.

Thanks,
Eugene

diff -Naur src.default/tapset/ChangeLog src/tapset/ChangeLog
--- src.default/tapset/ChangeLog	2008-01-05 03:39:54.000000000 +0800
+++ src/tapset/ChangeLog	2008-01-14 10:55:21.000000000 +0800
@@ -1,3 +1,16 @@
+2008-1-14  Eugene Teo  <eteo@redhat.com>
+
+	* signal.stp (get_sa_flags, get_sa_handler): New functions to
+	return addresses of sa_flags and sa_handler of struct k_sigaction.
+	(sigset_mask_str): New function. Returns a string containing the
+	set of signals to be blocked when executing the signal handler.
+	(is_sig_blocked): New function. Checks task_struct->blocked signal
+	mask for signals that are currently blocked.
+	(signal_str): New function. Translates a signal number.
+	(sa_flags_str): New function. Translates the sa_flags.
+	(sa_handler_str): New function. Returns the signal action or handler
+	associated to the signal.
+
 2008-1-4  Masami Hiramatsu <mhiramat@redhat.com>
 
 	* aux_syscalls.stp (_stp_fork_list): Check kernel version for new
diff -Naur src.default/tapset/signal.stp src/tapset/signal.stp
--- src.default/tapset/signal.stp	2007-12-27 14:58:23.000000000 +0800
+++ src/tapset/signal.stp	2008-01-14 10:37:55.000000000 +0800
@@ -1,6 +1,7 @@
 // Signal tapset
 // Copyright (C) 2006 IBM Corp.
 // Copyright (C) 2006 Intel Corporation.
+// Copyright (C) 2008 Red Hat, Inc.
 //
 // This file is part of systemtap, and is free software.  You can
 // redistribute it and/or modify it under the terms of the GNU General
@@ -505,3 +506,155 @@
     sig_pid = $t->pid
     pid_name = kernel_string($t->comm)
 } 
+
+function get_sa_flags:long (act:long) %{ /* pure */
+	struct k_sigaction *act = (struct k_sigaction *)((long)THIS->act);	
+	THIS->__retvalue = (long)act->sa.sa_flags;
+%}
+
+function get_sa_handler:long (act:long) %{ /* pure */
+	struct k_sigaction *act = (struct k_sigaction *)((long)THIS->act);	
+	THIS->__retvalue = (long)act->sa.sa_handler;
+%}
+
+/*
+ * sa_mask contains the set of signals to be blocked when executing the
+ * signal handler. This function returns a string, delimited by ",".
+ *
+ * struct task_struct {
+ * [...]
+ *         struct signal_struct *signal;
+ *         struct sighand_struct *sighand;
+ * [...]
+ * struct sighand_struct {
+ *         atomic_t                count;
+ *         struct k_sigaction      action[_NSIG];
+ * [...]
+ * struct k_sigaction {
+ *         struct sigaction sa;
+ * };
+ *
+ * struct sigaction {
+ * [...]
+ *         sigset_t sa_mask;
+ * };
+ */
+function sigset_mask_str:string (mask:long) %{ /* pure */
+	int i;
+	char str[256], tmp[10];
+	str[0] = '\0';
+	for (i = 1; i < _NSIG; ++i) {
+		if (THIS->mask & 1) {
+			sprintf(tmp, "%u,", i);
+			strcat(str, tmp);
+		}
+		THIS->mask >>= 1;
+	}
+	if (str[0] != '\0') str[strlen(str)-1] = '\0';
+	strlcpy (THIS->__retvalue, str, MAXSTRINGLEN);
+%}
+
+/*
+ * task_struct->blocked signal mask contains the set of signals that are
+ * currently blocked.
+ *
+ * struct task_struct {
+ * [...]
+ *         sigset_t blocked, real_blocked;
+ */
+function is_sig_blocked:long (task:long, sig:long) %{ /* pure */
+	struct task_struct *p = (struct task_struct *)((long)THIS->task);
+	THIS->__retvalue = !p ? -1 : sigismember(&p->blocked, THIS->sig);
+%}
+
+/*
+ * Signals start from 1 not 0.
+ */
+function signal_str(sig) {
+	if (sig == 1) return "HUP";
+	if (sig == 2) return "INT";
+	if (sig == 3) return "QUIT";
+	if (sig == 4) return "ILL";
+	if (sig == 5) return "TRAP";
+	if (sig == 6) return "ABRT"; /* or IOT */
+	if (sig == 7) return "BUS";
+	if (sig == 8) return "FPE";
+	if (sig == 9) return "KILL";
+	if (sig == 10) return "USR1";
+	if (sig == 11) return "SEGV";
+	if (sig == 12) return "USR2";
+	if (sig == 13) return "PIPE";
+	if (sig == 14) return "ALRM";
+	if (sig == 15) return "TERM";
+	if (sig == 16) return "STKFLT";
+	if (sig == 17) return "CHLD"; /* or CLD */
+	if (sig == 18) return "CONT";
+	if (sig == 19) return "STOP";
+	if (sig == 20) return "TSTP";
+	if (sig == 21) return "TTIN";
+	if (sig == 22) return "TTOU";
+	if (sig == 23) return "URG";
+	if (sig == 24) return "XCPU";
+	if (sig == 25) return "XFSZ";
+	if (sig == 26) return "VTALRM";
+	if (sig == 27) return "PROF";
+	if (sig == 28) return "WINCH";
+	if (sig == 29) return "IO/POLL";
+	if (sig == 30) return "PWR";
+	if (sig == 31) return "SYS"; /* or UNUSED */
+	if (sig == 32) return "RTMIN";
+	if (sig == 33) return "RTMIN+1";
+	if (sig == 34) return "RTMIN+2";
+	if (sig == 35) return "RTMIN+3";
+	if (sig == 36) return "RTMIN+4";
+	if (sig == 37) return "RTMIN+5";
+	if (sig == 38) return "RTMIN+6";
+	if (sig == 39) return "RTMIN+7";
+	if (sig == 40) return "RTMIN+8";
+	if (sig == 41) return "RTMIN+9";
+	if (sig == 42) return "RTMIN+10";
+	if (sig == 43) return "RTMIN+11";
+	if (sig == 44) return "RTMIN+12";
+	if (sig == 45) return "RTMIN+13";
+	if (sig == 46) return "RTMIN+14";
+	if (sig == 47) return "RTMIN+15";
+	if (sig == 48) return "RTMIN+16";
+	if (sig == 49) return "RTMAX-15";
+	if (sig == 50) return "RTMAX-14";
+	if (sig == 51) return "RTMAX-13";
+	if (sig == 52) return "RTMAX-12";
+	if (sig == 53) return "RTMAX-11";
+	if (sig == 54) return "RTMAX-10";
+	if (sig == 55) return "RTMAX-9";
+	if (sig == 56) return "RTMAX-8";
+	if (sig == 57) return "RTMAX-7";
+	if (sig == 58) return "RTMAX-6";
+	if (sig == 59) return "RTMAX-5";
+	if (sig == 60) return "RTMAX-4";
+	if (sig == 61) return "RTMAX-3";
+	if (sig == 62) return "RTMAX-2";
+	if (sig == 63) return "RTMAX-1";
+	if (sig == 64) return "RTMAX";
+}
+
+function sa_flags_str:string (sa_flags:long) %{ /* pure */
+	char str[256];
+	str[0] = '\0';
+	if (THIS->sa_flags & 0x00000001u) strcat(str, "NOCLDSTOP|");
+	if (THIS->sa_flags & 0x00000002u) strcat(str, "NOCLDWAIT|");
+	if (THIS->sa_flags & 0x00000004u) strcat(str, "SIGINFO|");
+	if (THIS->sa_flags & 0x08000000u) strcat(str, "ONSTACK|");
+	if (THIS->sa_flags & 0x10000000u) strcat(str, "RESTART|");
+	if (THIS->sa_flags & 0x40000000u) strcat(str, "NODEFER|");
+	if (THIS->sa_flags & 0x80000000u) strcat(str, "RESETHAND|");
+	if (THIS->sa_flags & 0x04000000) strcat(str, "RESTORER|");
+	if (str[0] != '\0') str[strlen(str)-1] = '\0';
+	strlcpy (THIS->__retvalue, str, MAXSTRINGLEN);
+%}
+
+function sa_handler_str(handler) {
+	if (handler == 0) return "default"; /* SIG_DFL */
+	if (handler == 1) return "ignored"; /* SIG_IGN */
+	if (handler == -1) return "error"; /* SIG_ERR */
+	return sprintf("%p", handler); /* userspace address */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]