1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/* upstart
*
* parse_conf.c - general configuration parsing
*
* Copyright © 2009 Canonical Ltd.
* Author: Scott James Remnant <scott@netsplit.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <nih/macros.h>
#include <nih/alloc.h>
#include <nih/list.h>
#include <nih/config.h>
#include <nih/logging.h>
#include <nih/error.h>
#include "conf.h"
#include "parse_conf.h"
/**
* stanzas:
*
* This is the table of known configuration stanzas and the functions
* that handle parsing them.
**/
static NihConfigStanza stanzas[] = {
NIH_CONFIG_LAST
};
/**
* parse_conf:
* @conffile: configuration file being parsed,
* @file: file or string to parse,
* @len: length of @file,
* @pos: offset within @file,
* @lineno: line number.
*
* This function is used to parse a job definition from @file, taking the
* name from the stanza itself. A block is expected containing a sequence
* of stanzas is expected, defining the parameters of the job.
*
* The necessary configuration item is allocated and attached to the file
* automatically.
*
* Returns: zero on success, negative value on raised error.
**/
int
parse_conf (ConfFile *conffile,
const char *file,
size_t len,
size_t *pos,
size_t *lineno)
{
nih_assert (conffile != NULL);
nih_assert (file != NULL);
nih_assert (pos != NULL);
/* If we update 'stanzas' to allow content in init.conf, this
* function must be updated in a similar manner to parse_job()
* to handle overrides files.
*/
nih_assert (sizeof(stanzas) / sizeof(stanzas[0]) == 1);
if (nih_config_parse_file (file, len, pos, lineno,
stanzas, conffile) < 0)
return -1;
return 0;
}
|