~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/conf.c

Merge of lp:~jamesodhunt/upstart/upstream-override-support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include "parse_conf.h"
49
49
#include "conf.h"
50
50
#include "errors.h"
51
 
 
 
51
#include "paths.h"
52
52
 
53
53
/* Prototypes for static functions */
54
54
static int  conf_source_reload_file    (ConfSource *source)
70
70
                                        struct stat *statbuf)
71
71
        __attribute__ ((warn_unused_result));
72
72
 
73
 
static int  conf_reload_path           (ConfSource *source, const char *path)
74
 
        __attribute__ ((warn_unused_result));
75
 
 
 
73
static int  conf_reload_path           (ConfSource *source, const char *path,
 
74
                                        const char *override_path)
 
75
        __attribute__ ((warn_unused_result));
 
76
 
 
77
static inline int  is_conf_file        (const char *path)
 
78
        __attribute__ ((warn_unused_result));
 
79
 
 
80
static inline int is_conf_file_std     (const char *path)
 
81
        __attribute__ ((warn_unused_result));
 
82
 
 
83
static inline int is_conf_file_override(const char *path)
 
84
        __attribute__ ((warn_unused_result));
76
85
 
77
86
/**
78
87
 * conf_sources:
85
94
 
86
95
 
87
96
/**
 
97
 * is_conf_file_std:
 
98
 * @path: path to check.
 
99
 *
 
100
 * Determine if specified path contains a legitimate
 
101
 * configuration file name.
 
102
 *
 
103
 * Returns: TRUE if @path contains a valid configuration file name,
 
104
 * else FALSE.
 
105
 *
 
106
 **/
 
107
static inline int
 
108
is_conf_file_std (const char *path)
 
109
{
 
110
        char *ptr = strrchr (path, '.');
 
111
 
 
112
        if (ptr && IS_CONF_EXT_STD (ptr))
 
113
                return TRUE;
 
114
 
 
115
        return FALSE;
 
116
}
 
117
 
 
118
/**
 
119
 * is_conf_file_override:
 
120
 * @path: path to check.
 
121
 *
 
122
 * Determine if specified path contains a legitimate
 
123
 * override file name.
 
124
 *
 
125
 * Returns: TRUE if @path contains a valid override file name,
 
126
 * else FALSE.
 
127
 *
 
128
 **/
 
129
static inline int
 
130
is_conf_file_override (const char *path)
 
131
{
 
132
        char *ptr = strrchr (path, '.');
 
133
 
 
134
        if (ptr && IS_CONF_EXT_OVERRIDE (ptr))
 
135
                return TRUE;
 
136
 
 
137
        return FALSE;
 
138
}
 
139
 
 
140
/**
 
141
 * is_conf_file:
 
142
 * @path: path to check.
 
143
 *
 
144
 * Determine if specified path contains a legitimate
 
145
 * configuration file or override file name.
 
146
 *
 
147
 * Returns: TRUE if @path contains a valid configuration
 
148
 * file or override file name, else FALSE.
 
149
 *
 
150
 **/
 
151
static inline int
 
152
is_conf_file (const char *path)
 
153
{
 
154
        char *ptr = strrchr (path, '.');
 
155
 
 
156
        if (ptr && (ptr > path) && (ptr[-1] != '/') && IS_CONF_EXT (ptr))
 
157
                return TRUE;
 
158
 
 
159
        return FALSE;
 
160
}
 
161
 
 
162
/**
 
163
 * Convert a configuration file name to an override file name and vice
 
164
 * versa.
 
165
 *
 
166
 * For example, if @path is "foo.conf", this function will return
 
167
 * "foo.override", whereas if @path is "foo.override", it will return
 
168
 * "foo.conf".
 
169
 *
 
170
 * Note that this function should be static, but isn't to allow the
 
171
 * tests to access it.
 
172
 *
 
173
 * @parent: parent of returned path,
 
174
 * @path: path to a configuration file.
 
175
 *
 
176
 * Returns: newly allocated toggled path, or NULL on error.
 
177
 **/
 
178
char *
 
179
toggle_conf_name (const void     *parent,
 
180
                 const char     *path)
 
181
{
 
182
        char *new_path;
 
183
        char *ext;
 
184
        char *new_ext;
 
185
        size_t len;
 
186
 
 
187
        ext = strrchr (path, '.');
 
188
        if (!ext)
 
189
                return NULL;
 
190
 
 
191
        new_ext = IS_CONF_EXT_STD (ext)
 
192
                ? CONF_EXT_OVERRIDE
 
193
                : CONF_EXT_STD;
 
194
 
 
195
        len = strlen (new_ext);
 
196
 
 
197
        new_path = NIH_MUST (nih_strndup (parent, path, (ext - path) + len));
 
198
 
 
199
        memcpy (new_path + (ext - path), new_ext, len);
 
200
 
 
201
        return new_path;
 
202
}
 
203
 
 
204
 
 
205
/**
88
206
 * conf_init:
89
207
 *
90
208
 * Initialise the conf_sources list.
329
447
conf_source_reload_file (ConfSource *source)
330
448
{
331
449
        NihError *err = NULL;
 
450
        nih_local char *override_path = NULL;
 
451
 
 
452
        struct stat statbuf;
332
453
 
333
454
        nih_assert (source != NULL);
334
455
        nih_assert (source->type == CONF_FILE);
335
456
 
 
457
        /* this function should only be called for standard
 
458
         * configuration files.
 
459
         */
336
460
        if (! source->watch) {
337
461
                nih_local char *dpath = NULL;
338
462
                char           *dname;
361
485
        /* Parse the file itself.  If this fails, then we can discard the
362
486
         * inotify error, since this one will be better.
363
487
         */
364
 
        if (conf_reload_path (source, source->path) < 0) {
 
488
        if (conf_reload_path (source, source->path, NULL) < 0) {
365
489
                if (err)
366
490
                        nih_free (err);
367
491
 
382
506
                nih_free (err);
383
507
        }
384
508
 
 
509
        if (! is_conf_file_std (source->path))
 
510
                return 0;
 
511
 
 
512
        override_path = toggle_conf_name (NULL, source->path);
 
513
 
 
514
        if (stat (override_path, &statbuf) != 0)
 
515
                return 0;
 
516
 
 
517
        nih_debug ("Updating configuration for %s from %s",
 
518
                  source->path, override_path);
 
519
        if (conf_reload_path (source, source->path, override_path) < 0) {
 
520
                if (err)
 
521
                        nih_free (err);
 
522
 
 
523
                return -1;
 
524
        }
 
525
 
385
526
        return 0;
386
527
}
387
528
 
501
642
 * @is_dir: TRUE of @path is a directory.
502
643
 *
503
644
 * This is the file filter used for the jobs directory, we only care
504
 
 * about paths with the ".conf" extension.  Directories that
505
 
 * match the nih_file_ignore() function are also ignored.
506
 
 *
507
 
 * Returns: FALSE if @path ends in ".conf", or is the original source,
508
 
 * TRUE otherwise.
 
645
 * about paths with particular extensions (see IS_CONF_EXT).
 
646
 *
 
647
 * Directories that match the nih_file_ignore() function are also ignored.
 
648
 *
 
649
 * Returns: FALSE if @path ends in ".conf" or ".override",
 
650
 * or is the original source, TRUE otherwise.
509
651
 **/
510
652
static int
511
653
conf_dir_filter (ConfSource *source,
512
654
                 const char *path,
513
655
                 int         is_dir)
514
656
{
515
 
        char *ptr;
516
 
 
517
657
        nih_assert (source != NULL);
518
658
        nih_assert (path != NULL);
519
659
 
523
663
        if (is_dir)
524
664
                return nih_file_ignore (NULL, path);
525
665
 
526
 
        ptr = strrchr (path, '.');
527
 
        if (ptr && (ptr > path) && (ptr[-1] != '/') && (! strcmp (ptr, ".conf")))
 
666
        if (is_conf_file (path))
528
667
                return FALSE;
529
668
 
530
669
        return TRUE;
546
685
 * After checking that it was a regular file that was changed, we reload it;
547
686
 * we expect this to fail sometimes since the file may be only partially
548
687
 * written.
549
 
  **/
 
688
 **/
550
689
static void
551
690
conf_create_modify_handler (ConfSource  *source,
552
691
                            NihWatch    *watch,
553
692
                            const char  *path,
554
693
                            struct stat *statbuf)
555
694
{
 
695
        ConfFile *file = NULL;
 
696
        const char *error_path = path;
 
697
        nih_local char *new_path = NULL;
 
698
        int ret;
 
699
 
556
700
        nih_assert (source != NULL);
557
701
        nih_assert (watch != NULL);
558
702
        nih_assert (path != NULL);
559
703
        nih_assert (statbuf != NULL);
560
704
 
 
705
        /* note that symbolic links are ignored */
561
706
        if (! S_ISREG (statbuf->st_mode))
562
707
                return;
563
708
 
564
 
        if (conf_reload_path (source, path) < 0) {
 
709
        new_path = toggle_conf_name (NULL, path);
 
710
        file = (ConfFile *)nih_hash_lookup (source->files, new_path);
 
711
 
 
712
        if (is_conf_file_override (path)) {
 
713
                if (! file) {
 
714
                        /* override file has no corresponding conf file */
 
715
                        nih_debug ("Ignoring orphan override file %s", path);
 
716
                        return;
 
717
                }
 
718
 
 
719
                /* reload conf file */
 
720
                nih_debug ("Loading configuration file %s", new_path);
 
721
                ret = conf_reload_path (source, new_path, NULL);
 
722
                if (ret < 0) {
 
723
                        error_path = new_path;
 
724
                        goto error;
 
725
                }
 
726
 
 
727
                /* overlay override settings */
 
728
                nih_debug ("Loading override file %s for %s", path, new_path);
 
729
                ret = conf_reload_path (source, new_path, path);
 
730
                if (ret < 0) {
 
731
                        error_path = path;
 
732
                        goto error;
 
733
                }
 
734
        } else {
 
735
                nih_debug ("Loading configuration and override files for %s", path);
 
736
 
 
737
                /* load conf file */
 
738
                nih_debug ("Loading configuration file %s", path);
 
739
                ret = conf_reload_path (source, path, NULL);
 
740
                if (ret < 0) {
 
741
                        error_path = path;
 
742
                        goto error;
 
743
                }
 
744
 
 
745
                /* ensure we ignore directory changes (which won't have overrides. */
 
746
                if (is_conf_file_std (path)) {
 
747
                        struct stat st;
 
748
                        if (stat (new_path, &st) == 0) {
 
749
                                /* overlay override settings */
 
750
                                nih_debug ("Loading override file %s for %s", new_path, path);
 
751
                                ret = conf_reload_path (source, path, new_path);
 
752
                                if (ret < 0) {
 
753
                                        error_path = new_path;
 
754
                                        goto error;
 
755
                                }
 
756
                        }
 
757
 
 
758
                }
 
759
        }
 
760
 
 
761
        return;
 
762
 
 
763
error:
 
764
        {
565
765
                NihError *err;
566
766
 
567
767
                err = nih_error_get ();
568
 
                nih_error ("%s: %s: %s", path,
569
 
                           _("Error while loading configuration file"),
570
 
                           err->message);
 
768
                nih_error ("%s: %s: %s", error_path,
 
769
                                _("Error while loading configuration file"),
 
770
                                err->message);
571
771
                nih_free (err);
 
772
                if (file)
 
773
                        nih_unref (file, source);
572
774
        }
573
775
}
574
776
 
585
787
 *
586
788
 * We lookup the file in our hash table, and if we can find it, perform
587
789
 * the usual deletion of it.
588
 
  **/
 
790
 **/
589
791
static void
590
792
conf_delete_handler (ConfSource *source,
591
793
                     NihWatch   *watch,
592
794
                     const char *path)
593
795
{
594
796
        ConfFile *file;
 
797
        nih_local char *new_path = NULL;
595
798
 
596
799
        nih_assert (source != NULL);
597
800
        nih_assert (watch != NULL);
603
806
         * it's probably a directory or something, so just ignore it.
604
807
         */
605
808
        file = (ConfFile *)nih_hash_lookup (source->files, path);
606
 
        if (! file) {
 
809
        /* Note we have to be careful to consider deletion of directories too.
 
810
         * This is handled implicitly by the override check which will return
 
811
         * false if passed a directory in this case.
 
812
         */
 
813
        if (! file && ! is_conf_file_override (path)) {
607
814
                if (! strcmp (watch->path, path)) {
608
815
                        nih_warn ("%s: %s", source->path,
609
816
                                  _("Configuration directory deleted"));
614
821
                return;
615
822
        }
616
823
 
617
 
        nih_unref (file, source);
 
824
        /* non-override files (and directories) are the simple case, so handle
 
825
         * them and leave.
 
826
         */ 
 
827
        if (! is_conf_file_override (path)) {
 
828
                nih_unref (file, source);
 
829
                return;
 
830
        }
 
831
 
 
832
        /* if an override file is deleted for which there is a corresponding
 
833
         * conf file, reload the conf file to remove any modifications
 
834
         * introduced by the override file.
 
835
         */
 
836
        new_path = toggle_conf_name (NULL, path);
 
837
        file = (ConfFile *)nih_hash_lookup (source->files, new_path);
 
838
 
 
839
        if (file) {
 
840
                nih_debug ("Reloading configuration for %s on deletion of overide (%s)",
 
841
                                new_path, path);
 
842
 
 
843
                if ( conf_reload_path (source, new_path, NULL) < 0 ) {
 
844
                        nih_warn ("%s: %s", new_path,
 
845
                                        _("Unable to reload configuration after override deletion"));
 
846
                }
 
847
        }
618
848
}
619
849
 
620
850
/**
637
867
                   const char  *path,
638
868
                   struct stat *statbuf)
639
869
{
 
870
        ConfFile *file = NULL;
 
871
        nih_local char *new_path = NULL;
 
872
 
640
873
        nih_assert (source != NULL);
641
874
        nih_assert (dirname != NULL);
642
875
        nih_assert (path != NULL);
643
876
        nih_assert (statbuf != NULL);
644
877
 
 
878
        /* We assume that CONF_EXT_STD files are visited before
 
879
         * CONF_EXT_OVERRIDE files. Happily, this assumption is currently
 
880
         * valid since CONF_EXT_STD comes before CONF_EXT_OVERRIDE if ordered
 
881
         * alphabetically.
 
882
         *
 
883
         * If this were ever to change (for example if we decided to
 
884
         * rename the CONF_EXT_OVERRIDE files to end in ".abc", say), the logic
 
885
         * in this function would be erroneous since it would never be possible when
 
886
         * visiting an override file (before a conf file) to lookup a conf file
 
887
         * in the hash, since the conf file would not yet have been seen and thus would
 
888
         * not exist in the hash (yet).
 
889
         */
 
890
        nih_assert (CONF_EXT_STD[1] < CONF_EXT_OVERRIDE[1]);
 
891
 
645
892
        if (! S_ISREG (statbuf->st_mode))
646
893
                return 0;
647
894
 
648
 
        if (conf_reload_path (source, path) < 0) {
649
 
                NihError *err;
650
 
 
651
 
                err = nih_error_get ();
652
 
                nih_error ("%s: %s: %s", path,
653
 
                           _("Error while loading configuration file"),
654
 
                           err->message);
655
 
                nih_free (err);
 
895
        if (is_conf_file_std (path)) {
 
896
                if (conf_reload_path (source, path, NULL) < 0) {
 
897
                        NihError *err;
 
898
 
 
899
                        err = nih_error_get ();
 
900
                        nih_error ("%s: %s: %s", path,
 
901
                                        _("Error while loading configuration file"),
 
902
                                        err->message);
 
903
                        nih_free (err);
 
904
                }
 
905
                return 0;
 
906
        }
 
907
 
 
908
        new_path = toggle_conf_name (NULL, path);
 
909
        file = (ConfFile *)nih_hash_lookup (source->files, new_path);
 
910
 
 
911
        if (file) {
 
912
                /* we're visiting an override file with an associated conf file that
 
913
                 * has already been loaded, so just overlay the override file. If
 
914
                 * there is no corresponding conf file, we ignore the override file.
 
915
                 */
 
916
                if (conf_reload_path (source, new_path, path) < 0) {
 
917
                        NihError *err;
 
918
 
 
919
                        err = nih_error_get ();
 
920
                        nih_error ("%s: %s: %s", new_path,
 
921
                                        _("Error while reloading configuration file"),
 
922
                                        err->message);
 
923
                        nih_free (err);
 
924
                }
656
925
        }
657
926
 
658
927
        return 0;
662
931
/**
663
932
 * conf_reload_path:
664
933
 * @source: configuration source,
665
 
 * @path: path of file to be reloaded.
 
934
 * @path: path of conf file to be reloaded.
 
935
 * @override_path: if not NULL and @path refers to a path associated with @source,
 
936
 * overlay the contents of @path into the existing @source entry for
 
937
 * @path. If FALSE, discard any existing knowledge of @path.
666
938
 *
667
 
 * This function is used to parse the file at @path in the context of the
668
 
 * given configuration @source.  Necessary ConfFile structures are allocated
669
 
 * and attached to @source as appropriate.  CONF_FILE sources always have
670
 
 * a single ConfFile when the file exists.
 
939
 * This function is used to parse the file at @path (or @override_path) in the
 
940
 * context of the given configuration @source.  Necessary ConfFile structures
 
941
 * are allocated and attached to @source as appropriate.  CONF_FILE sources
 
942
 * always have a single ConfFile when the file exists.
671
943
 *
672
944
 * If the file has been parsed before, then the existing item is deleted and
673
945
 * freed if the file fails to load, or after the new item has been parsed.
674
 
 * Items are not reused between reloads.
 
946
 * Items are only reused between reloads if @override_path is
 
947
 * non-NULL.
675
948
 *
676
949
 * Physical errors are returned, parse errors are not.
677
950
 *
679
952
 **/
680
953
static int
681
954
conf_reload_path (ConfSource *source,
682
 
                  const char *path)
 
955
          const char *path,
 
956
          const char *override_path)
683
957
{
684
 
        ConfFile       *file;
 
958
        ConfFile       *file = NULL;
685
959
        nih_local char *buf = NULL;
686
960
        const char     *start, *end;
687
961
        nih_local char *name = NULL;
688
962
        size_t          len, pos, lineno;
689
963
        NihError       *err = NULL;
 
964
        const char     *path_to_load;
690
965
 
691
966
        nih_assert (source != NULL);
692
967
        nih_assert (path != NULL);
693
968
 
694
 
        /* Look up the old file in memory, and then free it.  In cases
695
 
         * of failure, we discard it anyway, so there's no particular reason
 
969
        path_to_load = (override_path ? override_path : path);
 
970
 
 
971
        /* If there is no corresponding override file, look up the old
 
972
         * conf file in memory, and then free it.  In cases of failure,
 
973
         * we discard it anyway, so there's no particular reason
696
974
         * to keep it around anymore.
 
975
         *
 
976
         * Note: if @override_path has been specified, do not
 
977
         * free the file if found, since we want to _update_ the
 
978
         * existing entry.
697
979
         */
698
980
        file = (ConfFile *)nih_hash_lookup (source->files, path);
699
 
        if (file)
 
981
        if (! override_path && file)
700
982
                nih_unref (file, source);
701
983
 
702
984
        /* Read the file into memory for parsing, if this fails we don't
703
985
         * bother creating a new ConfFile structure for it and bail out
704
986
         * now.
705
987
         */
706
 
        buf = nih_file_read (NULL, path, &len);
 
988
        buf = nih_file_read (NULL, path_to_load, &len);
707
989
        if (! buf)
708
990
                return -1;
709
991
 
710
 
        /* Parse the file, storing the item in a new ConfFile structure. */
711
 
        file = NIH_MUST (conf_file_new (source, path));
 
992
        /* Create a new ConfFile structure (if no @override_path specified) */
 
993
        file = (ConfFile *)nih_hash_lookup (source->files, path);
 
994
        if (! file)
 
995
                file = NIH_MUST (conf_file_new (source, path));
712
996
 
713
997
        pos = 0;
714
998
        lineno = 1;
717
1001
        case CONF_FILE:
718
1002
        case CONF_DIR:
719
1003
                /* Simple file of options; usually no item attached to it. */
720
 
                nih_debug ("Loading configuration from %s", path);
 
1004
                if (override_path) {
 
1005
                        nih_debug ("Updating configuration for %s from %s",
 
1006
                                        path, override_path);
 
1007
                } else {
 
1008
                        nih_debug ("Loading configuration from %s %s",
 
1009
                                        (source->type == CONF_DIR ? "directory" : "file"), path);
 
1010
                }
 
1011
 
721
1012
                if (parse_conf (file, buf, len, &pos, &lineno) < 0)
722
1013
                        err = nih_error_get ();
723
1014
 
735
1026
                        start++;
736
1027
 
737
1028
                end = strrchr (start, '.');
738
 
                if (end && (! strcmp (end, ".conf"))) {
 
1029
                if (end && IS_CONF_EXT (end)) {
739
1030
                        name = NIH_MUST (nih_strndup (NULL, start, end - start));
740
1031
                } else {
741
1032
                        name = NIH_MUST (nih_strdup (NULL, start));
744
1035
                /* Create a new job item and parse the buffer to produce
745
1036
                 * the job definition.
746
1037
                 */
747
 
                nih_debug ("Loading %s from %s", name, path);
748
 
                file->job = parse_job (NULL, source->session,
749
 
                                       name, buf, len, &pos, &lineno);
 
1038
                if (override_path) {
 
1039
                        nih_debug ("Updating %s (%s) with %s",
 
1040
                                        name, path, override_path);
 
1041
                } else {
 
1042
                        nih_debug ("Loading %s from %s", name, path);
 
1043
                }
 
1044
 
 
1045
                file->job = parse_job (NULL, source->session, file->job,
 
1046
                                name, buf, len, &pos, &lineno);
 
1047
 
750
1048
                if (file->job) {
751
1049
                        job_class_consider (file->job);
752
1050
                } else {
780
1078
                case PARSE_EXPECTED_OPERATOR:
781
1079
                case PARSE_EXPECTED_VARIABLE:
782
1080
                case PARSE_MISMATCHED_PARENS:
783
 
                        nih_error ("%s:%zi: %s", path, lineno, err->message);
 
1081
                        nih_error ("%s:%zi: %s", path_to_load, lineno, err->message);
784
1082
                        nih_free (err);
785
1083
                        err = NULL;
786
1084
                        break;
887
1185
 
888
1186
        return NULL;
889
1187
}
 
1188
 
 
1189
#ifdef DEBUG
 
1190
 
 
1191
size_t
 
1192
debug_count_list_entries (const NihList *list)
 
1193
{
 
1194
        size_t i = 0;
 
1195
        NIH_LIST_FOREACH (list, iter) {
 
1196
                i++;
 
1197
        }
 
1198
        return i;
 
1199
}
 
1200
 
 
1201
size_t
 
1202
debug_count_hash_entries (const NihHash *hash)
 
1203
{
 
1204
        size_t i = 0;
 
1205
        NIH_HASH_FOREACH_SAFE (hash, iter) {
 
1206
                i++;
 
1207
        }
 
1208
        return i;
 
1209
}
 
1210
 
 
1211
void
 
1212
debug_show_job_class (const JobClass *job)
 
1213
{
 
1214
        int i;
 
1215
        char **env    = (char **)job->env;
 
1216
        char **export = (char **)job->export;
 
1217
 
 
1218
        nih_assert (job);
 
1219
 
 
1220
        nih_debug ("JobClass %p: name='%s', path='%s', task=%d, "
 
1221
                        "respawn=%d, console=%x, deleted=%d, debug=%d",
 
1222
                        job, job->name, job->path, job->task,
 
1223
                        job->respawn, job->console, job->deleted, job->debug);
 
1224
 
 
1225
        nih_debug ("\tstart_on=%p, stop_on=%p, emits=%p, process=%p",
 
1226
                        job->start_on, job->stop_on, job->emits, job->process);
 
1227
 
 
1228
        nih_debug ("\tauthor='%s', description='%s'",
 
1229
                        job->author, job->description);
 
1230
 
 
1231
        if (env && *env) {
 
1232
                nih_debug ("\tenv:");
 
1233
                i = 0;
 
1234
                while ( *env ) {
 
1235
                        nih_debug ("\t\tenv[%d]='%s' (len=%u+1)",
 
1236
                                        i, *env, strlen (*env));
 
1237
                        env++;
 
1238
                        ++i;
 
1239
                }
 
1240
        } else {
 
1241
                nih_debug ("\tenv: none.");
 
1242
        }
 
1243
 
 
1244
 
 
1245
        if (export && *export) {
 
1246
                nih_debug ("\texport:");
 
1247
                i = 0;
 
1248
                while ( *export ) {
 
1249
                        nih_debug ("\t\tenv[%d]='%s' (len=%u+1)",
 
1250
                                        i, *export, strlen (*export));
 
1251
                        export++;
 
1252
                        ++i;
 
1253
                }
 
1254
        }
 
1255
        else {
 
1256
                nih_debug ("\texport: none");
 
1257
        }
 
1258
}
 
1259
 
 
1260
void
 
1261
debug_show_job_classes (void)
 
1262
{
 
1263
        nih_debug ("job_classes:");
 
1264
 
 
1265
        NIH_HASH_FOREACH_SAFE (job_classes, iter) {
 
1266
                JobClass *job = (JobClass *)iter;
 
1267
                debug_show_job_class (job);
 
1268
        }
 
1269
}
 
1270
 
 
1271
void
 
1272
debug_show_event (const Event *event)
 
1273
{
 
1274
        nih_assert (event);
 
1275
 
 
1276
        nih_debug ("Event %p: name='%s', progress=%x, failed=%d, "
 
1277
                        "blockers=%d, blocking=%p",
 
1278
                        event, event->name, event->progress, event->failed,
 
1279
                        event->blockers, (void *)&event->blocking);
 
1280
}
 
1281
 
 
1282
void
 
1283
debug_show_conf_file (const ConfFile *file)
 
1284
{
 
1285
        nih_assert (file);
 
1286
 
 
1287
        nih_debug ("ConfFile %p: path='%s', source=%p, flag=%x, job=%p",
 
1288
                        file, file->path, file->source, file->flag, file->job);
 
1289
 
 
1290
        /* Some ConfFile objects won't have any JobClass details, for example,
 
1291
         * the ConfFile object associated with "/etc/init.conf".
 
1292
         */
 
1293
        if (! file->job) {
 
1294
                nih_debug ("ConfFile %p: job: no JobClass object.", file);
 
1295
                return;
 
1296
        }
 
1297
 
 
1298
        nih_debug ("ConfFile %p: job:", file);
 
1299
        debug_show_job_class (file->job);
 
1300
}
 
1301
 
 
1302
void
 
1303
debug_show_conf_source (const ConfSource *source)
 
1304
{
 
1305
        nih_assert (source);
 
1306
 
 
1307
        nih_debug ("ConfSource %p: path='%s', type=%x, flag=%x",
 
1308
                        source, source->path, source->type, source->flag);
 
1309
 
 
1310
        nih_debug ("ConfSource %p files (%d):", source,
 
1311
                        debug_count_hash_entries (source->files));
 
1312
 
 
1313
        NIH_HASH_FOREACH (source->files, file_iter) {
 
1314
                ConfFile *file = (ConfFile *)file_iter;
 
1315
                debug_show_conf_file (file);
 
1316
        }
 
1317
}
 
1318
 
 
1319
void
 
1320
debug_show_conf_sources (void)
 
1321
{
 
1322
        nih_assert (conf_sources);
 
1323
 
 
1324
        nih_debug ("conf_sources:");
 
1325
 
 
1326
        NIH_LIST_FOREACH (conf_sources, iter) {
 
1327
                ConfSource *source = (ConfSource *)iter;
 
1328
                debug_show_conf_source (source);
 
1329
        }
 
1330
}
 
1331
 
 
1332
#endif /* DEBUG */
 
1333