Changeset 5559712 in mainline for uspace/srv/locsrv


Ignore:
Timestamp:
2019-08-03T09:28:50Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
c0e4fc50
Parents:
2dda1d4
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-05-07 11:49:47)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:28:50)
Message:

sysman: Naive autostart instrumentation of locsrv

  • Add IPC_FLAG_AUTOSTART flag.
  • libsysman: sysman's broker and control API.
  • Simple implementation of service unit, exposee verification is missing.
  • Simple mapping of exposee to unit name in locsrv.
  • Temporary debug prints in locsrv.

Conflicts:

boot/Makefile.common
boot/arch/amd64/Makefile.inc
uspace/lib/c/include/ipc/services.h
uspace/srv/locsrv/locsrv.c

Location:
uspace/srv/locsrv
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/locsrv/Makefile

    r2dda1d4 r5559712  
    2929
    3030USPACE_PREFIX = ../..
     31LIBS = $(LIBSYSMAN_PREFIX)/libsysman.a
     32EXTRA_CFLAGS += -I$(LIBSYSMAN_PREFIX)/include
    3133BINARY = locsrv
    3234STATIC_NEEDED = y
  • uspace/srv/locsrv/locsrv.c

    r2dda1d4 r5559712  
    3636 */
    3737
     38#include <assert.h>
     39#include <async.h>
     40#include <errno.h>
     41#include <ipc/loc.h>
    3842#include <ipc/services.h>
    39 #include <ns.h>
    40 #include <async.h>
    41 #include <stdio.h>
    42 #include <errno.h>
    43 #include <stdbool.h>
    4443#include <fibril_synch.h>
    4544#include <macros.h>
     45#include <ns.h>
     46#include <stdbool.h>
     47#include <stdio.h>
    4648#include <stdlib.h>
    4749#include <str.h>
    4850#include <str_error.h>
    49 #include <ipc/loc.h>
    50 #include <assert.h>
     51#include <sysman/broker.h>
     52#include <sysman/ctl.h>
    5153
    5254#include "category.h"
     
    331333        free(service->name);
    332334        free(service);
     335}
     336
     337static int loc_service_request_start(const char *ns_name, const char *name)
     338{
     339        char *service_name = NULL;
     340
     341        if (str_cmp(ns_name, LOC_DEVICE_NAMESPACE) == 0) {
     342                asprintf(&service_name, "%s", SERVICE_NAME_DEVMAN);
     343        } else if (str_cmp(ns_name, "") == 0) {
     344                asprintf(&service_name, "%s", name);
     345        } else {
     346                asprintf(&service_name, "%s%s%s",
     347                    ns_name, LOC_UNIT_NAMESPACE_SEPARATOR, name);
     348        }
     349        if (service_name == NULL) {
     350                return ENOMEM;
     351        }
     352
     353        char *unit_name;
     354        asprintf(&unit_name, "%s%c%s",
     355            service_name, UNIT_NAME_SEPARATOR, UNIT_SVC_TYPE_NAME);
     356        if (unit_name == NULL) {
     357                free(service_name);
     358                return ENOMEM;
     359        }
     360
     361        printf("%s(%s) before\n", __func__, unit_name);
     362        int rc = sysman_unit_start(unit_name, IPC_FLAG_BLOCKING);
     363        printf("%s(%s) after %i\n", __func__, unit_name, rc);
     364        free(unit_name);
     365        free(service_name);
     366        return rc;
    333367}
    334368
     
    531565
    532566        list_append(&service->server_services, &service->server->services);
     567       
     568        printf("%s: broadcast new service '%s/%s'\n", NAME, namespace->name,
     569            service->name);
    533570
    534571        fibril_mutex_unlock(&service->server->services_mutex);
     
    542579 *
    543580 */
    544 static void loc_service_unregister(ipc_call_t *icall, loc_server_t *server)
     581static void loc_service_unregister(ipc_callid_t iid, ipc_call_t *icall,
     582    loc_server_t *server)
    545583{
    546584        loc_service_t *svc;
     
    762800        fibril_mutex_lock(&services_list_mutex);
    763801        const loc_service_t *svc;
    764 
     802        int flags = ipc_get_arg1(*icall);
     803       
    765804recheck:
    766805
     
    771810
    772811        /*
    773          * Device was not found.
     812         * Service was not found.
    774813         */
    775814        if (svc == NULL) {
    776                 if (ipc_get_arg1(icall) & IPC_FLAG_BLOCKING) {
    777                         /* Blocking lookup */
     815                printf("%s: service '%s/%s' not found\n", NAME, ns_name, name);
     816                if (flags & (IPC_FLAG_AUTOSTART | IPC_FLAG_BLOCKING)) {
     817                        /* TODO:
     818                         * consider non-blocking service start, return
     819                         * some dummy id and block only after connection
     820                         * request (actually makes more sense as those who asks
     821                         * for ID might be someone else than those connecting)
     822                         */
     823                        if (flags & IPC_FLAG_AUTOSTART) {
     824                                rc = loc_service_request_start(ns_name, name);
     825                                if (rc != EOK) {
     826                                        goto finish;
     827                                }
     828                        }
     829
    778830                        fibril_condvar_wait(&services_list_cv,
    779831                            &services_list_mutex);
    780832                        goto recheck;
    781833                }
    782 
    783                 async_answer_0(icall, ENOENT);
    784                 free(ns_name);
    785                 free(name);
    786                 fibril_mutex_unlock(&services_list_mutex);
    787                 return;
    788         }
    789 
    790         async_answer_1(icall, EOK, svc->id);
    791 
     834                rc = ENOENT;
     835        } else {
     836                printf("%s: service '%s/%s' FOUND\n", NAME, ns_name, name);
     837                rc = EOK;
     838        }
     839
     840finish:
     841        if (rc == EOK) {
     842                async_answer_1(iid, EOK, svc->id);
     843        } else {
     844                async_answer_0(iid, rc);
     845        }
     846       
    792847        fibril_mutex_unlock(&services_list_mutex);
    793848        free(ns_name);
     
    15651620        if (rc != EOK) {
    15661621                printf("%s: Error while registering broker service: %s\n", NAME, str_error(rc));
     1622
     1623        /* Let sysman know we are broker */
     1624        printf("%s: sysman_broker_register : pre\n", NAME);
     1625        rc = sysman_broker_register();
     1626        printf("%s: sysman_broker_register : post\n", NAME);
     1627        if (rc != EOK) {
     1628                printf("%s: Error registering at sysman (%i)\n", NAME, rc);
    15671629                return rc;
    15681630        }
Note: See TracChangeset for help on using the changeset viewer.