{
DIR *dir;
struct dirent *entry;
- int count = 0;
+ int count = 0;
dir = opendir("/proc/self/fd");
if (!dir) {
perror("# Failed to enumerate /proc/self/fd/ to count the number of used file descriptors");
- count = -1;
+ count = -1;
goto end;
}
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
continue;
}
- count++;
+ count++;
}
/* Don't account for the file descriptor opened by opendir(). */
- count--;
+ count--;
if (closedir(dir)) {
perror("# Failed to close test program's self/fd directory file descriptor");
}
static
void check_fd_count(int expected_count)
{
- int count = 0;
+ int count = 0;
- count = fd_count();
+ count = fd_count();
ok(count == expected_count, "Expected %d open file descriptors (%d are open)",
expected_count, count);
}
static
int noop_open(void *data, int *fds)
{
- *fds = *((int *) data);
+ *fds = *((int *) data);
return 0;
}
void track_std_fds(struct fd_tracker *tracker)
{
int i;
- struct { int fd; const char *name; } files[] = {
+ struct { int fd; const char *name; } files[] = {
{ .fd = fileno(stdin), .name = "stdin" },
{ .fd = fileno(stdout), .name = "stdout" },
{ .fd = fileno(stderr), .name = "stderr" },
void untrack_std_fds(struct fd_tracker *tracker)
{
int i;
- struct { int fd; const char *name; } files[] = {
+ struct { int fd; const char *name; } files[] = {
{ .fd = fileno(stdin), .name = "stdin" },
{ .fd = fileno(stdout), .name = "stdout" },
{ .fd = fileno(stderr), .name = "stderr" },
get_temporary_directories(&test_directory, &unlinked_files_directory);
- tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
ok(tracker, "Created an fd tracker with a limit of %d simulateously opened file descriptors",
TRACKER_FD_LIMIT);
if (!tracker) {
get_temporary_directories(&test_directory, &unlinked_files_directory);
- tracker = fd_tracker_create(test_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(test_directory, TRACKER_FD_LIMIT);
assert(tracker);
/* The error_open callback should fail and return 'expected_error'. */
get_temporary_directories(&test_directory, &unlinked_files_directory);
- tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
assert(tracker);
ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd,
/* This test assumes TRACKER_FD_LIMIT is a multiple of 2. */
assert((TRACKER_FD_LIMIT % 2 == 0) && TRACKER_FD_LIMIT);
- tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
assert(tracker);
ret = fd_tracker_open_unsuspendable_fd(tracker, fds,
get_temporary_directories(&test_directory, &unlinked_files_directory);
- tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
if (!tracker) {
goto end;;
}
for (i = 0; i < count; i++) {
int p_ret;
- char *file_path;
+ char *file_path;
struct fs_handle *handle;
mode_t mode = S_IWUSR | S_IRUSR;
p_ret = asprintf(&file_path, "file-%u", i);
assert(p_ret >= 0);
- file_paths[i] = file_path;
+ file_paths[i] = file_path;
handle = fd_tracker_open_fs_handle(tracker, directory, file_path,
O_RDWR | O_CREAT, &mode);
diag("Failed to unlink fs_handle to file %s", file_path);
ret = -1;
}
- if (fs_handle_close(handles[i])) {
+ if (fs_handle_close(handles[i])) {
diag("Failed to close fs_handle to file %s", file_path);
ret = -1;
}
get_temporary_directories(&test_directory, &unlinked_files_directory);
- tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
if (!tracker) {
goto end;
}
get_temporary_directories(&test_directory, &unlinked_files_directory);
- tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
+ tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT);
if (!tracker) {
goto end;
}
fd = fs_handle_get_fd(handle);
if (fd < 0) {
write_success = false;
- diag("Failed to restore fs_handle to %s",
- path);
+ diag("Failed to restore fs_handle to %s",
+ path);
goto skip_write;
}
if (ret != 1) {
write_success = false;
- PERROR("write() to %s failed", path);
+ PERROR("write() to %s failed", path);
goto skip_write;
}