static PyObject * pyscf_get_int(PyObject *o, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "name", NULL }; scf_simple_prop_t *prop; PyObject *obj; int64_t *val; char *name; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name)) return (NULL); prop = scf_simple_prop_get(NULL, XEND_FMRI, XEND_PG, name); if (prop == NULL) return (scf_exception("scf_simple_prop_get() failed", name)); if ((val = scf_simple_prop_next_integer(prop)) == NULL) return (scf_exception("scf_simple_prop_next_integer() failed", name)); obj = PyInt_FromLong((long)*val); scf_simple_prop_free(prop); return (obj); }
static void * get_smf_prop(const char *var, char type, void *def_val) { scf_simple_prop_t *prop; void *val; char *me = "get_smf_prop"; prop = scf_simple_prop_get(NULL, NULL, "config", var); if (prop) { switch (type) { case 'b': val = scf_simple_prop_next_boolean(prop); if (val != NULL) (void) memcpy(def_val, val, sizeof (uint8_t)); break; case 'i': val = scf_simple_prop_next_integer(prop); if (val != NULL) (void) memcpy(def_val, val, sizeof (int64_t)); break; } scf_simple_prop_free(prop); } if (prop == NULL || val == NULL) { char vs[64]; switch (type) { case 'b': if (*(uint8_t *)def_val) (void) strcpy(vs, "yes"); else (void) strcpy(vs, "no"); break; case 'i': (void) sprintf(vs, "%lld", *(int64_t *)def_val); break; } _NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_ALERT) (me, "no value for config/%s (%s). " "Using default \"%s\"\n", var, scf_strerror(scf_error()), vs); } return (def_val); }
/*ARGSUSED*/ scf_error_t read_prop(scf_handle_t *h, inetd_prop_t *iprop, int index, const char *inst, const char *pg_name) { scf_simple_prop_t *sprop; uint8_t *tmp_bool; int64_t *tmp_int; uint64_t *tmp_cnt; char *tmp_char; if ((sprop = scf_simple_prop_get(h, inst, pg_name, iprop->ip_name)) == NULL) return (scf_error()); switch (iprop->ip_type) { case INET_TYPE_STRING: if ((tmp_char = scf_simple_prop_next_astring(sprop)) == NULL) goto scf_error; if ((iprop->ip_value.iv_string = strdup(tmp_char)) == NULL) { scf_simple_prop_free(sprop); return (SCF_ERROR_NO_MEMORY); } break; case INET_TYPE_STRING_LIST: { int j = 0; while ((tmp_char = scf_simple_prop_next_astring(sprop)) != NULL) { char **cpp; if ((cpp = realloc( iprop->ip_value.iv_string_list, (j + 2) * sizeof (char *))) == NULL) { scf_simple_prop_free(sprop); return (SCF_ERROR_NO_MEMORY); } iprop->ip_value.iv_string_list = cpp; if ((cpp[j] = strdup(tmp_char)) == NULL) { scf_simple_prop_free(sprop); return (SCF_ERROR_NO_MEMORY); } cpp[++j] = NULL; } if ((j == 0) || (scf_error() != SCF_ERROR_NONE)) goto scf_error; } break; case INET_TYPE_BOOLEAN: if ((tmp_bool = scf_simple_prop_next_boolean(sprop)) == NULL) goto scf_error; iprop->ip_value.iv_boolean = (*tmp_bool == 0) ? B_FALSE : B_TRUE; break; case INET_TYPE_COUNT: if ((tmp_cnt = scf_simple_prop_next_count(sprop)) == NULL) goto scf_error; iprop->ip_value.iv_cnt = *tmp_cnt; break; case INET_TYPE_INTEGER: if ((tmp_int = scf_simple_prop_next_integer(sprop)) == NULL) goto scf_error; iprop->ip_value.iv_int = *tmp_int; break; default: assert(0); } iprop->ip_error = IVE_VALID; scf_simple_prop_free(sprop); return (0); scf_error: scf_simple_prop_free(sprop); if (scf_error() == SCF_ERROR_NONE) return (SCF_ERROR_NOT_FOUND); return (scf_error()); }