summaryrefslogtreecommitdiff
path: root/term
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-06-13 20:52:17 +0000
committerRoland McGrath <roland@gnu.org>2002-06-13 20:52:17 +0000
commit47488b9e4d2b815e429423a060054308dae0d995 (patch)
tree47d8f683fc1ecc69c86823e0b0a1fe8ba90dad7f /term
parent6475c2bf80f6af42dc9437879315651d71e74251 (diff)
2002-06-13 Roland McGrath <roland@frob.com>
* ptyio.c (pty_io_readable): int -> size_t in argument type. * term.h: Update decl. * users.c (trivfs_S_io_write): int -> size_t in AMT argument type. (trivfs_S_io_readable): Likewise. (trivfs_S_io_read): Likewise. Also u_int -> size_t, off_t -> loff_t. (trivfs_S_io_write): Likewise. (trivfs_S_io_map): Add reply port args.
Diffstat (limited to 'term')
-rw-r--r--term/ptyio.c56
-rw-r--r--term/term.h2
-rw-r--r--term/users.c46
3 files changed, 58 insertions, 46 deletions
diff --git a/term/ptyio.c b/term/ptyio.c
index 1bdb43d7..ee9db4a9 100644
--- a/term/ptyio.c
+++ b/term/ptyio.c
@@ -1,4 +1,4 @@
-/*
+/*
Copyright (C) 1995, 1996, 1999, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
@@ -62,7 +62,7 @@ ptyio_init (void)
condition_implies (&pty_read_wakeup, &pty_select_wakeup);
return 0;
}
-
+
error_t
pty_open_hook (struct trivfs_control *cntl,
struct iouser *user,
@@ -70,7 +70,7 @@ pty_open_hook (struct trivfs_control *cntl,
{
if ((flags & (O_READ|O_WRITE)) == 0)
return 0;
-
+
mutex_lock (&global_lock);
if (ptyopen)
@@ -78,7 +78,7 @@ pty_open_hook (struct trivfs_control *cntl,
mutex_unlock (&global_lock);
return EBUSY;
}
-
+
ptyopen = 1;
/* Re-initialize pty state. */
@@ -175,7 +175,7 @@ ptyio_suspend_physical_output ()
return 0;
}
-static int
+static int
ptyio_pending_output_size ()
{
/* We don't maintain any pending output buffer separate from the outputq. */
@@ -193,14 +193,14 @@ ptyio_notice_input_flushed ()
return 0;
}
-static error_t
+static error_t
ptyio_assert_dtr ()
{
dtr_on = 1;
return 0;
}
-static error_t
+static error_t
ptyio_desert_dtr ()
{
dtr_on = 0;
@@ -208,16 +208,16 @@ ptyio_desert_dtr ()
return 0;
}
-static error_t
+static error_t
ptyio_set_bits (struct termios *state)
{
if (packet_mode)
{
int wakeup = 0;
- int stop = ((state->c_iflag & IXON)
+ int stop = ((state->c_iflag & IXON)
&& CCEQ (state->c_cc[VSTOP], CHAR_DC3)
&& CCEQ (state->c_cc[VSTART], CHAR_DC1));
-
+
if (external_processing)
{
control_byte |= TIOCPKT_IOCTL;
@@ -247,7 +247,7 @@ ptyio_set_bits (struct termios *state)
/* These do nothing. In BSD the associated ioctls get errors, but
I'd rather just ignore them. */
-static error_t
+static error_t
ptyio_set_break ()
{
return 0;
@@ -303,9 +303,9 @@ pty_io_read (struct trivfs_protid *cred,
mach_msg_type_number_t amount)
{
int size;
-
+
mutex_lock (&global_lock);
-
+
if ((cred->po->openmodes & O_READ) == 0)
{
mutex_unlock (&global_lock);
@@ -328,7 +328,7 @@ pty_io_read (struct trivfs_protid *cred,
return EINTR;
}
}
-
+
if (control_byte)
{
size = 1;
@@ -341,7 +341,7 @@ pty_io_read (struct trivfs_protid *cred,
if (packet_mode || user_ioctl_mode)
size++;
}
-
+
if (size > amount)
size = amount;
if (size > *datalen)
@@ -372,7 +372,7 @@ pty_io_read (struct trivfs_protid *cred,
return 0;
}
-
+
/* Validation has already been done by trivfs_S_io_write. */
error_t
pty_io_write (struct trivfs_protid *cred,
@@ -384,7 +384,7 @@ pty_io_write (struct trivfs_protid *cred,
int cancel = 0;
mutex_lock (&global_lock);
-
+
if ((cred->po->openmodes & O_WRITE) == 0)
{
mutex_unlock (&global_lock);
@@ -411,7 +411,7 @@ pty_io_write (struct trivfs_protid *cred,
for (i = 0; i < datalen; i++)
enqueue (&inputq, data[i]);
-
+
/* Extra garbage charater */
enqueue (&inputq, 0);
}
@@ -439,7 +439,7 @@ pty_io_write (struct trivfs_protid *cred,
/* Validation has already been done by trivfs_S_io_readable */
error_t
-pty_io_readable (int *amt)
+pty_io_readable (size_t *amt)
{
mutex_lock (&global_lock);
if (control_byte)
@@ -460,7 +460,7 @@ pty_io_select (struct trivfs_protid *cred, mach_port_t reply,
int *type)
{
int avail = 0;
-
+
if (*type == 0)
return 0;
@@ -477,7 +477,7 @@ pty_io_select (struct trivfs_protid *cred, mach_port_t reply,
if ((*type & SELECT_WRITE) && (!remote_input_mode || !qsize (inputq)))
avail |= SELECT_WRITE;
-
+
if (avail)
{
*type = avail;
@@ -505,7 +505,7 @@ S_tioctl_tiocsig (io_t port,
port, pty_class);
if (!cred)
return EOPNOTSUPP;
-
+
mutex_lock (&global_lock);
drop_output ();
@@ -525,12 +525,12 @@ S_tioctl_tiocpkt (io_t port,
int mode)
{
error_t err;
-
+
struct trivfs_protid *cred = ports_lookup_port (term_bucket,
port, pty_class);
if (!cred)
return EOPNOTSUPP;
-
+
mutex_lock (&global_lock);
if (!!mode == !!packet_mode)
@@ -555,12 +555,12 @@ S_tioctl_tiocucntl (io_t port,
int mode)
{
error_t err;
-
+
struct trivfs_protid *cred = ports_lookup_port (term_bucket,
port, pty_class);
if (!cred)
return EOPNOTSUPP;
-
+
mutex_lock (&global_lock);
if (!!mode == !!user_ioctl_mode)
@@ -586,7 +586,7 @@ S_tioctl_tiocremote (io_t port,
{
struct trivfs_protid *cred = ports_lookup_port (term_bucket,
port, pty_class);
-
+
if (!cred)
return EOPNOTSUPP;
@@ -609,7 +609,7 @@ S_tioctl_tiocext (io_t port,
port, pty_class);
if (!cred)
return EOPNOTSUPP;
-
+
mutex_lock (&global_lock);
if (mode && !external_processing)
{
diff --git a/term/term.h b/term/term.h
index 7e4a69fb..c89e4425 100644
--- a/term/term.h
+++ b/term/term.h
@@ -331,7 +331,7 @@ error_t pty_io_write (struct trivfs_protid *, char *,
mach_msg_type_number_t, mach_msg_type_number_t *);
error_t pty_io_read (struct trivfs_protid *, char **,
mach_msg_type_number_t *, mach_msg_type_number_t);
-error_t pty_io_readable (int *);
+error_t pty_io_readable (size_t *);
error_t pty_io_select (struct trivfs_protid *, mach_port_t, int *);
error_t pty_open_hook (struct trivfs_control *, struct iouser *, int);
error_t pty_po_create_hook (struct trivfs_peropen *);
diff --git a/term/users.c b/term/users.c
index c0eb6f7c..0cba9de4 100644
--- a/term/users.c
+++ b/term/users.c
@@ -79,7 +79,7 @@ static error_t carrier_error;
struct protid_hook
{
int refcnt;
- pid_t pid, pgrp;
+ pid_t pid, pgrp, sid;
};
void
@@ -415,10 +415,10 @@ S_termctty_open_terminal (mach_port_t arg,
/* Implement term_become_ctty as described in <hurd/term.defs>. */
kern_return_t
S_term_open_ctty (mach_port_t arg,
- pid_t pid,
- pid_t pgrp,
- mach_port_t *newpt,
- mach_msg_type_name_t *newpttype)
+ pid_t pid,
+ pid_t pgrp,
+ mach_port_t *newpt,
+ mach_msg_type_name_t *newpttype)
{
error_t err;
struct trivfs_protid *newcred;
@@ -427,6 +427,12 @@ S_term_open_ctty (mach_port_t arg,
if (!cred)
return EOPNOTSUPP;
+ if (pid <= 0 || pgrp <= 0)
+ {
+ ports_port_deref (cred);
+ return EINVAL;
+ }
+
mutex_lock (&global_lock);
if (!cred->po->openmodes & (O_READ|O_WRITE))
@@ -445,6 +451,7 @@ S_term_open_ctty (mach_port_t arg,
hook->pid = pid;
hook->pgrp = pgrp;
+ hook->sid = getsid (pid);
hook->refcnt = 1;
if (newcred->hook)
@@ -560,9 +567,9 @@ trivfs_S_io_write (struct trivfs_protid *cred,
mach_port_t reply,
mach_msg_type_name_t replytype,
char *data,
- u_int datalen,
- off_t offset,
- int *amt)
+ size_t datalen,
+ loff_t offset,
+ size_t *amt)
{
int i;
int cancel;
@@ -637,9 +644,9 @@ trivfs_S_io_read (struct trivfs_protid *cred,
mach_port_t reply,
mach_msg_type_name_t replytype,
char **data,
- u_int *datalen,
- off_t offset,
- int amount)
+ size_t *datalen,
+ loff_t offset,
+ size_t amount)
{
int cancel;
int i, max;
@@ -817,7 +824,7 @@ error_t
trivfs_S_io_readable (struct trivfs_protid *cred,
mach_port_t reply,
mach_msg_type_name_t replytype,
- int *amt)
+ size_t *amt)
{
if (!cred)
return EOPNOTSUPP;
@@ -1634,6 +1641,9 @@ S_tioctl_tiocspgrp (io_t port,
mutex_lock (&global_lock);
if (!(cred->po->openmodes & (O_READ|O_WRITE)))
err = EBADF;
+ else if (!cred->hook
+ || getsid (-pgrp) != ((struct protid_hook *)cred->hook)->sid)
+ err = EPERM;
else
{
termflags &= ~NO_OWNER;
@@ -2032,11 +2042,13 @@ trivfs_S_io_select (struct trivfs_protid *cred,
}
kern_return_t
-trivfs_S_io_map (struct trivfs_protid *cred,
- mach_port_t *rdobj,
- mach_msg_type_name_t *rdtype,
- mach_port_t *wrobj,
- mach_msg_type_name_t *wrtype)
+trivfs_S_io_map (struct trivfs_protid *cred,
+ mach_port_t reply,
+ mach_msg_type_name_t replyPoly,
+ mach_port_t *rdobj,
+ mach_msg_type_name_t *rdtype,
+ mach_port_t *wrobj,
+ mach_msg_type_name_t *wrtype)
{
return EOPNOTSUPP;
}