Move event-que declarations to sysdeps, new backend interface process_removed

- the reason being that the que-handling was declared on global level, but
  was only implemented in one back end.  If this is deemed generally useful,
  it should all be moved to front end, but as things are it's all the same,
  so I'm preferring the less invasive change
diff --git a/sysdeps/linux-gnu/Makefile.am b/sysdeps/linux-gnu/Makefile.am
index e6fd7ef..e385ea7 100644
--- a/sysdeps/linux-gnu/Makefile.am
+++ b/sysdeps/linux-gnu/Makefile.am
@@ -29,7 +29,8 @@
 	arch_syscallent.h \
 	signalent1.h \
 	syscallent1.h \
-	trace.h
+	trace.h \
+	events.h
 
 EXTRA_DIST = \
 	arch_mksyscallent \
diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c
index 91d873e..21b327b 100644
--- a/sysdeps/linux-gnu/events.c
+++ b/sysdeps/linux-gnu/events.c
@@ -14,6 +14,7 @@
 #include "common.h"
 #include "breakpoint.h"
 #include "proc.h"
+#include "events.h"
 
 static Event event;
 
@@ -311,3 +312,20 @@
 
 	return &event;
 }
+
+static enum ecb_status
+event_for_proc(struct Event *event, void *data)
+{
+	if (event->proc == data)
+		return ecb_deque;
+	else
+		return ecb_cont;
+}
+
+void
+delete_events_for(struct Process *proc)
+{
+	struct Event *event;
+	while ((event = each_qd_event(&event_for_proc, proc)) != NULL)
+		free(event);
+}
diff --git a/sysdeps/linux-gnu/events.h b/sysdeps/linux-gnu/events.h
new file mode 100644
index 0000000..e91caa2
--- /dev/null
+++ b/sysdeps/linux-gnu/events.h
@@ -0,0 +1,21 @@
+#ifndef SYSDEPS_LINUX_GNU_EVENTS_H
+#define SYSDEPS_LINUX_GNU_EVENTS_H
+
+#include "forward.h"
+
+/* Declarations for event que functions.  */
+
+enum ecb_status {
+	ecb_cont, /* The iteration should continue.  */
+	ecb_yield, /* The iteration should stop, yielding this
+		    * event.  */
+	ecb_deque, /* Like ecb_stop, but the event should be removed
+		    * from the queue.  */
+};
+
+struct Event *each_qd_event(enum ecb_status (*cb)(struct Event *event,
+						  void *data), void *data);
+void delete_events_for(struct Process * proc);
+void enque_event(struct Event *event);
+
+#endif /* SYSDEPS_LINUX_GNU_EVENTS_H */
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index c5282e4..97969dc 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -15,10 +15,12 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "config.h"
 #include "common.h"
 #include "breakpoint.h"
 #include "proc.h"
 #include "library.h"
+#include "events.h"
 
 /* /proc/pid doesn't exist just after the fork, and sometimes `ltrace'
  * couldn't open it to find the executable.  So it may be necessary to
@@ -588,3 +590,9 @@
         ret = syscall (__NR_tkill, pid, sig);
 	return ret;
 }
+
+void
+process_removed(struct Process *proc)
+{
+	delete_events_for(proc);
+}
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index f25fabc..8407eea 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -20,6 +20,7 @@
 #include "proc.h"
 #include "linux-gnu/trace.h"
 #include "type.h"
+#include "events.h"
 
 /* If the system headers did not provide the constants, hard-code the normal
    values.  */