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


Ignore:
Timestamp:
2020-01-21T15:10:26Z (5 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/async/client.c

    rf8fb03b r01900b6  
    889889 * @param arg2  User defined argument.
    890890 * @param arg3  User defined argument.
     891 * @param rc    Placeholder for return code. Unused if NULL.
    891892 *
    892893 * @return New session on success or NULL on error.
     
    894895 */
    895896async_sess_t *async_connect_me_to(async_exch_t *exch, iface_t iface,
    896     sysarg_t arg2, sysarg_t arg3)
     897    sysarg_t arg2, sysarg_t arg3, errno_t *rc)
    897898{
    898899        if (exch == NULL) {
    899                 errno = ENOENT;
     900                if (rc != NULL)
     901                        *rc = ENOENT;
     902
    900903                return NULL;
    901904        }
     
    903906        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    904907        if (sess == NULL) {
    905                 errno = ENOMEM;
     908                if (rc != NULL)
     909                        *rc = ENOMEM;
     910
    906911                return NULL;
    907912        }
    908913
    909914        cap_phone_handle_t phone;
    910         errno_t rc = async_connect_me_to_internal(exch->phone, iface, arg2,
     915        errno_t ret = async_connect_me_to_internal(exch->phone, iface, arg2,
    911916            arg3, 0, &phone);
    912         if (rc != EOK) {
    913                 errno = rc;
     917        if (ret != EOK) {
     918                if (rc != NULL)
     919                        *rc = ret;
     920
    914921                free(sess);
    915922                return NULL;
     
    957964 * @param arg2  User defined argument.
    958965 * @param arg3  User defined argument.
     966 * @param rc    Placeholder for return code. Unused if NULL.
    959967 *
    960968 * @return New session on success or NULL on error.
     
    962970 */
    963971async_sess_t *async_connect_me_to_blocking(async_exch_t *exch, iface_t iface,
    964     sysarg_t arg2, sysarg_t arg3)
     972    sysarg_t arg2, sysarg_t arg3, errno_t *rc)
    965973{
    966974        if (exch == NULL) {
    967                 errno = ENOENT;
     975                if (rc != NULL)
     976                        *rc = ENOENT;
     977
    968978                return NULL;
    969979        }
     
    971981        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    972982        if (sess == NULL) {
    973                 errno = ENOMEM;
     983                if (rc != NULL)
     984                        *rc = ENOMEM;
     985
    974986                return NULL;
    975987        }
    976988
    977989        cap_phone_handle_t phone;
    978         errno_t rc = async_connect_me_to_internal(exch->phone, iface, arg2,
     990        errno_t ret = async_connect_me_to_internal(exch->phone, iface, arg2,
    979991            arg3, IPC_FLAG_BLOCKING, &phone);
    980         if (rc != EOK) {
    981                 errno = rc;
     992        if (ret != EOK) {
     993                if (rc != NULL)
     994                        *rc = ret;
     995
    982996                free(sess);
    983997                return NULL;
     
    9991013/** Connect to a task specified by id.
    10001014 *
    1001  */
    1002 async_sess_t *async_connect_kbox(task_id_t id)
     1015 * @param id Task to which to connect.
     1016 * @param rc Placeholder for return code. Unused if NULL.
     1017 *
     1018 * @return New session on success or NULL on error.
     1019 *
     1020 */
     1021async_sess_t *async_connect_kbox(task_id_t id, errno_t *rc)
    10031022{
    10041023        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    10051024        if (sess == NULL) {
    1006                 errno = ENOMEM;
     1025                if (rc != NULL)
     1026                        *rc = ENOMEM;
     1027
    10071028                return NULL;
    10081029        }
    10091030
    10101031        cap_phone_handle_t phone;
    1011         errno_t rc = ipc_connect_kbox(id, &phone);
    1012         if (rc != EOK) {
    1013                 errno = rc;
     1032        errno_t ret = ipc_connect_kbox(id, &phone);
     1033        if (ret != EOK) {
     1034                if (rc != NULL)
     1035                        *rc = ret;
     1036
    10141037                free(sess);
    10151038                return NULL;
Note: See TracChangeset for help on using the changeset viewer.