-
- /* check state */
- if (afb_export_is_started(desc->export)) {
- /* not an error when onneed */
- if (onneed != 0)
- goto done;
-
- /* already started: it is an error */
- ERROR("Service %s already started", afb_export_apiname(desc->export));
- 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);
-
- /* unshare the session if asked */
- if (!share_session) {
- rc = afb_export_unshare_session(desc->export);
- if (rc < 0) {
- ERROR("Can't unshare the session for %s", afb_export_apiname(desc->export));
- return -1;
- }
- }
-
- /* set event handling */
- rc = afb_export_handle_events(desc->export, onevent);
- if (rc < 0) {
- ERROR("Can't set event handler for %s", afb_export_apiname(desc->export));
- return -1;
- }
-
- /* Starts the service */
- rc = afb_export_start_v1(desc->export, init);
- if (rc < 0) {
- /* initialisation error */
- ERROR("Initialisation of service %s failed (%d): %m", afb_export_apiname(desc->export), rc);
- return rc;
- }
-
-done:
- return 0;