/* * smb_smf_end_transaction(handle) * * Commit the changes that were added to the transaction in the * handle. Do all necessary cleanup. */ int smb_smf_end_transaction(smb_scfhandle_t *handle) { int ret = SMBD_SMF_OK; int rc; if (handle == NULL) return (SMBD_SMF_SYSTEM_ERR); if (handle->scf_trans == NULL) { ret = SMBD_SMF_SYSTEM_ERR; } else { rc = scf_transaction_commit(handle->scf_trans); if (rc == 1) { ret = SMBD_SMF_OK; } else if (rc == 0) { ret = SMBD_SMF_INVALID_ARG; smb_smf_scf_log_error("Failed to commit, old pg: " "transaction: %s"); } else { ret = SMBD_SMF_SYSTEM_ERR; smb_smf_scf_log_error("Failed to commit, error: " "transaction: %s"); } scf_transaction_destroy_children(handle->scf_trans); scf_transaction_destroy(handle->scf_trans); handle->scf_trans = NULL; } return (ret); }
void mgmt_transaction_abort(targ_scf_t *h) { if (h->t_trans != NULL) { scf_transaction_reset_all(h->t_trans); scf_transaction_destroy_children(h->t_trans); scf_transaction_destroy(h->t_trans); h->t_trans = NULL; } }
Boolean_t mgmt_transaction_end(targ_scf_t *h) { Boolean_t ret = True; if (scf_transaction_commit(h->t_trans) < 0) ret = False; scf_pg_update(h->t_pg); scf_transaction_destroy_children(h->t_trans); scf_transaction_destroy(h->t_trans); h->t_trans = NULL; return (ret); }
/* * smb_smf_end_transaction(handle) * * Commit the changes that were added to the transaction in the * handle. Do all necessary cleanup. */ int smb_smf_end_transaction(smb_scfhandle_t *handle) { int ret = SMBC_SMF_OK; if (handle == NULL) { return (SMBC_SMF_SYSTEM_ERR); } if (handle->scf_trans == NULL) { ret = SMBC_SMF_SYSTEM_ERR; } else { if (scf_transaction_commit(handle->scf_trans) < 0) { ret = SMBC_SMF_SYSTEM_ERR; smb_smf_scf_log_error("Failed to commit " "transaction: %s"); } scf_transaction_destroy_children(handle->scf_trans); scf_transaction_destroy(handle->scf_trans); handle->scf_trans = NULL; } return (ret); }
static int add_pg_method(scf_handle_t *handle, scf_instance_t *instance, const char *kssl_entry, const char *pg_name, const char *flags, const char *value_str) { int len, rv; char *command; const char *base_command; int status = FAILURE; boolean_t errflag = B_FALSE; scf_transaction_t *tran; scf_propertygroup_t *pg; pg = add_property_group_to_instance(handle, instance, pg_name, SCF_GROUP_METHOD); if (pg == NULL) { /* flag is false to suppress duplicate error messages */ errflag = B_FALSE; goto out0; } KSSL_DEBUG("%s method added\n", pg_name); tran = scf_transaction_create(handle); if (tran == NULL) { KSSL_DEBUG("scf_transaction_create failed: %s\n", scf_strerror(scf_error())); errflag = B_TRUE; goto out0; } KSSL_DEBUG("scf_transaction_create succeeded\n"); do { if (scf_transaction_start(tran, pg) != 0) { KSSL_DEBUG("scf_transaction_start failed: %s\n", scf_strerror(scf_error())); if (scf_error() == SCF_ERROR_PERMISSION_DENIED) { (void) fprintf(stderr, gettext( "Error: Permission denied.\n")); errflag = B_FALSE; } else if (scf_error() == SCF_ERROR_DELETED) { (void) fprintf(stderr, gettext( "Error: property group %s has" " been deleted.\n"), pg_name); errflag = B_FALSE; } else errflag = B_TRUE; goto out1; } KSSL_DEBUG("scf_transaction_start succeeded\n"); if (strcmp(pg_name, "stop") == 0) base_command = "/usr/lib/kssladm delete"; else base_command = "/usr/lib/kssladm create"; len = strlen(base_command) + strlen(flags) + strlen(kssl_entry) + 3; command = malloc(len); if (command == NULL) { goto out2; } (void) snprintf(command, len, "%s %s %s", base_command, flags, kssl_entry); KSSL_DEBUG("command=%s\n", command); if (add_new_property(handle, SCF_PROPERTY_EXEC, SCF_TYPE_ASTRING, command, tran) != SUCCESS) { free(command); goto out2; } free(command); if (add_new_property(handle, SCF_PROPERTY_TIMEOUT, SCF_TYPE_COUNT, "60", tran) != SUCCESS) goto out2; if (set_method_context(handle, tran, value_str) != SUCCESS) goto out2; rv = scf_transaction_commit(tran); switch (rv) { case 1: KSSL_DEBUG("scf_transaction_commit succeeded\n"); status = SUCCESS; goto out2; case 0: scf_transaction_reset(tran); if (scf_pg_update(pg) == -1) { goto out2; } break; case -1: default: KSSL_DEBUG("ERROR: scf_transaction_commit failed: %s\n", scf_strerror(scf_error())); if (scf_error() == SCF_ERROR_PERMISSION_DENIED) { (void) fprintf(stderr, gettext( "Error: Permission denied.\n")); errflag = B_FALSE; } else { errflag = B_TRUE; } goto out2; } } while (rv == 0); out2: scf_transaction_reset(tran); out1: scf_transaction_destroy_children(tran); scf_transaction_destroy(tran); out0: if (pg != NULL) scf_pg_destroy(pg); if (errflag) (void) fprintf(stderr, gettext( "Unexpected fatal libscf error: %s. Exiting.\n"), scf_strerror(scf_error())); return (status); }