aboutsummaryrefslogtreecommitdiff
path: root/libltrace.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2011-07-09 11:14:11 +0200
committerPetr Machata <pmachata@redhat.com>2011-10-06 14:17:56 +0200
commitcebb88491e68bdf4d466b03970c9ca77f65615f8 (patch)
treede0830cb7548a42b9125c31c98b7286c9f3edf4a /libltrace.c
parentc7585b60235268e1f62bd91c5f040ef6df6e0ef3 (diff)
downloadltrace-cebb88491e68bdf4d466b03970c9ca77f65615f8.tar.gz
Conceal the list of processes behind an interface
Diffstat (limited to 'libltrace.c')
-rw-r--r--libltrace.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/libltrace.c b/libltrace.c
index 5408fb6..018923d 100644
--- a/libltrace.c
+++ b/libltrace.c
@@ -12,32 +12,39 @@
#include "common.h"
char *command = NULL;
-Process *list_of_processes = NULL;
int exiting = 0; /* =1 if a SIGINT or SIGTERM has been received */
-static void
-signal_alarm(int sig) {
- Process *tmp = list_of_processes;
+static enum pcb_status
+stop_non_p_processes (Process * proc, void * data)
+{
+ int stop = 1;
- signal(SIGALRM, SIG_DFL);
- while (tmp) {
- struct opt_p_t *tmp2 = opt_p;
- while (tmp2) {
- if (tmp->pid == tmp2->pid) {
- tmp = tmp->next;
- if (!tmp) {
- return;
- }
- tmp2 = opt_p;
- continue;
- }
- tmp2 = tmp2->next;
+ struct opt_p_t *it;
+ for (it = opt_p; it != NULL; it = it->next) {
+ Process * p_proc = pid2proc(it->pid);
+ if (p_proc == NULL) {
+ printf("stop_non_p_processes: %d terminated?\n", it->pid);
+ continue;
}
- debug(2, "Sending SIGSTOP to process %u\n", tmp->pid);
- kill(tmp->pid, SIGSTOP);
- tmp = tmp->next;
+ if (p_proc == proc) {
+ stop = 0;
+ break;
+ }
+ }
+
+ if (stop) {
+ debug(2, "Sending SIGSTOP to process %u", proc->pid);
+ kill(proc->pid, SIGSTOP);
}
+
+ return pcb_cont;
+}
+
+static void
+signal_alarm(int sig) {
+ signal(SIGALRM, SIG_DFL);
+ each_process(NULL, &stop_non_p_processes, NULL);
}
static void