X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fsession-config.c;h=1b0db12cc8d448ea175192c28861a3a170edaed8;hb=0ca413e056cf24ec5424cde5c78227138b0782c7;hp=624064a107ef6851e7a2a4820b4ce858722a9c63;hpb=cce35f915c90e726fdaf701ff2c2c504fcd3f0bc;p=lttng-tools.git diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 624064a10..1b0db12cc 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -185,6 +185,8 @@ LTTNG_HIDDEN const char * const config_event_context_interruptible = "INTERRUPTI LTTNG_HIDDEN const char * const config_event_context_preemptible = "PREEMPTIBLE"; LTTNG_HIDDEN const char * const config_event_context_need_reschedule = "NEED_RESCHEDULE"; LTTNG_HIDDEN const char * const config_event_context_migratable = "MIGRATABLE"; +LTTNG_HIDDEN const char * const config_event_context_callstack_user= "CALLSTACK_USER"; +LTTNG_HIDDEN const char * const config_event_context_callstack_kernel = "CALLSTACK_KERNEL"; /* Deprecated symbols */ const char * const config_element_perf; @@ -1018,6 +1020,12 @@ int get_context_type(xmlChar *context_type) } else if (!strcmp((char *) context_type, config_event_context_migratable)) { ret = LTTNG_EVENT_CONTEXT_MIGRATABLE; + } else if (!strcmp((char *) context_type, + config_event_context_callstack_user)) { + ret = LTTNG_EVENT_CONTEXT_CALLSTACK_USER; + } else if (!strcmp((char *) context_type, + config_event_context_callstack_kernel)) { + ret = LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL; } else { goto error; } @@ -2953,23 +2961,6 @@ end: return ret; } -/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */ -static -struct dirent *alloc_dirent(const char *path) -{ - size_t len; - long name_max; - struct dirent *entry; - - name_max = pathconf(path, _PC_NAME_MAX); - if (name_max == -1) { - name_max = PATH_MAX; - } - len = offsetof(struct dirent, d_name) + name_max + 1; - entry = zmalloc(len); - return entry; -} - static int load_session_from_path(const char *path, const char *session_name, struct session_config_validation_ctx *validation_ctx, int overwrite, @@ -3006,8 +2997,6 @@ int load_session_from_path(const char *path, const char *session_name, } } if (directory) { - struct dirent *entry; - struct dirent *result; size_t file_path_root_len; ret = lttng_dynamic_buffer_set_capacity(&file_path, @@ -3017,16 +3006,9 @@ int load_session_from_path(const char *path, const char *session_name, goto end; } - entry = alloc_dirent(path); - if (!entry) { - ret = -LTTNG_ERR_NOMEM; - goto end; - } - ret = lttng_dynamic_buffer_append(&file_path, path, path_len); if (ret) { ret = -LTTNG_ERR_NOMEM; - free(entry); goto end; } @@ -3040,8 +3022,35 @@ int load_session_from_path(const char *path, const char *session_name, file_path_root_len = file_path.size; /* Search for *.lttng files */ - while (!readdir_r(directory, entry, &result) && result) { - size_t file_name_len = strlen(result->d_name); + for (;;) { + size_t file_name_len; + struct dirent *result; + + /* + * When the end of the directory stream is reached, NULL + * is returned and errno is kept unchanged. When an + * error occurs, NULL is returned and errno is set + * accordingly. To distinguish between the two, set + * errno to zero before calling readdir(). + * + * On success, readdir() returns a pointer to a dirent + * structure. This structure may be statically + * allocated, do not attempt to free(3) it. + */ + errno = 0; + result = readdir(directory); + + /* Reached end of dir stream or error out. */ + if (!result) { + if (errno) { + PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path); + ret = -LTTNG_ERR_LOAD_IO_FAIL; + goto end; + } + break; + } + + file_name_len = strlen(result->d_name); if (file_name_len <= sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION)) { @@ -3089,7 +3098,6 @@ int load_session_from_path(const char *path, const char *session_name, } } - free(entry); } else { ret = load_session_from_file(path, session_name, validation_ctx, overwrite, overrides);