2020-07-30 21:38:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 21:38:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/FileSystem/FileDescription.h>
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
#include <Kernel/TTY/MasterPTY.h>
|
|
|
|
#include <Kernel/TTY/TTY.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-28 18:59:35 +00:00
|
|
|
KResultOr<FlatPtr> Process::sys$ttyname(int fd, Userspace<char*> buffer, size_t size)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2021-07-18 18:20:12 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2020-07-30 21:38:15 +00:00
|
|
|
REQUIRE_PROMISE(tty);
|
2021-06-22 18:22:17 +00:00
|
|
|
auto description = fds().file_description(fd);
|
2020-07-30 21:38:15 +00:00
|
|
|
if (!description)
|
2021-03-01 12:49:16 +00:00
|
|
|
return EBADF;
|
2020-07-30 21:38:15 +00:00
|
|
|
if (!description->is_tty())
|
2021-03-01 12:49:16 +00:00
|
|
|
return ENOTTY;
|
2020-08-04 14:27:52 +00:00
|
|
|
auto tty_name = description->tty()->tty_name();
|
|
|
|
if (size < tty_name.length() + 1)
|
2021-03-01 12:49:16 +00:00
|
|
|
return ERANGE;
|
2020-09-12 03:11:07 +00:00
|
|
|
if (!copy_to_user(buffer, tty_name.characters(), tty_name.length() + 1))
|
2021-03-01 12:49:16 +00:00
|
|
|
return EFAULT;
|
2020-07-30 21:38:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-28 18:59:35 +00:00
|
|
|
KResultOr<FlatPtr> Process::sys$ptsname(int fd, Userspace<char*> buffer, size_t size)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2021-07-18 18:20:12 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2020-07-30 21:38:15 +00:00
|
|
|
REQUIRE_PROMISE(tty);
|
2021-06-22 18:22:17 +00:00
|
|
|
auto description = fds().file_description(fd);
|
2020-07-30 21:38:15 +00:00
|
|
|
if (!description)
|
2021-03-01 12:49:16 +00:00
|
|
|
return EBADF;
|
2020-07-30 21:38:15 +00:00
|
|
|
auto* master_pty = description->master_pty();
|
|
|
|
if (!master_pty)
|
2021-03-01 12:49:16 +00:00
|
|
|
return ENOTTY;
|
2020-07-30 21:38:15 +00:00
|
|
|
auto pts_name = master_pty->pts_name();
|
2020-08-04 14:27:52 +00:00
|
|
|
if (size < pts_name.length() + 1)
|
2021-03-01 12:49:16 +00:00
|
|
|
return ERANGE;
|
2020-09-12 03:11:07 +00:00
|
|
|
if (!copy_to_user(buffer, pts_name.characters(), pts_name.length() + 1))
|
2021-03-01 12:49:16 +00:00
|
|
|
return EFAULT;
|
2020-07-30 21:38:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|