dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / svc / svccfg / svccfg.h
blob7c1121fb80dd91e97cfbd98c17c21dbcd8dcfa1f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
27 #ifndef _CMD_SVCCFG_H
28 #define _CMD_SVCCFG_H
31 #include <sys/types.h>
33 #include <libxml/tree.h>
35 #include <libscf.h>
36 #include <libscf_priv.h>
37 #include <libtecla.h>
38 #include <libuutil.h>
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /* Command scope bits for command tab completion */
45 #define CS_SCOPE 0x01
46 #define CS_SVC 0x02
47 #define CS_INST 0x04
48 #define CS_SNAP 0x08
49 #define CS_GLOBAL 0x0f
51 /* Flags for lscf_bundle_import() & co. */
52 #define SCI_NOREFRESH 0x01 /* Don't refresh instances */
53 #define SCI_GENERALLAST 0x04 /* Add general property group last */
54 #define SCI_NOENABLED 0x08 /* Don't import general/enabled. */
55 #define SCI_FRESH 0x10 /* Freshly imported service */
56 #define SCI_FORCE 0x20 /* Override-import. */
57 #define SCI_KEEP 0x40 /* Don't delete when SCI_FORCEing */
58 #define SCI_NOSNAP 0x80 /* Don't take last-import snapshot */
59 #define SCI_DELAYENABLE 0x100 /* Delay the general/enable property */
61 #define SCI_OP_IMPORT 0x1000
62 #define SCI_OP_APPLY 0x2000
63 #define SCI_OP_RESTORE 0x4000
65 #define HASH_SVC "smf/manifest"
68 * If the filesystem/minimal service is not online, do not consider
69 * manifests in the /var file system.
71 #define IGNORE_VAR (!est->sc_fs_minimal)
73 /* Flags for lscf_service_export() */
74 #define SCE_ALL_VALUES 0x01 /* Include all property values */
77 extern int lex_lineno;
79 #define MANIFEST_DTD_PATH "/usr/share/lib/xml/dtd/service_bundle.dtd.1"
81 * The following list must be kept in the same order as that of
82 * lxml_prop_types[]
84 typedef enum element {
85 SC_ASTRING = 0,
86 SC_BOOLEAN,
87 SC_CARDINALITY,
88 SC_CHOICES,
89 SC_COMMON_NAME,
90 SC_CONSTRAINTS,
91 SC_COUNT,
92 SC_INSTANCE_CREATE_DEFAULT,
93 SC_DEPENDENCY,
94 SC_DEPENDENT,
95 SC_DESCRIPTION,
96 SC_DOC_LINK,
97 SC_DOCUMENTATION,
98 SC_ENABLED,
99 SC_EVENT,
100 SC_EXEC_METHOD,
101 SC_FMRI,
102 SC_HOST,
103 SC_HOSTNAME,
104 SC_INCLUDE_VALUES,
105 SC_INSTANCE,
106 SC_INTEGER,
107 SC_INTERNAL_SEPARATORS,
108 SC_LOCTEXT,
109 SC_MANPAGE,
110 SC_METHOD_CONTEXT,
111 SC_METHOD_CREDENTIAL,
112 SC_METHOD_PROFILE,
113 SC_METHOD_ENVIRONMENT,
114 SC_METHOD_ENVVAR,
115 SC_NET_ADDR,
116 SC_NET_ADDR_V4,
117 SC_NET_ADDR_V6,
118 SC_NOTIFICATION_PARAMETERS,
119 SC_OPAQUE,
120 SC_PARAMETER,
121 SC_PARAMVAL,
122 SC_PG_PATTERN,
123 SC_PROP_PATTERN,
124 SC_PROPERTY,
125 SC_PROPERTY_GROUP,
126 SC_PROPVAL,
127 SC_RANGE,
128 SC_RESTARTER,
129 SC_SERVICE,
130 SC_SERVICE_BUNDLE,
131 SC_SERVICE_FMRI,
132 SC_INSTANCE_SINGLE,
133 SC_STABILITY,
134 SC_TEMPLATE,
135 SC_TIME,
136 SC_TYPE,
137 SC_UNITS,
138 SC_URI,
139 SC_USTRING,
140 SC_VALUE,
141 SC_VALUE_NODE,
142 SC_VALUES,
143 SC_VISIBILITY,
144 SC_XI_FALLBACK,
145 SC_XI_INCLUDE
146 } element_t;
148 typedef enum bundle_type {
149 SVCCFG_UNKNOWN_BUNDLE, SVCCFG_MANIFEST, SVCCFG_PROFILE, SVCCFG_ARCHIVE
150 } bundle_type_t;
152 typedef struct bundle {
153 uu_list_t *sc_bundle_services;
155 xmlChar *sc_bundle_name;
156 bundle_type_t sc_bundle_type;
157 } bundle_t;
159 typedef enum service_type {
160 SVCCFG_UNKNOWN_SERVICE = 0x0, SVCCFG_SERVICE, SVCCFG_RESTARTER,
161 SVCCFG_MILESTONE
162 } service_type_t;
164 typedef enum entity_type {
165 SVCCFG_SERVICE_OBJECT = 0x0, SVCCFG_INSTANCE_OBJECT
166 } entity_type_t;
168 enum import_state {
169 IMPORT_NONE = 0,
170 IMPORT_PREVIOUS,
171 IMPORT_PROP_BEGUN,
172 IMPORT_PROP_DONE,
173 IMPORT_COMPLETE,
174 IMPORT_REFRESHED
177 typedef enum svccfg_op {
178 SVCCFG_OP_NONE = -1,
179 SVCCFG_OP_IMPORT = 0,
180 SVCCFG_OP_APPLY,
181 SVCCFG_OP_RESTORE
182 } svccfg_op_t;
185 * Return values for functions that validate an entity against the templates.
187 typedef enum tmpl_validate_status {
188 TVS_SUCCESS = 0,
190 * Either conversion of ASTRING property value to a number failed,
191 * or base 32 decoding of a property value failed.
193 TVS_BAD_CONVERSION,
194 /* Template is defective. */
195 TVS_BAD_TEMPLATE,
196 /* Template type spec is invalid. */
197 TVS_INVALID_TYPE_SPECIFICATION,
198 /* Property group is missing a type specification. */
199 TVS_MISSING_PG_TYPE,
200 /* Template with required == true is missing type specification. */
201 TVS_MISSING_TYPE_SPECIFICATION,
202 /* No match was found for specified item. */
203 TVS_NOMATCH,
204 /* Validation error occurred */
205 TVS_VALIDATION,
206 /* Validation error that should not inhibit import. */
207 TVS_WARN,
208 /* Could not validate because of fatal errors. */
209 TVS_FATAL = -1
210 } tmpl_validate_status_t;
213 * The composed_pg structure is used for templates validation. It is
214 * defined in svccfg_tmpl.c
216 typedef struct composed_pg composed_pg_t;
218 typedef struct entity {
219 uu_list_node_t sc_node;
220 entity_type_t sc_etype;
222 /* Common fields to all entities. */
223 const char *sc_name;
224 const char *sc_fmri;
225 uu_list_t *sc_pgroups;
226 uu_list_t *sc_dependents;
227 struct entity *sc_parent;
228 enum import_state sc_import_state;
229 boolean_t sc_miss_type;
230 int sc_seen;
231 svccfg_op_t sc_op;
233 union {
234 struct {
235 uu_list_t *sc_service_instances;
236 service_type_t sc_service_type;
237 uint_t sc_service_version;
238 /* Following used by template validation */
239 struct entity *sc_restarter;
240 struct entity *sc_global;
241 } sc_service;
242 struct {
243 uu_avl_t *sc_composed;
244 /* Following used by template validation */
245 struct entity *sc_instance_restarter;
246 } sc_instance;
247 } sc_u;
248 } entity_t;
251 * sc_pgroup_composed is only used for templates validation of properties.
252 * It is created in build_composed_property_groups() and destroyed in
253 * composed_pg_destroy(). It will only be set for property groups that are
254 * part of an instance -- not for service property groups.
256 typedef struct pgroup {
257 uu_list_node_t sc_node;
258 uu_list_t *sc_pgroup_props;
259 composed_pg_t *sc_pgroup_composed; /* Composed properties */
261 const char *sc_pgroup_name;
262 const char *sc_pgroup_type;
263 uint_t sc_pgroup_flags;
264 struct entity *sc_parent;
266 int sc_pgroup_delete;
267 int sc_pgroup_override;
268 const char *sc_pgroup_fmri; /* Used for dependents */
270 int sc_pgroup_seen;
271 } pgroup_t;
273 typedef struct property {
274 uu_list_node_t sc_node;
275 uu_avl_node_t sc_composed_node; /* Composed props linkage */
276 uu_list_t *sc_property_values;
278 char *sc_property_name;
279 scf_type_t sc_value_type;
281 int sc_property_override;
282 int sc_seen;
283 } property_t;
285 typedef struct value {
286 uu_list_node_t sc_node;
288 scf_type_t sc_type;
290 void (*sc_free)(struct value *);
292 union {
293 uint64_t sc_count;
294 int64_t sc_integer;
295 char *sc_string;
296 } sc_u;
297 } value_t;
299 typedef struct scf_callback {
300 scf_handle_t *sc_handle;
301 void *sc_parent; /* immediate parent: scope, service, */
302 /* instance, property group, property */
303 scf_transaction_t *sc_trans;
304 int sc_service; /* True if sc_parent is a service. */
305 uint_t sc_flags;
306 pgroup_t *sc_general; /* pointer to general property group */
307 property_t *sc_enable; /* pointer to enable property */
309 const char *sc_source_fmri;
310 const char *sc_target_fmri;
311 int sc_err;
312 } scf_callback_t;
315 * Collection of template validation errors.
317 typedef struct tmpl_errors tmpl_errors_t;
319 #define bad_error(func, err) \
320 uu_panic("%s:%d: %s() failed with unexpected " \
321 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err));
323 #define SC_CMD_LINE 0x0
324 #define SC_CMD_FILE 0x1
325 #define SC_CMD_EOF 0x2
326 #define SC_CMD_IACTIVE 0x4
327 #define SC_CMD_DONT_EXIT 0x8
329 typedef struct engine_state {
330 uint_t sc_cmd_flags;
331 FILE *sc_cmd_file;
332 uint_t sc_cmd_lineno;
333 const char *sc_cmd_filename;
334 char *sc_cmd_buf;
335 size_t sc_cmd_bufsz;
336 off_t sc_cmd_bufoff;
337 GetLine *sc_gl;
338 boolean_t sc_fs_minimal; /* SCF_INSTANCE_FS_MINIMAL is online. */
339 boolean_t sc_in_emi; /* During early import */
340 boolean_t sc_miss_type; /* Apply profile found missing types */
342 pid_t sc_repo_pid;
343 const char *sc_repo_filename;
344 const char *sc_repo_doordir;
345 const char *sc_repo_doorname;
346 const char *sc_repo_server;
347 } engine_state_t;
349 extern engine_state_t *est;
351 typedef struct string_list {
352 uu_list_node_t node;
353 char *str;
354 } string_list_t;
356 extern uu_list_pool_t *string_pool;
358 struct help_message {
359 int token;
360 const char *message;
363 extern struct help_message help_messages[];
365 extern scf_handle_t *g_hndl; /* global repcached connection handle */
366 extern int g_exitcode;
367 extern int g_verbose;
369 extern ssize_t max_scf_fmri_len;
370 extern ssize_t max_scf_name_len;
371 extern ssize_t max_scf_value_len;
372 extern ssize_t max_scf_pg_type_len;
374 /* Common strings */
375 extern const char * const name_attr;
376 extern const char * const type_attr;
377 extern const char * const value_attr;
378 extern const char * const enabled_attr;
379 extern const char * const active_attr;
380 extern const char * const scf_pg_general;
381 extern const char * const scf_group_framework;
382 extern const char * const true;
383 extern const char * const false;
385 #define uu_list_append(list, elem) uu_list_insert_before(list, NULL, elem)
386 #define uu_list_prepend(list, elem) uu_list_insert_after(list, NULL, elem)
388 void *safe_malloc(size_t);
389 char *safe_strdup(const char *);
390 void warn(const char *, ...);
391 void synerr(int);
392 void semerr(const char *, ...);
394 void internal_init(void);
395 void internal_dump(bundle_t *);
397 int value_cmp(const void *, const void *, void *);
399 bundle_t *internal_bundle_new(void);
400 void internal_bundle_free(bundle_t *);
401 entity_t *internal_service_new(const char *);
402 void internal_service_free(entity_t *);
403 entity_t *internal_instance_new(const char *);
404 void internal_instance_free(entity_t *);
405 entity_t *internal_template_new(void);
406 pgroup_t *internal_pgroup_new(void);
407 void internal_pgroup_free(pgroup_t *);
408 pgroup_t *internal_pgroup_find(entity_t *, const char *, const char *);
409 pgroup_t *internal_dependent_find(entity_t *, const char *);
410 pgroup_t *internal_pgroup_find_or_create(entity_t *, const char *,
411 const char *);
412 pgroup_t *internal_pgroup_create_strict(entity_t *, const char *,
413 const char *);
414 property_t *internal_property_new(void);
415 void internal_property_free(property_t *);
416 property_t *internal_property_find(pgroup_t *, const char *);
417 property_t *internal_property_create(const char *, scf_type_t, uint_t, ...);
418 value_t *internal_value_new(void);
420 int internal_attach_service(bundle_t *, entity_t *);
421 int internal_attach_entity(entity_t *, entity_t *);
422 int internal_attach_pgroup(entity_t *, pgroup_t *);
423 void internal_detach_pgroup(entity_t *, pgroup_t *);
424 int internal_attach_dependent(entity_t *, pgroup_t *);
425 int internal_attach_property(pgroup_t *, property_t *);
426 void internal_detach_property(pgroup_t *, property_t *);
427 void internal_attach_value(property_t *, value_t *);
429 int load_init(void);
430 void load_fini(void);
431 int load_instance(const char *, const char *, entity_t **);
432 int load_pg_attrs(const scf_propertygroup_t *, pgroup_t **);
433 int load_pg(const scf_propertygroup_t *, pgroup_t **, const char *,
434 const char *);
435 int prop_equal(property_t *, property_t *, const char *, const char *, int);
436 int pg_attrs_equal(const pgroup_t *, const pgroup_t *, const char *, int);
437 int pg_equal(pgroup_t *, pgroup_t *);
439 void lscf_cleanup(void);
440 void lscf_prep_hndl(void);
441 void lscf_init(void);
442 int lscf_bundle_import(bundle_t *, const char *, uint_t);
443 int lscf_bundle_apply(bundle_t *, const char *);
444 void lscf_delete(const char *, int);
445 void lscf_list(const char *);
446 void lscf_select(const char *);
447 void lscf_unselect();
448 void lscf_get_selection_str(char *, size_t);
449 void lscf_add(const char *);
450 void lscf_listpg(const char *);
451 void lscf_addpg(const char *, const char *, const char *);
452 void lscf_delpg(char *);
453 void lscf_delhash(char *, int);
454 void lscf_listprop(const char *);
455 void lscf_addprop(char *, const char *, const uu_list_t *);
456 void lscf_delprop(char *);
457 int lscf_describe(uu_list_t *, int);
458 void lscf_listsnap();
459 void lscf_selectsnap(const char *);
460 void lscf_revert(const char *);
461 void lscf_refresh();
462 char *filename_to_propname(const char *);
463 int lscf_retrieve_hash(const char *, unsigned char *);
464 int lscf_store_hash(const char *, unsigned char *);
465 int lscf_service_cleanup(void *, scf_walkinfo_t *);
466 int lscf_hash_cleanup();
467 void lscf_delnotify(const char *, int);
468 void lscf_listnotify(const char *, int);
469 int lscf_setnotify(uu_list_t *);
471 CPL_MATCH_FN(complete_select);
472 CPL_MATCH_FN(complete_command);
474 int lxml_init(void);
475 int lxml_get_bundle_file(bundle_t *, const char *, svccfg_op_t);
476 void lxml_store_value(value_t *, element_t, const xmlChar *);
478 void engine_init(void);
479 int engine_exec_cmd(void);
480 int engine_exec(char *);
481 int add_cmd_matches(WordCompletion *, const char *, int, uint32_t);
482 int engine_interp(void);
483 int engine_source(const char *, boolean_t);
484 int engine_import(uu_list_t *);
485 int engine_cleanup(int);
486 void help(int);
488 int engine_cmd_getc(engine_state_t *);
489 int engine_cmd_ungetc(engine_state_t *, char);
490 void engine_cmd_nputs(engine_state_t *, char *, size_t);
492 void tmpl_errors_destroy(tmpl_errors_t *);
493 void tmpl_errors_print(FILE *, tmpl_errors_t *, const char *);
494 void tmpl_init(void);
495 void tmpl_property_fini(property_t *);
496 void tmpl_property_init(property_t *);
497 tmpl_validate_status_t tmpl_validate_bundle(bundle_t *, tmpl_errors_t **);
499 #define FMA_TOKENS 0
500 #define MIXED_TOKENS -1
501 #define INVALID_TOKENS -2
503 char **tokenize(char *, const char *);
504 int32_t check_tokens(char **);
505 const char *de_tag(const char *);
506 const char *tset_to_string(int32_t);
508 #ifdef __cplusplus
510 #endif
512 #endif /* _CMD_SVCCFG_H */