From 990570edd474b304d4c935d82be6201d872025e4 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Fri, 20 Jan 2012 16:30:23 -0500 Subject: [PATCH] Split and remove lttng-share header file This header is split into two files: defaults.h and macros.h. A third header is introduce here which is common.h including runas.h and macros.h which are part of the common library. Since the defaults.h contains only defaults values, it seems ok to keep it seperate from the common library having only macros and function calls. Signed-off-by: David Goulet --- src/bin/lttng-consumerd/lttng-consumerd.c | 13 ++--- src/bin/lttng-sessiond/channel.c | 3 +- src/bin/lttng-sessiond/kernel.c | 2 +- src/bin/lttng-sessiond/main.c | 7 +-- src/bin/lttng-sessiond/session.c | 3 +- src/bin/lttng-sessiond/trace-kernel.c | 3 +- src/bin/lttng-sessiond/trace-ust.c | 3 +- src/bin/lttng-sessiond/ust-app.c | 3 +- src/bin/lttng-sessiond/ust-consumer.c | 3 +- src/bin/lttng/command.h | 3 +- src/common/Makefile.am | 4 +- src/common/common.h | 26 +++++++++ src/common/compat/compat-epoll.c | 7 +-- src/common/compat/compat-poll.c | 5 +- src/common/compat/poll.h | 10 +--- src/common/consumer.c | 2 +- src/common/{lttng-share.h => defaults.h} | 56 +++++++------------- src/common/hashtable/hashtable.c | 4 +- src/common/kernel-consumer/kernel-consumer.c | 3 +- src/common/macros.h | 55 +++++++++++++++++++ src/common/sessiond-comm/sessiond-comm.c | 2 + src/common/sessiond-comm/sessiond-comm.h | 44 +++++++-------- src/common/ust-consumer/ust-consumer.c | 3 +- src/lib/lttng-ctl/lttng-ctl.c | 3 +- tests/test_kernel_data_trace.c | 2 +- tests/test_ust_data_trace.c | 2 +- 26 files changed, 164 insertions(+), 107 deletions(-) create mode 100644 src/common/common.h rename src/common/{lttng-share.h => defaults.h} (71%) create mode 100644 src/common/macros.h diff --git a/src/bin/lttng-consumerd/lttng-consumerd.c b/src/bin/lttng-consumerd/lttng-consumerd.c index 8cb264ab1..b501be873 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.c +++ b/src/bin/lttng-consumerd/lttng-consumerd.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "lttng-consumerd.h" @@ -253,15 +254,15 @@ int main(int argc, char **argv) switch (opt_type) { case LTTNG_CONSUMER_KERNEL: snprintf(command_sock_path, PATH_MAX, KCONSUMERD_CMD_SOCK_PATH, - LTTNG_RUNDIR); + DEFAULT_LTTNG_RUNDIR); break; case LTTNG_CONSUMER64_UST: snprintf(command_sock_path, PATH_MAX, - USTCONSUMERD64_CMD_SOCK_PATH, LTTNG_RUNDIR); + USTCONSUMERD64_CMD_SOCK_PATH, DEFAULT_LTTNG_RUNDIR); break; case LTTNG_CONSUMER32_UST: snprintf(command_sock_path, PATH_MAX, - USTCONSUMERD32_CMD_SOCK_PATH, LTTNG_RUNDIR); + USTCONSUMERD32_CMD_SOCK_PATH, DEFAULT_LTTNG_RUNDIR); break; default: WARN("Unknown consumerd type"); @@ -284,15 +285,15 @@ int main(int argc, char **argv) switch (opt_type) { case LTTNG_CONSUMER_KERNEL: snprintf(error_sock_path, PATH_MAX, KCONSUMERD_ERR_SOCK_PATH, - LTTNG_RUNDIR); + DEFAULT_LTTNG_RUNDIR); break; case LTTNG_CONSUMER64_UST: snprintf(error_sock_path, PATH_MAX, - USTCONSUMERD64_ERR_SOCK_PATH, LTTNG_RUNDIR); + USTCONSUMERD64_ERR_SOCK_PATH, DEFAULT_LTTNG_RUNDIR); break; case LTTNG_CONSUMER32_UST: snprintf(error_sock_path, PATH_MAX, - USTCONSUMERD32_ERR_SOCK_PATH, LTTNG_RUNDIR); + USTCONSUMERD32_ERR_SOCK_PATH, DEFAULT_LTTNG_RUNDIR); break; default: WARN("Unknown consumerd type"); diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index df411b228..d7fdbaec6 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "channel.h" #include "kernel.h" diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 6264521de..2ebd5acbd 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include "kernel.h" diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 521c78868..8b512f01d 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -42,7 +42,8 @@ #include #include #include -#include +#include +#include #include #include "lttng-sessiond.h" @@ -4278,7 +4279,7 @@ int main(int argc, char **argv) is_root = !getuid(); if (is_root) { - rundir = strdup(LTTNG_RUNDIR); + rundir = strdup(DEFAULT_LTTNG_RUNDIR); /* Create global run dir with root access */ ret = create_lttng_rundir(rundir); @@ -4325,7 +4326,7 @@ int main(int argc, char **argv) * Create rundir from home path. This will create something like * $HOME/.lttng */ - ret = asprintf(&rundir, LTTNG_HOME_RUNDIR, home_path); + ret = asprintf(&rundir, DEFAULT_LTTNG_HOME_RUNDIR, home_path); if (ret < 0) { ret = -ENOMEM; goto error; diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 68edeb9ee..ba2cefaae 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -26,9 +26,8 @@ #include #include -#include #include -#include +#include #include "session.h" diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index d1225c07c..79e4a2f4e 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -23,7 +23,8 @@ #include #include -#include +#include +#include #include "trace-kernel.h" diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index a947dada5..ed6658d7f 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -22,7 +22,8 @@ #include #include -#include +#include +#include #include "trace-ust.h" diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 057f675e4..bd91b3c39 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -28,8 +28,7 @@ #include #include -#include -#include +#include #include "ust-app.h" #include "ust-consumer.h" diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c index c0d5069e7..63381cea4 100644 --- a/src/bin/lttng-sessiond/ust-consumer.c +++ b/src/bin/lttng-sessiond/ust-consumer.c @@ -23,7 +23,8 @@ #include #include -#include +#include +#include #include #include diff --git a/src/bin/lttng/command.h b/src/bin/lttng/command.h index d7670f26d..9caa7b403 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "conf.h" #include "utils.h" diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 6b11d5084..ade89de86 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -4,11 +4,11 @@ SUBDIRS = hashtable kernel-ctl sessiond-comm kernel-consumer ust-consumer AM_CFLAGS = -fno-strict-aliasing -noinst_HEADERS = lttng-share.h lttngerr.h lttng-kernel.h +noinst_HEADERS = lttngerr.h lttng-kernel.h defaults.h macros.h noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = runas.c runas.h +libcommon_la_SOURCES = runas.c runas.h common.h # Consumer library noinst_LTLIBRARIES += libconsumer.la diff --git a/src/common/common.h b/src/common/common.h new file mode 100644 index 000000000..952a10a55 --- /dev/null +++ b/src/common/common.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2011 - David Goulet + * Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; only version 2 of the License. + * + * This program 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _COMMON_H +#define _COMMON_H + +#include "lttngerr.h" +#include "macros.h" +#include "runas.h" + +#endif /* _COMMON_H */ diff --git a/src/common/compat/compat-epoll.c b/src/common/compat/compat-epoll.c index 5e969ee01..460bc3b37 100644 --- a/src/common/compat/compat-epoll.c +++ b/src/common/compat/compat-epoll.c @@ -24,6 +24,7 @@ #include #include +#include #include "poll.h" @@ -195,9 +196,9 @@ void compat_epoll_set_max_size(void) int ret, fd; char buf[64]; - poll_max_size = LTTNG_POLL_DEFAULT_SIZE; + poll_max_size = DEFAULT_POLL_SIZE; - fd = open(LTTNG_EPOLL_PROC_PATH, O_RDONLY); + fd = open(COMPAT_EPOLL_PROC_PATH, O_RDONLY); if (fd < 0) { return; } @@ -211,7 +212,7 @@ void compat_epoll_set_max_size(void) poll_max_size = atoi(buf); if (poll_max_size <= 0) { /* Extra precaution */ - poll_max_size = LTTNG_POLL_DEFAULT_SIZE; + poll_max_size = DEFAULT_POLL_SIZE; } DBG("epoll set max size is %d", poll_max_size); diff --git a/src/common/compat/compat-poll.c b/src/common/compat/compat-poll.c index 50ef37472..7b15c737e 100644 --- a/src/common/compat/compat-poll.c +++ b/src/common/compat/compat-poll.c @@ -20,6 +20,7 @@ #include #include +#include #include "poll.h" @@ -177,7 +178,7 @@ void compat_poll_set_max_size(void) struct rlimit lim; /* Default value */ - poll_max_size = LTTNG_POLL_DEFAULT_SIZE; + poll_max_size = DEFAULT_POLL_SIZE; ret = getrlimit(RLIMIT_NOFILE, &lim); if (ret < 0) { @@ -188,7 +189,7 @@ void compat_poll_set_max_size(void) poll_max_size = lim.rlim_cur; if (poll_max_size <= 0) { /* Extra precaution */ - poll_max_size = LTTNG_POLL_DEFAULT_SIZE; + poll_max_size = DEFAULT_POLL_SIZE; } DBG("poll set max size set to %u", poll_max_size); diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index a7766400d..6dca76d81 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -21,13 +21,7 @@ #include #include -#include - -/* - * Value taken from the hard limit allowed by the kernel when using setrlimit - * with RLIMIT_NOFILE on an Intel i7 CPU and Linux 3.0.3. - */ -#define LTTNG_POLL_DEFAULT_SIZE 65535 +#include /* * Maximum number of fd we can monitor. @@ -58,7 +52,7 @@ static inline void __lttng_poll_free(void *events) #include /* See man epoll(7) for this define path */ -#define LTTNG_EPOLL_PROC_PATH "/proc/sys/fs/epoll/max_user_watches" +#define COMPAT_EPOLL_PROC_PATH "/proc/sys/fs/epoll/max_user_watches" enum { /* Polling variables compatibility for epoll */ diff --git a/src/common/consumer.c b/src/common/consumer.c index 9e7256568..cba9e6406 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -29,8 +29,8 @@ #include #include +#include #include -#include #include #include #include diff --git a/src/common/lttng-share.h b/src/common/defaults.h similarity index 71% rename from src/common/lttng-share.h rename to src/common/defaults.h index e859ead91..6be44c7c3 100644 --- a/src/common/lttng-share.h +++ b/src/common/defaults.h @@ -16,14 +16,28 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef _LTTNG_SHARE_H -#define _LTTNG_SHARE_H - -#include +#ifndef _DEFAULTS_H +#define _DEFAULTS_H /* Default size of a hash table */ #define DEFAULT_HT_SIZE 4 +/* Default lttng run directory */ +#define DEFAULT_LTTNG_RUNDIR "/var/run/lttng" +#define DEFAULT_LTTNG_HOME_RUNDIR "%s/.lttng" + +/* Default unix socket path */ +#define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK DEFAULT_LTTNG_RUNDIR "/client-lttng-sessiond" +#define DEFAULT_GLOBAL_APPS_UNIX_SOCK DEFAULT_LTTNG_RUNDIR "/apps-lttng-sessiond" +#define DEFAULT_HOME_APPS_UNIX_SOCK DEFAULT_LTTNG_HOME_RUNDIR "/apps-lttng-sessiond" +#define DEFAULT_HOME_CLIENT_UNIX_SOCK DEFAULT_LTTNG_HOME_RUNDIR "/client-lttng-sessiond" + +/* + * Value taken from the hard limit allowed by the kernel when using setrlimit + * with RLIMIT_NOFILE on an Intel i7 CPU and Linux 3.0.3. + */ +#define DEFAULT_POLL_SIZE 65535 + /* Default channel attributes */ #define DEFAULT_CHANNEL_NAME "channel0" #define DEFAULT_CHANNEL_OVERWRITE 0 /* usec */ @@ -63,36 +77,4 @@ */ #define DEFAULT_SEM_WAIT_TIMEOUT 30 /* in seconds */ -/* - * Takes a pointer x and transform it so we can use it to access members - * without a function call. Here an example: - * - * #define GET_SIZE(x) LTTNG_REF(x)->size - * - * struct { int size; } s; - * - * printf("size : %d\n", GET_SIZE(&s)); - * - * For this example we can't use something like this for compatibility purpose - * since this will fail: - * - * #define GET_SIZE(x) x->size; - * - * This is mostly use for the compatibility layer of lttng-tools. See - * poll/epoll for a good example. Since x can be on the stack or allocated - * memory using malloc(), we must use generic accessors for compat in order to - * *not* use a function to access members and not the variable name. - */ -#define LTTNG_REF(x) ((typeof(*x) *)(x)) - -/* - * Memory allocation zeroed - */ -#define zmalloc(x) calloc(1, x) - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0]))) -#endif - - -#endif /* _LTTNG_SHARE_H */ +#endif /* _DEFAULTS_H */ diff --git a/src/common/hashtable/hashtable.c b/src/common/hashtable/hashtable.c index 4f64778df..208010700 100644 --- a/src/common/hashtable/hashtable.c +++ b/src/common/hashtable/hashtable.c @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include "hashtable.h" #include "utils.h" diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 87436371f..3489ab6ed 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -29,9 +29,8 @@ #include #include +#include #include -#include -#include #include #include "kernel-consumer.h" diff --git a/src/common/macros.h b/src/common/macros.h new file mode 100644 index 000000000..3c72285c3 --- /dev/null +++ b/src/common/macros.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011 - David Goulet + * Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; only version 2 of the License. + * + * This program 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _MACROS_H +#define _MACROS_H + +#include + +/* + * Takes a pointer x and transform it so we can use it to access members + * without a function call. Here an example: + * + * #define GET_SIZE(x) LTTNG_REF(x)->size + * + * struct { int size; } s; + * + * printf("size : %d\n", GET_SIZE(&s)); + * + * For this example we can't use something like this for compatibility purpose + * since this will fail: + * + * #define GET_SIZE(x) x->size; + * + * This is mostly use for the compatibility layer of lttng-tools. See + * poll/epoll for a good example. Since x can be on the stack or allocated + * memory using malloc(), we must use generic accessors for compat in order to + * *not* use a function to access members and not the variable name. + */ +#define LTTNG_REF(x) ((typeof(*x) *)(x)) + +/* + * Memory allocation zeroed + */ +#define zmalloc(x) calloc(1, x) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0]))) +#endif + +#endif /* _MACROS_H */ diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 59b76aae1..4171b79f2 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -28,6 +28,8 @@ #include #include +#include + #include "sessiond-comm.h" /* diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 48cf93321..10748bbfa 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -1,48 +1,41 @@ -#ifndef _LTTNG_SESSIOND_COMM_H -#define _LTTNG_SESSIOND_COMM_H - /* * Copyright (C) 2011 - David Goulet * Julien Desfossez * Mathieu Desnoyers * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; only version 2 - * of the License. + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; only version 2 of the License. * - * This program 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 General Public License for more details. + * This program 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 General Public License for + * more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. */ /* - * This header is meant for liblttng and libust internal use ONLY. - * These declarations should NOT be considered stable API. + * This header is meant for liblttng and libust internal use ONLY. These + * declarations should NOT be considered stable API. */ +#ifndef _LTTNG_SESSIOND_COMM_H +#define _LTTNG_SESSIOND_COMM_H + #define _GNU_SOURCE #include #include #include -#define LTTNG_RUNDIR "/var/run/lttng" -#define LTTNG_HOME_RUNDIR "%s/.lttng" - -/* Default unix socket path */ -#define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-lttng-sessiond" -#define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-lttng-sessiond" -#define DEFAULT_HOME_APPS_UNIX_SOCK LTTNG_HOME_RUNDIR "/apps-lttng-sessiond" -#define DEFAULT_HOME_CLIENT_UNIX_SOCK LTTNG_HOME_RUNDIR "/client-lttng-sessiond" - /* Queue size of listen(2) */ #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64 +/* Maximum number of FDs that can be sent over a Unix socket */ +#define LTTCOMM_MAX_SEND_FDS 4 + /* * Get the error code index from 0 since LTTCOMM_OK start at 1000 */ @@ -284,7 +277,6 @@ extern int lttcomm_accept_unix_sock(int sock); extern int lttcomm_listen_unix_sock(int sock); extern int lttcomm_close_unix_sock(int sock); -#define LTTCOMM_MAX_SEND_FDS 4 /* Send a message accompanied by fd(s) over a unix socket. */ extern ssize_t lttcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd); /* Recv a message accompanied by fd(s) from a unix socket */ diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 16c09af8a..5f5e95825 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -30,8 +30,7 @@ #include #include -#include -#include +#include #include #include "ust-consumer.h" diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 2125c600a..838afedba 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -29,8 +29,9 @@ #include #include -#include #include +#include +#include #include /* Socket to session daemon for communication */ diff --git a/tests/test_kernel_data_trace.c b/tests/test_kernel_data_trace.c index c079e2c66..30d79a4eb 100644 --- a/tests/test_kernel_data_trace.c +++ b/tests/test_kernel_data_trace.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include "utils.h" diff --git a/tests/test_ust_data_trace.c b/tests/test_ust_data_trace.c index e4d42b40a..78a31215f 100644 --- a/tests/test_ust_data_trace.c +++ b/tests/test_ust_data_trace.c @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include "utils.h" -- 2.34.1