diff options
author | Gavin Maltby <gavin.maltby@oracle.com> | 2010-07-30 17:04:17 +1000 |
---|---|---|
committer | Gavin Maltby <gavin.maltby@oracle.com> | 2010-07-30 17:04:17 +1000 |
commit | f6e214c7418f43af38bd8c3a557e3d0a1d311cfa (patch) | |
tree | 0f0e4cee5ead68ee30660107f9eccf7cd9e72c2e /usr/src/lib/libscf/common/midlevel.c | |
parent | 265a964d7aa43c47170d21d2f01bcf873d7fd79d (diff) | |
download | illumos-joyent-f6e214c7418f43af38bd8c3a557e3d0a1d311cfa.tar.gz |
PSARC/2009/617 Software Events Notification Parameters CLI
PSARC/2009/618 snmp-notify: SNMP Notification Daemon for Software Events
PSARC/2009/619 smtp-notify: Email Notification Daemon for Software Events
PSARC/2010/225 fmd for non-global Solaris zones
PSARC/2010/226 Solaris Instance UUID
PSARC/2010/227 nvlist_nvflag(3NVPAIR)
PSARC/2010/228 libfmevent additions
PSARC/2010/257 sysevent_evc_setpropnvl and sysevent_evc_getpropnvl
PSARC/2010/265 FMRI and FMA Event Stabilty, 'ireport' category 1 event class, and the 'sw' FMRI scheme
PSARC/2010/278 FMA/SMF integration: instance state transitions
PSARC/2010/279 Modelling panics within FMA
PSARC/2010/290 logadm.conf upgrade
6392476 fmdump needs to pretty-print
6393375 userland ereport/ireport event generation interfaces
6445732 Add email notification agent for FMA and software events
6804168 RFE: Allow an efficient means to monitor SMF services status changes
6866661 scf_values_destroy(3SCF) will segfault if is passed NULL
6884709 Add snmp notification agent for FMA and software events
6884712 Add private interface to tap into libfmd_msg macro expansion capabilities
6897919 fmd to run in a non-global zone
6897937 fmd use of non-private doors is not safe
6900081 add a UUID to Solaris kernel image for use in crashdump identification
6914884 model panic events as a defect diagnosis in FMA
6944862 fmd_case_open_uuid, fmd_case_uuisresolved, fmd_nvl_create_defect
6944866 log legacy sysevents in fmd
6944867 enumerate svc scheme in topo
6944868 software-diagnosis and software-response fmd modules
6944870 model SMF maintenance state as a defect diagnosis in FMA
6944876 savecore runs in foreground for systems with zfs root and dedicated dump
6965796 Implement notification parameters for SMF state transitions and FMA events
6968287 SUN-FM-MIB.mib needs to be updated to reflect Oracle information
6972331 logadm.conf upgrade PSARC/2010/290
Diffstat (limited to 'usr/src/lib/libscf/common/midlevel.c')
-rw-r--r-- | usr/src/lib/libscf/common/midlevel.c | 150 |
1 files changed, 121 insertions, 29 deletions
diff --git a/usr/src/lib/libscf/common/midlevel.c b/usr/src/lib/libscf/common/midlevel.c index c466391761..71b72404f1 100644 --- a/usr/src/lib/libscf/common/midlevel.c +++ b/usr/src/lib/libscf/common/midlevel.c @@ -28,7 +28,6 @@ #include <assert.h> #include <libuutil.h> #include <stdio.h> -#include <strings.h> #include <string.h> #include <stdlib.h> #include <sys/param.h> @@ -51,25 +50,6 @@ /* Path to speedy files area must end with a slash */ #define SMF_SPEEDY_FILES_PATH "/etc/svc/volatile/" -/* - * Internal private function that creates and binds a handle. - */ -static scf_handle_t * -handle_create(void) -{ - scf_handle_t *h; - - h = scf_handle_create(SCF_VERSION); - if (h == NULL) - return (NULL); - - if (scf_handle_bind(h) == -1) { - scf_handle_destroy(h); - return (NULL); - } - return (h); -} - void scf_simple_handle_destroy(scf_simple_handle_t *simple_h) { @@ -939,7 +919,7 @@ set_inst_action(const char *fmri, const char *action) scf_instance_t *inst; int ret = -1; - h = handle_create(); + h = _scf_handle_create_and_bind(SCF_VERSION); if (h == NULL) return (-1); @@ -1082,7 +1062,7 @@ set_inst_enabled_flags(const char *fmri, int flags, uint8_t desired) return (ret); } - if ((h = handle_create()) == NULL) + if ((h = _scf_handle_create_and_bind(SCF_VERSION)) == NULL) return (ret); if ((inst = scf_instance_create(h)) == NULL) { @@ -1184,6 +1164,35 @@ _smf_refresh_instance_i(scf_instance_t *inst) } int +_smf_refresh_all_instances(scf_service_t *s) +{ + scf_handle_t *h = scf_service_handle(s); + scf_instance_t *i = scf_instance_create(h); + scf_iter_t *it = scf_iter_create(h); + int err, r = -1; + + if (h == NULL || i == NULL || it == NULL) + goto error; + + if (scf_iter_service_instances(it, s) != 0) + goto error; + + while ((err = scf_iter_next_instance(it, i)) == 1) + if (_smf_refresh_instance_i(i) != 0) + goto error; + + if (err == -1) + goto error; + + r = 0; +error: + scf_instance_destroy(i); + scf_iter_destroy(it); + + return (r); +} + +int smf_refresh_instance(const char *instance) { return (set_inst_action(instance, SCF_PROPERTY_REFRESH)); @@ -1320,7 +1329,7 @@ scf_general_pg_setup(const char *fmri, const char *pg_name) return (NULL); } else { - ret->h = handle_create(); + ret->h = _scf_handle_create_and_bind(SCF_VERSION); ret->inst = scf_instance_create(ret->h); ret->snap = scf_snapshot_create(ret->h); ret->running_pg = scf_pg_create(ret->h); @@ -1564,7 +1573,7 @@ scf_simple_walk_instances(uint_t state_flags, void *private, int svc_iter_ret, inst_iter_ret; int inst_state; - if ((h = handle_create()) == NULL) + if ((h = _scf_handle_create_and_bind(SCF_VERSION)) == NULL) return (ret); if (((scope = scf_scope_create(h)) == NULL) || @@ -1654,7 +1663,7 @@ scf_simple_prop_get(scf_handle_t *hin, const char *instance, const char *pgname, local_h = B_FALSE; } - if (local_h && ((h = handle_create()) == NULL)) + if (local_h && ((h = _scf_handle_create_and_bind(SCF_VERSION)) == NULL)) return (NULL); if ((fmri_buf = assemble_fmri(h, instance, pgname, propname)) == NULL) { @@ -1795,7 +1804,7 @@ scf_simple_app_props_get(scf_handle_t *hin, const char *inst_fmri) local_h = B_FALSE; } - if (local_h && ((h = handle_create()) == NULL)) + if (local_h && ((h = _scf_handle_create_and_bind(SCF_VERSION)) == NULL)) return (NULL); if (inst_fmri == NULL) { @@ -2495,7 +2504,7 @@ gen_filenms_from_fmri(const char *fmri, const char *name, char *filename, return (0); } -static scf_type_t +scf_type_t scf_true_base_type(scf_type_t type) { scf_type_t base = type; @@ -2576,7 +2585,7 @@ int scf_read_propvec(const char *fmri, const char *pgname, boolean_t running, scf_propvec_t *properties, scf_propvec_t **badprop) { - scf_handle_t *h = handle_create(); + scf_handle_t *h = _scf_handle_create_and_bind(SCF_VERSION); scf_service_t *s = scf_service_create(h); scf_instance_t *i = scf_instance_create(h); scf_snapshot_t *snap = running ? scf_snapshot_create(h) : NULL; @@ -2742,7 +2751,7 @@ int scf_write_propvec(const char *fmri, const char *pgname, scf_propvec_t *properties, scf_propvec_t **badprop) { - scf_handle_t *h = handle_create(); + scf_handle_t *h = _scf_handle_create_and_bind(SCF_VERSION); scf_service_t *s = scf_service_create(h); scf_instance_t *inst = scf_instance_create(h); scf_snapshot_t *snap = scf_snapshot_create(h); @@ -3052,3 +3061,86 @@ _check_services(char **svcs) } } } + +/*ARGSUSED*/ +static int +str_compare(const char *s1, const char *s2, size_t n) +{ + return (strcmp(s1, s2)); +} + +static int +str_n_compare(const char *s1, const char *s2, size_t n) +{ + return (strncmp(s1, s2, n)); +} + +int32_t +state_from_string(const char *state, size_t l) +{ + int (*str_cmp)(const char *, const char *, size_t); + + if (l == 0) + str_cmp = str_compare; + else + str_cmp = str_n_compare; + + if (str_cmp(SCF_STATE_STRING_UNINIT, state, l) == 0) + return (SCF_STATE_UNINIT); + else if (str_cmp(SCF_STATE_STRING_MAINT, state, l) == 0) + return (SCF_STATE_MAINT); + else if (str_cmp(SCF_STATE_STRING_OFFLINE, state, l) == 0) + return (SCF_STATE_OFFLINE); + else if (str_cmp(SCF_STATE_STRING_DISABLED, state, l) == 0) + return (SCF_STATE_DISABLED); + else if (str_cmp(SCF_STATE_STRING_ONLINE, state, l) == 0) + return (SCF_STATE_ONLINE); + else if (str_cmp(SCF_STATE_STRING_DEGRADED, state, l) == 0) + return (SCF_STATE_DEGRADED); + else if (str_cmp("all", state, l) == 0) + return (SCF_STATE_ALL); + else + return (-1); +} + +/* + * int32_t smf_state_from_string() + * return the value of the macro SCF_STATE_* for the corresponding state + * it returns SCF_STATE_ALL if "all" is passed. -1 if the string passed doesn't + * correspond to any valid state. + */ +int32_t +smf_state_from_string(const char *state) +{ + return (state_from_string(state, 0)); +} + +/* + * smf_state_to_string() + * Takes an int32_t representing an SMF state and returns + * the corresponding string. The string is read only and need not to be + * freed. + * returns NULL on invalid input. + */ +const char * +smf_state_to_string(int32_t s) +{ + switch (s) { + case SCF_STATE_UNINIT: + return (SCF_STATE_STRING_UNINIT); + case SCF_STATE_MAINT: + return (SCF_STATE_STRING_MAINT); + case SCF_STATE_OFFLINE: + return (SCF_STATE_STRING_OFFLINE); + case SCF_STATE_DISABLED: + return (SCF_STATE_STRING_DISABLED); + case SCF_STATE_ONLINE: + return (SCF_STATE_STRING_ONLINE); + case SCF_STATE_DEGRADED: + return (SCF_STATE_STRING_DEGRADED); + case SCF_STATE_ALL: + return ("all"); + default: + return (NULL); + } +} |