If no \fB\-o, \-\-output\fP is specified, the traces will be written in
$HOME/lttng-traces.
+
+The $HOME environment variable can be overridden by defining the environment
+variable LTTNG_HOME. This is useful when the user running the commands has
+a non-writeable home directory.
.fi
.B OPTIONS:
#include "lttng-relayd.h"
#include "utils.h"
-/*
- * Returns the HOME directory path. Caller MUST NOT free(3) the return pointer.
- */
-static char *get_default_path(void)
-{
- return getenv("HOME");
-}
-
static char *create_output_path_auto(char *path_name)
{
int ret;
char *alloc_path = NULL;
char *default_path;
- default_path = get_default_path();
+ default_path = utils_get_home_dir();
if (default_path == NULL) {
ERR("Home path not found.\n \
Please specify an output path using -o, --output PATH");
DBG2("Kernel consumer cmd path: %s",
kconsumer_data.cmd_unix_sock_path);
} else {
- home_path = get_home_dir();
+ home_path = utils_get_home_dir();
if (home_path == NULL) {
/* TODO: Add --socket PATH option */
ERR("Can't get HOME directory for sockets creation.");
return ret;
}
-/*
- * Return pointer to home directory path using the env variable HOME.
- *
- * No home, NULL is returned.
- */
-const char *get_home_dir(void)
-{
- return ((const char *) getenv("HOME"));
-}
-
void ht_cleanup_push(struct lttng_ht *ht)
{
int ret;
print_str_url = url;
} else {
/* Auto output path */
- alloc_path = config_get_default_path();
+ alloc_path = utils_get_home_dir();
if (alloc_path == NULL) {
ERR("HOME path not found.\n \
Please specify an output path using -o, --output PATH");
#include <unistd.h>
#include <common/error.h>
+#include <common/utils.h>
#include "conf.h"
return ret;
}
-/*
- * Returns the HOME directory path. Caller MUST NOT free(3) the return pointer.
- */
-char *config_get_default_path(void)
-{
- return getenv("HOME");
-}
-
/*
* Destroys directory config and file config.
*/
*/
void config_destroy_default(void)
{
- char *path = config_get_default_path();
+ char *path = utils_get_home_dir();
if (path == NULL) {
return;
}
int ret;
char *path;
- path = config_get_default_path();
+ path = utils_get_home_dir();
if (path == NULL) {
ret = -1;
goto error;
int config_exists(const char *path);
int config_init(char *path);
int config_add_session_name(char *path, char *name);
-char *config_get_default_path(void);
/* Must free() the return pointer */
char *config_read_session_name(char *path);
#include <limits.h>
#include <common/error.h>
+#include <common/utils.h>
#include "conf.h"
#include "utils.h"
char *path, *session_name = NULL;
/* Get path to config file */
- path = config_get_default_path();
+ path = utils_get_home_dir();
if (path == NULL) {
goto error;
}
#define DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH DEFAULT_USTCONSUMERD32_PATH "/error"
/* Default lttng run directory */
+#define DEFAULT_LTTNG_HOME_ENV_VAR "LTTNG_HOME"
+#define DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR "HOME"
#define DEFAULT_LTTNG_RUNDIR "/var/run/lttng"
#define DEFAULT_LTTNG_HOME_RUNDIR "%s/.lttng"
#define DEFAULT_LTTNG_SESSIOND_PIDFILE "lttng-sessiond.pid"
#include <common/runas.h>
#include "utils.h"
+#include "defaults.h"
/*
* Return the realpath(3) of the path even if the last directory token does not
return fls_u32(x - 1);
}
+
+/**
+ * Obtain the value of LTTNG_HOME environment variable, if exists.
+ * Otherwise returns the value of HOME.
+ */
+char *utils_get_home_dir(void)
+{
+ char *val = NULL;
+ val = getenv(DEFAULT_LTTNG_HOME_ENV_VAR);
+ if (val != NULL) {
+ return val;
+ }
+ return getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR);
+}
uint64_t count, int uid, int gid, int out_fd, uint64_t *new_count);
int utils_parse_size_suffix(char *str, uint64_t *size);
int utils_get_count_order_u32(uint32_t x);
+char *utils_get_home_dir(void);
#endif /* _COMMON_UTILS_H */
#include <common/defaults.h>
#include <common/sessiond-comm/sessiond-comm.h>
#include <common/uri.h>
+#include <common/utils.h>
#include <lttng/lttng.h>
#include "filter/filter-ast.h"
* With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
*/
ret = snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
- DEFAULT_HOME_CLIENT_UNIX_SOCK, getenv("HOME"));
+ DEFAULT_HOME_CLIENT_UNIX_SOCK, utils_get_home_dir());
if ((ret < 0) || (ret >= sizeof(sessiond_sock_path))) {
goto error;
}
* With GNU C < 2.1, snprintf returns -1 if the target buffer is too small;
* With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
*/
- home = getenv("HOME");
+ home = utils_get_home_dir();
if (home == NULL) {
/* Fallback in /tmp .. */
home = "/tmp";