Merge branch 'master' into ust/callsite
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Oct 2012 00:56:19 +0000 (20:56 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Oct 2012 00:56:19 +0000 (20:56 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 files changed:
.gitignore
configure.ac
liblttng-ust-fork/ustfork.c
liblttng-ust/compat.h
liblttng-ust/ltt-events.c
liblttng-ust/ltt-probes.c
liblttng-ust/lttng-filter.c
tests/Makefile.am
tests/daemon/Makefile.am [new file with mode: 0644]
tests/daemon/README [new file with mode: 0644]
tests/daemon/daemon.c [new file with mode: 0644]
tests/daemon/run [new file with mode: 0755]
tests/daemon/ust_tests_daemon.h [new file with mode: 0644]

index 076cd007cca120b6f08082d207507b52296814b5..446765245fb28200313f71b32f0f5fb1ba043162 100644 (file)
@@ -33,6 +33,7 @@ ust-consumerd/ust-consumerd
 
 tests/basic/basic
 tests/basic_long/basic_long
+tests/daemon/daemon
 tests/demo/demo
 tests/dlopen/dlopen
 tests/exit-fast/exit-fast
index ea7324391f8ad1c3307f66b1f13470bffe9373f6..91ad8d935fc869a8ad5709acd231a06940cf9b59 100644 (file)
@@ -330,6 +330,7 @@ AC_CONFIG_FILES([
        tests/hello/Makefile
        tests/hello-static-lib/Makefile
        tests/hello.cxx/Makefile
+       tests/daemon/Makefile
        tests/demo/Makefile
        tests/fork/Makefile
        tests/ust-basic-tracing/Makefile
index 2e4c8a8fb73c167acbf1d7ade1f01e4698daf7f0..13f77cfc47ba9e24207080d00c7f72763680f2b0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009  Pierre-Marc Fournier
- * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2011-2012  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -38,6 +38,7 @@ pid_t fork(void)
                plibc_func = dlsym(RTLD_NEXT, "fork");
                if (plibc_func == NULL) {
                        fprintf(stderr, "libustfork: unable to find \"fork\" symbol\n");
+                       errno = ENOSYS;
                        return -1;
                }
        }
@@ -54,6 +55,34 @@ pid_t fork(void)
        return retval;
 }
 
+int daemon(int nochdir, int noclose)
+{
+       static int (*plibc_func)(int nochdir, int noclose) = NULL;
+       sigset_t sigset;
+       int retval;
+
+       if (plibc_func == NULL) {
+               plibc_func = dlsym(RTLD_NEXT, "daemon");
+               if (plibc_func == NULL) {
+                       fprintf(stderr, "libustfork: unable to find \"daemon\" symbol\n");
+                       errno = ENOSYS;
+                       return -1;
+               }
+       }
+
+       ust_before_fork(&sigset);
+       /* Do the real daemon call */
+       retval = plibc_func(nochdir, noclose);
+       if (retval == 0) {
+               /* child, parent called _exit() directly */
+               ust_after_fork_child(&sigset);
+       } else {
+               /* on error in the parent */
+               ust_after_fork_parent(&sigset);
+       }
+       return retval;
+}
+
 #ifdef __linux__
 
 struct user_desc;
@@ -96,6 +125,7 @@ int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...)
                plibc_func = dlsym(RTLD_NEXT, "clone");
                if (plibc_func == NULL) {
                        fprintf(stderr, "libustfork: unable to find \"clone\" symbol.\n");
+                       errno = ENOSYS;
                        return -1;
                }
        }
@@ -132,6 +162,7 @@ pid_t rfork(int flags)
                plibc_func = dlsym(RTLD_NEXT, "rfork");
                if (plibc_func == NULL) {
                        fprintf(stderr, "libustfork: unable to find \"rfork\" symbol\n");
+                       errno = ENOSYS;
                        return -1;
                }
        }
index 4d4a4368fa8bc7f716953821246007e20061c1b5..43b2223e43b84ad5c5dc373a8c327eb365fd32f4 100644 (file)
@@ -56,7 +56,7 @@ void lttng_ust_getprocname(char *name)
        if (!bsd_name)
                name[0] = '\0';
        else
-               memcpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1);
+               strncpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1);
 }
 
 #endif
index 0b6e61c41a44f855f26a3724d174b101477b1fcb..2109b8c21823a868bf49396fdb5d9fce29cc5343 100644 (file)
@@ -258,9 +258,10 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
 
                                memcpy(&event_param, &sw->event_param,
                                                sizeof(event_param));
-                               memcpy(event_param.name,
+                               strncpy(event_param.name,
                                        desc->name,
                                        sizeof(event_param.name));
+                               event_param.name[sizeof(event_param.name) - 1] = '\0';
                                /* create event */
                                ret = ltt_event_create(sw->chan,
                                        &event_param, &ev);
index d04ce2215a4e2db6b1765d328910565b30341ed7..aeb6db65224340a311ca320142b841800b9e9772 100644 (file)
@@ -390,9 +390,10 @@ void ltt_probes_create_wildcard_events(struct wildcard_entry *entry,
 
                                memcpy(&event_param, &wildcard->event_param,
                                                sizeof(event_param));
-                               memcpy(event_param.name,
+                               strncpy(event_param.name,
                                        event_desc->name,
                                        sizeof(event_param.name));
+                               event_param.name[sizeof(event_param.name) - 1] = '\0';
                                /* create event */
                                ret = ltt_event_create(wildcard->chan,
                                        &event_param, &ev);
index 68a5931158140ec735fb67ccacee9a71958407bb..1a0921fd72ac0ca78b4cc7c3f08667ab5767c300 100644 (file)
@@ -315,7 +315,7 @@ void lttng_filter_wildcard_link_bytecode(struct session_wildcard *wildcard)
                ret = _lttng_filter_event_link_bytecode(event,
                                wildcard->filter_bytecode);
                if (ret) {
-                       fprintf(stderr, "[lttng filter] error linking wildcard bytecode\n");
+                       dbg_printf("[lttng filter] error linking wildcard bytecode");
                }
 
        }
index e79ab7cec1760c256a1b25589ca8037f217608da..2b124228e2990484f3f35766139a366a0be6f12a 100644 (file)
@@ -1,4 +1,5 @@
-SUBDIRS = . hello hello-static-lib fork ust-basic-tracing ust-multi-test demo hello.cxx
+SUBDIRS = . hello hello-static-lib fork ust-basic-tracing ust-multi-test \
+               demo hello.cxx daemon
 #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/daemon/Makefile.am b/tests/daemon/Makefile.am
new file mode 100644 (file)
index 0000000..e641826
--- /dev/null
@@ -0,0 +1,16 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include -Wsystem-headers
+
+noinst_PROGRAMS = daemon
+daemon_SOURCES = daemon.c ust_tests_daemon.h
+daemon_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la \
+               $(top_builddir)/liblttng-ust-fork/liblttng-ust-fork.la
+
+if LTTNG_UST_BUILD_WITH_LIBDL
+daemon_LDADD += -ldl
+endif
+if LTTNG_UST_BUILD_WITH_LIBC_DL
+daemon_LDADD += -lc
+endif
+
+noinst_SCRIPTS = run
+EXTRA_DIST = run
diff --git a/tests/daemon/README b/tests/daemon/README
new file mode 100644 (file)
index 0000000..3c96cb6
--- /dev/null
@@ -0,0 +1,2 @@
+This test checks if tracing works correctly in a child process created by
+a daemon() call.
diff --git a/tests/daemon/daemon.c b/tests/daemon/daemon.c
new file mode 100644 (file)
index 0000000..c53074e
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009  Pierre-Marc Fournier
+ * Copyright (C) 2011-2012  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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; 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
+ * 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
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_daemon.h"
+
+int main(int argc, char **argv, char *env[])
+{
+       int result;
+
+       if (argc < 1) {
+               fprintf(stderr, "usage: daemon\n");
+               exit(1);
+       }
+
+       printf("daemon test program, parent pid is %d\n", getpid());
+       tracepoint(ust_tests_daemon, before_daemon);
+
+       result = daemon(0, 1);
+       if (result == 0) {
+               printf("Child pid is %d\n", getpid());
+
+               tracepoint(ust_tests_daemon, after_daemon_child, getpid());
+       } else {
+               tracepoint(ust_tests_daemon, after_daemon_parent);
+               perror("daemon");
+               exit(1);
+       }
+
+       return 0;
+}
diff --git a/tests/daemon/run b/tests/daemon/run
new file mode 100755 (executable)
index 0000000..be0e287
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+./daemon
diff --git a/tests/daemon/ust_tests_daemon.h b/tests/daemon/ust_tests_daemon.h
new file mode 100644 (file)
index 0000000..58b41a4
--- /dev/null
@@ -0,0 +1,47 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_daemon
+
+#if !defined(_TRACEPOINT_UST_TESTS_DAEMON_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_DAEMON_H
+
+/*
+ * Copyright (C) 2012  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <lttng/tracepoint.h>
+#include <sys/types.h>
+
+TRACEPOINT_EVENT(ust_tests_daemon, before_daemon,
+       TP_ARGS(),
+       TP_FIELDS()
+)
+
+TRACEPOINT_EVENT(ust_tests_daemon, after_daemon_child,
+       TP_ARGS(pid_t, pid),
+       TP_FIELDS(
+               ctf_integer(pid_t, pid, pid)
+       )
+)
+
+TRACEPOINT_EVENT(ust_tests_daemon, after_daemon_parent,
+       TP_ARGS(),
+       TP_FIELDS()
+)
+
+#endif /* _TRACEPOINT_UST_TESTS_DAEMON_H */
+
+#undef TRACEPOINT_INCLUDE_FILE
+#define TRACEPOINT_INCLUDE_FILE ./ust_tests_daemon.h
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
This page took 0.031265 seconds and 4 git commands to generate.