MKMAP *mkmap_open(const char *type, const char *path, int open_flags, int dict_flags) { MKMAP *mkmap; const MKMAP_OPEN_INFO *mp; /* * Find out what map type to use. */ for (mp = mkmap_types; /* void */ ; mp++) { if (mp->type == 0) msg_fatal("unsupported map type: %s", type); if (strcmp(type, mp->type) == 0) break; } if (msg_verbose) msg_info("open %s %s", type, path); /* * Do whatever before-open initialization is needed, such as acquiring a * global exclusive lock on an existing database file. Individual Postfix * dict modules implement locking only for individual record operations, * because most Postfix applications don't need global exclusive locks. */ mkmap = mp->before_open(path); /* * Delay signal delivery, so that we won't leave the database in an * inconsistent state if we can avoid it. */ sigdelay(); /* * Truncate the database upon open, and update it. Read-write mode is * needed because the underlying routines read as well as write. */ mkmap->dict = mkmap->open(path, open_flags, dict_flags); mkmap->dict->lock_fd = -1; /* XXX just in case */ mkmap->dict->stat_fd = -1; /* XXX just in case */ mkmap->dict->flags |= DICT_FLAG_DUP_WARN; /* * Do whatever post-open initialization is needed, such as acquiring a * global exclusive lock on a database file that did not exist. * Individual Postfix dict modules implement locking only for individual * record operations, because most Postfix applications don't need global * exclusive locks. */ if (mkmap->after_open) mkmap->after_open(mkmap); return (mkmap); }
MKMAP *mkmap_open(const char *type, const char *path, int open_flags, int dict_flags) { MKMAP *mkmap; const MKMAP_OPEN_INFO *mp; /* * Find out what map type to use. */ for (mp = mkmap_types; /* void */ ; mp++) { if (mp->type == 0) msg_fatal("unsupported map type for this operation: %s", type); if (strcmp(type, mp->type) == 0) break; } if (msg_verbose) msg_info("open %s %s", type, path); /* * Do whatever before-open initialization is needed, such as acquiring a * global exclusive lock on an existing database file. Individual Postfix * dict modules implement locking only for individual record operations, * because most Postfix applications don't need global exclusive locks. */ mkmap = mp->before_open(path); /* * Delay signal delivery, so that we won't leave the database in an * inconsistent state if we can avoid it. */ sigdelay(); /* * Truncate the database upon open, and update it. Read-write mode is * needed because the underlying routines read as well as write. We * explicitly clobber lock_fd to trigger a fatal error when a map wants * to unlock the database after individual transactions: that would * result in race condition problems. We clobbber stat_fd as well, * because that, too, is used only for individual-transaction clients. */ mkmap->dict = mkmap->open(path, open_flags, dict_flags); mkmap->dict->lock_fd = -1; /* XXX just in case */ mkmap->dict->stat_fd = -1; /* XXX just in case */ mkmap->dict->flags |= DICT_FLAG_DUP_WARN; mkmap->multi_writer = (mkmap->dict->flags & DICT_FLAG_MULTI_WRITER); /* * Do whatever post-open initialization is needed, such as acquiring a * global exclusive lock on a database file that did not exist. * Individual Postfix dict modules implement locking only for individual * record operations, because most Postfix applications don't need global * exclusive locks. */ if (mkmap->after_open) mkmap->after_open(mkmap); /* * Resume signal delivery if multi-writer safe. */ if (mkmap->multi_writer) sigresume(); return (mkmap); }