X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fmain.c;h=7cb0140c6e40205cdb33cda92fc65016ecffc84d;hb=724899701538a09ed8325784d84a5eedde4f2650;hp=43498017dd0b41cbbafe908dbb69e1287c57d066;hpb=a8cad46163850205f0dc2607e361a63b4fab3f7a;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 43498017d..7cb0140c6 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -34,11 +34,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -59,6 +61,7 @@ #include #include +#include "version.h" #include "cmd.h" #include "ctf-trace.h" #include "index.h" @@ -83,8 +86,10 @@ enum relay_connection_status { }; /* command line options */ -char *opt_output_path; -static int opt_daemon, opt_background; +char *opt_output_path, *opt_working_directory; +static int opt_daemon, opt_background, opt_print_version; +int opt_group_output_by_session; +int opt_group_output_by_host; /* * We need to wait for listener and live listener threads, as well as @@ -145,6 +150,9 @@ static uint64_t last_relay_stream_id; */ static struct relay_conn_queue relay_conn_queue; +/* Cap of file desriptors to be in simultaneous use by the relay daemon. */ +static unsigned int lttng_opt_fd_cap; + /* Global relay stream hash table. */ struct lttng_ht *relay_streams_ht; @@ -164,16 +172,37 @@ static struct option long_options[] = { { "daemonize", 0, 0, 'd', }, { "background", 0, 0, 'b', }, { "group", 1, 0, 'g', }, + { "fd-cap", 1, 0, '\0', }, { "help", 0, 0, 'h', }, { "output", 1, 0, 'o', }, { "verbose", 0, 0, 'v', }, { "config", 1, 0, 'f' }, { "version", 0, 0, 'V' }, + { "working-directory", 1, 0, 'w', }, + { "group-output-by-session", 0, 0, 's', }, + { "group-output-by-host", 0, 0, 'p', }, { NULL, 0, 0, 0, }, }; static const char *config_ignore_options[] = { "help", "config", "version" }; +static void print_version(void) { + fprintf(stdout, "%s\n", VERSION); +} + +static void relayd_config_log(void) +{ + DBG("LTTng-relayd " VERSION " - " VERSION_NAME "%s%s", + GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION, + EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " EXTRA_VERSION_NAME); + if (EXTRA_VERSION_DESCRIPTION[0] != '\0') { + DBG("LTTng-relayd extra version description:\n\t" EXTRA_VERSION_DESCRIPTION "\n"); + } + if (EXTRA_VERSION_PATCHES[0] != '\0') { + DBG("LTTng-relayd extra patches:\n\t" EXTRA_VERSION_PATCHES "\n"); + } +} + /* * Take an option from the getopt output and set it in the right variable to be * used later. @@ -186,9 +215,33 @@ static int set_option(int opt, const char *arg, const char *optname) switch (opt) { case 0: - fprintf(stderr, "option %s", optname); - if (arg) { - fprintf(stderr, " with arg %s\n", arg); + if (!strcmp(optname, "fd-cap")) { + unsigned long v; + + errno = 0; + v = strtoul(arg, NULL, 0); + if (errno != 0 || !isdigit(arg[0])) { + ERR("Wrong value in --fd-cap parameter: %s", arg); + ret = -1; + goto end; + } + if (v < DEFAULT_RELAYD_MINIMAL_FD_CAP) { + ERR("File descriptor cap must be set to at least %d", + DEFAULT_RELAYD_MINIMAL_FD_CAP); + } + if (v >= UINT_MAX) { + ERR("File descriptor cap overflow in --fd-cap parameter: %s", arg); + ret = -1; + goto end; + } + lttng_opt_fd_cap = (unsigned int) v; + DBG3("File descriptor cap set to %u", lttng_opt_fd_cap); + + } else { + fprintf(stderr, "unknown option %s", optname); + if (arg) { + fprintf(stderr, " with arg %s\n", arg); + } } break; case 'C': @@ -264,8 +317,8 @@ static int set_option(int opt, const char *arg, const char *optname) } exit(EXIT_FAILURE); case 'V': - fprintf(stdout, "%s\n", VERSION); - exit(EXIT_SUCCESS); + opt_print_version = 1; + break; case 'o': if (lttng_is_setuid_setgid()) { WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", @@ -279,6 +332,20 @@ static int set_option(int opt, const char *arg, const char *optname) } } break; + case 'w': + if (lttng_is_setuid_setgid()) { + WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", + "-w, --working-directory"); + } else { + ret = asprintf(&opt_working_directory, "%s", arg); + if (ret < 0) { + ret = -errno; + PERROR("asprintf working_directory"); + goto end; + } + } + break; + case 'v': /* Verbose level can increase using multiple -v */ if (arg) { @@ -290,6 +357,20 @@ static int set_option(int opt, const char *arg, const char *optname) } } break; + case 's': + if (opt_group_output_by_host) { + ERR("Cannot set --group-output-by-session, --group-output-by-host already defined"); + exit(EXIT_FAILURE); + } + opt_group_output_by_session = 1; + break; + case 'p': + if (opt_group_output_by_session) { + ERR("Cannot set --group-output-by-host, --group-output-by-session already defined"); + exit(EXIT_FAILURE); + } + opt_group_output_by_host = 1; + break; default: /* Unknown option or other error. * Error is printed by getopt, just return */ @@ -359,6 +440,16 @@ end: return ret; } +static void parse_env_options(void) +{ + char *value = NULL; + + value = lttng_secure_getenv(DEFAULT_LTTNG_RELAYD_WORKING_DIRECTORY_ENV); + if (value) { + opt_working_directory = value; + } +} + static int set_options(int argc, char **argv) { int c, ret = 0, option_index = 0, retval = 0; @@ -476,6 +567,23 @@ static int set_options(int argc, char **argv) goto exit; } } + if (lttng_opt_fd_cap == 0) { + int ret; + struct rlimit rlimit; + + ret = getrlimit(RLIMIT_NOFILE, &rlimit); + if (ret) { + PERROR("Failed to get file descriptor limit"); + retval = -1; + } + + lttng_opt_fd_cap = rlimit.rlim_cur; + } + + if (!opt_group_output_by_session && !opt_group_output_by_host) { + /* Group by host by default */ + opt_group_output_by_host = 1; + } exit: free(optstring); @@ -1194,12 +1302,13 @@ static int relay_add_stream(const struct lttcomm_relayd_hdr *recv_hdr, switch (session->minor) { case 1: /* LTTng sessiond 2.1. Allocates path_name and channel_name. */ ret = cmd_recv_stream_2_1(payload, &path_name, - &channel_name); + &channel_name, session); break; case 2: /* LTTng sessiond 2.2. Allocates path_name and channel_name. */ default: ret = cmd_recv_stream_2_2(payload, &path_name, - &channel_name, &tracefile_size, &tracefile_count); + &channel_name, &tracefile_size, &tracefile_count, + session); break; } if (ret < 0) { @@ -3141,7 +3250,13 @@ int main(int argc, char **argv) int ret = 0, retval = 0; void *status; - /* Parse arguments */ + /* Parse environment variables */ + parse_env_options(); + + /* + * Parse arguments. + * Command line arguments overwrite environment. + */ progname = argv[0]; if (set_options(argc, argv)) { retval = -1; @@ -3153,6 +3268,14 @@ int main(int argc, char **argv) goto exit_options; } + relayd_config_log(); + + if (opt_print_version) { + print_version(); + retval = 0; + goto exit_options; + } + /* Try to create directory if -o, --output is specified. */ if (opt_output_path) { if (*opt_output_path != '/') { @@ -3191,6 +3314,15 @@ int main(int argc, char **argv) } } + + if (opt_working_directory) { + ret = utils_change_working_dir(opt_working_directory); + if (ret) { + ERR("Changing working directory"); + goto exit_options; + } + } + /* Initialize thread health monitoring */ health_relayd = health_app_create(NR_HEALTH_RELAYD_TYPES); if (!health_relayd) {