Changeset 01900b6 in mainline for uspace/lib/c/generic/ns.c


Ignore:
Timestamp:
2020-01-21T15:10:26Z (4 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
51da086
Parents:
f8fb03b
Message:

Use an optional output argument instead of errno to propagate the error

The use of errno is troublesome in all other than top-level library
functions since the value in errno might get overwritten by subsequent
inner calls on the error path (e.g. cleanup, deallocation, etc.). The
optional output argument makes it possible to explicitly ignore the
error code if it is not needed, but still to pass it reliably back to
the original caller.

This change affecs async_connect_me_to(),
async_connect_me_to_blocking(), async_connect_kbox(), service_connect(),
service_connect_blocking() and loader_connect().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/ns.c

    rf8fb03b r01900b6  
    4949    async_port_handler_t handler, void *data)
    5050{
    51         async_sess_t *sess = ns_session_get();
    52         if (sess == NULL)
    53                 return EIO;
     51        errno_t rc;
     52        async_sess_t *sess = ns_session_get(&rc);
     53        if (sess == NULL)
     54                return rc;
    5455
    5556        port_id_t port;
    56         errno_t rc = async_create_port(iface, handler, data, &port);
     57        rc = async_create_port(iface, handler, data, &port);
    5758        if (rc != EOK)
    5859                return rc;
     
    8182        async_set_fallback_port_handler(handler, data);
    8283
    83         async_sess_t *sess = ns_session_get();
    84         if (sess == NULL)
    85                 return EIO;
     84        errno_t rc;
     85        async_sess_t *sess = ns_session_get(&rc);
     86        if (sess == NULL)
     87                return rc;
    8688
    8789        async_exch_t *exch = async_exchange_begin(sess);
     
    8991        ipc_call_t answer;
    9092        aid_t req = async_send_1(exch, NS_REGISTER_BROKER, service, &answer);
    91         errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
     93        rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
    9294
    9395        async_exchange_end(exch);
     
    103105}
    104106
    105 async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
    106 {
    107         async_sess_t *sess = ns_session_get();
     107/** Connect to a singleton service.
     108 *
     109 * @param service Singleton service ID.
     110 * @param iface   Interface to connect to.
     111 * @param arg3    Custom connection argument.
     112 * @param rc      Placeholder for return code. Unused if NULL.
     113 *
     114 * @return New session on success or NULL on error.
     115 *
     116 */
     117async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3,
     118    errno_t *rc)
     119{
     120        async_sess_t *sess = ns_session_get(rc);
    108121        if (sess == NULL)
    109122                return NULL;
     
    114127
    115128        async_sess_t *csess =
    116             async_connect_me_to(exch, iface, service, arg3);
     129            async_connect_me_to(exch, iface, service, arg3, rc);
    117130        async_exchange_end(exch);
    118131
     
    130143}
    131144
     145/** Wait and connect to a singleton service.
     146 *
     147 * @param service Singleton service ID.
     148 * @param iface   Interface to connect to.
     149 * @param arg3    Custom connection argument.
     150 * @param rc      Placeholder for return code. Unused if NULL.
     151 *
     152 * @return New session on success or NULL on error.
     153 *
     154 */
    132155async_sess_t *service_connect_blocking(service_t service, iface_t iface,
    133     sysarg_t arg3)
    134 {
    135         async_sess_t *sess = ns_session_get();
     156    sysarg_t arg3, errno_t *rc)
     157{
     158        async_sess_t *sess = ns_session_get(rc);
    136159        if (sess == NULL)
    137160                return NULL;
     
    139162        async_exch_t *exch = async_exchange_begin(sess);
    140163        async_sess_t *csess =
    141             async_connect_me_to_blocking(exch, iface, service, arg3);
     164            async_connect_me_to_blocking(exch, iface, service, arg3, rc);
    142165        async_exchange_end(exch);
    143166
     
    157180errno_t ns_ping(void)
    158181{
    159         async_sess_t *sess = ns_session_get();
     182        errno_t rc;
     183        async_sess_t *sess = ns_session_get(&rc);
     184        if (sess == NULL)
     185                return rc;
     186
     187        async_exch_t *exch = async_exchange_begin(sess);
     188        rc = async_req_0_0(exch, NS_PING);
     189        async_exchange_end(exch);
     190
     191        return rc;
     192}
     193
     194errno_t ns_intro(task_id_t id)
     195{
     196        errno_t rc;
     197        async_sess_t *sess = ns_session_get(&rc);
    160198        if (sess == NULL)
    161199                return EIO;
    162200
    163201        async_exch_t *exch = async_exchange_begin(sess);
    164         errno_t rc = async_req_0_0(exch, NS_PING);
    165         async_exchange_end(exch);
    166 
    167         return rc;
    168 }
    169 
    170 errno_t ns_intro(task_id_t id)
    171 {
    172         async_exch_t *exch;
    173         async_sess_t *sess = ns_session_get();
    174         if (sess == NULL)
    175                 return EIO;
    176 
    177         exch = async_exchange_begin(sess);
    178         errno_t rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
    179         async_exchange_end(exch);
    180 
    181         return rc;
    182 }
    183 
    184 async_sess_t *ns_session_get(void)
     202        rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
     203        async_exchange_end(exch);
     204
     205        return rc;
     206}
     207
     208async_sess_t *ns_session_get(errno_t *rc)
    185209{
    186210        async_exch_t *exch;
     
    188212        if (sess_ns == NULL) {
    189213                exch = async_exchange_begin(&session_ns);
    190                 sess_ns = async_connect_me_to(exch, 0, 0, 0);
     214                sess_ns = async_connect_me_to(exch, 0, 0, 0, rc);
    191215                async_exchange_end(exch);
    192216                if (sess_ns == NULL)
Note: See TracChangeset for help on using the changeset viewer.