Fix retval value assignment on error
[ust.git] / libust / tracectl.c
1 /* Copyright (C) 2009 Pierre-Marc Fournier
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 /* This file contains the implementation of the UST listener thread, which
19 * receives trace control commands. It also coordinates the initialization of
20 * libust.
21 */
22
23 #define _GNU_SOURCE
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <pthread.h>
28 #include <signal.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
32 #include <fcntl.h>
33 #include <poll.h>
34 #include <regex.h>
35 #include <urcu/uatomic_arch.h>
36
37 #include <ust/marker.h>
38 #include <ust/tracectl.h>
39 #include "tracer.h"
40 #include "usterr.h"
41 #include "ustcomm.h"
42 #include "buffers.h"
43 #include "marker-control.h"
44 #include "multipoll.h"
45
46 #define USTSIGNAL SIGIO
47
48 #define MAX_MSG_SIZE (100)
49 #define MSG_NOTIF 1
50 #define MSG_REGISTER_NOTIF 2
51
52 /* This should only be accessed by the constructor, before the creation
53 * of the listener, and then only by the listener.
54 */
55 s64 pidunique = -1LL;
56
57 extern struct chan_info_struct chan_infos[];
58
59 struct list_head blocked_consumers = LIST_HEAD_INIT(blocked_consumers);
60
61 static struct ustcomm_app ustcomm_app;
62
63 struct tracecmd { /* no padding */
64 uint32_t size;
65 uint16_t command;
66 };
67
68 /* volatile because shared between the listener and the main thread */
69 int buffers_to_export = 0;
70
71 struct trctl_msg {
72 /* size: the size of all the fields except size itself */
73 uint32_t size;
74 uint16_t type;
75 /* Only the necessary part of the payload is transferred. It
76 * may even be none of it.
77 */
78 char payload[94];
79 };
80
81 struct consumer_channel {
82 int fd;
83 struct ltt_channel_struct *chan;
84 };
85
86 struct blocked_consumer {
87 int fd_consumer;
88 int fd_producer;
89 int tmp_poll_idx;
90
91 /* args to ustcomm_send_reply */
92 struct ustcomm_server server;
93 struct ustcomm_source src;
94
95 /* args to ust_buffers_get_subbuf */
96 struct ust_buffer *buf;
97
98 struct list_head list;
99 };
100
101 static long long make_pidunique(void)
102 {
103 s64 retval;
104 struct timeval tv;
105
106 gettimeofday(&tv, NULL);
107
108 retval = tv.tv_sec;
109 retval <<= 32;
110 retval |= tv.tv_usec;
111
112 return retval;
113 }
114
115 static void print_markers(FILE *fp)
116 {
117 struct marker_iter iter;
118
119 lock_markers();
120 marker_iter_reset(&iter);
121 marker_iter_start(&iter);
122
123 while(iter.marker) {
124 fprintf(fp, "marker: %s/%s %d \"%s\" %p\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format, iter.marker->location);
125 marker_iter_next(&iter);
126 }
127 unlock_markers();
128 }
129
130 static int init_socket(void);
131
132 /* Ask the daemon to collect a trace called trace_name and being
133 * produced by this pid.
134 *
135 * The trace must be at least allocated. (It can also be started.)
136 * This is because _ltt_trace_find is used.
137 */
138
139 static void inform_consumer_daemon(const char *trace_name)
140 {
141 int i,j;
142 struct ust_trace *trace;
143 pid_t pid = getpid();
144 int result;
145
146 ltt_lock_traces();
147
148 trace = _ltt_trace_find(trace_name);
149 if(trace == NULL) {
150 WARN("inform_consumer_daemon: could not find trace \"%s\"; it is probably already destroyed", trace_name);
151 goto finish;
152 }
153
154 for(i=0; i < trace->nr_channels; i++) {
155 if(trace->channels[i].request_collection) {
156 /* iterate on all cpus */
157 for(j=0; j<trace->channels[i].n_cpus; j++) {
158 char *buf;
159 if (asprintf(&buf, "%s_%d", trace->channels[i].channel_name, j) < 0) {
160 ERR("inform_consumer_daemon : asprintf failed (%s_%d)",
161 trace->channels[i].channel_name, j);
162 goto finish;
163 }
164 result = ustcomm_request_consumer(pid, buf);
165 if(result == -1) {
166 WARN("Failed to request collection for channel %s. Is the daemon available?", trace->channels[i].channel_name);
167 /* continue even if fail */
168 }
169 free(buf);
170 STORE_SHARED(buffers_to_export, LOAD_SHARED(buffers_to_export)+1);
171 }
172 }
173 }
174
175 finish:
176 ltt_unlock_traces();
177 }
178
179 int process_blkd_consumer_act(void *priv, int fd, short events)
180 {
181 int result;
182 long consumed_old = 0;
183 char *reply;
184 struct blocked_consumer *bc = (struct blocked_consumer *) priv;
185 char inbuf;
186
187 result = read(bc->fd_producer, &inbuf, 1);
188 if(result == -1) {
189 PERROR("read");
190 return -1;
191 }
192 if(result == 0) {
193 int res;
194 DBG("listener: got messsage that a buffer ended");
195
196 res = close(bc->fd_producer);
197 if(res == -1) {
198 PERROR("close");
199 }
200
201 list_del(&bc->list);
202
203 result = ustcomm_send_reply(&bc->server, "END", &bc->src);
204 if(result < 0) {
205 ERR("ustcomm_send_reply failed");
206 return -1;
207 }
208
209 return 0;
210 }
211
212 result = ust_buffers_get_subbuf(bc->buf, &consumed_old);
213 if(result == -EAGAIN) {
214 WARN("missed buffer?");
215 return 0;
216 }
217 else if(result < 0) {
218 ERR("ust_buffers_get_subbuf: error: %s", strerror(-result));
219 }
220 if (asprintf(&reply, "%s %ld", "OK", consumed_old) < 0) {
221 ERR("process_blkd_consumer_act : asprintf failed (OK %ld)",
222 consumed_old);
223 return -1;
224 }
225 result = ustcomm_send_reply(&bc->server, reply, &bc->src);
226 if(result < 0) {
227 ERR("ustcomm_send_reply failed");
228 free(reply);
229 return -1;
230 }
231 free(reply);
232
233 list_del(&bc->list);
234
235 return 0;
236 }
237
238 void blocked_consumers_add_to_mp(struct mpentries *ent)
239 {
240 struct blocked_consumer *bc;
241
242 list_for_each_entry(bc, &blocked_consumers, list) {
243 multipoll_add(ent, bc->fd_producer, POLLIN, process_blkd_consumer_act, bc, NULL);
244 }
245
246 }
247
248 void seperate_channel_cpu(const char *channel_and_cpu, char **channel, int *cpu)
249 {
250 const char *sep;
251
252 sep = rindex(channel_and_cpu, '_');
253 if(sep == NULL) {
254 *cpu = -1;
255 sep = channel_and_cpu + strlen(channel_and_cpu);
256 }
257 else {
258 *cpu = atoi(sep+1);
259 }
260
261 if (asprintf(channel, "%.*s", (int)(sep-channel_and_cpu), channel_and_cpu) < 0) {
262 ERR("seperate_channel_cpu : asprintf failed (%.*s)",
263 (int)(sep-channel_and_cpu), channel_and_cpu);
264 return;
265 }
266 }
267
268 static int do_cmd_get_shmid(const char *recvbuf, struct ustcomm_source *src)
269 {
270 int retval = 0;
271 struct ust_trace *trace;
272 char trace_name[] = "auto";
273 int i;
274 char *channel_and_cpu;
275 int found = 0;
276 int result;
277 char *ch_name;
278 int ch_cpu;
279
280 DBG("get_shmid");
281
282 channel_and_cpu = nth_token(recvbuf, 1);
283 if(channel_and_cpu == NULL) {
284 ERR("cannot parse channel");
285 retval = -1;
286 goto end;
287 }
288
289 seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
290 if(ch_cpu == -1) {
291 ERR("problem parsing channel name");
292 retval = -1;
293 goto free_short_chan_name;
294 }
295
296 ltt_lock_traces();
297 trace = _ltt_trace_find(trace_name);
298 ltt_unlock_traces();
299
300 if(trace == NULL) {
301 ERR("cannot find trace!");
302 retval = -1;
303 goto free_short_chan_name;
304 }
305
306 for(i=0; i<trace->nr_channels; i++) {
307 struct ust_channel *channel = &trace->channels[i];
308 struct ust_buffer *buf = channel->buf[ch_cpu];
309
310 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
311 char *reply;
312
313 // DBG("the shmid for the requested channel is %d", buf->shmid);
314 // DBG("the shmid for its buffer structure is %d", channel->buf_struct_shmids);
315 if (asprintf(&reply, "%d %d", buf->shmid, channel->buf_struct_shmids[ch_cpu]) < 0) {
316 ERR("do_cmd_get_shmid : asprintf failed (%d %d)",
317 buf->shmid, channel->buf_struct_shmids[ch_cpu]);
318 retval = -1;
319 goto free_short_chan_name;
320 }
321
322 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
323 if(result) {
324 ERR("ustcomm_send_reply failed");
325 free(reply);
326 retval = -1;
327 goto free_short_chan_name;
328 }
329
330 free(reply);
331
332 found = 1;
333 break;
334 }
335 }
336
337 if(!found) {
338 ERR("channel not found (%s)", channel_and_cpu);
339 }
340
341 free_short_chan_name:
342 free(ch_name);
343
344 end:
345 return retval;
346 }
347
348 static int do_cmd_get_n_subbufs(const char *recvbuf, struct ustcomm_source *src)
349 {
350 int retval = 0;
351 struct ust_trace *trace;
352 char trace_name[] = "auto";
353 int i;
354 char *channel_and_cpu;
355 int found = 0;
356 int result;
357 char *ch_name;
358 int ch_cpu;
359
360 DBG("get_n_subbufs");
361
362 channel_and_cpu = nth_token(recvbuf, 1);
363 if(channel_and_cpu == NULL) {
364 ERR("cannot parse channel");
365 retval = -1;
366 goto end;
367 }
368
369 seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
370 if(ch_cpu == -1) {
371 ERR("problem parsing channel name");
372 retval = -1;
373 goto free_short_chan_name;
374 }
375
376 ltt_lock_traces();
377 trace = _ltt_trace_find(trace_name);
378 ltt_unlock_traces();
379
380 if(trace == NULL) {
381 ERR("cannot find trace!");
382 retval = -1;
383 goto free_short_chan_name;
384 }
385
386 for(i=0; i<trace->nr_channels; i++) {
387 struct ust_channel *channel = &trace->channels[i];
388
389 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
390 char *reply;
391
392 DBG("the n_subbufs for the requested channel is %d", channel->subbuf_cnt);
393 if (asprintf(&reply, "%d", channel->subbuf_cnt) < 0) {
394 ERR("do_cmd_get_n_subbufs : asprintf failed (%d)",
395 channel->subbuf_cnt);
396 retval = -1;
397 goto free_short_chan_name;
398 }
399
400 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
401 if(result) {
402 ERR("ustcomm_send_reply failed");
403 free(reply);
404 retval = -1;
405 goto free_short_chan_name;
406 }
407
408 free(reply);
409 found = 1;
410 break;
411 }
412 }
413 if(found == 0) {
414 ERR("unable to find channel");
415 }
416
417 free_short_chan_name:
418 free(ch_name);
419
420 end:
421 return retval;
422 }
423
424 static int do_cmd_get_subbuf_size(const char *recvbuf, struct ustcomm_source *src)
425 {
426 int retval = 0;
427 struct ust_trace *trace;
428 char trace_name[] = "auto";
429 int i;
430 char *channel_and_cpu;
431 int found = 0;
432 int result;
433 char *ch_name;
434 int ch_cpu;
435
436 DBG("get_subbuf_size");
437
438 channel_and_cpu = nth_token(recvbuf, 1);
439 if(channel_and_cpu == NULL) {
440 ERR("cannot parse channel");
441 retval = -1;
442 goto end;
443 }
444
445 seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
446 if(ch_cpu == -1) {
447 ERR("problem parsing channel name");
448 retval = -1;
449 goto free_short_chan_name;
450 }
451
452 ltt_lock_traces();
453 trace = _ltt_trace_find(trace_name);
454 ltt_unlock_traces();
455
456 if(trace == NULL) {
457 ERR("cannot find trace!");
458 retval = -1;
459 goto free_short_chan_name;
460 }
461
462 for(i=0; i<trace->nr_channels; i++) {
463 struct ust_channel *channel = &trace->channels[i];
464
465 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
466 char *reply;
467
468 DBG("the subbuf_size for the requested channel is %zd", channel->subbuf_size);
469 if (asprintf(&reply, "%zd", channel->subbuf_size) < 0) {
470 ERR("do_cmd_get_subbuf_size : asprintf failed (%zd)",
471 channel->subbuf_size);
472 retval = -1;
473 goto free_short_chan_name;
474 }
475
476 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
477 if(result) {
478 ERR("ustcomm_send_reply failed");
479 free(reply);
480 retval = -1;
481 goto free_short_chan_name;
482 }
483
484 free(reply);
485 found = 1;
486 break;
487 }
488 }
489 if(found == 0) {
490 ERR("unable to find channel");
491 }
492
493 free_short_chan_name:
494 free(ch_name);
495
496 end:
497 return retval;
498 }
499
500 /* Return the power of two which is equal or higher to v */
501
502 static unsigned int pow2_higher_or_eq(unsigned int v)
503 {
504 int hb = fls(v);
505 int retval = 1<<(hb-1);
506
507 if(v-retval == 0)
508 return retval;
509 else
510 return retval<<1;
511 }
512
513 static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *src)
514 {
515 char *channel_slash_size;
516 char ch_name[256]="";
517 unsigned int size, power;
518 int retval = 0;
519 struct ust_trace *trace;
520 char trace_name[] = "auto";
521 int i;
522 int found = 0;
523
524 DBG("set_subbuf_size");
525
526 channel_slash_size = nth_token(recvbuf, 1);
527 sscanf(channel_slash_size, "%255[^/]/%u", ch_name, &size);
528
529 if(ch_name == NULL) {
530 ERR("cannot parse channel");
531 retval = -1;
532 goto end;
533 }
534
535 power = pow2_higher_or_eq(size);
536 power = max_t(unsigned int, 2u, power);
537 if (power != size)
538 WARN("using the next power of two for buffer size = %u\n", power);
539
540 ltt_lock_traces();
541 trace = _ltt_trace_find_setup(trace_name);
542 if(trace == NULL) {
543 ERR("cannot find trace!");
544 retval = -1;
545 goto end;
546 }
547
548 for(i = 0; i < trace->nr_channels; i++) {
549 struct ust_channel *channel = &trace->channels[i];
550
551 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
552
553 channel->subbuf_size = power;
554 DBG("the set_subbuf_size for the requested channel is %zd", channel->subbuf_size);
555
556 found = 1;
557 break;
558 }
559 }
560 if(found == 0) {
561 ERR("unable to find channel");
562 }
563
564 end:
565 ltt_unlock_traces();
566 return retval;
567 }
568
569 static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src)
570 {
571 char *channel_slash_num;
572 char ch_name[256]="";
573 unsigned int num;
574 int retval = 0;
575 struct ust_trace *trace;
576 char trace_name[] = "auto";
577 int i;
578 int found = 0;
579
580 DBG("set_subbuf_num");
581
582 channel_slash_num = nth_token(recvbuf, 1);
583 sscanf(channel_slash_num, "%255[^/]/%u", ch_name, &num);
584
585 if(ch_name == NULL) {
586 ERR("cannot parse channel");
587 retval = -1;
588 goto end;
589 }
590 if (num < 2) {
591 ERR("subbuffer count should be greater than 2");
592 retval = -1;
593 goto end;
594 }
595
596 ltt_lock_traces();
597 trace = _ltt_trace_find_setup(trace_name);
598 if(trace == NULL) {
599 ERR("cannot find trace!");
600 retval = -1;
601 goto end;
602 }
603
604 for(i = 0; i < trace->nr_channels; i++) {
605 struct ust_channel *channel = &trace->channels[i];
606
607 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
608
609 channel->subbuf_cnt = num;
610 DBG("the set_subbuf_cnt for the requested channel is %zd", channel->subbuf_cnt);
611
612 found = 1;
613 break;
614 }
615 }
616 if(found == 0) {
617 ERR("unable to find channel");
618 }
619
620 end:
621 ltt_unlock_traces();
622 return retval;
623 }
624
625 static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
626 {
627 int retval = 0;
628 struct ust_trace *trace;
629 char trace_name[] = "auto";
630 int i;
631 char *channel_and_cpu;
632 int found = 0;
633 char *ch_name;
634 int ch_cpu;
635
636 DBG("get_subbuf");
637
638 channel_and_cpu = nth_token(recvbuf, 1);
639 if(channel_and_cpu == NULL) {
640 ERR("cannot parse channel");
641 retval = -1;
642 goto end;
643 }
644
645 seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
646 if(ch_cpu == -1) {
647 ERR("problem parsing channel name");
648 retval = -1;
649 goto free_short_chan_name;
650 }
651
652 ltt_lock_traces();
653 trace = _ltt_trace_find(trace_name);
654
655 if(trace == NULL) {
656 int result;
657
658 DBG("Cannot find trace. It was likely destroyed by the user.");
659 result = ustcomm_send_reply(&ustcomm_app.server, "NOTFOUND", src);
660 if(result) {
661 ERR("ustcomm_send_reply failed");
662 retval = -1;
663 goto unlock_traces;
664 }
665
666 goto unlock_traces;
667 }
668
669 for(i=0; i<trace->nr_channels; i++) {
670 struct ust_channel *channel = &trace->channels[i];
671
672 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
673 struct ust_buffer *buf = channel->buf[ch_cpu];
674 struct blocked_consumer *bc;
675
676 found = 1;
677
678 bc = (struct blocked_consumer *) malloc(sizeof(struct blocked_consumer));
679 if(bc == NULL) {
680 ERR("malloc returned NULL");
681 goto unlock_traces;
682 }
683 bc->fd_consumer = src->fd;
684 bc->fd_producer = buf->data_ready_fd_read;
685 bc->buf = buf;
686 bc->src = *src;
687 bc->server = ustcomm_app.server;
688
689 list_add(&bc->list, &blocked_consumers);
690
691 /* Being here is the proof the daemon has mapped the buffer in its
692 * memory. We may now decrement buffers_to_export.
693 */
694 if(uatomic_read(&buf->consumed) == 0) {
695 DBG("decrementing buffers_to_export");
696 STORE_SHARED(buffers_to_export, LOAD_SHARED(buffers_to_export)-1);
697 }
698
699 break;
700 }
701 }
702 if(found == 0) {
703 ERR("unable to find channel");
704 }
705
706 unlock_traces:
707 ltt_unlock_traces();
708
709 free_short_chan_name:
710 free(ch_name);
711
712 end:
713 return retval;
714 }
715
716 static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src)
717 {
718 int retval = 0;
719 struct ust_trace *trace;
720 char trace_name[] = "auto";
721 int i;
722 char *channel_and_cpu;
723 int found = 0;
724 int result;
725 char *ch_name;
726 int ch_cpu;
727 long consumed_old;
728 char *consumed_old_str;
729 char *endptr;
730 char *reply = NULL;
731
732 DBG("put_subbuf");
733
734 channel_and_cpu = strdup(nth_token(recvbuf, 1));
735 if(channel_and_cpu == NULL) {
736 ERR("cannot parse channel");
737 retval = -1;
738 goto end;
739 }
740
741 consumed_old_str = strdup(nth_token(recvbuf, 2));
742 if(consumed_old_str == NULL) {
743 ERR("cannot parse consumed_old");
744 retval = -1;
745 goto free_channel_and_cpu;
746 }
747 consumed_old = strtol(consumed_old_str, &endptr, 10);
748 if(*endptr != '\0') {
749 ERR("invalid value for consumed_old");
750 retval = -1;
751 goto free_consumed_old_str;
752 }
753
754 seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
755 if(ch_cpu == -1) {
756 ERR("problem parsing channel name");
757 retval = -1;
758 goto free_short_chan_name;
759 }
760
761 ltt_lock_traces();
762 trace = _ltt_trace_find(trace_name);
763
764 if(trace == NULL) {
765 DBG("Cannot find trace. It was likely destroyed by the user.");
766 result = ustcomm_send_reply(&ustcomm_app.server, "NOTFOUND", src);
767 if(result) {
768 ERR("ustcomm_send_reply failed");
769 retval = -1;
770 goto unlock_traces;
771 }
772
773 goto unlock_traces;
774 }
775
776 for(i=0; i<trace->nr_channels; i++) {
777 struct ust_channel *channel = &trace->channels[i];
778
779 if(!strcmp(trace->channels[i].channel_name, ch_name)) {
780 struct ust_buffer *buf = channel->buf[ch_cpu];
781
782 found = 1;
783
784 result = ust_buffers_put_subbuf(buf, consumed_old);
785 if(result < 0) {
786 WARN("ust_buffers_put_subbuf: error (subbuf=%s)", channel_and_cpu);
787 if (asprintf(&reply, "%s", "ERROR") < 0) {
788 ERR("do_cmd_put_subbuffer : asprintf failed (ERROR)");
789 retval = -1;
790 goto unlock_traces;
791 }
792 }
793 else {
794 DBG("ust_buffers_put_subbuf: success (subbuf=%s)", channel_and_cpu);
795 if (asprintf(&reply, "%s", "OK") < 0) {
796 ERR("do_cmd_put_subbuffer : asprintf failed (OK)");
797 retval = -1;
798 goto unlock_traces;
799 }
800 }
801
802 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
803 if(result) {
804 ERR("ustcomm_send_reply failed");
805 free(reply);
806 retval = -1;
807 goto unlock_traces;
808 }
809
810 free(reply);
811 break;
812 }
813 }
814 if(found == 0) {
815 ERR("unable to find channel");
816 }
817
818 unlock_traces:
819 ltt_unlock_traces();
820 free_short_chan_name:
821 free(ch_name);
822 free_consumed_old_str:
823 free(consumed_old_str);
824 free_channel_and_cpu:
825 free(channel_and_cpu);
826
827 end:
828 return retval;
829 }
830
831 static void listener_cleanup(void *ptr)
832 {
833 ustcomm_fini_app(&ustcomm_app, 0);
834 }
835
836 static void do_cmd_force_switch()
837 {
838 struct blocked_consumer *bc;
839
840 list_for_each_entry(bc, &blocked_consumers, list) {
841 ltt_force_switch(bc->buf, FORCE_FLUSH);
842 }
843 }
844
845 int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
846 {
847 int result;
848 char trace_name[] = "auto";
849 char trace_type[] = "ustrelay";
850 int len;
851
852 DBG("received a message! it's: %s", recvbuf);
853 len = strlen(recvbuf);
854
855 if(!strcmp(recvbuf, "print_markers")) {
856 print_markers(stderr);
857 }
858 else if(!strcmp(recvbuf, "list_markers")) {
859 char *ptr;
860 size_t size;
861 FILE *fp;
862
863 fp = open_memstream(&ptr, &size);
864 print_markers(fp);
865 fclose(fp);
866
867 result = ustcomm_send_reply(&ustcomm_app.server, ptr, src);
868
869 free(ptr);
870 }
871 else if(!strcmp(recvbuf, "start")) {
872 /* start is an operation that setups the trace, allocates it and starts it */
873 result = ltt_trace_setup(trace_name);
874 if(result < 0) {
875 ERR("ltt_trace_setup failed");
876 return -1;
877 }
878
879 result = ltt_trace_set_type(trace_name, trace_type);
880 if(result < 0) {
881 ERR("ltt_trace_set_type failed");
882 return -1;
883 }
884
885 result = ltt_trace_alloc(trace_name);
886 if(result < 0) {
887 ERR("ltt_trace_alloc failed");
888 return -1;
889 }
890
891 inform_consumer_daemon(trace_name);
892
893 result = ltt_trace_start(trace_name);
894 if(result < 0) {
895 ERR("ltt_trace_start failed");
896 return -1;
897 }
898 }
899 else if(!strcmp(recvbuf, "trace_setup")) {
900 DBG("trace setup");
901
902 result = ltt_trace_setup(trace_name);
903 if(result < 0) {
904 ERR("ltt_trace_setup failed");
905 return -1;
906 }
907
908 result = ltt_trace_set_type(trace_name, trace_type);
909 if(result < 0) {
910 ERR("ltt_trace_set_type failed");
911 return -1;
912 }
913 }
914 else if(!strcmp(recvbuf, "trace_alloc")) {
915 DBG("trace alloc");
916
917 result = ltt_trace_alloc(trace_name);
918 if(result < 0) {
919 ERR("ltt_trace_alloc failed");
920 return -1;
921 }
922 inform_consumer_daemon(trace_name);
923 }
924 else if(!strcmp(recvbuf, "trace_create")) {
925 DBG("trace create");
926
927 result = ltt_trace_setup(trace_name);
928 if(result < 0) {
929 ERR("ltt_trace_setup failed");
930 return -1;
931 }
932
933 result = ltt_trace_set_type(trace_name, trace_type);
934 if(result < 0) {
935 ERR("ltt_trace_set_type failed");
936 return -1;
937 }
938 }
939 else if(!strcmp(recvbuf, "trace_start")) {
940 DBG("trace start");
941
942 result = ltt_trace_alloc(trace_name);
943 if(result < 0) {
944 ERR("ltt_trace_alloc failed");
945 return -1;
946 }
947 if(!result) {
948 inform_consumer_daemon(trace_name);
949 }
950
951 result = ltt_trace_start(trace_name);
952 if(result < 0) {
953 ERR("ltt_trace_start failed");
954 return -1;
955 }
956 }
957 else if(!strcmp(recvbuf, "trace_stop")) {
958 DBG("trace stop");
959
960 result = ltt_trace_stop(trace_name);
961 if(result < 0) {
962 ERR("ltt_trace_stop failed");
963 return -1;
964 }
965 }
966 else if(!strcmp(recvbuf, "trace_destroy")) {
967
968 DBG("trace destroy");
969
970 result = ltt_trace_destroy(trace_name, 0);
971 if(result < 0) {
972 ERR("ltt_trace_destroy failed");
973 return -1;
974 }
975 }
976 else if(nth_token_is(recvbuf, "get_shmid", 0) == 1) {
977 do_cmd_get_shmid(recvbuf, src);
978 }
979 else if(nth_token_is(recvbuf, "get_n_subbufs", 0) == 1) {
980 do_cmd_get_n_subbufs(recvbuf, src);
981 }
982 else if(nth_token_is(recvbuf, "get_subbuf_size", 0) == 1) {
983 do_cmd_get_subbuf_size(recvbuf, src);
984 }
985 else if(nth_token_is(recvbuf, "load_probe_lib", 0) == 1) {
986 char *libfile;
987
988 libfile = nth_token(recvbuf, 1);
989
990 DBG("load_probe_lib loading %s", libfile);
991
992 free(libfile);
993 }
994 else if(nth_token_is(recvbuf, "get_subbuffer", 0) == 1) {
995 do_cmd_get_subbuffer(recvbuf, src);
996 }
997 else if(nth_token_is(recvbuf, "put_subbuffer", 0) == 1) {
998 do_cmd_put_subbuffer(recvbuf, src);
999 }
1000 else if(nth_token_is(recvbuf, "set_subbuf_size", 0) == 1) {
1001 do_cmd_set_subbuf_size(recvbuf, src);
1002 }
1003 else if(nth_token_is(recvbuf, "set_subbuf_num", 0) == 1) {
1004 do_cmd_set_subbuf_num(recvbuf, src);
1005 }
1006 else if(nth_token_is(recvbuf, "enable_marker", 0) == 1) {
1007 char *channel_slash_name = nth_token(recvbuf, 1);
1008 char channel_name[256]="";
1009 char marker_name[256]="";
1010
1011 result = sscanf(channel_slash_name, "%255[^/]/%255s", channel_name, marker_name);
1012
1013 if(channel_name == NULL || marker_name == NULL) {
1014 WARN("invalid marker name");
1015 goto next_cmd;
1016 }
1017
1018 result = ltt_marker_connect(channel_name, marker_name, "default");
1019 if(result < 0) {
1020 WARN("could not enable marker; channel=%s, name=%s", channel_name, marker_name);
1021 }
1022 }
1023 else if(nth_token_is(recvbuf, "disable_marker", 0) == 1) {
1024 char *channel_slash_name = nth_token(recvbuf, 1);
1025 char *marker_name;
1026 char *channel_name;
1027
1028 result = sscanf(channel_slash_name, "%a[^/]/%as", &channel_name, &marker_name);
1029
1030 if(marker_name == NULL) {
1031 }
1032
1033 result = ltt_marker_disconnect(channel_name, marker_name, "default");
1034 if(result < 0) {
1035 WARN("could not disable marker; channel=%s, name=%s", channel_name, marker_name);
1036 }
1037 }
1038 else if(nth_token_is(recvbuf, "get_pidunique", 0) == 1) {
1039 char *reply;
1040
1041 if (asprintf(&reply, "%lld", pidunique) < 0) {
1042 ERR("process_client_cmd : asprintf failed (%lld)",
1043 pidunique);
1044 goto next_cmd;
1045 }
1046
1047 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
1048 if(result) {
1049 ERR("listener: get_pidunique: ustcomm_send_reply failed");
1050 goto next_cmd;
1051 }
1052
1053 free(reply);
1054 }
1055 else if(nth_token_is(recvbuf, "get_sock_path", 0) == 1) {
1056 char *reply = getenv("UST_DAEMON_SOCKET");
1057 if(!reply) {
1058 if (asprintf(&reply, "%s/%s", SOCK_DIR, "ustd") < 0) {
1059 ERR("process_client_cmd : asprintf failed (%s/ustd)",
1060 SOCK_DIR);
1061 goto next_cmd;
1062 }
1063 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
1064 free(reply);
1065 }
1066 else {
1067 result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
1068 }
1069 if(result)
1070 ERR("ustcomm_send_reply failed");
1071 }
1072 else if(nth_token_is(recvbuf, "set_sock_path", 0) == 1) {
1073 char *sock_path = nth_token(recvbuf, 1);
1074 result = setenv("UST_DAEMON_SOCKET", sock_path, 1);
1075 if(result)
1076 ERR("cannot set UST_DAEMON_SOCKET environment variable");
1077 }
1078 else if(nth_token_is(recvbuf, "force_switch", 0) == 1) {
1079 do_cmd_force_switch();
1080 }
1081 else {
1082 ERR("unable to parse message: %s", recvbuf);
1083 }
1084
1085 next_cmd:
1086
1087 return 0;
1088 }
1089
1090 void *listener_main(void *p)
1091 {
1092 int result;
1093
1094 DBG("LISTENER");
1095
1096 pthread_cleanup_push(listener_cleanup, NULL);
1097
1098 for(;;) {
1099 struct mpentries mpent;
1100
1101 multipoll_init(&mpent);
1102
1103 blocked_consumers_add_to_mp(&mpent);
1104 ustcomm_mp_add_app_clients(&mpent, &ustcomm_app, process_client_cmd);
1105
1106 result = multipoll_poll(&mpent, -1);
1107 if(result == -1) {
1108 ERR("error in multipoll_poll");
1109 }
1110
1111 multipoll_destroy(&mpent);
1112 }
1113
1114 pthread_cleanup_pop(1);
1115 }
1116
1117 /* These should only be accessed in the parent thread,
1118 * not the listener.
1119 */
1120 static volatile sig_atomic_t have_listener = 0;
1121 static pthread_t listener_thread;
1122
1123 void create_listener(void)
1124 {
1125 int result;
1126 sigset_t sig_all_blocked;
1127 sigset_t orig_parent_mask;
1128
1129 if(have_listener) {
1130 WARN("not creating listener because we already had one");
1131 return;
1132 }
1133
1134 /* A new thread created by pthread_create inherits the signal mask
1135 * from the parent. To avoid any signal being received by the
1136 * listener thread, we block all signals temporarily in the parent,
1137 * while we create the listener thread.
1138 */
1139
1140 sigfillset(&sig_all_blocked);
1141
1142 result = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_parent_mask);
1143 if(result) {
1144 PERROR("pthread_sigmask: %s", strerror(result));
1145 }
1146
1147 result = pthread_create(&listener_thread, NULL, listener_main, NULL);
1148 if(result == -1) {
1149 PERROR("pthread_create");
1150 }
1151
1152 /* Restore original signal mask in parent */
1153 result = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL);
1154 if(result) {
1155 PERROR("pthread_sigmask: %s", strerror(result));
1156 }
1157 else {
1158 have_listener = 1;
1159 }
1160 }
1161
1162 static int init_socket(void)
1163 {
1164 return ustcomm_init_app(getpid(), &ustcomm_app);
1165 }
1166
1167 #define AUTOPROBE_DISABLED 0
1168 #define AUTOPROBE_ENABLE_ALL 1
1169 #define AUTOPROBE_ENABLE_REGEX 2
1170 static int autoprobe_method = AUTOPROBE_DISABLED;
1171 static regex_t autoprobe_regex;
1172
1173 static void auto_probe_connect(struct marker *m)
1174 {
1175 int result;
1176
1177 char* concat_name = NULL;
1178 const char *probe_name = "default";
1179
1180 if(autoprobe_method == AUTOPROBE_DISABLED) {
1181 return;
1182 }
1183 else if(autoprobe_method == AUTOPROBE_ENABLE_REGEX) {
1184 result = asprintf(&concat_name, "%s/%s", m->channel, m->name);
1185 if(result == -1) {
1186 ERR("auto_probe_connect: asprintf failed (marker %s/%s)",
1187 m->channel, m->name);
1188 return;
1189 }
1190 if (regexec(&autoprobe_regex, concat_name, 0, NULL, 0)) {
1191 free(concat_name);
1192 return;
1193 }
1194 free(concat_name);
1195 }
1196
1197 result = ltt_marker_connect(m->channel, m->name, probe_name);
1198 if(result && result != -EEXIST)
1199 ERR("ltt_marker_connect (marker = %s/%s, errno = %d)", m->channel, m->name, -result);
1200
1201 DBG("auto connected marker %s (addr: %p) %s to probe default", m->channel, m, m->name);
1202
1203 }
1204
1205 static void __attribute__((constructor)) init()
1206 {
1207 int result;
1208 char* autoprobe_val = NULL;
1209 char* subbuffer_size_val = NULL;
1210 char* subbuffer_count_val = NULL;
1211 unsigned int subbuffer_size;
1212 unsigned int subbuffer_count;
1213 unsigned int power;
1214
1215 /* Assign the pidunique, to be able to differentiate the processes with same
1216 * pid, (before and after an exec).
1217 */
1218 pidunique = make_pidunique();
1219
1220 DBG("Tracectl constructor");
1221
1222 result = init_socket();
1223 if(result == -1) {
1224 ERR("init_socket error");
1225 return;
1226 }
1227
1228 create_listener();
1229
1230 autoprobe_val = getenv("UST_AUTOPROBE");
1231 if(autoprobe_val) {
1232 struct marker_iter iter;
1233
1234 DBG("Autoprobe enabled.");
1235
1236 /* Ensure markers are initialized */
1237 //init_markers();
1238
1239 /* Ensure marker control is initialized, for the probe */
1240 init_marker_control();
1241
1242 /* first, set the callback that will connect the
1243 * probe on new markers
1244 */
1245 if(autoprobe_val[0] == '/') {
1246 result = regcomp(&autoprobe_regex, autoprobe_val+1, 0);
1247 if (result) {
1248 char regexerr[150];
1249
1250 regerror(result, &autoprobe_regex, regexerr, sizeof(regexerr));
1251 ERR("cannot parse regex %s (%s), will ignore UST_AUTOPROBE", autoprobe_val, regexerr);
1252 /* don't crash the application just for this */
1253 }
1254 else {
1255 autoprobe_method = AUTOPROBE_ENABLE_REGEX;
1256 }
1257 }
1258 else {
1259 /* just enable all instrumentation */
1260 autoprobe_method = AUTOPROBE_ENABLE_ALL;
1261 }
1262
1263 marker_set_new_marker_cb(auto_probe_connect);
1264
1265 /* Now, connect the probes that were already registered. */
1266 marker_iter_reset(&iter);
1267 marker_iter_start(&iter);
1268
1269 DBG("now iterating on markers already registered");
1270 while(iter.marker) {
1271 DBG("now iterating on marker %s", iter.marker->name);
1272 auto_probe_connect(iter.marker);
1273 marker_iter_next(&iter);
1274 }
1275 }
1276
1277 if(getenv("UST_OVERWRITE")) {
1278 int val = atoi(getenv("UST_OVERWRITE"));
1279 if(val == 0 || val == 1) {
1280 STORE_SHARED(ust_channels_overwrite_by_default, val);
1281 }
1282 else {
1283 WARN("invalid value for UST_OVERWRITE");
1284 }
1285 }
1286
1287 if(getenv("UST_AUTOCOLLECT")) {
1288 int val = atoi(getenv("UST_AUTOCOLLECT"));
1289 if(val == 0 || val == 1) {
1290 STORE_SHARED(ust_channels_request_collection_by_default, val);
1291 }
1292 else {
1293 WARN("invalid value for UST_AUTOCOLLECT");
1294 }
1295 }
1296
1297 subbuffer_size_val = getenv("UST_SUBBUF_SIZE");
1298 if(subbuffer_size_val) {
1299 sscanf(subbuffer_size_val, "%u", &subbuffer_size);
1300 power = pow2_higher_or_eq(subbuffer_size);
1301 if(power != subbuffer_size)
1302 WARN("using the next power of two for buffer size = %u\n", power);
1303 chan_infos[LTT_CHANNEL_UST].def_subbufsize = power;
1304 }
1305
1306 subbuffer_count_val = getenv("UST_SUBBUF_NUM");
1307 if(subbuffer_count_val) {
1308 sscanf(subbuffer_count_val, "%u", &subbuffer_count);
1309 if(subbuffer_count < 2)
1310 subbuffer_count = 2;
1311 chan_infos[LTT_CHANNEL_UST].def_subbufcount = subbuffer_count;
1312 }
1313
1314 if(getenv("UST_TRACE")) {
1315 char trace_name[] = "auto";
1316 char trace_type[] = "ustrelay";
1317
1318 DBG("starting early tracing");
1319
1320 /* Ensure marker control is initialized */
1321 init_marker_control();
1322
1323 /* Ensure markers are initialized */
1324 init_markers();
1325
1326 /* Ensure buffers are initialized, for the transport to be available.
1327 * We are about to set a trace type and it will fail without this.
1328 */
1329 init_ustrelay_transport();
1330
1331 /* FIXME: When starting early tracing (here), depending on the
1332 * order of constructors, it is very well possible some marker
1333 * sections are not yet registered. Because of this, some
1334 * channels may not be registered. Yet, we are about to ask the
1335 * daemon to collect the channels. Channels which are not yet
1336 * registered will not be collected.
1337 *
1338 * Currently, in LTTng, there is no way to add a channel after
1339 * trace start. The reason for this is that it induces complex
1340 * concurrency issues on the trace structures, which can only
1341 * be resolved using RCU. This has not been done yet. As a
1342 * workaround, we are forcing the registration of the "ust"
1343 * channel here. This is the only channel (apart from metadata)
1344 * that can be reliably used in early tracing.
1345 *
1346 * Non-early tracing does not have this problem and can use
1347 * arbitrary channel names.
1348 */
1349 ltt_channels_register("ust");
1350
1351 result = ltt_trace_setup(trace_name);
1352 if(result < 0) {
1353 ERR("ltt_trace_setup failed");
1354 return;
1355 }
1356
1357 result = ltt_trace_set_type(trace_name, trace_type);
1358 if(result < 0) {
1359 ERR("ltt_trace_set_type failed");
1360 return;
1361 }
1362
1363 result = ltt_trace_alloc(trace_name);
1364 if(result < 0) {
1365 ERR("ltt_trace_alloc failed");
1366 return;
1367 }
1368
1369 result = ltt_trace_start(trace_name);
1370 if(result < 0) {
1371 ERR("ltt_trace_start failed");
1372 return;
1373 }
1374
1375 /* Do this after the trace is started in order to avoid creating confusion
1376 * if the trace fails to start. */
1377 inform_consumer_daemon(trace_name);
1378 }
1379
1380 return;
1381
1382 /* should decrementally destroy stuff if error */
1383
1384 }
1385
1386 /* This is only called if we terminate normally, not with an unhandled signal,
1387 * so we cannot rely on it. However, for now, LTTV requires that the header of
1388 * the last sub-buffer contain a valid end time for the trace. This is done
1389 * automatically only when the trace is properly stopped.
1390 *
1391 * If the traced program crashed, it is always possible to manually add the
1392 * right value in the header, or to open the trace in text mode.
1393 *
1394 * FIXME: Fix LTTV so it doesn't need this.
1395 */
1396
1397 static void destroy_traces(void)
1398 {
1399 int result;
1400
1401 /* if trace running, finish it */
1402
1403 DBG("destructor stopping traces");
1404
1405 result = ltt_trace_stop("auto");
1406 if(result == -1) {
1407 ERR("ltt_trace_stop error");
1408 }
1409
1410 result = ltt_trace_destroy("auto", 0);
1411 if(result == -1) {
1412 ERR("ltt_trace_destroy error");
1413 }
1414 }
1415
1416 static int trace_recording(void)
1417 {
1418 int retval = 0;
1419 struct ust_trace *trace;
1420
1421 ltt_lock_traces();
1422
1423 list_for_each_entry(trace, &ltt_traces.head, list) {
1424 if(trace->active) {
1425 retval = 1;
1426 break;
1427 }
1428 }
1429
1430 ltt_unlock_traces();
1431
1432 return retval;
1433 }
1434
1435 #if 0
1436 static int have_consumer(void)
1437 {
1438 return !list_empty(&blocked_consumers);
1439 }
1440 #endif
1441
1442 int restarting_usleep(useconds_t usecs)
1443 {
1444 struct timespec tv;
1445 int result;
1446
1447 tv.tv_sec = 0;
1448 tv.tv_nsec = usecs * 1000;
1449
1450 do {
1451 result = nanosleep(&tv, &tv);
1452 } while(result == -1 && errno == EINTR);
1453
1454 return result;
1455 }
1456
1457 static void stop_listener(void)
1458 {
1459 int result;
1460
1461 if(!have_listener)
1462 return;
1463
1464 result = pthread_cancel(listener_thread);
1465 if(result != 0) {
1466 ERR("pthread_cancel: %s", strerror(result));
1467 }
1468 result = pthread_join(listener_thread, NULL);
1469 if(result != 0) {
1470 ERR("pthread_join: %s", strerror(result));
1471 }
1472 }
1473
1474 /* This destructor keeps the process alive for a few seconds in order
1475 * to leave time to ustd to connect to its buffers. This is necessary
1476 * for programs whose execution is very short. It is also useful in all
1477 * programs when tracing is started close to the end of the program
1478 * execution.
1479 *
1480 * FIXME: For now, this only works for the first trace created in a
1481 * process.
1482 */
1483
1484 static void __attribute__((destructor)) keepalive()
1485 {
1486 if(trace_recording() && LOAD_SHARED(buffers_to_export)) {
1487 int total = 0;
1488 DBG("Keeping process alive for consumer daemon...");
1489 while(LOAD_SHARED(buffers_to_export)) {
1490 const int interv = 200000;
1491 restarting_usleep(interv);
1492 total += interv;
1493
1494 if(total >= 3000000) {
1495 WARN("non-consumed buffers remaining after wait limit; not waiting anymore");
1496 break;
1497 }
1498 }
1499 DBG("Finally dying...");
1500 }
1501
1502 destroy_traces();
1503
1504 /* Ask the listener to stop and clean up. */
1505 stop_listener();
1506 }
1507
1508 void ust_potential_exec(void)
1509 {
1510 trace_mark(ust, potential_exec, MARK_NOARGS);
1511
1512 DBG("test");
1513
1514 keepalive();
1515 }
1516
1517 /* Notify ust that there was a fork. This needs to be called inside
1518 * the new process, anytime a process whose memory is not shared with
1519 * the parent is created. If this function is not called, the events
1520 * of the new process will not be collected.
1521 *
1522 * Signals should be disabled before the fork and reenabled only after
1523 * this call in order to guarantee tracing is not started before ust_fork()
1524 * sanitizes the new process.
1525 */
1526
1527 static void ust_fork(void)
1528 {
1529 struct blocked_consumer *bc;
1530 struct blocked_consumer *deletable_bc = NULL;
1531 int result;
1532
1533 /* FIXME: technically, the locks could have been taken before the fork */
1534 DBG("ust: forking");
1535
1536 /* break lock if necessary */
1537 ltt_unlock_traces();
1538
1539 ltt_trace_stop("auto");
1540 ltt_trace_destroy("auto", 1);
1541 /* Delete all active connections */
1542 ustcomm_close_all_connections(&ustcomm_app.server);
1543
1544 /* Delete all blocked consumers */
1545 list_for_each_entry(bc, &blocked_consumers, list) {
1546 result = close(bc->fd_producer);
1547 if(result == -1) {
1548 PERROR("close");
1549 }
1550 free(deletable_bc);
1551 deletable_bc = bc;
1552 list_del(&bc->list);
1553 }
1554
1555 /* free app, keeping socket file */
1556 ustcomm_fini_app(&ustcomm_app, 1);
1557
1558 STORE_SHARED(buffers_to_export, 0);
1559 have_listener = 0;
1560 init_socket();
1561 create_listener();
1562 ltt_trace_setup("auto");
1563 result = ltt_trace_set_type("auto", "ustrelay");
1564 if(result < 0) {
1565 ERR("ltt_trace_set_type failed");
1566 return;
1567 }
1568
1569 ltt_trace_alloc("auto");
1570 ltt_trace_start("auto");
1571 inform_consumer_daemon("auto");
1572 }
1573
1574 void ust_before_fork(ust_fork_info_t *fork_info)
1575 {
1576 /* Disable signals. This is to avoid that the child
1577 * intervenes before it is properly setup for tracing. It is
1578 * safer to disable all signals, because then we know we are not
1579 * breaking anything by restoring the original mask.
1580 */
1581 sigset_t all_sigs;
1582 int result;
1583
1584 /* FIXME:
1585 - only do this if tracing is active
1586 */
1587
1588 /* Disable signals */
1589 sigfillset(&all_sigs);
1590 result = sigprocmask(SIG_BLOCK, &all_sigs, &fork_info->orig_sigs);
1591 if(result == -1) {
1592 PERROR("sigprocmask");
1593 return;
1594 }
1595 }
1596
1597 /* Don't call this function directly in a traced program */
1598 static void ust_after_fork_common(ust_fork_info_t *fork_info)
1599 {
1600 int result;
1601
1602 /* Restore signals */
1603 result = sigprocmask(SIG_SETMASK, &fork_info->orig_sigs, NULL);
1604 if(result == -1) {
1605 PERROR("sigprocmask");
1606 return;
1607 }
1608 }
1609
1610 void ust_after_fork_parent(ust_fork_info_t *fork_info)
1611 {
1612 /* Reenable signals */
1613 ust_after_fork_common(fork_info);
1614 }
1615
1616 void ust_after_fork_child(ust_fork_info_t *fork_info)
1617 {
1618 /* First sanitize the child */
1619 ust_fork();
1620
1621 /* Then reenable interrupts */
1622 ust_after_fork_common(fork_info);
1623 }
1624
This page took 0.063517 seconds and 5 git commands to generate.