4376
4398
JobClass *class1, *class2, *class3;
4377
4399
Job *job1, *job2, *job3, *job4, *job5, *ptr;
4378
4400
ProcessType process;
4403
session = session_new (NULL, NULL, getuid ());
4404
TEST_NE_P (session, NULL);
4380
4406
TEST_FUNCTION ("job_process_find");
4381
class1 = job_class_new (NULL, "foo");
4407
class1 = job_class_new (NULL, "foo", session);
4382
4408
class1->process[PROCESS_MAIN] = process_new (class1);
4383
4409
class1->process[PROCESS_POST_START] = process_new (class1);
4384
4410
class1->instance = "$FOO";
4385
4411
nih_hash_add (job_classes, &class1->entry);
4387
class2 = job_class_new (NULL, "bar");
4413
class2 = job_class_new (NULL, "bar", session);
4388
4414
class2->process[PROCESS_PRE_START] = process_new (class2);
4389
4415
class2->process[PROCESS_MAIN] = process_new (class2);
4390
4416
class2->process[PROCESS_PRE_STOP] = process_new (class2);
4391
4417
class2->instance = "$FOO";
4392
4418
nih_hash_add (job_classes, &class2->entry);
4394
class3 = job_class_new (NULL, "baz");
4420
class3 = job_class_new (NULL, "baz", session);
4395
4421
class3->process[PROCESS_POST_STOP] = process_new (class3);
4396
4422
nih_hash_add (job_classes, &class3->entry);
4495
4521
nih_free (class1);
4496
4522
nih_free (class2);
4497
4523
nih_free (class3);
4498
4525
ptr = job_process_find (20, NULL);
4500
4527
TEST_EQ_P (ptr, NULL);
4536
Blocked * blocked = NULL;
4539
char utmpname[PATH_MAX];
4540
struct utmpx utmp, *utmptr;
4544
session = session_new (NULL, NULL, getuid ());
4545
TEST_NE_P (session, NULL);
4547
TEST_FUNCTION ("job_process_handler");
4548
program_name = "test";
4550
class = job_class_new (NULL, "test", session);
4551
class->process[PROCESS_MAIN] = process_new (class);
4552
class->process[PROCESS_MAIN]->command = "echo";
4554
class->start_on = event_operator_new (class, EVENT_MATCH,
4556
class->stop_on = event_operator_new (class, EVENT_MATCH,
4558
nih_hash_add (job_classes, &class->entry);
4560
event = event_new (NULL, "foo", NULL);
4562
TEST_FILENAME(utmpname);
4564
/* Check that utmp record for the running task of the job terminating
4565
* is properly changed to DEAD_PROCESS
4567
TEST_FEATURE ("with LOGIN_PROCESS utmp entry");
4570
job = job_new (class, "");
4572
blocked = blocked_new (job, BLOCKED_EVENT, event);
4573
event_block (event);
4574
nih_list_add (&job->blocking, &blocked->entry);
4577
job->goal = JOB_START;
4578
job->state = JOB_RUNNING;
4579
job->pid[PROCESS_MAIN] = 1;
4581
TEST_FREE_TAG (blocked);
4583
job->blocker = NULL;
4584
event->failed = FALSE;
4586
job->failed = FALSE;
4587
job->failed_process = -1;
4588
job->exit_status = 0;
4590
output = fopen (utmpname, "w");
4594
utmpxname(utmpname);
4596
/* set up utmp entries */
4597
memset (&utmp, 0, sizeof utmp);
4599
strcpy(utmp.ut_id, "2");
4600
utmp.ut_type = LOGIN_PROCESS;
4603
gettimeofday(&tv, NULL);
4604
utmp.ut_tv.tv_sec = tv.tv_sec;
4605
utmp.ut_tv.tv_usec = tv.tv_usec;
4610
strcpy(utmp.ut_id, "1");
4616
job_process_handler (NULL, 1, NIH_CHILD_EXITED, 0);
4620
utmptr = getutxent();
4621
TEST_NE_P(utmptr, NULL);
4622
TEST_EQ(utmptr->ut_pid, 2);
4623
TEST_EQ(utmptr->ut_type, LOGIN_PROCESS);
4625
utmptr = getutxent();
4626
TEST_NE_P(utmptr, NULL);
4627
TEST_EQ(utmptr->ut_pid, 1);
4628
TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
4632
TEST_FEATURE ("with USER_PROCESS utmp entry");
4635
job = job_new (class, "");
4637
blocked = blocked_new (job, BLOCKED_EVENT, event);
4638
event_block (event);
4639
nih_list_add (&job->blocking, &blocked->entry);
4642
job->goal = JOB_START;
4643
job->state = JOB_RUNNING;
4644
job->pid[PROCESS_MAIN] = 1;
4646
TEST_FREE_TAG (blocked);
4648
job->blocker = NULL;
4649
event->failed = FALSE;
4651
job->failed = FALSE;
4652
job->failed_process = -1;
4653
job->exit_status = 0;
4655
output = fopen (utmpname, "w");
4659
utmpxname(utmpname);
4661
/* set up utmp entries */
4662
memset (&utmp, 0, sizeof utmp);
4664
strcpy(utmp.ut_id, "2");
4665
utmp.ut_type = USER_PROCESS;
4668
gettimeofday(&tv, NULL);
4669
utmp.ut_tv.tv_sec = tv.tv_sec;
4670
utmp.ut_tv.tv_usec = tv.tv_usec;
4675
strcpy(utmp.ut_id, "1");
4681
job_process_handler (NULL, 1, NIH_CHILD_EXITED, 0);
4685
utmptr = getutxent();
4686
TEST_NE_P(utmptr, NULL);
4687
TEST_EQ(utmptr->ut_pid, 2);
4688
TEST_EQ(utmptr->ut_type, USER_PROCESS);
4690
utmptr = getutxent();
4691
TEST_NE_P(utmptr, NULL);
4692
TEST_EQ(utmptr->ut_pid, 1);
4693
TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
4698
/* new mingetty doesn't use entries with DEAD_PROCESS until it's last entry so
4699
* we need to check if upstart sets DEAD_PROCESS for correct entry */
4700
TEST_FEATURE ("with multiple entries with same ut_id");
4703
job = job_new (class, "");
4705
blocked = blocked_new (job, BLOCKED_EVENT, event);
4706
event_block (event);
4707
nih_list_add (&job->blocking, &blocked->entry);
4710
job->goal = JOB_START;
4711
job->state = JOB_RUNNING;
4712
job->pid[PROCESS_MAIN] = 2;
4714
TEST_FREE_TAG (blocked);
4716
job->blocker = NULL;
4717
event->failed = FALSE;
4719
job->failed = FALSE;
4720
job->failed_process = -1;
4721
job->exit_status = 0;
4723
output = fopen (utmpname, "w");
4727
utmpxname(utmpname);
4729
/* set up utmp entries */
4730
memset (&utmp, 0, sizeof utmp);
4732
strcpy(utmp.ut_id, "2");
4733
utmp.ut_type = DEAD_PROCESS;
4736
gettimeofday(&tv, NULL);
4742
strcpy(utmp.ut_id, "2");
4743
utmp.ut_type = USER_PROCESS;
4745
utmp.ut_tv.tv_sec = tv.tv_sec;
4746
utmp.ut_tv.tv_usec = tv.tv_usec;
4751
job_process_handler (NULL, 2, NIH_CHILD_EXITED, 0);
4755
utmptr = getutxent();
4756
TEST_NE_P(utmptr, NULL);
4757
TEST_EQ(utmptr->ut_pid, 1);
4758
TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
4760
utmptr = getutxent();
4761
TEST_NE_P(utmptr, NULL);
4762
TEST_EQ(utmptr->ut_pid, 2);
4763
TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
4764
TEST_EQ(utmptr->ut_time, 0);
4505
4773
main (int argc,