Skip to content

Commit

Permalink
[Pal] Enhance device "dev:tty" checking
Browse files Browse the repository at this point in the history
Find special devices "dev:tty" by checking `realpath` instead of `fd`.

Signed-off-by: Li, Xun <xun.li@intel.com>
  • Loading branch information
llly committed Jan 4, 2023
1 parent be3331f commit 07466cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions pal/src/host/linux-sgx/pal_devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ static int dev_close(PAL_HANDLE handle) {
if (handle->hdr.type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

/* currently we just assign `0`/`1` FDs without duplicating, so close is a no-op for them */
int ret = 0;
if (handle->dev.fd != PAL_IDX_POISON && handle->dev.fd != 0 && handle->dev.fd != 1) {
if (handle->dev.realpath) {
ret = ocall_close(handle->dev.fd);
}
handle->dev.fd = PAL_IDX_POISON;
Expand Down Expand Up @@ -175,7 +174,7 @@ static int dev_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
if (handle->hdr.type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

if (handle->dev.fd == 0 || handle->dev.fd == 1) {
if (!handle->dev.realpath) {
/* special case of "dev:tty" device which is the standard input + standard output */
attr->share_flags = 0;
attr->pending_size = 0;
Expand Down
5 changes: 2 additions & 3 deletions pal/src/host/linux/pal_devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ static int dev_close(PAL_HANDLE handle) {
if (handle->hdr.type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

/* currently we just assign `0`/`1` FDs without duplicating, so close is a no-op for them */
int ret = 0;
if (handle->dev.fd != PAL_IDX_POISON && handle->dev.fd != 0 && handle->dev.fd != 1) {
if (handle->dev.realpath) {
ret = DO_SYSCALL(close, handle->dev.fd);
}
handle->dev.fd = PAL_IDX_POISON;
Expand Down Expand Up @@ -165,7 +164,7 @@ static int dev_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
if (handle->hdr.type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

if (handle->dev.fd == 0 || handle->dev.fd == 1) {
if (!handle->dev.realpath) {
/* special case of "dev:tty" device which is the standard input + standard output */
attr->share_flags = 0;
attr->pending_size = 0;
Expand Down

0 comments on commit 07466cb

Please sign in to comment.