53e0b1efe647c1b4c8a7ec1a3cf22003ae0a4606
[lttng-ust.git] / libust / lttng-ust-comm.c
1 /*
2 * lttng-ust-comm.c
3 *
4 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; only
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <sys/prctl.h>
25 #include <sys/mman.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <pthread.h>
33 #include <semaphore.h>
34 #include <time.h>
35 #include <assert.h>
36 #include <signal.h>
37 #include <urcu/uatomic.h>
38
39 #include <lttng-ust-comm.h>
40 #include <ust/usterr-signal-safe.h>
41 #include <ust/lttng-ust-abi.h>
42 #include <ust/tracepoint.h>
43 #include <ust/tracepoint-internal.h>
44 #include <ust/ust.h>
45 #include "ltt-tracer-core.h"
46
47 /*
48 * Has lttng ust comm constructor been called ?
49 */
50 static int initialized;
51
52 /*
53 * The ust_lock/ust_unlock lock is used as a communication thread mutex.
54 * Held when handling a command, also held by fork() to deal with
55 * removal of threads, and by exit path.
56 */
57
58 /* Should the ust comm thread quit ? */
59 static int lttng_ust_comm_should_quit;
60
61 /*
62 * Wait for either of these before continuing to the main
63 * program:
64 * - the register_done message from sessiond daemon
65 * (will let the sessiond daemon enable sessions before main
66 * starts.)
67 * - sessiond daemon is not reachable.
68 * - timeout (ensuring applications are resilient to session
69 * daemon problems).
70 */
71 static sem_t constructor_wait;
72 /*
73 * Doing this for both the global and local sessiond.
74 */
75 static int sem_count = { 2 };
76
77 /*
78 * Info about socket and associated listener thread.
79 */
80 struct sock_info {
81 const char *name;
82 pthread_t ust_listener; /* listener thread */
83 int root_handle;
84 int constructor_sem_posted;
85 int allowed;
86 int global;
87
88 char sock_path[PATH_MAX];
89 int socket;
90
91 char wait_shm_path[PATH_MAX];
92 char *wait_shm_mmap;
93 };
94
95 /* Socket from app (connect) to session daemon (listen) for communication */
96 struct sock_info global_apps = {
97 .name = "global",
98 .global = 1,
99
100 .root_handle = -1,
101 .allowed = 1,
102
103 .sock_path = DEFAULT_GLOBAL_APPS_UNIX_SOCK,
104 .socket = -1,
105
106 .wait_shm_path = DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH,
107 };
108
109 /* TODO: allow global_apps_sock_path override */
110
111 struct sock_info local_apps = {
112 .name = "local",
113 .global = 0,
114 .root_handle = -1,
115 .allowed = 0, /* Check setuid bit first */
116
117 .socket = -1,
118 };
119
120 extern void ltt_ring_buffer_client_overwrite_init(void);
121 extern void ltt_ring_buffer_client_discard_init(void);
122 extern void ltt_ring_buffer_metadata_client_init(void);
123 extern void ltt_ring_buffer_client_overwrite_exit(void);
124 extern void ltt_ring_buffer_client_discard_exit(void);
125 extern void ltt_ring_buffer_metadata_client_exit(void);
126
127 static
128 int setup_local_apps(void)
129 {
130 const char *home_dir;
131 uid_t uid;
132
133 uid = getuid();
134 /*
135 * Disallow per-user tracing for setuid binaries.
136 */
137 if (uid != geteuid()) {
138 local_apps.allowed = 0;
139 return 0;
140 } else {
141 local_apps.allowed = 1;
142 }
143 home_dir = (const char *) getenv("HOME");
144 if (!home_dir)
145 return -ENOENT;
146 snprintf(local_apps.sock_path, PATH_MAX,
147 DEFAULT_HOME_APPS_UNIX_SOCK, home_dir);
148 snprintf(local_apps.wait_shm_path, PATH_MAX,
149 DEFAULT_HOME_APPS_WAIT_SHM_PATH, uid);
150 return 0;
151 }
152
153 static
154 int register_app_to_sessiond(int socket)
155 {
156 ssize_t ret;
157 int prctl_ret;
158 struct {
159 uint32_t major;
160 uint32_t minor;
161 pid_t pid;
162 pid_t ppid;
163 uid_t uid;
164 gid_t gid;
165 char name[16]; /* process name */
166 } reg_msg;
167
168 reg_msg.major = LTTNG_UST_COMM_VERSION_MAJOR;
169 reg_msg.minor = LTTNG_UST_COMM_VERSION_MINOR;
170 reg_msg.pid = getpid();
171 reg_msg.ppid = getppid();
172 reg_msg.uid = getuid();
173 reg_msg.gid = getgid();
174 prctl_ret = prctl(PR_GET_NAME, (unsigned long) reg_msg.name, 0, 0, 0);
175 if (prctl_ret) {
176 ERR("Error executing prctl");
177 return -errno;
178 }
179
180 ret = lttcomm_send_unix_sock(socket, &reg_msg, sizeof(reg_msg));
181 if (ret >= 0 && ret != sizeof(reg_msg))
182 return -EIO;
183 return ret;
184 }
185
186 static
187 int send_reply(int sock, struct lttcomm_ust_reply *lur)
188 {
189 ssize_t len;
190
191 len = lttcomm_send_unix_sock(sock, lur, sizeof(*lur));
192 switch (len) {
193 case sizeof(*lur):
194 DBG("message successfully sent");
195 return 0;
196 case -1:
197 if (errno == ECONNRESET) {
198 printf("remote end closed connection\n");
199 return 0;
200 }
201 return -1;
202 default:
203 printf("incorrect message size: %zd\n", len);
204 return -1;
205 }
206 }
207
208 static
209 int handle_register_done(struct sock_info *sock_info)
210 {
211 int ret;
212
213 if (sock_info->constructor_sem_posted)
214 return 0;
215 sock_info->constructor_sem_posted = 1;
216 ret = uatomic_add_return(&sem_count, -1);
217 if (ret == 0) {
218 ret = sem_post(&constructor_wait);
219 assert(!ret);
220 }
221 return 0;
222 }
223
224 static
225 int handle_message(struct sock_info *sock_info,
226 int sock, struct lttcomm_ust_msg *lum)
227 {
228 int ret = 0;
229 const struct objd_ops *ops;
230 struct lttcomm_ust_reply lur;
231
232 ust_lock();
233
234 memset(&lur, 0, sizeof(lur));
235
236 if (lttng_ust_comm_should_quit) {
237 ret = -EPERM;
238 goto end;
239 }
240
241 ops = objd_ops(lum->handle);
242 if (!ops) {
243 ret = -ENOENT;
244 goto end;
245 }
246
247 switch (lum->cmd) {
248 case LTTNG_UST_REGISTER_DONE:
249 if (lum->handle == LTTNG_UST_ROOT_HANDLE)
250 ret = handle_register_done(sock_info);
251 else
252 ret = -EINVAL;
253 break;
254 case LTTNG_UST_RELEASE:
255 if (lum->handle == LTTNG_UST_ROOT_HANDLE)
256 ret = -EPERM;
257 else
258 ret = objd_unref(lum->handle);
259 break;
260 default:
261 if (ops->cmd)
262 ret = ops->cmd(lum->handle, lum->cmd,
263 (unsigned long) &lum->u);
264 else
265 ret = -ENOSYS;
266 break;
267 }
268
269 end:
270 lur.handle = lum->handle;
271 lur.cmd = lum->cmd;
272 lur.ret_val = ret;
273 if (ret >= 0) {
274 lur.ret_code = LTTCOMM_OK;
275 } else {
276 lur.ret_code = LTTCOMM_SESSION_FAIL;
277 }
278 ret = send_reply(sock, &lur);
279
280 ust_unlock();
281 return ret;
282 }
283
284 static
285 void cleanup_sock_info(struct sock_info *sock_info)
286 {
287 int ret;
288
289 if (sock_info->socket != -1) {
290 ret = close(sock_info->socket);
291 if (ret) {
292 ERR("Error closing apps socket");
293 }
294 sock_info->socket = -1;
295 }
296 if (sock_info->root_handle != -1) {
297 ret = objd_unref(sock_info->root_handle);
298 if (ret) {
299 ERR("Error unref root handle");
300 }
301 sock_info->root_handle = -1;
302 }
303 sock_info->constructor_sem_posted = 0;
304 if (sock_info->wait_shm_mmap) {
305 ret = munmap(sock_info->wait_shm_mmap, sysconf(_SC_PAGE_SIZE));
306 if (ret) {
307 ERR("Error unmapping wait shm");
308 }
309 sock_info->wait_shm_mmap = NULL;
310 }
311 }
312
313 /*
314 * Using fork to set umask to 0777 in the child process (not
315 * multi-thread safe).
316 */
317 static
318 int get_wait_shm(struct sock_info *sock_info, size_t mmap_size)
319 {
320 int wait_shm_fd, ret;
321 int read_mode;
322 pid_t pid;
323
324 /*
325 * At this point, we should be able to open it for
326 * reading. If it fails, then it's because there is
327 * something wrong: bail out in that case.
328 */
329 read_mode = S_IRUSR | S_IRGRP;
330 if (sock_info->global)
331 read_mode |= S_IROTH;
332
333 /*
334 * Try to open read-only. If it is set read-only, it
335 * means the shm size has been already set with
336 * ftruncate. Note: all processes creating shm need to
337 * call ftruncate on the shm before restricting its
338 * access rights to read-only. The shm should never be
339 * unlinked. It a rogue process try to create a non-accessible
340 * shm or to unlink it, the worse-case scenario is that we don't
341 * use the shm wakeup method and sleep/retry instead.
342 */
343 wait_shm_fd = shm_open(sock_info->wait_shm_path,
344 O_RDONLY, read_mode);
345 if (wait_shm_fd >= 0) {
346 goto end;
347 } else if (wait_shm_fd < 0 && errno != ENOENT) {
348 /*
349 * Real-only open did not work. It's a failure
350 * that prohibits using shm.
351 */
352 ERR("Error opening shm %s", sock_info->wait_shm_path);
353 goto end;
354 }
355
356 /*
357 * If the open failed because the file did not exist, try
358 * creating it ourself.
359 */
360 pid = fork();
361 if (pid > 0) {
362 int status;
363
364 /*
365 * Parent: wait for child to return, in which case the
366 * shared memory map will have been created.
367 */
368 pid = wait(&status);
369 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
370 wait_shm_fd = -1;
371 goto end;
372 }
373 /*
374 * Try to open read-only again after creation.
375 */
376 wait_shm_fd = shm_open(sock_info->wait_shm_path,
377 O_RDONLY, read_mode);
378 if (wait_shm_fd < 0) {
379 /*
380 * Real-only open did not work. It's a failure
381 * that prohibits using shm.
382 */
383 ERR("Error opening shm %s", sock_info->wait_shm_path);
384 goto end;
385 }
386 goto end;
387 } else if (pid == 0) {
388 int create_mode;
389
390 /* Child */
391 create_mode = S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
392 if (sock_info->global)
393 create_mode |= S_IROTH | S_IWOTH;
394 /*
395 * We're alone in a child process, so we can modify the
396 * process-wide umask.
397 */
398 umask(create_mode);
399 /*
400 * First try creating shm (or get rw access). We need to start
401 * by this because of the ftruncate vs concurrent map race.
402 * We need to give write access to everyone because of the
403 * ftruncate vs mmap race too. We don't do an exclusive
404 * open, because we allow other processes to
405 * create+ftruncate it concurrently.
406 */
407 wait_shm_fd = shm_open(sock_info->wait_shm_path,
408 O_RDWR | O_CREAT, create_mode);
409 if (wait_shm_fd >= 0) {
410 ret = ftruncate(wait_shm_fd, mmap_size);
411 if (ret) {
412 PERROR("ftruncate");
413 exit(EXIT_FAILURE);
414 }
415 ret = fchmod(wait_shm_fd, read_mode);
416 if (ret) {
417 PERROR("fchmod");
418 exit(EXIT_FAILURE);
419 }
420 exit(EXIT_SUCCESS);
421 }
422 if (errno != EACCES) {
423 ERR("Error opening shm %s", sock_info->wait_shm_path);
424 exit(EXIT_FAILURE);
425 }
426 /*
427 * The shm exists, but we cannot open it RW. It means it
428 * has already been setup and ftruncated, so we can
429 * let the child exit.
430 */
431 exit(EXIT_SUCCESS);
432 } else {
433 return -1;
434 }
435 end:
436 return wait_shm_fd;
437 }
438
439 static
440 char *get_map_shm(struct sock_info *sock_info)
441 {
442 size_t mmap_size = sysconf(_SC_PAGE_SIZE);
443 int wait_shm_fd, ret;
444 char *wait_shm_mmap;
445
446 wait_shm_fd = get_wait_shm(sock_info, mmap_size);
447 if (wait_shm_fd < 0) {
448 goto error;
449 }
450 wait_shm_mmap = mmap(NULL, mmap_size, PROT_READ,
451 MAP_SHARED, wait_shm_fd, 0);
452 if (wait_shm_mmap == MAP_FAILED) {
453 PERROR("mmap");
454 goto error;
455 }
456 /* close shm fd immediately after taking the mmap reference */
457 ret = close(wait_shm_fd);
458 if (ret) {
459 ERR("Error closing fd");
460 }
461 return wait_shm_mmap;
462
463 error:
464 return NULL;
465 }
466
467 static
468 void wait_for_sessiond(struct sock_info *sock_info)
469 {
470 ust_lock();
471 if (lttng_ust_comm_should_quit) {
472 goto quit;
473 }
474 if (!sock_info->wait_shm_mmap) {
475 sock_info->wait_shm_mmap = get_map_shm(sock_info);
476 if (!sock_info->wait_shm_mmap)
477 goto error;
478 }
479 ust_unlock();
480
481 DBG("Waiting for %s apps sessiond", sock_info->name);
482 /* Wait for futex wakeup TODO */
483 sleep(5);
484
485 return;
486
487 quit:
488 ust_unlock();
489 return;
490
491 error:
492 ust_unlock();
493 /* Error handling: fallback on a 5 seconds sleep. */
494 sleep(5);
495 return;
496 }
497
498 /*
499 * This thread does not allocate any resource, except within
500 * handle_message, within mutex protection. This mutex protects against
501 * fork and exit.
502 * The other moment it allocates resources is at socket connexion, which
503 * is also protected by the mutex.
504 */
505 static
506 void *ust_listener_thread(void *arg)
507 {
508 struct sock_info *sock_info = arg;
509 int sock, ret;
510
511 /* Restart trying to connect to the session daemon */
512 restart:
513 ust_lock();
514
515 if (lttng_ust_comm_should_quit) {
516 ust_unlock();
517 goto quit;
518 }
519
520 if (sock_info->socket != -1) {
521 ret = close(sock_info->socket);
522 if (ret) {
523 ERR("Error closing %s apps socket", sock_info->name);
524 }
525 sock_info->socket = -1;
526 }
527
528 /* Register */
529 ret = lttcomm_connect_unix_sock(sock_info->sock_path);
530 if (ret < 0) {
531 ERR("Error connecting to %s apps socket", sock_info->name);
532 /*
533 * If we cannot find the sessiond daemon, don't delay
534 * constructor execution.
535 */
536 ret = handle_register_done(sock_info);
537 assert(!ret);
538 ust_unlock();
539
540 /* Wait for sessiond availability with pipe */
541 wait_for_sessiond(sock_info);
542 goto restart;
543 }
544
545 sock_info->socket = sock = ret;
546
547 /*
548 * Create only one root handle per listener thread for the whole
549 * process lifetime.
550 */
551 if (sock_info->root_handle == -1) {
552 ret = lttng_abi_create_root_handle();
553 if (ret) {
554 ERR("Error creating root handle");
555 ust_unlock();
556 goto quit;
557 }
558 sock_info->root_handle = ret;
559 }
560
561 ret = register_app_to_sessiond(sock);
562 if (ret < 0) {
563 ERR("Error registering to %s apps socket", sock_info->name);
564 /*
565 * If we cannot register to the sessiond daemon, don't
566 * delay constructor execution.
567 */
568 ret = handle_register_done(sock_info);
569 assert(!ret);
570 ust_unlock();
571 wait_for_sessiond(sock_info);
572 goto restart;
573 }
574 ust_unlock();
575
576 for (;;) {
577 ssize_t len;
578 struct lttcomm_ust_msg lum;
579
580 len = lttcomm_recv_unix_sock(sock, &lum, sizeof(lum));
581 switch (len) {
582 case 0: /* orderly shutdown */
583 DBG("%s ltt-sessiond has performed an orderly shutdown\n", sock_info->name);
584 goto end;
585 case sizeof(lum):
586 DBG("message received\n");
587 ret = handle_message(sock_info, sock, &lum);
588 if (ret < 0) {
589 ERR("Error handling message for %s socket", sock_info->name);
590 }
591 continue;
592 case -1:
593 if (errno == ECONNRESET) {
594 ERR("%s remote end closed connection\n", sock_info->name);
595 goto end;
596 }
597 goto end;
598 default:
599 ERR("incorrect message size (%s socket): %zd\n", sock_info->name, len);
600 continue;
601 }
602
603 }
604 end:
605 goto restart; /* try to reconnect */
606 quit:
607 return NULL;
608 }
609
610 /*
611 * Return values: -1: don't wait. 0: wait forever. 1: timeout wait.
612 */
613 static
614 int get_timeout(struct timespec *constructor_timeout)
615 {
616 long constructor_delay_ms = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS;
617 char *str_delay;
618 int ret;
619
620 str_delay = getenv("UST_REGISTER_TIMEOUT");
621 if (str_delay) {
622 constructor_delay_ms = strtol(str_delay, NULL, 10);
623 }
624
625 switch (constructor_delay_ms) {
626 case -1:/* fall-through */
627 case 0:
628 return constructor_delay_ms;
629 default:
630 break;
631 }
632
633 /*
634 * If we are unable to find the current time, don't wait.
635 */
636 ret = clock_gettime(CLOCK_REALTIME, constructor_timeout);
637 if (ret) {
638 return -1;
639 }
640 constructor_timeout->tv_sec += constructor_delay_ms / 1000UL;
641 constructor_timeout->tv_nsec +=
642 (constructor_delay_ms % 1000UL) * 1000000UL;
643 if (constructor_timeout->tv_nsec >= 1000000000UL) {
644 constructor_timeout->tv_sec++;
645 constructor_timeout->tv_nsec -= 1000000000UL;
646 }
647 return 1;
648 }
649
650 /*
651 * sessiond monitoring thread: monitor presence of global and per-user
652 * sessiond by polling the application common named pipe.
653 */
654 /* TODO */
655
656 void __attribute__((constructor)) lttng_ust_init(void)
657 {
658 struct timespec constructor_timeout;
659 int timeout_mode;
660 int ret;
661
662 if (uatomic_xchg(&initialized, 1) == 1)
663 return;
664
665 /*
666 * We want precise control over the order in which we construct
667 * our sub-libraries vs starting to receive commands from
668 * sessiond (otherwise leading to errors when trying to create
669 * sessiond before the init functions are completed).
670 */
671 init_usterr();
672 init_tracepoint();
673 ltt_ring_buffer_metadata_client_init();
674 ltt_ring_buffer_client_overwrite_init();
675 ltt_ring_buffer_client_discard_init();
676
677 timeout_mode = get_timeout(&constructor_timeout);
678
679 ret = sem_init(&constructor_wait, 0, 0);
680 assert(!ret);
681
682 ret = setup_local_apps();
683 if (ret) {
684 ERR("Error setting up to local apps");
685 }
686 ret = pthread_create(&local_apps.ust_listener, NULL,
687 ust_listener_thread, &local_apps);
688
689 if (local_apps.allowed) {
690 ret = pthread_create(&global_apps.ust_listener, NULL,
691 ust_listener_thread, &global_apps);
692 } else {
693 handle_register_done(&local_apps);
694 }
695
696 switch (timeout_mode) {
697 case 1: /* timeout wait */
698 do {
699 ret = sem_timedwait(&constructor_wait,
700 &constructor_timeout);
701 } while (ret < 0 && errno == EINTR);
702 if (ret < 0 && errno == ETIMEDOUT) {
703 ERR("Timed out waiting for ltt-sessiond");
704 } else {
705 assert(!ret);
706 }
707 break;
708 case -1:/* wait forever */
709 do {
710 ret = sem_wait(&constructor_wait);
711 } while (ret < 0 && errno == EINTR);
712 assert(!ret);
713 break;
714 case 0: /* no timeout */
715 break;
716 }
717 }
718
719 static
720 void lttng_ust_cleanup(int exiting)
721 {
722 cleanup_sock_info(&global_apps);
723 if (local_apps.allowed) {
724 cleanup_sock_info(&local_apps);
725 }
726 lttng_ust_abi_exit();
727 ltt_events_exit();
728 ltt_ring_buffer_client_discard_exit();
729 ltt_ring_buffer_client_overwrite_exit();
730 ltt_ring_buffer_metadata_client_exit();
731 exit_tracepoint();
732 if (!exiting) {
733 /* Reinitialize values for fork */
734 sem_count = 2;
735 lttng_ust_comm_should_quit = 0;
736 initialized = 0;
737 }
738 }
739
740 void __attribute__((destructor)) lttng_ust_exit(void)
741 {
742 int ret;
743
744 /*
745 * Using pthread_cancel here because:
746 * A) we don't want to hang application teardown.
747 * B) the thread is not allocating any resource.
748 */
749
750 /*
751 * Require the communication thread to quit. Synchronize with
752 * mutexes to ensure it is not in a mutex critical section when
753 * pthread_cancel is later called.
754 */
755 ust_lock();
756 lttng_ust_comm_should_quit = 1;
757 ust_unlock();
758
759 ret = pthread_cancel(global_apps.ust_listener);
760 if (ret) {
761 ERR("Error cancelling global ust listener thread");
762 }
763 if (local_apps.allowed) {
764 ret = pthread_cancel(local_apps.ust_listener);
765 if (ret) {
766 ERR("Error cancelling local ust listener thread");
767 }
768 }
769 lttng_ust_cleanup(1);
770 }
771
772 /*
773 * We exclude the worker threads across fork and clone (except
774 * CLONE_VM), because these system calls only keep the forking thread
775 * running in the child. Therefore, we don't want to call fork or clone
776 * in the middle of an tracepoint or ust tracing state modification.
777 * Holding this mutex protects these structures across fork and clone.
778 */
779 void ust_before_fork(ust_fork_info_t *fork_info)
780 {
781 /*
782 * Disable signals. This is to avoid that the child intervenes
783 * before it is properly setup for tracing. It is safer to
784 * disable all signals, because then we know we are not breaking
785 * anything by restoring the original mask.
786 */
787 sigset_t all_sigs;
788 int ret;
789
790 /* Disable signals */
791 sigfillset(&all_sigs);
792 ret = sigprocmask(SIG_BLOCK, &all_sigs, &fork_info->orig_sigs);
793 if (ret == -1) {
794 PERROR("sigprocmask");
795 }
796 ust_lock();
797 rcu_bp_before_fork();
798 }
799
800 static void ust_after_fork_common(ust_fork_info_t *fork_info)
801 {
802 int ret;
803
804 DBG("process %d", getpid());
805 ust_unlock();
806 /* Restore signals */
807 ret = sigprocmask(SIG_SETMASK, &fork_info->orig_sigs, NULL);
808 if (ret == -1) {
809 PERROR("sigprocmask");
810 }
811 }
812
813 void ust_after_fork_parent(ust_fork_info_t *fork_info)
814 {
815 DBG("process %d", getpid());
816 rcu_bp_after_fork_parent();
817 /* Release mutexes and reenable signals */
818 ust_after_fork_common(fork_info);
819 }
820
821 /*
822 * After fork, in the child, we need to cleanup all the leftover state,
823 * except the worker thread which already magically disappeared thanks
824 * to the weird Linux fork semantics. After tyding up, we call
825 * lttng_ust_init() again to start over as a new PID.
826 *
827 * This is meant for forks() that have tracing in the child between the
828 * fork and following exec call (if there is any).
829 */
830 void ust_after_fork_child(ust_fork_info_t *fork_info)
831 {
832 DBG("process %d", getpid());
833 /* Release urcu mutexes */
834 rcu_bp_after_fork_child();
835 lttng_ust_cleanup(0);
836 /* Release mutexes and reenable signals */
837 ust_after_fork_common(fork_info);
838 lttng_ust_init();
839 }
This page took 0.047263 seconds and 4 git commands to generate.