#define _GNU_SOURCE
#include <assert.h>
+#include <sys/stat.h>
#include <common/common.h>
#include <common/defaults.h>
uint64_t size, uint64_t count)
{
int ret, fd = -1;
- struct lttng_packet_index_file_hdr hdr;
+ ssize_t size_ret;
+ struct ctf_packet_index_file_hdr hdr;
+ char fullpath[PATH_MAX];
- ret = utils_create_stream_file(path_name, stream_name, size, count, uid,
+ ret = snprintf(fullpath, sizeof(fullpath), "%s/" DEFAULT_INDEX_DIR,
+ path_name);
+ if (ret < 0) {
+ PERROR("snprintf index path");
+ goto error;
+ }
+
+ /* Create index directory if necessary. */
+ ret = run_as_mkdir(fullpath, S_IRWXU | S_IRWXG, uid, gid);
+ if (ret < 0) {
+ if (ret != -EEXIST) {
+ ERR("Index trace directory creation error");
+ goto error;
+ }
+ }
+
+ ret = utils_create_stream_file(fullpath, stream_name, size, count, uid,
gid, DEFAULT_INDEX_FILE_SUFFIX);
if (ret < 0) {
goto error;
}
fd = ret;
- memcpy(hdr.magic, INDEX_MAGIC, sizeof(hdr.magic));
- hdr.index_major = htobe32(INDEX_MAJOR);
- hdr.index_minor = htobe32(INDEX_MINOR);
+ hdr.magic = htobe32(CTF_INDEX_MAGIC);
+ hdr.index_major = htobe32(CTF_INDEX_MAJOR);
+ hdr.index_minor = htobe32(CTF_INDEX_MINOR);
+ hdr.packet_index_len = sizeof(struct ctf_packet_index);
- do {
- ret = write(fd, &hdr, sizeof(hdr));
- } while (ret < 0 && errno == EINTR);
- if (ret < 0) {
+ size_ret = lttng_write(fd, &hdr, sizeof(hdr));
+ if (size_ret < sizeof(hdr)) {
PERROR("write index header");
+ ret = -1;
goto error;
}
/*
* Write index values to the given fd of size len.
*
- * Return 0 on success or else a negative value on error.
+ * Return "len" on success or else < len on error. errno contains error
+ * details.
*/
-int index_write(int fd, struct lttng_packet_index *index, size_t len)
+ssize_t index_write(int fd, struct ctf_packet_index *index, size_t len)
{
- int ret;
+ ssize_t ret;
assert(fd >= 0);
assert(index);
- do {
- ret = write(fd, index, len);
- } while (ret < 0 && errno == EINTR);
- if (ret < 0) {
+ ret = lttng_write(fd, index, len);
+ if (ret < len) {
PERROR("writing index file");
}