static NTSTATUS RegSrvIpcRegisterHandle( LWMsgCall* pCall, PCSTR pszHandleType, PVOID pData, LWMsgHandleCleanupFunction pfnCleanup, LWMsgHandle** ppHandle ) { NTSTATUS status = 0; LWMsgSession* pSession = lwmsg_call_get_session(pCall); status = MAP_LWMSG_ERROR(lwmsg_session_register_handle(pSession, pszHandleType, pData, pfnCleanup, ppHandle)); BAIL_ON_NT_STATUS(status); error: return status; }
static LWMsgStatus counter_srv_open(LWMsgCall* call, const LWMsgParams* request_msg, LWMsgParams* reply_msg, void* data) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; CounterHandle* handle = malloc(sizeof(*handle)); CounterRequest* request = request_msg->data; LWMsgSession* session = lwmsg_call_get_session(call); pthread_mutex_init(&handle->lock, NULL); handle->counter = request->counter; MU_TRY(lwmsg_session_register_handle(session, "CounterHandle", handle, free)); reply_msg->tag = COUNTER_OPEN_SUCCESS; reply_msg->data = handle; MU_TRY(lwmsg_session_retain_handle(session, handle)); return status; }
/* Implementation of fserv_open() */ static LWMsgStatus fserv_open_srv( LWMsgCall* call, const LWMsgParams* in, LWMsgParams* out, void* data ) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; OpenRequest* req = (OpenRequest*) in->data; FileHandle* handle = NULL; StatusReply* sreply = NULL; LWMsgSession* session = lwmsg_call_get_session(call); int flags = 0; int fd = -1; int ret; LWMsgHandle* lwmsg_handle = NULL; LOG("fserv_open() of %s on session %p\n", req->path, session); /* Check permissions */ ret = fserv_check_permissions(session, req->path, req->mode); if (ret) { /* Allocate status reply */ sreply = malloc(sizeof(*sreply)); /* Bail out on allocation failure */ if (!handle) { status = LWMSG_STATUS_MEMORY; goto error; } /* Set output parameters */ sreply->err = ret; out->tag = FSERV_ERROR_RES; out->data = (void*) sreply; } else { if ((req->mode & OPEN_MODE_READ) && !(req->mode & OPEN_MODE_WRITE)) { flags |= O_RDONLY; } if ((req->mode & OPEN_MODE_WRITE) && !(req->mode & OPEN_MODE_READ)) { flags |= O_WRONLY; } if ((req->mode & OPEN_MODE_WRITE) && (req->mode & OPEN_MODE_READ)) { flags |= O_RDWR; } if ((req->mode & OPEN_MODE_APPEND)) { flags |= O_APPEND; } /* Open file */ fd = open(req->path, flags); if (fd >= 0) { /* Create handle structure */ handle = malloc(sizeof(*handle)); if (!handle) { status = LWMSG_STATUS_MEMORY; goto error; } /* Fill in handle */ handle->fd = fd; handle->mode = req->mode; /* Register handle */ status = lwmsg_session_register_handle( session, "FileHandle", handle, fserv_free_handle, &lwmsg_handle); if (status) { goto error; } /* Set output parameters */ out->tag = FSERV_OPEN_RES; out->data = lwmsg_handle; handle = NULL; /* Retain handle */ lwmsg_session_retain_handle(session, lwmsg_handle); LOG("Successfully opened %s as fd %i for session %p\n", req->path, fd, session); } else { sreply = malloc(sizeof(*sreply)); if (!handle) { status = LWMSG_STATUS_MEMORY; goto error; } sreply->err = errno; out->tag = FSERV_ERROR_RES; out->data = (void*) sreply; } } error: if (handle) { fserv_free_handle(handle); } return status; }