#include <sys/stat.h>
#include <fcntl.h>
#include <babeltrace/compat/mman-internal.h>
-#include <babeltrace/compat/dirent-internal.h>
+#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
{
int fd, metadata_fd, ret;
DIR *dir;
- int dir_fd;
FILE *metadata_fp;
+ char *file_path;
ret = parse_args(argc, argv);
if (ret) {
perror("opendir");
goto error_rmdir;
}
- dir_fd = bt_dirfd(dir);
- if (dir_fd < 0) {
- perror("dirfd");
+
+ file_path = g_build_filename(s_outputname, "datastream", NULL);
+ if (file_path == NULL) {
+ perror("g_build_filename");
goto error_closedir;
}
-
- fd = openat(dir_fd, "datastream", O_RDWR|O_CREAT,
+ fd = open(file_path, O_RDWR|O_CREAT,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+ g_free(file_path);
if (fd < 0) {
- perror("openat");
- goto error_closedirfd;
+ perror("open");
+ goto error_closedir;
}
- metadata_fd = openat(dir_fd, "metadata", O_RDWR|O_CREAT,
+ file_path = g_build_filename(s_outputname, "metadata", NULL);
+ if (file_path == NULL) {
+ perror("g_build_filename");
+ goto error_closedatastream;
+ }
+ metadata_fd = open(file_path, O_RDWR|O_CREAT,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+ g_free(file_path);
if (metadata_fd < 0) {
- perror("openat");
+ perror("open");
goto error_closedatastream;
}
metadata_fp = fdopen(metadata_fd, "w");
ret = close(fd);
if (ret)
perror("close");
-error_closedirfd:
- ret = close(dir_fd);
- if (ret)
- perror("close");
error_closedir:
ret = closedir(dir);
if (ret)
AC_FUNC_STRERROR_R
AC_CHECK_FUNCS([ \
atexit \
- dirfd \
dup2 \
ftruncate \
gethostbyname \
]
)
-# Check for faccessat
-AC_CHECK_LIB([c], [faccessat],
-[
- AC_DEFINE_UNQUOTED([BABELTRACE_HAVE_FACCESSAT], 1, [Has faccessat support.])
-]
-)
-
AC_CHECK_LIB([popt], [poptGetContext], [],
[AC_MSG_ERROR([Cannot find popt.])]
)
babeltrace/babeltrace-internal.h \
babeltrace/bitfield-internal.h \
babeltrace/common-internal.h \
- babeltrace/compat/dirent-internal.h \
babeltrace/compat/fcntl-internal.h \
babeltrace/compat/glib-internal.h \
babeltrace/compat/limits-internal.h \
+++ /dev/null
-#ifndef _BABELTRACE_COMPAT_DIRENT_H
-#define _BABELTRACE_COMPAT_DIRENT_H
-
-/*
- * babeltrace/compat/dirent.h
- *
- * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <dirent.h>
-
-#ifdef HAVE_DIRFD
-static inline
-int bt_dirfd(DIR *dir) {
- return dirfd(dir);
-}
-#else
-# ifndef __XOPEN_OR_POSIX
-static inline
-int bt_dirfd(DIR *dir) {
- return dir->dd_fd;
-}
-# else
-static inline
-int bt_dirfd(DIR *dir) {
- return dir->d_fd;
-}
-# endif
-#endif
-
-#endif /* _BABELTRACE_COMPAT_DIRENT_H */
}
#endif /* #else #ifdef BABELTRACE_HAVE_POSIX_FALLOCATE */
-
-#ifdef BABELTRACE_HAVE_FACCESSAT
-
-#include <fcntl.h>
-#include <unistd.h>
-
-static inline
-int bt_faccessat(int dirfd, const char *dirname,
- const char *pathname, int mode, int flags)
-{
- return faccessat(dirfd, pathname, mode, flags);
-}
-
-#else /* #ifdef BABELTRACE_HAVE_FACCESSAT */
-
-#include <string.h>
-#include <unistd.h>
-
-static inline
-int bt_faccessat(int dirfd, const char *dirname,
- const char *pathname, int mode, int flags)
-{
- char cpath[PATH_MAX];
-
- if (flags != 0) {
- errno = EINVAL;
- return -1;
- }
- /* Includes middle / and final \0. */
- if (strlen(dirname) + strlen(pathname) + 2 > PATH_MAX) {
- return -1;
- }
- strcpy(cpath, dirname);
- strcat(cpath, "/");
- strcat(cpath, pathname);
- return access(cpath, mode);
-}
-
-#endif /* #else #ifdef BABELTRACE_HAVE_FACCESSAT */
-
#endif /* _BABELTRACE_COMPAT_FCNTL_H */
int frozen; /* Protects attributes that can't be changed mid-trace */
struct bt_ctf_trace *trace;
GString *path;
- int trace_dir_fd;
int metadata_fd;
};
{
int fd;
GString *filename = g_string_new(stream->stream_class->name->str);
+ char *file_path;
BT_LOGD("Creating stream file: writer-addr=%p, stream-addr=%p, "
"stream-name=\"%s\", stream-class-addr=%p, stream-class-name=\"%s\"",
}
g_string_append_printf(filename, "_%" PRId64, stream->id);
- fd = openat(writer->trace_dir_fd, filename->str,
+ file_path = g_build_filename(writer->path->str, filename->str, NULL);
+ if (file_path == NULL) {
+ fd = -1;
+ goto end;
+ }
+ fd = open(file_path,
O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+ g_free(file_path);
if (fd < 0) {
BT_LOGW("Failed to open stream file for writing: %s: "
- "writer-trace-dir-fd=%d, filename=\"%s\", "
+ "filename=\"%s\", "
"ret=%d, errno=%d", strerror(errno),
- writer->trace_dir_fd, filename->str, fd, errno);
+ filename->str, fd, errno);
goto end;
}
BT_LOGD("Created stream file for writing: "
- "stream-addr=%p, stream-name=\"%s\", writer-trace-dir-fd=%d, "
+ "stream-addr=%p, stream-name=\"%s\", "
"filename=\"%s\", fd=%d", stream, bt_ctf_stream_get_name(stream),
- writer->trace_dir_fd, filename->str, fd);
+ filename->str, fd);
end:
g_string_free(filename, TRUE);
int ret;
struct bt_ctf_writer *writer = NULL;
unsigned char uuid[16];
+ char *metadata_path = NULL;
if (!path) {
goto error;
goto error;
}
+ metadata_path = g_build_filename(path, "metadata", NULL);
+
bt_object_init(writer, bt_ctf_writer_destroy);
writer->path = g_string_new(path);
if (!writer->path) {
goto error_destroy;
}
- writer->trace_dir_fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG);
- if (writer->trace_dir_fd < 0) {
+ writer->metadata_fd = open(metadata_path,
+ O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+ if (writer->metadata_fd < 0) {
perror("open");
goto error_destroy;
}
- writer->metadata_fd = openat(writer->trace_dir_fd, "metadata",
- O_WRONLY | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
-
+ g_free(metadata_path);
return writer;
error_destroy:
- unlinkat(writer->trace_dir_fd, "metadata", 0);
BT_PUT(writer);
error:
+ g_free(metadata_path);
return writer;
}
g_string_free(writer->path, TRUE);
}
- if (writer->trace_dir_fd > 0) {
- if (close(writer->trace_dir_fd)) {
- perror("close");
- }
- }
-
if (writer->metadata_fd > 0) {
if (close(writer->metadata_fd)) {
perror("close");
#include <unistd.h>
#include <stdio.h>
-#include <babeltrace/compat/dirent-internal.h>
+#include <dirent.h>
#include <babeltrace/compat/limits-internal.h>
#include <sys/stat.h>
#include <assert.h>
#include <sys/wait.h>
#include <fcntl.h>
-#include <babeltrace/compat/dirent-internal.h>
#include "tap/tap.h"
#include <math.h>
#include <float.h>