416
416
TEST_EQ (job->process[PROCESS_MAIN]->script, TRUE);
417
417
TEST_EQ_STR (job->process[PROCESS_MAIN]->command, "echo\n");
419
TEST_EQ_P (item->entry.next, &file->items);
419
TEST_EQ_P (job->replacement, NULL);
420
TEST_EQ_P (job->replacement_for, NULL);
422
TEST_EQ_P (item->entry.next, &file->items);
427
/* Check that a file in the directory we're watching can be modified
428
* using the direct writing technique; it should be parsed and the
429
* previous job marked for deletion.
431
TEST_FEATURE ("with modified job (direct write)");
432
strcpy (filename, job_dirname);
433
strcat (filename, "/frodo/bar");
435
f = fopen (filename, "w");
436
fprintf (f, "respawn\n");
437
fprintf (f, "script\n");
438
fprintf (f, " sleep 5\n");
439
fprintf (f, "end script\n");
445
FD_ZERO (&exceptfds);
447
nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds);
448
nih_io_handle_fds (&readfds, &writefds, &exceptfds);
450
file = (ConfFile *)nih_hash_lookup (source->files, filename);
452
TEST_ALLOC_SIZE (file, sizeof (ConfFile));
453
TEST_ALLOC_PARENT (file, source);
454
TEST_EQ (file->flag, source->flag);
455
TEST_LIST_NOT_EMPTY (&file->items);
457
item = (ConfItem *)file->items.next;
459
TEST_ALLOC_SIZE (item, sizeof (ConfItem));
460
TEST_ALLOC_PARENT (item, file);
461
TEST_NE_P (item->job, NULL);
463
job = job_find_by_name ("frodo/bar");
464
TEST_EQ_P (item->job, job);
466
TEST_TRUE (job->respawn);
467
TEST_NE_P (job->process[PROCESS_MAIN], NULL);
468
TEST_EQ (job->process[PROCESS_MAIN]->script, TRUE);
469
TEST_EQ_STR (job->process[PROCESS_MAIN]->command, "sleep 5\n");
471
TEST_EQ_P (job->replacement, NULL);
472
TEST_EQ_P (job->replacement_for, NULL);
474
TEST_EQ_P (old_job->replacement, job);
475
TEST_EQ (old_job->state, JOB_DELETED);
477
TEST_EQ_P (item->entry.next, &file->items);
482
/* Check that a file in the directory we're watching can be modified
483
* using the write and then rename technique; it should be parsed and
484
* the previous job marked for deletion.
486
TEST_FEATURE ("with modified job (atomic rename)");
487
strcpy (filename, job_dirname);
488
strcat (filename, "/frodo/bar");
490
strcpy (tmpname, job_dirname);
491
strcat (tmpname, "/frodo/.bar.swp");
493
f = fopen (tmpname, "w");
494
fprintf (f, "respawn\n");
495
fprintf (f, "script\n");
496
fprintf (f, " sleep 15\n");
497
fprintf (f, "end script\n");
500
rename (tmpname, filename);
505
FD_ZERO (&exceptfds);
507
nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds);
508
nih_io_handle_fds (&readfds, &writefds, &exceptfds);
510
file = (ConfFile *)nih_hash_lookup (source->files, filename);
512
TEST_ALLOC_SIZE (file, sizeof (ConfFile));
513
TEST_ALLOC_PARENT (file, source);
514
TEST_EQ (file->flag, source->flag);
515
TEST_LIST_NOT_EMPTY (&file->items);
517
item = (ConfItem *)file->items.next;
519
TEST_ALLOC_SIZE (item, sizeof (ConfItem));
520
TEST_ALLOC_PARENT (item, file);
521
TEST_NE_P (item->job, NULL);
523
job = job_find_by_name ("frodo/bar");
524
TEST_EQ_P (item->job, job);
526
TEST_TRUE (job->respawn);
527
TEST_NE_P (job->process[PROCESS_MAIN], NULL);
528
TEST_EQ (job->process[PROCESS_MAIN]->script, TRUE);
529
TEST_EQ_STR (job->process[PROCESS_MAIN]->command, "sleep 15\n");
531
TEST_EQ_P (job->replacement, NULL);
532
TEST_EQ_P (job->replacement_for, NULL);
534
TEST_EQ_P (old_job->replacement, job);
535
TEST_EQ (old_job->state, JOB_DELETED);
537
TEST_EQ_P (item->entry.next, &file->items);
542
/* Check that we can delete a file from the directory, the metadata
543
* for it should be lost and the job should be queued for deletion.
545
TEST_FEATURE ("with deleted job");
546
strcpy (filename, job_dirname);
547
strcat (filename, "/frodo/bar");
422
549
unlink (filename);
554
FD_ZERO (&exceptfds);
556
nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds);
557
nih_io_handle_fds (&readfds, &writefds, &exceptfds);
559
file = (ConfFile *)nih_hash_lookup (source->files, filename);
561
TEST_EQ_P (file, NULL);
563
job = job_find_by_name ("frodo/bar");
564
TEST_EQ_P (job, NULL);
566
TEST_EQ_P (old_job->replacement, (void *)-1);
567
TEST_EQ (old_job->state, JOB_DELETED);
423
570
conf_source_free (source);
426
572
/* Consume all available inotify instances so that the following
427
573
* tests run without inotify.