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
89
90
91
92
93
94
95
96
97
98
|
/* 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.
**/
JobClass *
parse_conf (const void *parent,
Session *session,
JobClass *update,
const char *file,
size_t len,
size_t *pos,
size_t *lineno)
{
JobClass *class;
nih_assert (file != NULL);
nih_assert (pos != NULL);
if (update) {
class = update;
nih_debug ("Reusing template JobClass");
} else {
nih_debug ("Creating new template JobClass");
class = job_class_new (parent, "GLOBAL", NULL, session);
if (! class)
nih_return_system_error (NULL);
}
if (nih_config_parse_file (file, len, pos, lineno,
stanzas, class) < 0) {
if (!update)
nih_free (class);
return NULL;
}
return class;
}
|