~jamesodhunt/ubuntu/natty/upstart/fix-chroot-sessions

« back to all changes in this revision

Viewing changes to init/tests/test_job_process.c

  • Committer: Colin Watson
  • Date: 2011-02-28 20:20:50 UTC
  • mfrom: (1295.1.3 ubuntu-natty-upstart)
  • Revision ID: cjwatson@canonical.com-20110228202050-mcykx2rwzbc5q4wc
merge lp:~jamesodhunt/ubuntu/natty/upstart/proposed

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * test_job_process.c - test suite for init/job_process.c
4
4
 *
5
 
 * Copyright © 2010 Canonical Ltd.
 
5
 * Copyright © 2011 Canonical Ltd.
6
6
 * Author: Scott James Remnant <scott@netsplit.com>.
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
36
36
#include <stdlib.h>
37
37
#include <string.h>
38
38
#include <unistd.h>
 
39
#include <utmp.h>
 
40
#include <utmpx.h>
39
41
 
40
42
#include <nih/macros.h>
41
43
#include <nih/string.h>
129
131
        char         filename[PATH_MAX], buf[80];
130
132
        int          ret = -1, status, first;
131
133
        siginfo_t    info;
 
134
        Session     *session;
 
135
 
 
136
        session = session_new (NULL, NULL, getuid ());
 
137
        TEST_NE_P (session, NULL);
132
138
 
133
139
        TEST_FUNCTION ("job_process_run");
134
140
        job_class_init ();
145
151
        TEST_FEATURE ("with simple command");
146
152
        TEST_ALLOC_FAIL {
147
153
                TEST_ALLOC_SAFE {
148
 
                        class = job_class_new (NULL, "test");
 
154
                        class = job_class_new (NULL, "test", session);
149
155
                        class->process[PROCESS_MAIN] = process_new (class);
150
156
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
151
157
                                class->process[PROCESS_MAIN],
177
183
        TEST_FEATURE ("with shell command");
178
184
        TEST_ALLOC_FAIL {
179
185
                TEST_ALLOC_SAFE {
180
 
                        class = job_class_new (NULL, "test");
 
186
                        class = job_class_new (NULL, "test", session);
181
187
                        class->process[PROCESS_MAIN] = process_new (class);
182
188
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
183
189
                                class->process[PROCESS_MAIN],
214
220
        TEST_FEATURE ("with small script");
215
221
        TEST_ALLOC_FAIL {
216
222
                TEST_ALLOC_SAFE {
217
 
                        class = job_class_new (NULL, "test");
 
223
                        class = job_class_new (NULL, "test", session);
218
224
                        class->process[PROCESS_MAIN] = process_new (class);
219
225
                        class->process[PROCESS_MAIN]->script = TRUE;
220
226
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
251
257
        TEST_FEATURE ("with small script and trailing newlines");
252
258
        TEST_ALLOC_FAIL {
253
259
                TEST_ALLOC_SAFE {
254
 
                        class = job_class_new (NULL, "test");
 
260
                        class = job_class_new (NULL, "test", session);
255
261
                        class->process[PROCESS_MAIN] = process_new (class);
256
262
                        class->process[PROCESS_MAIN]->script = TRUE;
257
263
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
288
294
        TEST_FEATURE ("with script that will fail");
289
295
        TEST_ALLOC_FAIL {
290
296
                TEST_ALLOC_SAFE {
291
 
                        class = job_class_new (NULL, "test");
 
297
                        class = job_class_new (NULL, "test", session);
292
298
                        class->process[PROCESS_MAIN] = process_new (class);
293
299
                        class->process[PROCESS_MAIN]->script = TRUE;
294
300
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
325
331
        TEST_FEATURE ("with environment of unnamed instance");
326
332
        TEST_ALLOC_FAIL {
327
333
                TEST_ALLOC_SAFE {
328
 
                        class = job_class_new (NULL, "test");
 
334
                        class = job_class_new (NULL, "test", session);
329
335
                        class->process[PROCESS_MAIN] = process_new (class);
330
336
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
331
337
                                class->process[PROCESS_MAIN],
374
380
        TEST_FEATURE ("with environment of named instance");
375
381
        TEST_ALLOC_FAIL {
376
382
                TEST_ALLOC_SAFE {
377
 
                        class = job_class_new (NULL, "test");
 
383
                        class = job_class_new (NULL, "test", session);
378
384
                        class->process[PROCESS_MAIN] = process_new (class);
379
385
                        class->process[PROCESS_MAIN]->command = nih_sprintf (
380
386
                                class->process[PROCESS_MAIN],
424
430
        TEST_FEATURE ("with environment for pre-stop");
425
431
        TEST_ALLOC_FAIL {
426
432
                TEST_ALLOC_SAFE {
427
 
                        class = job_class_new (NULL, "test");
 
433
                        class = job_class_new (NULL, "test", session);
428
434
                        class->process[PROCESS_PRE_STOP] = process_new (class);
429
435
                        class->process[PROCESS_PRE_STOP]->command = nih_sprintf (
430
436
                                class->process[PROCESS_PRE_STOP],
475
481
        TEST_FEATURE ("with environment for post-stop");
476
482
        TEST_ALLOC_FAIL {
477
483
                TEST_ALLOC_SAFE {
478
 
                        class = job_class_new (NULL, "test");
 
484
                        class = job_class_new (NULL, "test", session);
479
485
                        class->process[PROCESS_POST_STOP] = process_new (class);
480
486
                        class->process[PROCESS_POST_STOP]->command = nih_sprintf (
481
487
                                class->process[PROCESS_POST_STOP],
526
532
        TEST_FEATURE ("with long script");
527
533
        TEST_ALLOC_FAIL {
528
534
                TEST_ALLOC_SAFE {
529
 
                        class = job_class_new (NULL, "test");
 
535
                        class = job_class_new (NULL, "test", session);
530
536
                        class->process[PROCESS_MAIN] = process_new (class);
531
537
                        class->process[PROCESS_MAIN]->script = TRUE;
532
538
                        class->process[PROCESS_MAIN]->command = nih_alloc (
591
597
        TEST_FEATURE ("with non-daemon job");
592
598
        TEST_ALLOC_FAIL {
593
599
                TEST_ALLOC_SAFE {
594
 
                        class = job_class_new (NULL, "test");
 
600
                        class = job_class_new (NULL, "test", session);
595
601
                        class->process[PROCESS_MAIN] = process_new (class);
596
602
                        class->process[PROCESS_MAIN]->command = "true";
597
603
 
627
633
        TEST_FEATURE ("with script for daemon job");
628
634
        TEST_ALLOC_FAIL {
629
635
                TEST_ALLOC_SAFE {
630
 
                        class = job_class_new (NULL, "test");
 
636
                        class = job_class_new (NULL, "test", session);
631
637
                        class->process[PROCESS_PRE_START] = process_new (class);
632
638
                        class->process[PROCESS_PRE_START]->command = "true";
633
639
 
664
670
        TEST_FEATURE ("with daemon job");
665
671
        TEST_ALLOC_FAIL {
666
672
                TEST_ALLOC_SAFE {
667
 
                        class = job_class_new (NULL, "test");
 
673
                        class = job_class_new (NULL, "test", session);
668
674
                        class->expect = EXPECT_DAEMON;
669
675
                        class->process[PROCESS_MAIN] = process_new (class);
670
676
                        class->process[PROCESS_MAIN]->command = "true";
711
717
        TEST_FEATURE ("with forking job");
712
718
        TEST_ALLOC_FAIL {
713
719
                TEST_ALLOC_SAFE {
714
 
                        class = job_class_new (NULL, "test");
 
720
                        class = job_class_new (NULL, "test", session);
715
721
                        class->expect = EXPECT_FORK;
716
722
                        class->process[PROCESS_MAIN] = process_new (class);
717
723
                        class->process[PROCESS_MAIN]->command = "true";
760
766
 
761
767
        TEST_ALLOC_FAIL {
762
768
                TEST_ALLOC_SAFE {
763
 
                        class = job_class_new (NULL, "test");
 
769
                        class = job_class_new (NULL, "test", session);
764
770
                        class->process[PROCESS_MAIN] = process_new (class);
765
771
                        class->process[PROCESS_MAIN]->command = filename;
766
772
 
785
791
 
786
792
                nih_free (class);
787
793
        }
 
794
        nih_free (session);
788
795
}
789
796
 
790
797
 
801
808
        NihError         *err;
802
809
        JobProcessError  *perr;
803
810
        int               status;
 
811
        Session          *session;
 
812
 
 
813
        session = session_new (NULL, NULL, getuid ());
 
814
        TEST_NE_P (session, NULL);
804
815
 
805
816
        TEST_FUNCTION ("job_process_spawn");
806
817
        TEST_FILENAME (filename);
817
828
        TEST_FEATURE ("with simple job");
818
829
        sprintf (function, "%d", TEST_PIDS);
819
830
 
820
 
        class = job_class_new (NULL, "test");
 
831
        class = job_class_new (NULL, "test", session);
821
832
 
822
833
        pid = job_process_spawn (class, args, NULL, FALSE);
823
834
        TEST_GT (pid, 0);
854
865
        TEST_FEATURE ("with no console");
855
866
        sprintf (function, "%d", TEST_CONSOLE);
856
867
 
857
 
        class = job_class_new (NULL, "test");
 
868
        class = job_class_new (NULL, "test", session);
858
869
        class->console = CONSOLE_NONE;
859
870
 
860
871
        pid = job_process_spawn (class, args, NULL, FALSE);
880
891
        TEST_FEATURE ("with working directory");
881
892
        sprintf (function, "%d", TEST_PWD);
882
893
 
883
 
        class = job_class_new (NULL, "test");
 
894
        class = job_class_new (NULL, "test", session);
884
895
        class->chdir = "/tmp";
885
896
 
886
897
        pid = job_process_spawn (class, args, NULL, FALSE);
909
920
        env[1] = "FOO=bar";
910
921
        env[2] = NULL;
911
922
 
912
 
        class = job_class_new (NULL, "test");
 
923
        class = job_class_new (NULL, "test", session);
913
924
 
914
925
        pid = job_process_spawn (class, args, env, FALSE);
915
926
        TEST_GT (pid, 0);
934
945
        TEST_FEATURE ("with non-daemon job");
935
946
        sprintf (function, "%d", TEST_SIMPLE);
936
947
 
937
 
        class = job_class_new (NULL, "test");
 
948
        class = job_class_new (NULL, "test", session);
938
949
 
939
950
        pid = job_process_spawn (class, args, NULL, FALSE);
940
951
        TEST_GT (pid, 0);
954
965
        TEST_FEATURE ("with daemon job");
955
966
        sprintf (function, "%d", TEST_SIMPLE);
956
967
 
957
 
        class = job_class_new (NULL, "test");
 
968
        class = job_class_new (NULL, "test", session);
958
969
 
959
970
        pid = job_process_spawn (class, args, NULL, TRUE);
960
971
        TEST_GT (pid, 0);
983
994
        args[1] = filename;
984
995
        args[2] = NULL;
985
996
 
986
 
        class = job_class_new (NULL, "test");
 
997
        class = job_class_new (NULL, "test", session);
987
998
 
988
999
        pid = job_process_spawn (class, args, NULL, FALSE);
989
1000
        TEST_LT (pid, 0);
1002
1013
         */
1003
1014
        TEST_FEATURE ("with debug enabled");
1004
1015
 
1005
 
        class = job_class_new (NULL, "test");
 
1016
        class = job_class_new (NULL, "test", session);
1006
1017
        class->debug = TRUE;
1007
1018
 
1008
1019
        sprintf (function, "%s", "/bin/true");
1031
1042
        TEST_EQ (WEXITSTATUS (status), 0);
1032
1043
 
1033
1044
        nih_free (class);
 
1045
        nih_free (session);
1034
1046
}
1035
1047
 
1036
1048
 
1043
1055
        struct timespec now;
1044
1056
        pid_t           pid;
1045
1057
        int             status;
 
1058
        Session        *session;
 
1059
 
 
1060
        session = session_new (NULL, NULL, getuid ());
 
1061
        TEST_NE_P (session, NULL);
1046
1062
 
1047
1063
        TEST_FUNCTION ("job_process_kill");
1048
1064
        nih_timer_init ();
1049
1065
        event_init ();
1050
1066
 
1051
 
        class = job_class_new (NULL, "test");
 
1067
        class = job_class_new (NULL, "test", session);
1052
1068
        class->kill_timeout = 1000;
1053
1069
 
1054
1070
        class->process[PROCESS_MAIN] = process_new (class);
1175
1191
        }
1176
1192
 
1177
1193
        nih_free (class);
 
1194
        nih_free (session);
1178
1195
}
1179
1196
 
1180
1197
 
1195
1212
        siginfo_t       info;
1196
1213
        unsigned long   data;
1197
1214
        struct timespec now;
 
1215
        Session        *session;
 
1216
 
 
1217
        session = session_new (NULL, NULL, getuid ());
 
1218
        TEST_NE_P (session, NULL);
1198
1219
 
1199
1220
        TEST_FUNCTION ("job_process_handler");
1200
1221
        program_name = "test";
1202
1223
 
1203
1224
        source = conf_source_new (NULL, "/tmp", CONF_JOB_DIR);
1204
1225
        file = conf_file_new (source, "/tmp/test");
1205
 
        file->job = class = job_class_new (NULL, "test");
 
1226
        file->job = class = job_class_new (NULL, "test", session);
1206
1227
        class->process[PROCESS_MAIN] = process_new (class);
1207
1228
        class->process[PROCESS_MAIN]->command = "echo";
1208
1229
 
4366
4387
        nih_free (source);
4367
4388
 
4368
4389
        nih_free (event);
 
4390
        nih_free (session);
4369
4391
        event_poll ();
4370
4392
}
4371
4393
 
4376
4398
        JobClass    *class1, *class2, *class3;
4377
4399
        Job         *job1, *job2, *job3, *job4, *job5, *ptr;
4378
4400
        ProcessType  process;
 
4401
        Session     *session;
 
4402
 
 
4403
        session = session_new (NULL, NULL, getuid ());
 
4404
        TEST_NE_P (session, NULL);
4379
4405
 
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);
4386
4412
 
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);
4393
4419
 
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);
4397
4423
 
4495
4521
        nih_free (class1);
4496
4522
        nih_free (class2);
4497
4523
        nih_free (class3);
 
4524
        nih_free (session);
4498
4525
        ptr = job_process_find (20, NULL);
4499
4526
 
4500
4527
        TEST_EQ_P (ptr, NULL);
4501
4528
}
4502
4529
 
4503
4530
 
 
4531
void
 
4532
test_utmp (void)
 
4533
{
 
4534
        JobClass *      class;
 
4535
        Job *           job = NULL;
 
4536
        Blocked *       blocked = NULL;
 
4537
        Event *         event;
 
4538
        FILE *          output;
 
4539
        char            utmpname[PATH_MAX];
 
4540
        struct utmpx    utmp, *utmptr;
 
4541
        struct timeval  tv;
 
4542
        Session        *session;
 
4543
 
 
4544
        session = session_new (NULL, NULL, getuid ());
 
4545
        TEST_NE_P (session, NULL);
 
4546
 
 
4547
        TEST_FUNCTION ("job_process_handler");
 
4548
        program_name = "test";
 
4549
 
 
4550
        class = job_class_new (NULL, "test", session);
 
4551
        class->process[PROCESS_MAIN] = process_new (class);
 
4552
        class->process[PROCESS_MAIN]->command = "echo";
 
4553
 
 
4554
        class->start_on = event_operator_new (class, EVENT_MATCH,
 
4555
                                               "foo", NULL);
 
4556
        class->stop_on = event_operator_new (class, EVENT_MATCH,
 
4557
                                              "foo", NULL);
 
4558
        nih_hash_add (job_classes, &class->entry);
 
4559
 
 
4560
        event = event_new (NULL, "foo", NULL);
 
4561
 
 
4562
        TEST_FILENAME(utmpname);
 
4563
 
 
4564
        /* Check that utmp record for the running task of the job terminating
 
4565
         * is properly changed to DEAD_PROCESS
 
4566
         */
 
4567
        TEST_FEATURE ("with LOGIN_PROCESS utmp entry");
 
4568
        TEST_ALLOC_FAIL {
 
4569
                TEST_ALLOC_SAFE {
 
4570
                        job = job_new (class, "");
 
4571
 
 
4572
                        blocked = blocked_new (job, BLOCKED_EVENT, event);
 
4573
                        event_block (event);
 
4574
                        nih_list_add (&job->blocking, &blocked->entry);
 
4575
                }
 
4576
 
 
4577
                job->goal = JOB_START;
 
4578
                job->state = JOB_RUNNING;
 
4579
                job->pid[PROCESS_MAIN] = 1;
 
4580
 
 
4581
                TEST_FREE_TAG (blocked);
 
4582
 
 
4583
                job->blocker = NULL;
 
4584
                event->failed = FALSE;
 
4585
 
 
4586
                job->failed = FALSE;
 
4587
                job->failed_process = -1;
 
4588
                job->exit_status = 0;
 
4589
 
 
4590
                output = fopen (utmpname, "w");
 
4591
                fclose (output);
 
4592
 
 
4593
                /* set utmp file */
 
4594
                utmpxname(utmpname);
 
4595
 
 
4596
                /* set up utmp entries */
 
4597
                memset (&utmp, 0, sizeof utmp);
 
4598
 
 
4599
                strcpy(utmp.ut_id, "2");
 
4600
                utmp.ut_type = LOGIN_PROCESS;
 
4601
                utmp.ut_pid = 2;
 
4602
 
 
4603
                gettimeofday(&tv, NULL);
 
4604
                utmp.ut_tv.tv_sec = tv.tv_sec;
 
4605
                utmp.ut_tv.tv_usec = tv.tv_usec;
 
4606
 
 
4607
                setutxent();
 
4608
                pututxline(&utmp);
 
4609
 
 
4610
                strcpy(utmp.ut_id, "1");
 
4611
                utmp.ut_pid = 1;
 
4612
                pututxline(&utmp);
 
4613
 
 
4614
                endutxent();
 
4615
 
 
4616
                job_process_handler (NULL, 1, NIH_CHILD_EXITED, 0);
 
4617
 
 
4618
                setutxent();
 
4619
 
 
4620
                utmptr = getutxent();
 
4621
                TEST_NE_P(utmptr, NULL);
 
4622
                TEST_EQ(utmptr->ut_pid, 2);
 
4623
                TEST_EQ(utmptr->ut_type, LOGIN_PROCESS);
 
4624
 
 
4625
                utmptr = getutxent();
 
4626
                TEST_NE_P(utmptr, NULL);
 
4627
                TEST_EQ(utmptr->ut_pid, 1);
 
4628
                TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
 
4629
 
 
4630
                nih_free (job);
 
4631
        }
 
4632
        TEST_FEATURE ("with USER_PROCESS utmp entry");
 
4633
        TEST_ALLOC_FAIL {
 
4634
                TEST_ALLOC_SAFE {
 
4635
                        job = job_new (class, "");
 
4636
 
 
4637
                        blocked = blocked_new (job, BLOCKED_EVENT, event);
 
4638
                        event_block (event);
 
4639
                        nih_list_add (&job->blocking, &blocked->entry);
 
4640
                }
 
4641
 
 
4642
                job->goal = JOB_START;
 
4643
                job->state = JOB_RUNNING;
 
4644
                job->pid[PROCESS_MAIN] = 1;
 
4645
 
 
4646
                TEST_FREE_TAG (blocked);
 
4647
 
 
4648
                job->blocker = NULL;
 
4649
                event->failed = FALSE;
 
4650
 
 
4651
                job->failed = FALSE;
 
4652
                job->failed_process = -1;
 
4653
                job->exit_status = 0;
 
4654
 
 
4655
                output = fopen (utmpname, "w");
 
4656
                fclose (output);
 
4657
 
 
4658
                /* set utmp file */
 
4659
                utmpxname(utmpname);
 
4660
 
 
4661
                /* set up utmp entries */
 
4662
                memset (&utmp, 0, sizeof utmp);
 
4663
 
 
4664
                strcpy(utmp.ut_id, "2");
 
4665
                utmp.ut_type = USER_PROCESS;
 
4666
                utmp.ut_pid = 2;
 
4667
 
 
4668
                gettimeofday(&tv, NULL);
 
4669
                utmp.ut_tv.tv_sec = tv.tv_sec;
 
4670
                utmp.ut_tv.tv_usec = tv.tv_usec;
 
4671
 
 
4672
                setutxent();
 
4673
                pututxline(&utmp);
 
4674
 
 
4675
                strcpy(utmp.ut_id, "1");
 
4676
                utmp.ut_pid = 1;
 
4677
                pututxline(&utmp);
 
4678
 
 
4679
                endutxent();
 
4680
 
 
4681
                job_process_handler (NULL, 1, NIH_CHILD_EXITED, 0);
 
4682
 
 
4683
                setutxent();
 
4684
 
 
4685
                utmptr = getutxent();
 
4686
                TEST_NE_P(utmptr, NULL);
 
4687
                TEST_EQ(utmptr->ut_pid, 2);
 
4688
                TEST_EQ(utmptr->ut_type, USER_PROCESS);
 
4689
 
 
4690
                utmptr = getutxent();
 
4691
                TEST_NE_P(utmptr, NULL);
 
4692
                TEST_EQ(utmptr->ut_pid, 1);
 
4693
                TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
 
4694
 
 
4695
                nih_free (job);
 
4696
        }
 
4697
 
 
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");
 
4701
        TEST_ALLOC_FAIL {
 
4702
                TEST_ALLOC_SAFE {
 
4703
                        job = job_new (class, "");
 
4704
 
 
4705
                        blocked = blocked_new (job, BLOCKED_EVENT, event);
 
4706
                        event_block (event);
 
4707
                        nih_list_add (&job->blocking, &blocked->entry);
 
4708
                }
 
4709
 
 
4710
                job->goal = JOB_START;
 
4711
                job->state = JOB_RUNNING;
 
4712
                job->pid[PROCESS_MAIN] = 2;
 
4713
 
 
4714
                TEST_FREE_TAG (blocked);
 
4715
 
 
4716
                job->blocker = NULL;
 
4717
                event->failed = FALSE;
 
4718
 
 
4719
                job->failed = FALSE;
 
4720
                job->failed_process = -1;
 
4721
                job->exit_status = 0;
 
4722
 
 
4723
                output = fopen (utmpname, "w");
 
4724
                fclose (output);
 
4725
 
 
4726
                /* set utmp file */
 
4727
                utmpxname(utmpname);
 
4728
 
 
4729
                /* set up utmp entries */
 
4730
                memset (&utmp, 0, sizeof utmp);
 
4731
 
 
4732
                strcpy(utmp.ut_id, "2");
 
4733
                utmp.ut_type = DEAD_PROCESS;
 
4734
                utmp.ut_pid = 1;
 
4735
 
 
4736
                gettimeofday(&tv, NULL);
 
4737
                utmp.ut_time = 0;
 
4738
 
 
4739
                setutxent();
 
4740
                pututxline(&utmp);
 
4741
 
 
4742
                strcpy(utmp.ut_id, "2");
 
4743
                utmp.ut_type = USER_PROCESS;
 
4744
                utmp.ut_pid = 2;
 
4745
                utmp.ut_tv.tv_sec = tv.tv_sec;
 
4746
                utmp.ut_tv.tv_usec = tv.tv_usec;
 
4747
                pututxline(&utmp);
 
4748
 
 
4749
                endutxent();
 
4750
 
 
4751
                job_process_handler (NULL, 2, NIH_CHILD_EXITED, 0);
 
4752
 
 
4753
                setutxent();
 
4754
 
 
4755
                utmptr = getutxent();
 
4756
                TEST_NE_P(utmptr, NULL);
 
4757
                TEST_EQ(utmptr->ut_pid, 1);
 
4758
                TEST_EQ(utmptr->ut_type, DEAD_PROCESS);
 
4759
 
 
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);
 
4765
 
 
4766
                nih_free (job);
 
4767
        }
 
4768
        nih_free (session);
 
4769
}
 
4770
 
 
4771
 
4504
4772
int
4505
4773
main (int   argc,
4506
4774
      char *argv[])
4532
4800
        test_spawn ();
4533
4801
        test_kill ();
4534
4802
        test_handler ();
 
4803
        test_utmp ();
4535
4804
 
4536
4805
        test_find ();
4537
4806