diff options
Diffstat (limited to 'pflocal/io.c')
-rw-r--r-- | pflocal/io.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/pflocal/io.c b/pflocal/io.c index 02dfbd40..36221a66 100644 --- a/pflocal/io.c +++ b/pflocal/io.c @@ -1,8 +1,9 @@ /* Socket I/O operations - Copyright (C) 1995, 1996 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1998, 1999, 2000, 2002, 2007 + Free Software Foundation, Inc. - Written by Miles Bader <miles@gnu.ai.mit.edu> + Written by Miles Bader <miles@gnu.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -23,6 +24,7 @@ #include <sys/types.h> #include <sys/fcntl.h> #include <sys/stat.h> +#include <sys/mman.h> #include <hurd.h> /* for getauth() */ #include <hurd/hurd_types.h> @@ -104,7 +106,7 @@ S_io_write (struct sock_user *user, { err = pipe_write (pipe, user->sock->flags & SOCK_NONBLOCK, source_addr, data, data_len, amount); - if (source_addr) + if (err && source_addr) ports_port_deref (source_addr); } @@ -117,7 +119,7 @@ S_io_write (struct sock_user *user, /* Tell how much data can be read from the object without blocking for a "long time" (this should be the same meaning of "long time" used by the nonblocking flag. */ -error_t +error_t S_io_readable (struct sock_user *user, mach_msg_type_number_t *amount) { error_t err; @@ -196,17 +198,19 @@ S_io_select (struct sock_user *user, *select_type &= SELECT_READ; if (*select_type & SELECT_READ) - /* Wait for a connect. Passing in NULL for REQ means that the - request won't be dequeued. */ - if (connq_listen (sock->listen_queue, 1, NULL, NULL) == 0) - /* We can satisfy this request immediately. */ - return 0; - else - /* Gotta wait... */ - { - ports_interrupt_self_on_port_death (user, reply); - return connq_listen (sock->listen_queue, 0, NULL, NULL); - } + { + /* Wait for a connect. Passing in NULL for REQ means that the + request won't be dequeued. */ + if (connq_listen (sock->listen_queue, 1, NULL, NULL) == 0) + /* We can satisfy this request immediately. */ + return 0; + else + /* Gotta wait... */ + { + ports_interrupt_self_on_port_death (user, reply); + return connq_listen (sock->listen_queue, 0, NULL, NULL); + } + } } else /* Sock is a normal read/write socket. */ @@ -270,10 +274,10 @@ S_io_stat (struct sock_user *user, struct stat *st) struct sock *sock; struct pipe *rpipe, *wpipe; - void copy_time (time_value_t *from, time_t *to_sec, unsigned long *to_usec) + void copy_time (time_value_t *from, time_t *to_sec, unsigned long *to_nsec) { *to_sec = from->seconds; - *to_usec = from->microseconds; + *to_nsec = from->microseconds * 1000; } if (!user) @@ -284,7 +288,7 @@ S_io_stat (struct sock_user *user, struct stat *st) bzero (st, sizeof (struct stat)); st->st_fstype = FSTYPE_SOCKET; - st->st_mode = S_IFSOCK; + st->st_mode = sock->mode; st->st_fsid = getpid (); st->st_ino = sock->id; /* As we try to be clever with large transfers, ask for them. */ @@ -298,7 +302,7 @@ S_io_stat (struct sock_user *user, struct stat *st) if (rpipe) { mutex_lock (&rpipe->lock); - copy_time (&rpipe->read_time, &st->st_atime, &st->st_atime_usec); + copy_time (&rpipe->read_time, &st->st_atim.tv_sec, &st->st_atim.tv_nsec); /* This seems useful. */ st->st_size = pipe_readable (rpipe, 1); mutex_unlock (&rpipe->lock); @@ -307,11 +311,11 @@ S_io_stat (struct sock_user *user, struct stat *st) if (wpipe) { mutex_lock (&wpipe->lock); - copy_time (&wpipe->write_time, &st->st_mtime, &st->st_mtime_usec); + copy_time (&wpipe->write_time, &st->st_mtim.tv_sec, &st->st_mtim.tv_nsec); mutex_unlock (&wpipe->lock); } - copy_time (&sock->change_time, &st->st_ctime, &st->st_ctime_usec); + copy_time (&sock->change_time, &st->st_ctim.tv_sec, &st->st_ctim.tv_nsec); mutex_unlock (&sock->lock); @@ -389,8 +393,8 @@ S_io_reauthenticate (struct sock_user *user, mach_port_t rendezvous) uid_t *uids = uids_buf, *aux_uids = aux_uids_buf; gid_t gids_buf[NIDS], aux_gids_buf[NIDS]; gid_t *gids = gids_buf, *aux_gids = aux_gids_buf; - unsigned num_uids = NIDS, num_aux_uids = NIDS; - unsigned num_gids = NIDS, num_aux_gids = NIDS; + size_t num_uids = NIDS, num_aux_uids = NIDS; + size_t num_gids = NIDS, num_aux_gids = NIDS; if (!user) return EOPNOTSUPP; @@ -402,14 +406,14 @@ S_io_reauthenticate (struct sock_user *user, mach_port_t rendezvous) return err; auth_server = getauth (); - err = mach_port_insert_right (mach_task_self (), new_user_port, + err = mach_port_insert_right (mach_task_self (), new_user_port, new_user_port, MACH_MSG_TYPE_MAKE_SEND); assert_perror (err); do err = - auth_server_authenticate (auth_server, + auth_server_authenticate (auth_server, rendezvous, MACH_MSG_TYPE_COPY_SEND, - new_user_port, MACH_MSG_TYPE_COPY_SEND, + new_user_port, MACH_MSG_TYPE_COPY_SEND, &uids, &num_uids, &aux_uids, &num_aux_uids, &gids, &num_gids, &aux_gids, &num_aux_gids); while (err == EINTR); @@ -420,7 +424,7 @@ S_io_reauthenticate (struct sock_user *user, mach_port_t rendezvous) /* Throw away the ids we went through all that trouble to get... */ #define TRASH_IDS(ids, buf, num) \ if (buf != ids) \ - vm_deallocate (mach_task_self (), (vm_address_t)ids, num * sizeof (uid_t)); + munmap (ids, num * sizeof (uid_t)); TRASH_IDS (uids, uids_buf, num_uids); TRASH_IDS (gids, gids_buf, num_gids); @@ -434,8 +438,8 @@ error_t S_io_restrict_auth (struct sock_user *user, mach_port_t *new_port, mach_msg_type_name_t *new_port_type, - uid_t *uids, unsigned num_uids, - uid_t *gids, unsigned num_gids) + uid_t *uids, size_t num_uids, + uid_t *gids, size_t num_gids) { if (!user) return EOPNOTSUPP; @@ -466,7 +470,7 @@ error_t S_io_identity (struct sock_user *user, mach_port_t *id, mach_msg_type_name_t *id_type, mach_port_t *fsys_id, mach_msg_type_name_t *fsys_id_type, - int *fileno) + ino_t *fileno) { static mach_port_t server_id = MACH_PORT_NULL; error_t err = 0; @@ -508,10 +512,17 @@ S_io_identity (struct sock_user *user, return err; } + /* Stubs for currently unsupported rpcs. */ error_t +S_io_revoke (struct sock_user *user) +{ + return EOPNOTSUPP; +} + +error_t S_io_async(struct sock_user *user, mach_port_t notify_port, mach_port_t *async_id_port, @@ -526,7 +537,7 @@ S_io_mod_owner(struct sock_user *user, pid_t owner) return EOPNOTSUPP; } -error_t +error_t S_io_get_owner(struct sock_user *user, pid_t *owner) { return EOPNOTSUPP; |