예제 #1
0
/*
 * smb_smf_scf_init()
 *
 * must be called before using any of the SCF functions.
 * Returns smb_scfhandle_t pointer if success.
 */
smb_scfhandle_t *
smb_smf_scf_init(char *svc_name)
{
	smb_scfhandle_t *handle;

	handle = malloc(sizeof (smb_scfhandle_t));
	if (handle != NULL) {
		bzero((char *)handle, sizeof (smb_scfhandle_t));
		handle->scf_state = SCH_STATE_INITIALIZING;
		handle->scf_handle = scf_handle_create(SCF_VERSION);
		if (handle->scf_handle != NULL) {
			if (scf_handle_bind(handle->scf_handle) == 0) {
				handle->scf_scope =
				    scf_scope_create(handle->scf_handle);

				if (handle->scf_scope == NULL)
					goto err;

				if (scf_handle_get_local_scope(
				    handle->scf_handle, handle->scf_scope) != 0)
					goto err;

				handle->scf_service =
				    scf_service_create(handle->scf_handle);

				if (handle->scf_service == NULL)
					goto err;

				if (scf_scope_get_service(handle->scf_scope,
				    svc_name, handle->scf_service)
				    != SCF_SUCCESS) {
					goto err;
				}
				handle->scf_pg =
				    scf_pg_create(handle->scf_handle);

				if (handle->scf_pg == NULL)
					goto err;

				handle->scf_state = SCH_STATE_INIT;
			} else {
				goto err;
			}
		} else {
			free(handle);
			handle = NULL;
			smb_smf_scf_log_error("Could not access SMF "
			    "repository: %s\n");
		}
	}
	return (handle);

	/* error handling/unwinding */
err:
	(void) smb_smf_scf_fini(handle);
	(void) smb_smf_scf_log_error("SMF initialization problem: %s\n");
	return (NULL);
}
예제 #2
0
fs_smfhandle_t *
fs_smf_init(char *fmri, char *instance)
{
	fs_smfhandle_t *handle = NULL;
	char *svcname, srv[MAXPATHLEN];

	/*
	 * svc name is of the form svc://network/fs/server:instance1
	 * FMRI portion is /network/fs/server
	 */
	snprintf(srv, MAXPATHLEN, "%s", fmri + strlen("svc:/"));
	svcname = strrchr(srv, ':');
	if (svcname != NULL)
		*svcname = '\0';
	svcname = srv;

	handle = calloc(1, sizeof (fs_smfhandle_t));
	if (handle != NULL) {
		handle->fs_handle = scf_handle_create(SCF_VERSION);
		if (handle->fs_handle == NULL)
			goto out;
		if (scf_handle_bind(handle->fs_handle) != 0)
			goto out;
		handle->fs_service =
		    scf_service_create(handle->fs_handle);
		handle->fs_scope =
		    scf_scope_create(handle->fs_handle);
		if (scf_handle_get_local_scope(handle->fs_handle,
		    handle->fs_scope) != 0)
			goto out;
		if (scf_scope_get_service(handle->fs_scope,
		    svcname, handle->fs_service)  != SCF_SUCCESS) {
			goto out;
		}
		handle->fs_pg =
		    scf_pg_create(handle->fs_handle);
		handle->fs_instance =
		    scf_instance_create(handle->fs_handle);
		handle->fs_property =
		    scf_property_create(handle->fs_handle);
		handle->fs_value =
		    scf_value_create(handle->fs_handle);
	} else {
		fprintf(stderr,
		    gettext("Cannot access SMF repository: %s\n"), fmri);
	}
	return (handle);

out:
	fs_smf_fini(handle);
	fprintf(stderr, gettext("SMF Initialization problems..%s\n"), fmri);
	return (NULL);
}