48
48
#include <error.h> /* error() */
49
49
#include <sysexits.h> /* EX_USAGE, EX_OSERR, EX_OSFILE */
50
50
#include <errno.h> /* errno, error_t, EACCES,
51
ENAMETOOLONG, ENOENT, ENOTDIR,
52
ENOMEM, EEXIST, ECHILD, EPERM,
53
EAGAIN, EINTR, ENOBUFS, EADDRINUSE,
51
ENAMETOOLONG, ENOENT, EEXIST,
52
ECHILD, EPERM, ENOMEM, EAGAIN,
53
EINTR, ENOBUFS, EADDRINUSE,
54
54
ECONNREFUSED, ECONNRESET,
55
55
ETOOMANYREFS, EMSGSIZE, EBADF,
84
83
#include <sys/mman.h> /* munlock(), mlock() */
85
84
#include <fcntl.h> /* O_CLOEXEC, O_NONBLOCK, fcntl(),
86
85
F_GETFD, F_GETFL, FD_CLOEXEC,
87
open(), O_WRONLY, O_NOCTTY,
88
O_RDONLY, O_NOFOLLOW */
86
open(), O_WRONLY, O_RDONLY */
89
87
#include <sys/wait.h> /* waitpid(), WNOHANG, WIFEXITED(),
91
89
#include <limits.h> /* PIPE_BUF, NAME_MAX, INT_MAX */
92
90
#include <sys/inotify.h> /* inotify_init1(), IN_NONBLOCK,
93
91
IN_CLOEXEC, inotify_add_watch(),
94
92
IN_CLOSE_WRITE, IN_MOVED_TO,
95
IN_MOVED_FROM, IN_DELETE,
96
IN_EXCL_UNLINK, IN_ONLYDIR,
97
struct inotify_event */
93
IN_DELETE, struct inotify_event */
98
94
#include <fnmatch.h> /* fnmatch(), FNM_FILE_NAME */
99
#include <stdio.h> /* asprintf(), FILE, stderr, fopen(),
100
fclose(), getline(), sscanf(),
101
feof(), ferror(), rename(),
102
fdopen(), fprintf(), fscanf() */
95
#include <stdio.h> /* asprintf(), FILE, fopen(),
96
getline(), sscanf(), feof(),
97
ferror(), fclose(), stderr,
98
rename(), fdopen(), fprintf(),
103
100
#include <glib.h> /* GKeyFile, g_key_file_free(), g_key_file_new(),
104
101
GError, g_key_file_load_from_file(),
105
102
G_KEY_FILE_NONE, TRUE, G_FILE_ERROR_NOENT,
652
648
__attribute__((nonnull, warn_unused_result))
653
649
bool add_to_queue(task_queue *const queue, const task_context task){
654
if((queue->length + 1) > (SIZE_MAX / sizeof(task_context))){
656
error(0, ENOMEM, "Failed to allocate %" PRIuMAX
657
" tasks for queue->tasks", (uintmax_t)(queue->length + 1));
661
650
const size_t needed_size = sizeof(task_context)*(queue->length + 1);
662
651
if(needed_size > (queue->allocated)){
663
652
task_context *const new_tasks = realloc(queue->tasks,
1089
1071
/* "sufficient to read at least one event." - inotify(7) */
1090
1072
const size_t ievent_size = (sizeof(struct inotify_event)
1091
1073
+ NAME_MAX + 1);
1093
struct inotify_event event;
1094
char name_buffer[NAME_MAX + 1];
1096
struct inotify_event *const ievent = &ievent_buffer.event;
1074
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
1075
struct inotify_event *ievent = ((struct inotify_event *)
1098
1078
const ssize_t read_length = read(fd, ievent, ievent_size);
1099
1079
if(read_length == 0){ /* EOF */
1897
1877
g_assert_true(queue->tasks[0].func == dummy_func);
1900
static void test_add_to_queue_overflow(__attribute__((unused))
1901
test_fixture *fixture,
1902
__attribute__((unused))
1903
gconstpointer user_data){
1904
__attribute__((cleanup(cleanup_queue)))
1905
task_queue *queue = create_queue();
1906
g_assert_nonnull(queue);
1907
g_assert_true(queue->length == 0);
1908
queue->length = SIZE_MAX / sizeof(task_context); /* fake max size */
1910
FILE *real_stderr = stderr;
1911
FILE *devnull = fopen("/dev/null", "we");
1912
g_assert_nonnull(devnull);
1914
const bool ret = add_to_queue(queue,
1915
(task_context){ .func=dummy_func });
1916
g_assert_true(errno == ENOMEM);
1917
g_assert_false(ret);
1918
stderr = real_stderr;
1919
g_assert_cmpint(fclose(devnull), ==, 0);
1920
queue->length = 0; /* Restore real size */
1923
1880
static void dummy_func(__attribute__((unused))
1924
1881
const task_context task,
1925
1882
__attribute__((unused))
3499
3450
g_assert_cmpuint((unsigned int)queue->length, ==, 0);
3502
static void test_add_inotify_dir_watch_nondir(__attribute__((unused))
3503
test_fixture *fixture,
3504
__attribute__((unused))
3507
__attribute__((cleanup(cleanup_close)))
3508
const int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
3509
g_assert_cmpint(epoll_fd, >=, 0);
3510
__attribute__((cleanup(cleanup_queue)))
3511
task_queue *queue = create_queue();
3512
g_assert_nonnull(queue);
3513
__attribute__((cleanup(string_set_clear)))
3514
string_set cancelled_filenames = {};
3515
const mono_microsecs current_time = 0;
3517
bool quit_now = false;
3518
buffer password = {};
3519
bool mandos_client_exited = false;
3520
bool password_is_read = false;
3522
const char not_a_directory[] = "/dev/tty";
3524
FILE *real_stderr = stderr;
3525
FILE *devnull = fopen("/dev/null", "we");
3526
g_assert_nonnull(devnull);
3528
g_assert_false(add_inotify_dir_watch(queue, epoll_fd, &quit_now,
3529
&password, not_a_directory,
3530
&cancelled_filenames,
3532
&mandos_client_exited,
3533
&password_is_read));
3534
stderr = real_stderr;
3535
g_assert_cmpint(fclose(devnull), ==, 0);
3537
g_assert_cmpuint((unsigned int)queue->length, ==, 0);
3540
3453
static void test_add_inotify_dir_watch_EAGAIN(__attribute__((unused))
3541
3454
test_fixture *fixture,
3542
3455
__attribute__((unused))
3760
void test_add_inotify_dir_watch_IN_MOVED_FROM(__attribute__((unused))
3761
test_fixture *fixture,
3762
__attribute__((unused))
3765
__attribute__((cleanup(cleanup_close)))
3766
const int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
3767
g_assert_cmpint(epoll_fd, >=, 0);
3768
__attribute__((cleanup(cleanup_queue)))
3769
task_queue *queue = create_queue();
3770
g_assert_nonnull(queue);
3771
__attribute__((cleanup(string_set_clear)))
3772
string_set cancelled_filenames = {};
3773
const mono_microsecs current_time = 0;
3775
bool quit_now = false;
3776
buffer password = {};
3777
bool mandos_client_exited = false;
3778
bool password_is_read = false;
3780
__attribute__((cleanup(cleanup_string)))
3781
char *tempdir = make_temporary_directory();
3782
g_assert_nonnull(tempdir);
3784
__attribute__((cleanup(cleanup_string)))
3785
char *tempfilename = make_temporary_file_in_directory(tempdir);
3786
g_assert_nonnull(tempfilename);
3788
__attribute__((cleanup(cleanup_string)))
3789
char *targetdir = make_temporary_directory();
3790
g_assert_nonnull(targetdir);
3792
__attribute__((cleanup(cleanup_string)))
3793
char *targetfilename = NULL;
3794
g_assert_cmpint(asprintf(&targetfilename, "%s/%s", targetdir,
3795
basename(tempfilename)), >, 0);
3796
g_assert_nonnull(targetfilename);
3798
g_assert_true(add_inotify_dir_watch(queue, epoll_fd, &quit_now,
3800
&cancelled_filenames,
3802
&mandos_client_exited,
3803
&password_is_read));
3805
g_assert_cmpint(rename(tempfilename, targetfilename), ==, 0);
3807
const task_context *const added_read_task
3808
= find_matching_task(queue,
3809
(task_context){ .func=read_inotify_event });
3810
g_assert_nonnull(added_read_task);
3812
/* "sufficient to read at least one event." - inotify(7) */
3813
const size_t ievent_size = (sizeof(struct inotify_event)
3815
struct inotify_event *ievent = malloc(ievent_size);
3816
g_assert_nonnull(ievent);
3818
ssize_t read_size = read(added_read_task->fd, ievent, ievent_size);
3820
g_assert_cmpint((int)read_size, >, 0);
3821
g_assert_true(ievent->mask & IN_MOVED_FROM);
3822
g_assert_cmpstr(ievent->name, ==, basename(tempfilename));
3826
g_assert_cmpint(unlink(targetfilename), ==, 0);
3827
g_assert_cmpint(rmdir(targetdir), ==, 0);
3828
g_assert_cmpint(rmdir(tempdir), ==, 0);
3832
3673
void test_add_inotify_dir_watch_IN_DELETE(__attribute__((unused))
3833
3674
test_fixture *fixture,
3834
3675
__attribute__((unused))
3892
3733
g_assert_cmpint(rmdir(tempdir), ==, 0);
3896
void test_add_inotify_dir_watch_IN_EXCL_UNLINK(__attribute__((unused))
3897
test_fixture *fixture,
3898
__attribute__((unused))
3901
__attribute__((cleanup(cleanup_close)))
3902
const int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
3903
g_assert_cmpint(epoll_fd, >=, 0);
3904
__attribute__((cleanup(cleanup_queue)))
3905
task_queue *queue = create_queue();
3906
g_assert_nonnull(queue);
3907
__attribute__((cleanup(string_set_clear)))
3908
string_set cancelled_filenames = {};
3909
const mono_microsecs current_time = 0;
3911
bool quit_now = false;
3912
buffer password = {};
3913
bool mandos_client_exited = false;
3914
bool password_is_read = false;
3916
__attribute__((cleanup(cleanup_string)))
3917
char *tempdir = make_temporary_directory();
3918
g_assert_nonnull(tempdir);
3920
__attribute__((cleanup(cleanup_string)))
3921
char *tempfile = make_temporary_file_in_directory(tempdir);
3922
g_assert_nonnull(tempfile);
3923
int tempfile_fd = open(tempfile, O_WRONLY | O_CLOEXEC | O_NOCTTY
3925
g_assert_cmpint(tempfile_fd, >, 2);
3927
g_assert_true(add_inotify_dir_watch(queue, epoll_fd, &quit_now,
3929
&cancelled_filenames,
3931
&mandos_client_exited,
3932
&password_is_read));
3933
g_assert_cmpint(unlink(tempfile), ==, 0);
3935
g_assert_cmpuint((unsigned int)queue->length, >, 0);
3937
const task_context *const added_read_task
3938
= find_matching_task(queue,
3939
(task_context){ .func=read_inotify_event });
3940
g_assert_nonnull(added_read_task);
3942
g_assert_cmpint(added_read_task->fd, >, 2);
3943
g_assert_true(fd_has_cloexec_and_nonblock(added_read_task->fd));
3945
/* "sufficient to read at least one event." - inotify(7) */
3946
const size_t ievent_size = (sizeof(struct inotify_event)
3948
struct inotify_event *ievent = malloc(ievent_size);
3949
g_assert_nonnull(ievent);
3951
ssize_t read_size = 0;
3952
read_size = read(added_read_task->fd, ievent, ievent_size);
3954
g_assert_cmpint((int)read_size, >, 0);
3955
g_assert_true(ievent->mask & IN_DELETE);
3956
g_assert_cmpstr(ievent->name, ==, basename(tempfile));
3958
g_assert_cmpint(close(tempfile_fd), ==, 0);
3960
/* IN_EXCL_UNLINK should make the closing of the previously unlinked
3961
file not appear as an ievent, so we should not see it now. */
3962
read_size = read(added_read_task->fd, ievent, ievent_size);
3963
g_assert_cmpint((int)read_size, ==, -1);
3964
g_assert_true(errno == EAGAIN);
3968
g_assert_cmpint(rmdir(tempdir), ==, 0);
3971
3736
static void test_read_inotify_event_readerror(__attribute__((unused))
3972
3737
test_fixture *fixture,
3973
3738
__attribute__((unused))
4165
3929
const size_t ievent_max_size = (sizeof(struct inotify_event)
4166
3930
+ NAME_MAX + 1);
4167
3931
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4169
struct inotify_event event;
4170
char name_buffer[NAME_MAX + 1];
4172
struct inotify_event *const ievent = &ievent_buffer.event;
3932
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
3933
struct inotify_event *ievent = ((struct inotify_event *)
4174
3936
const char dummy_file_name[] = "ask.dummy_file_name";
4175
3937
ievent->mask = IN_CLOSE_WRITE;
4177
3939
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4178
3940
const size_t ievent_size = (sizeof(struct inotify_event)
4179
3941
+ sizeof(dummy_file_name));
4180
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
3942
g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
4181
3943
==, ievent_size);
4182
3944
g_assert_cmpint(close(pipefds[1]), ==, 0);
4260
4022
const size_t ievent_max_size = (sizeof(struct inotify_event)
4261
4023
+ NAME_MAX + 1);
4262
4024
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4264
struct inotify_event event;
4265
char name_buffer[NAME_MAX + 1];
4267
struct inotify_event *const ievent = &ievent_buffer.event;
4025
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4026
struct inotify_event *ievent = ((struct inotify_event *)
4269
4029
const char dummy_file_name[] = "ask.dummy_file_name";
4270
4030
ievent->mask = IN_MOVED_TO;
4272
4032
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4273
4033
const size_t ievent_size = (sizeof(struct inotify_event)
4274
4034
+ sizeof(dummy_file_name));
4275
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4035
g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
4276
4036
==, ievent_size);
4277
4037
g_assert_cmpint(close(pipefds[1]), ==, 0);
4342
void test_read_inotify_event_IN_MOVED_FROM(__attribute__((unused))
4343
test_fixture *fixture,
4344
__attribute__((unused))
4345
gconstpointer user_data){
4346
__attribute__((cleanup(cleanup_close)))
4347
const int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
4348
g_assert_cmpint(epoll_fd, >=, 0);
4349
__attribute__((cleanup(string_set_clear)))
4350
string_set cancelled_filenames = {};
4351
const mono_microsecs current_time = 0;
4354
g_assert_cmpint(pipe2(pipefds, O_CLOEXEC | O_NONBLOCK), ==, 0);
4356
/* "sufficient to read at least one event." - inotify(7) */
4357
const size_t ievent_max_size = (sizeof(struct inotify_event)
4359
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4361
struct inotify_event event;
4362
char name_buffer[NAME_MAX + 1];
4364
struct inotify_event *const ievent = &ievent_buffer.event;
4366
const char dummy_file_name[] = "ask.dummy_file_name";
4367
ievent->mask = IN_MOVED_FROM;
4368
ievent->len = sizeof(dummy_file_name);
4369
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4370
const size_t ievent_size = (sizeof(struct inotify_event)
4371
+ sizeof(dummy_file_name));
4372
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4374
g_assert_cmpint(close(pipefds[1]), ==, 0);
4376
bool quit_now = false;
4377
buffer password = {};
4378
bool mandos_client_exited = false;
4379
bool password_is_read = false;
4380
__attribute__((cleanup(cleanup_queue)))
4381
task_queue *queue = create_queue();
4382
g_assert_nonnull(queue);
4384
task_context task = {
4385
.func=read_inotify_event,
4388
.quit_now=&quit_now,
4389
.password=&password,
4390
.filename=strdup("/nonexistent"),
4391
.cancelled_filenames=&cancelled_filenames,
4392
.current_time=¤t_time,
4393
.mandos_client_exited=&mandos_client_exited,
4394
.password_is_read=&password_is_read,
4396
task.func(task, queue);
4397
g_assert_false(quit_now);
4398
g_assert_true(queue->next_run == 0);
4399
g_assert_cmpuint((unsigned int)queue->length, ==, 1);
4401
g_assert_nonnull(find_matching_task(queue, (task_context){
4402
.func=read_inotify_event,
4405
.quit_now=&quit_now,
4406
.password=&password,
4407
.filename=task.filename,
4408
.cancelled_filenames=&cancelled_filenames,
4409
.current_time=¤t_time,
4410
.mandos_client_exited=&mandos_client_exited,
4411
.password_is_read=&password_is_read,
4414
g_assert_true(epoll_set_contains(epoll_fd, pipefds[0],
4415
EPOLLIN | EPOLLRDHUP));
4417
__attribute__((cleanup(cleanup_string)))
4418
char *filename = NULL;
4419
g_assert_cmpint(asprintf(&filename, "%s/%s", task.filename,
4420
dummy_file_name), >, 0);
4421
g_assert_nonnull(filename);
4422
g_assert_true(string_set_contains(*task.cancelled_filenames,
4426
4101
static void test_read_inotify_event_IN_DELETE(__attribute__((unused))
4427
4102
test_fixture *fixture,
4428
4103
__attribute__((unused))
4442
4117
const size_t ievent_max_size = (sizeof(struct inotify_event)
4443
4118
+ NAME_MAX + 1);
4444
4119
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4446
struct inotify_event event;
4447
char name_buffer[NAME_MAX + 1];
4449
struct inotify_event *const ievent = &ievent_buffer.event;
4120
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4121
struct inotify_event *ievent = ((struct inotify_event *)
4451
4124
const char dummy_file_name[] = "ask.dummy_file_name";
4452
4125
ievent->mask = IN_DELETE;
4454
4127
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4455
4128
const size_t ievent_size = (sizeof(struct inotify_event)
4456
4129
+ sizeof(dummy_file_name));
4457
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4130
g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
4458
4131
==, ievent_size);
4459
4132
g_assert_cmpint(close(pipefds[1]), ==, 0);
4526
4199
const size_t ievent_max_size = (sizeof(struct inotify_event)
4527
4200
+ NAME_MAX + 1);
4528
4201
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4530
struct inotify_event event;
4531
char name_buffer[NAME_MAX + 1];
4533
struct inotify_event *const ievent = &ievent_buffer.event;
4202
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4203
struct inotify_event *ievent = ((struct inotify_event *)
4535
4206
const char dummy_file_name[] = "ignored.dummy_file_name";
4536
4207
ievent->mask = IN_CLOSE_WRITE;
4538
4209
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4539
4210
const size_t ievent_size = (sizeof(struct inotify_event)
4540
4211
+ sizeof(dummy_file_name));
4541
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4212
g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
4542
4213
==, ievent_size);
4543
4214
g_assert_cmpint(close(pipefds[1]), ==, 0);
4602
4273
const size_t ievent_max_size = (sizeof(struct inotify_event)
4603
4274
+ NAME_MAX + 1);
4604
4275
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4606
struct inotify_event event;
4607
char name_buffer[NAME_MAX + 1];
4609
struct inotify_event *const ievent = &ievent_buffer.event;
4276
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4277
struct inotify_event *ievent = ((struct inotify_event *)
4611
4280
const char dummy_file_name[] = "ignored.dummy_file_name";
4612
4281
ievent->mask = IN_MOVED_TO;
4614
4283
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4615
4284
const size_t ievent_size = (sizeof(struct inotify_event)
4616
4285
+ sizeof(dummy_file_name));
4617
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4286
g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
4618
4287
==, ievent_size);
4619
4288
g_assert_cmpint(close(pipefds[1]), ==, 0);
4661
4330
EPOLLIN | EPOLLRDHUP));
4665
test_read_inotify_event_IN_MOVED_FROM_badname(__attribute__((unused))
4666
test_fixture *fixture,
4667
__attribute__((unused))
4670
__attribute__((cleanup(cleanup_close)))
4671
const int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
4672
g_assert_cmpint(epoll_fd, >=, 0);
4673
__attribute__((cleanup(string_set_clear)))
4674
string_set cancelled_filenames = {};
4675
const mono_microsecs current_time = 0;
4678
g_assert_cmpint(pipe2(pipefds, O_CLOEXEC | O_NONBLOCK), ==, 0);
4680
/* "sufficient to read at least one event." - inotify(7) */
4681
const size_t ievent_max_size = (sizeof(struct inotify_event)
4683
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4685
struct inotify_event event;
4686
char name_buffer[NAME_MAX + 1];
4688
struct inotify_event *const ievent = &ievent_buffer.event;
4690
const char dummy_file_name[] = "ignored.dummy_file_name";
4691
ievent->mask = IN_MOVED_FROM;
4692
ievent->len = sizeof(dummy_file_name);
4693
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4694
const size_t ievent_size = (sizeof(struct inotify_event)
4695
+ sizeof(dummy_file_name));
4696
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4698
g_assert_cmpint(close(pipefds[1]), ==, 0);
4700
bool quit_now = false;
4701
buffer password = {};
4702
bool mandos_client_exited = false;
4703
bool password_is_read = false;
4704
__attribute__((cleanup(cleanup_queue)))
4705
task_queue *queue = create_queue();
4706
g_assert_nonnull(queue);
4708
task_context task = {
4709
.func=read_inotify_event,
4712
.quit_now=&quit_now,
4713
.password=&password,
4714
.filename=strdup("/nonexistent"),
4715
.cancelled_filenames=&cancelled_filenames,
4716
.current_time=¤t_time,
4717
.mandos_client_exited=&mandos_client_exited,
4718
.password_is_read=&password_is_read,
4720
task.func(task, queue);
4721
g_assert_false(quit_now);
4722
g_assert_true(queue->next_run == 0);
4723
g_assert_cmpuint((unsigned int)queue->length, ==, 1);
4725
g_assert_nonnull(find_matching_task(queue, (task_context){
4726
.func=read_inotify_event,
4729
.quit_now=&quit_now,
4730
.password=&password,
4731
.filename=task.filename,
4732
.cancelled_filenames=&cancelled_filenames,
4733
.current_time=¤t_time,
4734
.mandos_client_exited=&mandos_client_exited,
4735
.password_is_read=&password_is_read,
4738
g_assert_true(epoll_set_contains(epoll_fd, pipefds[0],
4739
EPOLLIN | EPOLLRDHUP));
4741
__attribute__((cleanup(cleanup_string)))
4742
char *filename = NULL;
4743
g_assert_cmpint(asprintf(&filename, "%s/%s", task.filename,
4744
dummy_file_name), >, 0);
4745
g_assert_nonnull(filename);
4746
g_assert_false(string_set_contains(cancelled_filenames, filename));
4750
4334
void test_read_inotify_event_IN_DELETE_badname(__attribute__((unused))
4751
4335
test_fixture *fixture,
4766
4350
const size_t ievent_max_size = (sizeof(struct inotify_event)
4767
4351
+ NAME_MAX + 1);
4768
4352
g_assert_cmpint(ievent_max_size, <=, PIPE_BUF);
4770
struct inotify_event event;
4771
char name_buffer[NAME_MAX + 1];
4773
struct inotify_event *const ievent = &ievent_buffer.event;
4353
char ievent_buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
4354
struct inotify_event *ievent = ((struct inotify_event *)
4775
4357
const char dummy_file_name[] = "ignored.dummy_file_name";
4776
4358
ievent->mask = IN_DELETE;
4778
4360
memcpy(ievent->name, dummy_file_name, sizeof(dummy_file_name));
4779
4361
const size_t ievent_size = (sizeof(struct inotify_event)
4780
4362
+ sizeof(dummy_file_name));
4781
g_assert_cmpint(write(pipefds[1], (char *)ievent, ievent_size),
4363
g_assert_cmpint(write(pipefds[1], ievent_buffer, ievent_size),
4782
4364
==, ievent_size);
4783
4365
g_assert_cmpint(close(pipefds[1]), ==, 0);
7906
7481
test_add("/parse_arguments/mixed", test_parse_arguments_mixed);
7907
7482
test_add("/queue/create", test_create_queue);
7908
7483
test_add("/queue/add", test_add_to_queue);
7909
test_add("/queue/add/overflow", test_add_to_queue_overflow);
7910
7484
test_add("/queue/has_question/empty",
7911
7485
test_queue_has_question_empty);
7912
7486
test_add("/queue/has_question/false",
7999
7573
test_add_inotify_dir_watch);
8000
7574
test_add_st("/task-creators/add_inotify_dir_watch/fail",
8001
7575
test_add_inotify_dir_watch_fail);
8002
test_add_st("/task-creators/add_inotify_dir_watch/not-a-directory",
8003
test_add_inotify_dir_watch_nondir);
8004
7576
test_add_st("/task-creators/add_inotify_dir_watch/EAGAIN",
8005
7577
test_add_inotify_dir_watch_EAGAIN);
8006
7578
test_add_st("/task-creators/add_inotify_dir_watch/IN_CLOSE_WRITE",
8007
7579
test_add_inotify_dir_watch_IN_CLOSE_WRITE);
8008
7580
test_add_st("/task-creators/add_inotify_dir_watch/IN_MOVED_TO",
8009
7581
test_add_inotify_dir_watch_IN_MOVED_TO);
8010
test_add_st("/task-creators/add_inotify_dir_watch/IN_MOVED_FROM",
8011
test_add_inotify_dir_watch_IN_MOVED_FROM);
8012
test_add_st("/task-creators/add_inotify_dir_watch/IN_EXCL_UNLINK",
8013
test_add_inotify_dir_watch_IN_EXCL_UNLINK);
8014
7582
test_add_st("/task-creators/add_inotify_dir_watch/IN_DELETE",
8015
7583
test_add_inotify_dir_watch_IN_DELETE);
8016
7584
test_add_st("/task/read_inotify_event/readerror",
8025
7593
test_read_inotify_event_IN_CLOSE_WRITE);
8026
7594
test_add_st("/task/read_inotify_event/IN_MOVED_TO",
8027
7595
test_read_inotify_event_IN_MOVED_TO);
8028
test_add_st("/task/read_inotify_event/IN_MOVED_FROM",
8029
test_read_inotify_event_IN_MOVED_FROM);
8030
7596
test_add_st("/task/read_inotify_event/IN_DELETE",
8031
7597
test_read_inotify_event_IN_DELETE);
8032
7598
test_add_st("/task/read_inotify_event/IN_CLOSE_WRITE/badname",
8033
7599
test_read_inotify_event_IN_CLOSE_WRITE_badname);
8034
7600
test_add_st("/task/read_inotify_event/IN_MOVED_TO/badname",
8035
7601
test_read_inotify_event_IN_MOVED_TO_badname);
8036
test_add_st("/task/read_inotify_event/IN_MOVED_FROM/badname",
8037
test_read_inotify_event_IN_MOVED_FROM_badname);
8038
7602
test_add_st("/task/read_inotify_event/IN_DELETE/badname",
8039
7603
test_read_inotify_event_IN_DELETE_badname);
8040
7604
test_add_st("/task/open_and_parse_question/ENOENT",
8137
7701
g_option_context_set_help_enabled(context, FALSE);
8138
7702
g_option_context_set_ignore_unknown_options(context, TRUE);
8140
gboolean should_run_tests = FALSE;
7704
gboolean run_tests = FALSE;
8141
7705
GOptionEntry entries[] = {
8142
7706
{ "test", 0, 0, G_OPTION_ARG_NONE,
8143
&should_run_tests, "Run tests", NULL },
7707
&run_tests, "Run tests", NULL },
8146
7710
g_option_context_add_main_entries(context, entries, NULL);