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

« back to all changes in this revision

Viewing changes to init/conf.c

  • Committer: Scott James Remnant
  • Date: 2007-06-10 15:49:13 UTC
  • Revision ID: scott@netsplit.com-20070610154913-uymy8eiihn2trg0l
* init/conf.c (conf_reload_path): It turns out that the flag trick
doesn't work for items since we often reparse them within the same
file tag (it works with files because they're atomic and reparsed).
Store the old items in a different list instead.
(conf_source_free): We need to be careful about freeing sources,
so have a function to do it properly.
(conf_item_new): Since the flag member isn't useful, don't bother
setting it.
* init/conf.h: Add conf_source_free prototype.
(ConfFile): Remove flag member.
* init/tests/test_conf.c (test_source_reload): Add test for inotify
create detection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
 * current configuration.  Normally you would set up all of the sources and
114
114
 * then call conf_reload() which will load them all.
115
115
 *
 
116
 * Since a source has attached files, items and inotify watches, you should
 
117
 * use conf_source_free() to free it and not attempt to free it directly.
 
118
 *
116
119
 * If @parent is not NULL, it should be a pointer to another allocated
117
120
 * block which will be used as the parent for this block.  When @parent
118
121
 * is freed, the returned block will be freed too.  If you have clean-up
237
240
        nih_list_init (&item->entry);
238
241
 
239
242
        item->type = type;
240
 
        item->flag = file->flag;
241
243
        item->data = NULL;
242
244
 
243
245
        nih_list_add (&file->items, &item->entry);
646
648
                  const char *path)
647
649
{
648
650
        ConfFile   *file;
 
651
        NihList     old_items;
649
652
        ConfItem   *item;
650
653
        const char *buf, *name;
651
654
        size_t      len, pos, lineno;
661
664
        if (! buf)
662
665
                return -1;
663
666
 
 
667
        /* If we've parsed this file before, we'll have a list of old items
 
668
         * that once existed and need to be cleaned up once we've parsed
 
669
         * the new items.  The easiest way to identify them is to put
 
670
         * them into a different list for safe-keeping.
 
671
         */
 
672
        nih_list_init (&old_items);
 
673
        nih_list_add (&old_items, file->items.next);
 
674
        nih_list_remove (&file->items);
 
675
 
664
676
        /* Parse the file buffer, registering items found against the
665
677
         * ConfFile; the existing items are removed later.
666
678
         */
730
742
                }
731
743
        }
732
744
 
733
 
        /* Delete the old items from the file, these are easy to detect
734
 
         * as only the new items will have the right flag.
 
745
        /* Delete the old items now we've parsed in the list of new ones.
735
746
         */
736
 
        NIH_LIST_FOREACH_SAFE (&file->items, item_iter) {
737
 
                ConfItem *item = (ConfItem *)item_iter;
 
747
        NIH_LIST_FOREACH_SAFE (&old_items, iter) {
 
748
                ConfItem *item = (ConfItem *)iter;
738
749
 
739
 
                if (item->flag != file->flag)
740
 
                        conf_item_free (item);
 
750
                conf_item_free (item);
741
751
        }
742
752
 
743
753
        /* Unmap the file again; in theory this shouldn't fail, but if
760
770
 
761
771
 
762
772
/**
 
773
 * conf_source_free:
 
774
 * @source: configuration source to be freed.
 
775
 *
 
776
 * Frees the watch held by @source, all files parsed by source and the items
 
777
 * helped by them, and then frees the source itself.
 
778
 *
 
779
 * Returns: return value from destructor, or 0.
 
780
 **/
 
781
int
 
782
conf_source_free (ConfSource *source)
 
783
{
 
784
        nih_assert (source != NULL);
 
785
 
 
786
        NIH_HASH_FOREACH_SAFE (source->files, iter) {
 
787
                ConfFile *file = (ConfFile *)iter;
 
788
 
 
789
                conf_file_free (file);
 
790
        }
 
791
 
 
792
        if (source->watch)
 
793
                nih_watch_free (source->watch);
 
794
 
 
795
        return nih_list_free (&source->entry);
 
796
}
 
797
 
 
798
/**
763
799
 * conf_file_free:
764
800
 * @file: configuration file to be deleted and freed.
765
801
 *