/*- * Copyright (c) 2009, 2013 The FreeBSD Foundation * All rights reserved. * * This software was developed by Ed Schouten under sponsorship from the * FreeBSD Foundation. * * Portions of this software were developed by Oleksandr Rybalko * under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _VTSUBSYS_SELECT_H_ #define _VTSUBSYS_SELECT_H_ #include #include #include #include struct vtsubsys_data { char *name; char *envvar; char *envprivar; int priority; }; SET_DECLARE(vtsubsys_set, struct vtsubsys_data); static int is_vtsubsys_selected(char *name) { struct vtsubsys_data **data, *best, *me; int value, priority; /* If subsys $name is only one, return 0. */ if (SET_COUNT(vtsubsys_set) <= 1) return (1); best = me = NULL; SET_FOREACH(data, vtsubsys_set) { /* Skip items marked as root.enabled=0. */ if (getenv_int((*data)->envvar, &value) || value == 0) continue; /* Identify item with same name as passed. */ if (strcmp((*data)->name, name) == 0) me = *data; /* Check if this module is better. Allow override priority. */ if (best == NULL || ((getenv_int((*data)->envprivar, &priority)) ? priority : (*data)->priority) > best->priority) best = *data; } if (me != NULL && me == best) return (1); return (0); } #define VTSUBSYS_DECLARE(_name, _envvarroot, _priority) \ static struct vtsubsys_data _name ## _vtsubsys_data = { \ .name = #_name, \ .envvar = _envvarroot ".enabled", \ .envprivar = _envvarroot ".priority", \ .priority = (_priority), \ }; \ DATA_SET(vtsubsys_set, _name ## _vtsubsys_data) #endif /* _VTSUBSYS_SELECT_H_ */