Kernel: Fix SYS_FCNTL command handling :)
I had misunderstood how these work
This commit is contained in:
parent
e6a2f55a59
commit
0fab7ad63b
|
@ -202,20 +202,23 @@ namespace Kernel
|
|||
{
|
||||
TRY(validate_fd(fd));
|
||||
|
||||
constexpr int creation_flags = O_CLOEXEC | O_CREAT | O_DIRECTORY | O_EXCL | O_NOCTTY | O_NOFOLLOW | O_TRUNC | O_TTY_INIT;
|
||||
dprintln("fcntl({} ('{}'), {}, {H})", fd, m_open_files[fd]->path(), cmd, extra);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case F_GETFD:
|
||||
return m_open_files[fd]->flags;
|
||||
return m_open_files[fd]->flags & FD_CLOEXEC;
|
||||
case F_SETFD:
|
||||
// FIXME: validate permissions to set access flags
|
||||
m_open_files[fd]->flags = extra;
|
||||
m_open_files[fd]->flags &= ~FD_CLOEXEC;
|
||||
m_open_files[fd]->flags |= extra & FD_CLOEXEC;
|
||||
dprintln(" set CLOEXEC to {}", !!(m_open_files[fd]->flags & FD_CLOEXEC));
|
||||
return 0;
|
||||
case F_GETFL:
|
||||
return m_open_files[fd]->flags & ~creation_flags;
|
||||
return m_open_files[fd]->flags & ~(O_APPEND | O_DSYNC | O_NONBLOCK | O_RSYNC | O_SYNC | O_ACCMODE);
|
||||
case F_SETFL:
|
||||
m_open_files[fd]->flags |= extra & ~(O_ACCMODE | creation_flags);
|
||||
m_open_files[fd]->flags &= ~O_NONBLOCK;
|
||||
m_open_files[fd]->flags |= extra & O_NONBLOCK;
|
||||
dprintln(" set NONBLOCK to {}", !!(m_open_files[fd]->flags & O_NONBLOCK));
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -27,8 +27,6 @@ __BEGIN_DECLS
|
|||
#define F_GETOWN 10
|
||||
#define F_SETOWN 11
|
||||
|
||||
#define FD_CLOEXEC 1
|
||||
|
||||
#define F_RDLCK 1
|
||||
#define F_UNLCK 2
|
||||
#define F_WRLCK 3
|
||||
|
@ -38,6 +36,14 @@ __BEGIN_DECLS
|
|||
#define SEEK_CUR 2
|
||||
#define SEEK_END 3
|
||||
|
||||
/* bits 0-3 */
|
||||
#define O_RDONLY 0x00001
|
||||
#define O_WRONLY 0x00002
|
||||
#define O_RDWR (O_RDONLY | O_WRONLY)
|
||||
#define O_SEARCH 0x00004
|
||||
#define O_EXEC 0x00008
|
||||
#define O_ACCMODE 0x0000F
|
||||
|
||||
/* bits 4-11 */
|
||||
#define O_CLOEXEC 0x00010
|
||||
#define O_CREAT 0x00020
|
||||
|
@ -47,6 +53,7 @@ __BEGIN_DECLS
|
|||
#define O_NOFOLLOW 0x00200
|
||||
#define O_TRUNC 0x00400
|
||||
#define O_TTY_INIT 0x00800
|
||||
#define FD_CLOEXEC O_CLOEXEC
|
||||
|
||||
/* bits 12-16 */
|
||||
#define O_APPEND 0x01000
|
||||
|
@ -55,14 +62,6 @@ __BEGIN_DECLS
|
|||
#define O_RSYNC 0x08000
|
||||
#define O_SYNC 0x10000
|
||||
|
||||
/* bits 0-3 */
|
||||
#define O_RDONLY 0x00001
|
||||
#define O_WRONLY 0x00002
|
||||
#define O_RDWR (O_RDONLY | O_WRONLY)
|
||||
#define O_SEARCH 0x00004
|
||||
#define O_EXEC 0x00008
|
||||
#define O_ACCMODE 0x0000F
|
||||
|
||||
/* bit 17 */
|
||||
#define AT_FDCWD 0x20000
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace LibGUI
|
|||
return BAN::Error::from_errno(errno);
|
||||
BAN::ScopeGuard server_closer([server_fd] { close(server_fd); });
|
||||
|
||||
if (fcntl(server_fd, F_SETFL, fcntl(server_fd, F_GETFL) | O_CLOEXEC) == -1)
|
||||
if (fcntl(server_fd, F_SETFD, fcntl(server_fd, F_GETFD) | FD_CLOEXEC) == -1)
|
||||
return BAN::Error::from_errno(errno);
|
||||
|
||||
timespec start_time;
|
||||
|
|
|
@ -202,7 +202,7 @@ void update()
|
|||
int main()
|
||||
{
|
||||
// Make stdin non blocking
|
||||
if (fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK))
|
||||
if (fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK))
|
||||
{
|
||||
perror("fcntl");
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue