History

connector: Added coredumping event to the process connector

Process connector can now also detect coredumping events. Main aim of patch is get notified at start of coredumping, instead of having to wait for it to finish and then being notified through EXIT event. Could be used for instance by process-managers that want to get notified as soon as possible about process failures, and not necessarily beeing notified after coredump, which could be in the order of minutes depending on size of coredump, piping and so on.

Jesper Derehag committed 13 years ago

Commit 2b5faa41 parent 800c6444 files · +40 −1Browse files

Unified · Split

4 files
  1. drivers/connector/cn_proc.c +25 −0
  2. include/linux/cn_proc.h +4 −0
  3. include/uapi/linux/cn_proc.h +9 −1
  4. kernel/signal.c +2 −0
drivers/connector/cn_proc.c+25−0
@@ -232,6 +232,31 @@ void proc_comm_connector(struct task_struct *task) · 231 unmodified lines
232232 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
233233 }
234234
235+void proc_coredump_connector(struct task_struct *task)
236+{
237+ struct cn_msg *msg;
238+ struct proc_event *ev;
239+ __u8 buffer[CN_PROC_MSG_SIZE];
240+ struct timespec ts;
241+
242+ if (atomic_read(&proc_event_num_listeners) < 1)
243+ return;
244+
245+ msg = (struct cn_msg *)buffer;
246+ ev = (struct proc_event *)msg->data;
247+ get_seq(&msg->seq, &ev->cpu);
248+ ktime_get_ts(&ts); /* get high res monotonic timestamp */
249+ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
250+ ev->what = PROC_EVENT_COREDUMP;
251+ ev->event_data.coredump.process_pid = task->pid;
252+ ev->event_data.coredump.process_tgid = task->tgid;
253+
254+ memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
255+ msg->ack = 0; /* not used */
256+ msg->len = sizeof(*ev);
257+ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
258+}
259+
235260 void proc_exit_connector(struct task_struct *task)
236261 {
237262 struct cn_msg *msg;
include/linux/cn_proc.h+4−0
@@ -26,6 +26,7 @@ void proc_id_connector(struct task_struct *task, int which_id); · 25 unmodified lines
2626 void proc_sid_connector(struct task_struct *task);
2727 void proc_ptrace_connector(struct task_struct *task, int which_id);
2828 void proc_comm_connector(struct task_struct *task);
29+void proc_coredump_connector(struct task_struct *task);
2930 void proc_exit_connector(struct task_struct *task);
3031 #else
3132 static inline void proc_fork_connector(struct task_struct *task)
@@ -48,6 +49,9 @@ static inline void proc_ptrace_connector(struct task_struct *task, · 16 unmodified lines
4849 int ptrace_id)
4950 {}
5051
52+static inline void proc_coredump_connector(struct task_struct *task)
53+{}
54+
5155 static inline void proc_exit_connector(struct task_struct *task)
5256 {}
5357 #endif /* CONFIG_PROC_EVENTS */
include/uapi/linux/cn_proc.h+9−1
@@ -56,7 +56,9 @@ struct proc_event { · 55 unmodified lines
5656 PROC_EVENT_PTRACE = 0x00000100,
5757 PROC_EVENT_COMM = 0x00000200,
5858 /* "next" should be 0x00000400 */
59− /* "last" is the last process event: exit */
59+ /* "last" is the last process event: exit,
60+ * while "next to last" is coredumping event */
61+ PROC_EVENT_COREDUMP = 0x40000000,
6062 PROC_EVENT_EXIT = 0x80000000
6163 } what;
6264 __u32 cpu;
@@ -110,11 +112,17 @@ struct proc_event { · 47 unmodified lines
110112 char comm[16];
111113 } comm;
112114
115+ struct coredump_proc_event {
116+ __kernel_pid_t process_pid;
117+ __kernel_pid_t process_tgid;
118+ } coredump;
119+
113120 struct exit_proc_event {
114121 __kernel_pid_t process_pid;
115122 __kernel_pid_t process_tgid;
116123 __u32 exit_code, exit_signal;
117124 } exit;
125+
118126 } event_data;
119127 };
120128
kernel/signal.c+2−0
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 #include <linux/user_namespace.h>
3333 #include <linux/uprobes.h>
3434 #include <linux/compat.h>
35+#include <linux/cn_proc.h>
3536 #define CREATE_TRACE_POINTS
3637 #include <trace/events/signal.h>
3738
@@ -2350,6 +2351,7 @@ relock: · 2312 unmodified lines
23502351 if (sig_kernel_coredump(signr)) {
23512352 if (print_fatal_signals)
23522353 print_fatal_signal(info->si_signo);
2354+ proc_coredump_connector(current);
23532355 /*
23542356 * If it was able to dump core, this kills all
23552357 * other threads in the group and synchronizes with

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t