}
}
-static int fd_count(void)
+static int fd_count()
{
DIR *dir;
struct dirent *entry;
goto end;
}
- while ((entry = readdir(dir)) != NULL) {
+ while ((entry = readdir(dir)) != nullptr) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
continue;
}
for (i = 0; i < sizeof(files) / sizeof(*files); i++) {
int fd = files[i].fd;
int ret = fd_tracker_close_unsuspendable_fd(
- tracker, &files[i].fd, 1, noop_close, NULL);
+ tracker, &files[i].fd, 1, noop_close, nullptr);
ok(ret == 0, "Untrack unsuspendable fd %d (%s)", fd, files[i].name);
}
/*
* Basic test opening and closing three unsuspendable fds.
*/
-static void test_unsuspendable_basic(void)
+static void test_unsuspendable_basic()
{
int ret;
struct fd_tracker *tracker;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
get_temporary_directories(&test_directory, &unlinked_files_directory);
* Validate that user callback return values are returned to the
* caller of the fd tracker.
*/
-static void test_unsuspendable_cb_return(void)
+static void test_unsuspendable_cb_return()
{
int ret, stdout_fd = fileno(stdout), out_fd = 42;
struct fd_tracker *tracker;
int expected_error = -ENETDOWN;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
get_temporary_directories(&test_directory, &unlinked_files_directory);
/* The error_open callback should fail and return 'expected_error'. */
ret = fd_tracker_open_unsuspendable_fd(
- tracker, &out_fd, NULL, 1, error_open, &expected_error);
+ tracker, &out_fd, nullptr, 1, error_open, &expected_error);
ok(ret == expected_error,
"fd_tracker_open_unsuspendable_fd() forwards the user callback's error code");
ok(out_fd == 42,
* Track a valid fd since we don't want the tracker to fail with an
* invalid fd error for this test.
*/
- ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd);
+ ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, nullptr, 1, noop_open, &stdout_fd);
ok(out_fd == stdout_fd,
"fd_tracker_open_unsuspendable_fd() sets the output fd parameter to the newly-tracked fd's value");
LTTNG_ASSERT(!ret);
* Validate that the tracker refuses to track two identical unsuspendable
* file descriptors.
*/
-static void test_unsuspendable_duplicate(void)
+static void test_unsuspendable_duplicate()
{
int ret, stdout_fd = fileno(stdout), out_fd;
struct fd_tracker *tracker;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
get_temporary_directories(&test_directory, &unlinked_files_directory);
tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
LTTNG_ASSERT(tracker);
- ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd);
+ ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, nullptr, 1, noop_open, &stdout_fd);
LTTNG_ASSERT(!ret);
- ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd);
+ ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, nullptr, 1, noop_open, &stdout_fd);
ok(ret == -EEXIST, "EEXIST reported on open of an already tracked file descriptor");
- ret = fd_tracker_close_unsuspendable_fd(tracker, &stdout_fd, 1, noop_close, NULL);
+ ret = fd_tracker_close_unsuspendable_fd(tracker, &stdout_fd, 1, noop_close, nullptr);
LTTNG_ASSERT(!ret);
fd_tracker_destroy(tracker);
* Validate that the tracker enforces the open file descriptor limit
* when unsuspendable file descriptors are being opened.
*/
-static void test_unsuspendable_limit(void)
+static void test_unsuspendable_limit()
{
struct fd_tracker *tracker;
int ret, stdout_fd = fileno(stdout), out_fd;
int fds[TRACKER_FD_LIMIT];
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
get_temporary_directories(&test_directory, &unlinked_files_directory);
LTTNG_ASSERT(tracker);
ret = fd_tracker_open_unsuspendable_fd(
- tracker, fds, NULL, TRACKER_FD_LIMIT, open_pipes, NULL);
+ tracker, fds, nullptr, TRACKER_FD_LIMIT, open_pipes, nullptr);
ok(ret == 0,
"File descriptor tracker allowed the user to meet its limit with unsuspendable file descriptors (%d)",
TRACKER_FD_LIMIT);
- ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd);
+ ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, nullptr, 1, noop_open, &stdout_fd);
ok(ret == -EMFILE,
"EMFILE reported when exceeding the file descriptor limit while opening an unsuspendable fd");
- ret = fd_tracker_close_unsuspendable_fd(tracker, fds, TRACKER_FD_LIMIT, close_pipes, NULL);
+ ret = fd_tracker_close_unsuspendable_fd(
+ tracker, fds, TRACKER_FD_LIMIT, close_pipes, nullptr);
LTTNG_ASSERT(!ret);
fd_tracker_destroy(tracker);
* Validate that the tracker refuses to track two identical unsuspendable
* file descriptors.
*/
-static void test_unsuspendable_close_untracked(void)
+static void test_unsuspendable_close_untracked()
{
int ret, stdout_fd = fileno(stdout), unknown_fds[2], out_fd;
struct fd_tracker *tracker;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
get_temporary_directories(&test_directory, &unlinked_files_directory);
ret = close(unknown_fds[1]);
LTTNG_ASSERT(ret == 0);
- ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd);
+ ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, nullptr, 1, noop_open, &stdout_fd);
LTTNG_ASSERT(!ret);
- ret = fd_tracker_close_unsuspendable_fd(tracker, unknown_fds, 1, noop_close, NULL);
+ ret = fd_tracker_close_unsuspendable_fd(tracker, unknown_fds, 1, noop_close, nullptr);
ok(ret == -EINVAL, "EINVAL reported on close of an untracked file descriptor");
- ret = fd_tracker_close_unsuspendable_fd(tracker, &stdout_fd, 1, noop_close, NULL);
+ ret = fd_tracker_close_unsuspendable_fd(tracker, &stdout_fd, 1, noop_close, nullptr);
LTTNG_ASSERT(!ret);
fd_tracker_destroy(tracker);
return ret;
}
-static void test_suspendable_limit(void)
+static void test_suspendable_limit()
{
int ret;
const int files_to_create = TRACKER_FD_LIMIT * 10;
struct fd_tracker *tracker;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
char *output_files[files_to_create];
struct fs_handle *handles[files_to_create];
- struct lttng_directory_handle *dir_handle = NULL;
+ struct lttng_directory_handle *dir_handle = nullptr;
int dir_handle_fd_count;
memset(output_files, 0, sizeof(output_files));
free(unlinked_files_directory);
}
-static void test_mixed_limit(void)
+static void test_mixed_limit()
{
int ret;
const int files_to_create = TRACKER_FD_LIMIT;
struct fd_tracker *tracker;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
char *output_files[files_to_create];
struct fs_handle *handles[files_to_create];
- struct lttng_directory_handle *dir_handle = NULL;
+ struct lttng_directory_handle *dir_handle = nullptr;
int dir_handle_fd_count;
memset(output_files, 0, sizeof(output_files));
*
* The content of the files is also verified at the end.
*/
-static void test_suspendable_restore(void)
+static void test_suspendable_restore()
{
int ret;
const int files_to_create = TRACKER_FD_LIMIT * 10;
bool write_success = true;
bool fd_cap_respected = true;
bool content_ok = true;
- struct lttng_directory_handle *dir_handle = NULL;
+ struct lttng_directory_handle *dir_handle = nullptr;
int dir_handle_fd_count;
- char *test_directory = NULL, *unlinked_files_directory = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
memset(output_files, 0, sizeof(output_files));
memset(handles, 0, sizeof(handles));
break;
}
- if (strcmp(file_contents, read_buf)) {
+ if (strcmp(file_contents, read_buf) != 0) {
content_ok = false;
diag("File content doesn't match the expectated string");
(void) close(fd);
free(unlinked_files_directory);
}
-static void test_unlink(void)
+static void test_unlink()
{
int ret;
struct fd_tracker *tracker;
const int handles_to_open = 2;
struct fs_handle *handles[handles_to_open];
- struct fs_handle *new_handle = NULL;
+ struct fs_handle *new_handle = nullptr;
struct stat statbuf;
- struct lttng_directory_handle *dir_handle = NULL;
+ struct lttng_directory_handle *dir_handle = nullptr;
const char file_name[] = "my_file";
- char *test_directory = NULL, *unlinked_files_directory = NULL;
- char *unlinked_file_zero = NULL, *unlinked_file_one = NULL;
+ char *test_directory = nullptr, *unlinked_files_directory = nullptr;
+ char *unlinked_file_zero = nullptr, *unlinked_file_one = nullptr;
int fd;
get_temporary_directories(&test_directory, &unlinked_files_directory);
lttng_directory_handle_put(dir_handle);
}
-int main(void)
+int main()
{
plan_tests(NUM_TESTS);
diag("File descriptor tracker unit tests");