-
- /* check state */
- if (desc->service != NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- goto done;
-
- /* already started: it is an error */
- ERROR("Service %s already started", desc->binding->v1.prefix);
- return -1;
- }
-
- /* get the initialisation */
- init = dlsym(desc->handle, afb_api_so_v1_service_init);
- onevent = dlsym(desc->handle, afb_api_so_v1_service_event);
- if (init == NULL && onevent == NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- goto done;
-
- /* no initialisation method */
- ERROR("Binding %s is not a service", desc->binding->v1.prefix);
- return -1;
- }
-
- /* get the event handler if any */
- desc->service = afb_svc_create(desc->binding->v1.prefix, apiset, share_session, onevent, NULL);
- if (desc->service == NULL) {
- ERROR("Creation of service %s failed", desc->binding->v1.prefix);
- return -1;
- }
-
- /* Starts the service */
- desc->ditf.state = Daemon_Init;
- rc = afb_svc_start_v1(desc->service, init);
- if (rc < 0) {
- /* initialisation error */
- ERROR("Initialisation of service %s failed (%d): %m", desc->binding->v1.prefix, rc);
- afb_svc_destroy(desc->service, NULL);
- desc->service = NULL;
- return rc;
- }
-
-done:
- desc->ditf.state = Daemon_Run;
- return 0;