From: Mathieu Desnoyers Date: Fri, 26 Aug 2011 13:05:38 +0000 (-0400) Subject: Remove libust-initializer X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=e822f505be95ac8c30c7b535a7b48c05ed0c1293;p=lttng-ust.git Remove libust-initializer Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile.am b/Makefile.am index 79ff7535..fd9cbe94 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,30 +1,10 @@ ACLOCAL_AMFLAGS = -I config -# The order here is tricky. SUBDIRS applies both to compilation and -# installation. Programs depending on the libs must be built after -# libust and '.' (that contains the linker script). However, '.' -# must be installed after libust so it can overwrite libust.so with -# the linker script. -SUBDIRS = snprintf liblttng-ust-comm libringbuffer libust include doc tests \ - libustjava +SUBDIRS = . snprintf liblttng-ust-comm libringbuffer libust include doc tests \ + libustjava libustfork #temporarily disabled -# . libustinstr-malloc libustfork - -EXTRA_DIST = libust.ldscript.in libust-initializer.c libust-initializer.h - -ldscriptsdir = $(libdir) -ldscripts_DATA = libust.so libust-initializer.o - -CLEANFILES = $(ldscripts_DATA) ./tests/libust-initializer.Po - -libust.so: libust.ldscript.in - $(SED) -e $(if $(LIBFORMAT),"s@\@FORMAT\@@$(LIBFORMAT)@","s@.*\@FORMAT\@.*@@") < $< > $@ - -# It is very important to compile the initializer with PIC otherwise we -# may get obscure errors when linking to shared libraries. -libust-initializer.o: libust-initializer.c - $(CC) $(CFLAGS) -fno-strict-aliasing -fPIC -c -I$(top_srcdir)/include -I$(top_srcdir) -o $@ $< +# . libustinstr-malloc pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = ust.pc diff --git a/include/Makefile.am b/include/Makefile.am index a754d04b..dcec467b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -11,7 +11,8 @@ nobase_include_HEADERS = \ ust/lttng-tracer.h \ ust/usterr-signal-safe.h \ ust/core.h \ - ust/share.h + ust/share.h \ + ust/ust.h # note: usterr-signal-safe.h, core.h and share.h need namespace cleanup. @@ -30,6 +31,5 @@ noinst_HEADERS = \ ust/kcompat/jhash.h \ ust/kcompat/compiler.h \ ust/kcompat/types.h \ - ust/tracectl.h \ ust/stringify.h \ ust/wait.h diff --git a/include/ust/tracectl.h b/include/ust/tracectl.h deleted file mode 100644 index c0ee7b14..00000000 --- a/include/ust/tracectl.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2009 Pierre-Marc Fournier - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef UST_TRACECTL_H -#define UST_TRACECTL_H - -typedef struct ust_fork_info { - sigset_t orig_sigs; -} ust_fork_info_t; - -extern void ust_potential_exec(void); - -extern void ust_before_fork(ust_fork_info_t *fork_info); -extern void ust_after_fork_parent(ust_fork_info_t *fork_info); -extern void ust_after_fork_child(ust_fork_info_t *fork_info); - -#endif /* UST_TRACECTL_H */ diff --git a/libust-initializer.c b/libust-initializer.c deleted file mode 100644 index d7eedf0e..00000000 --- a/libust-initializer.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2009 Novell Inc. - * - * Author: Jan Blunck - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 2.1 as - * published by the Free Software Foundation. - */ - -//DISABLED #include -#include - -//DISABLED UST_MARKER_LIB; -TRACEPOINT_LIB; diff --git a/libust-initializer.h b/libust-initializer.h deleted file mode 100644 index 3c4e95bb..00000000 --- a/libust-initializer.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2010 Nils Carlson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM ust_dummy - -#if !defined(_TRACEPOINT_EVENT_TEST_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACEPOINT_EVENT_TEST_H - -#include - -TRACEPOINT_EVENT(ust_dummy_event, - - TP_PROTO(int dummy_int), - - TP_ARGS(dummy_int), - - TP_STRUCT__entry( - __field( int, dummy ) - ), - - TP_fast_assign( - __entry->dummy = dummy_int; - ), - - TP_printf("dummy=%d", __entry->dummy) -); - -#endif /* _TRACEPOINT_EVENT_TEST_H */ - -/* This part must be outside protection */ -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . -#define TRACE_INCLUDE_FILE libust-initializer -#include diff --git a/libust.ldscript.in b/libust.ldscript.in deleted file mode 100644 index d3f9fe84..00000000 --- a/libust.ldscript.in +++ /dev/null @@ -1,4 +0,0 @@ -/* GNU ld script - Use the shared library, but the link with initializer too */ -OUTPUT_FORMAT(@FORMAT@) -GROUP ( libust.so.0 libust-initializer.o ) diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c index 0f7bc34b..1e4031be 100644 --- a/libust/lttng-ust-comm.c +++ b/libust/lttng-ust-comm.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include /* * Has lttng ust comm constructor been called ? @@ -541,3 +543,58 @@ void __attribute__((destructor)) lttng_ust_exit(void) ltt_ring_buffer_metadata_client_exit(); exit_tracepoint(); } + +/* + * We exclude the worker threads across fork and clone (except + * CLONE_VM), because these system calls only keep the forking thread + * running in the child. Therefore, we don't want to call fork or clone + * in the middle of an tracepoint or ust tracing state modification. + * Holding this mutex protects these structures across fork and clone. + */ +void ust_before_fork(ust_fork_info_t *fork_info) +{ + /* + * Disable signals. This is to avoid that the child intervenes + * before it is properly setup for tracing. It is safer to + * disable all signals, because then we know we are not breaking + * anything by restoring the original mask. + */ + sigset_t all_sigs; + int ret; + + /* Disable signals */ + sigfillset(&all_sigs); + ret = sigprocmask(SIG_BLOCK, &all_sigs, &fork_info->orig_sigs); + if (ret == -1) { + PERROR("sigprocmask"); + } + pthread_mutex_lock(<tng_ust_comm_mutex); + rcu_bp_before_fork(); +} + +static void ust_after_fork_common(ust_fork_info_t *fork_info) +{ + int ret; + + pthread_mutex_unlock(<tng_ust_comm_mutex); + /* Restore signals */ + ret = sigprocmask(SIG_SETMASK, &fork_info->orig_sigs, NULL); + if (ret == -1) { + PERROR("sigprocmask"); + } +} + +void ust_after_fork_parent(ust_fork_info_t *fork_info) +{ + rcu_bp_after_fork_parent(); + /* Release mutexes and reenable signals */ + ust_after_fork_common(fork_info); +} + +void ust_after_fork_child(ust_fork_info_t *fork_info) +{ + /* Release urcu mutexes */ + rcu_bp_after_fork_child(); + /* Release mutexes and reenable signals */ + ust_after_fork_common(fork_info); +} diff --git a/libustfork/ustfork.c b/libustfork/ustfork.c index c88805f7..b16d4150 100644 --- a/libustfork/ustfork.c +++ b/libustfork/ustfork.c @@ -1,9 +1,11 @@ -/* Copyright (C) 2009 Pierre-Marc Fournier +/* + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * License as published by the Free Software Foundation; version 2.1 of + * the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,64 +24,39 @@ #include #include #include -#include #include "usterr.h" +#include + struct user_desc; pid_t fork(void) { static pid_t (*plibc_func)(void) = NULL; ust_fork_info_t fork_info; - pid_t retval; - if(plibc_func == NULL) { + if (plibc_func == NULL) { plibc_func = dlsym(RTLD_NEXT, "fork"); - if(plibc_func == NULL) { - fprintf(stderr, "libcwrap: unable to find fork\n"); + if (plibc_func == NULL) { + fprintf(stderr, "libustfork: unable to find \"fork\" symbol\n"); return -1; } } ust_before_fork(&fork_info); - /* Do the real fork */ retval = plibc_func(); - - if(retval == 0) { + if (retval == 0) { /* child */ ust_after_fork_child(&fork_info); - } - else { + } else { ust_after_fork_parent(&fork_info); } - return retval; } -int execve(const char *filename, char *const argv[], char *const envp[]) -{ - static int (*plibc_func)(const char *filename, char *const argv[], char *const envp[]) = NULL; - - pid_t retval; - - if(plibc_func == NULL) { - plibc_func = dlsym(RTLD_NEXT, "execve"); - if(plibc_func == NULL) { - fprintf(stderr, "libinterfork: unable to find execve\n"); - return -1; - } - } - - ust_potential_exec(); - - retval = plibc_func(filename, argv, envp); - - return retval; -} - -struct interfork_clone_info { +struct ustfork_clone_info { int (*fn)(void *); void *arg; ust_fork_info_t fork_info; @@ -87,26 +64,25 @@ struct interfork_clone_info { static int clone_fn(void *arg) { - struct interfork_clone_info *info = (struct interfork_clone_info *)arg; + struct ustfork_clone_info *info = (struct ustfork_clone_info *) arg; /* clone is now done and we are in child */ ust_after_fork_child(&info->fork_info); - return info->fn(info->arg); } int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...) { - static int (*plibc_func)(int (*fn)(void *), void *child_stack, int flags, void *arg, pid_t *ptid, struct user_desc *tls, pid_t *ctid) = NULL; - - /* varargs */ + static int (*plibc_func)(int (*fn)(void *), void *child_stack, + int flags, void *arg, pid_t *ptid, + struct user_desc *tls, pid_t *ctid) = NULL; + /* var args */ pid_t *ptid; struct user_desc *tls; pid_t *ctid; - - int retval; - + /* end of var args */ va_list ap; + int retval; va_start(ap, arg); ptid = va_arg(ap, pid_t *); @@ -114,29 +90,30 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...) ctid = va_arg(ap, pid_t *); va_end(ap); - if(plibc_func == NULL) { + if (plibc_func == NULL) { plibc_func = dlsym(RTLD_NEXT, "clone"); - if(plibc_func == NULL) { - fprintf(stderr, "libinterfork: unable to find clone\n"); + if (plibc_func == NULL) { + fprintf(stderr, "libustfork: unable to find \"clone\" symbol.\n"); return -1; } } - if(flags & CLONE_VM) { - /* creating a thread, no need to intervene, just pass on the arguments */ - retval = plibc_func(fn, child_stack, flags, arg, ptid, tls, ctid); - } - else { - /* creating a real process, we need to intervene */ - struct interfork_clone_info info = { fn: fn, arg: arg }; + if (flags & CLONE_VM) { + /* + * Creating a thread, no need to intervene, just pass on + * the arguments. + */ + retval = plibc_func(fn, child_stack, flags, arg, ptid, + tls, ctid); + } else { + /* Creating a real process, we need to intervene. */ + struct ustfork_clone_info info = { fn: fn, arg: arg }; ust_before_fork(&info.fork_info); - - retval = plibc_func(clone_fn, child_stack, flags, &info, ptid, tls, ctid); - - /* The child doesn't get here */ + retval = plibc_func(clone_fn, child_stack, flags, &info, + ptid, tls, ctid); + /* The child doesn't get here. */ ust_after_fork_parent(&info.fork_info); } - return retval; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 4ab0b21b..a9ba3262 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = . hello -#SUBDIRS = . hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test tracepoint libustctl_function_tests exit-fast +SUBDIRS = . hello fork +#SUBDIRS = . hello2 basic basic_long simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test tracepoint libustctl_function_tests exit-fast dist_noinst_SCRIPTS = test_loop runtests trace_matches diff --git a/tests/fork/Makefile.am b/tests/fork/Makefile.am index ef93b6f9..5c936853 100644 --- a/tests/fork/Makefile.am +++ b/tests/fork/Makefile.am @@ -1,10 +1,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include noinst_PROGRAMS = fork fork2 -fork_SOURCES = fork.c -fork_LDADD = $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o +fork_SOURCES = fork.c ust_tests_fork.h +fork_LDADD = $(top_builddir)/libust/libust.la fork2_SOURCES = fork2.c -fork2_LDADD = $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o +fork2_LDADD = $(top_builddir)/libust/libust.la noinst_SCRIPTS = run EXTRA_DIST = run diff --git a/tests/fork/fork.c b/tests/fork/fork.c index f9b515c1..be96d817 100644 --- a/tests/fork/fork.c +++ b/tests/fork/fork.c @@ -1,9 +1,11 @@ -/* Copyright (C) 2009 Pierre-Marc Fournier +/* + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * License as published by the Free Software Foundation; version 2.1 of + * the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,47 +22,41 @@ #include #include -#include +#define TRACEPOINT_CREATE_PROBES +#include "ust_tests_fork.h" +TRACEPOINT_LIB int main(int argc, char **argv, char *env[]) { int result; - if(argc < 2 ) { + if (argc < 2) { fprintf(stderr, "usage: fork PROG_TO_EXEC\n"); exit(1); } printf("Fork test program, parent pid is %d\n", getpid()); - ust_marker(before_fork, UST_MARKER_NOARGS); - - /* Sleep here to make sure the consumer is initialized before we fork */ - sleep(1); + tracepoint(ust_tests_fork_before_fork); result = fork(); - if(result == -1) { + if (result == -1) { perror("fork"); return 1; } - if(result == 0) { - char *args[] = {"fork2", NULL}; + if (result == 0) { + char *args[] = { "fork2", NULL }; printf("Child pid is %d\n", getpid()); - ust_marker(after_fork_child, UST_MARKER_NOARGS); - - ust_marker(before_exec, "pid %d", getpid()); + tracepoint(ust_tests_fork_after_fork_child, getpid()); result = execve(argv[1], args, env); - if(result == -1) { + if (result == -1) { perror("execve"); return 1; } - - ust_marker(after_exec, "pid %d", getpid()); - } - else { - ust_marker(after_fork_parent, UST_MARKER_NOARGS); + } else { + tracepoint(ust_tests_fork_after_fork_parent); } return 0; diff --git a/tests/fork/fork2.c b/tests/fork/fork2.c index b156ac1e..42e2faca 100644 --- a/tests/fork/fork2.c +++ b/tests/fork/fork2.c @@ -18,13 +18,15 @@ #include #include -#include +#define TRACEPOINT_CREATE_PROBES +#include "ust_tests_fork.h" +TRACEPOINT_LIB int main() { printf("IN FORK2\n"); - ust_marker(after_exec, UST_MARKER_NOARGS); + tracepoint(ust_tests_fork_after_exec); return 0; } diff --git a/tests/hello/Makefile.am b/tests/hello/Makefile.am index e26d949e..8447e24a 100644 --- a/tests/hello/Makefile.am +++ b/tests/hello/Makefile.am @@ -2,8 +2,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libust noinst_PROGRAMS = hello hello_SOURCES = hello.c tp.c tp.h -hello_LDADD = $(top_builddir)/libust/libust.la \ - $(top_builddir)/libust-initializer.o +hello_LDADD = $(top_builddir)/libust/libust.la noinst_SCRIPTS = run EXTRA_DIST = run diff --git a/tests/hello/hello.c b/tests/hello/hello.c index 72a30d09..b265b348 100644 --- a/tests/hello/hello.c +++ b/tests/hello/hello.c @@ -28,6 +28,7 @@ #include #include "ust_tests_hello.h" +TRACEPOINT_LIB void inthandler(int sig) {