This is an automated email from the git hooks/post-receive script. sthibault pushed a commit to branch master in repository hurd.
commit cb8b393b29fdb5e4c017a03be3969a886b239bd8 Author: Samuel Thibault <[email protected]> Date: Sun Oct 23 22:22:42 2016 +0000 New upstream snapshot --- boot/boot.c | 3 +- console-client/trans.c | 4 +- daemons/Makefile | 7 +- daemons/{runsystem.hurd => runsystem.hurd.sh} | 0 eth-multiplexer/device_impl.c | 12 -- exec/exec.c | 15 +- exec/hashexec.c | 12 +- ext2fs/ext2fs.c | 9 ++ ext2fs/ext2fs.h | 14 +- ext2fs/pager.c | 2 +- ext2fs/pokel.c | 6 +- hurd/auth_request.defs | 2 +- hurd/io_request.defs | 2 +- hurd/process_request.defs | 2 +- init/init.c | 2 +- libddekit/thread.c | 208 ++++---------------------- libdiskfs/file-set-trans.c | 15 +- libdiskfs/init-startup.c | 2 +- libfshelp/fetch-control.c | 15 +- libfshelp/translator-list.c | 9 +- libports/manage-multithread.c | 5 + proc/main.c | 7 +- procfs/rootdir.c | 44 ++++-- random/gnupg-random.c | 19 ++- random/random.c | 2 +- startup/startup.c | 2 + trans/crash.c | 30 +++- trans/remap.c | 7 + utils/fakeroot.sh | 3 + utils/msgids.c | 5 +- 30 files changed, 207 insertions(+), 258 deletions(-) diff --git a/boot/boot.c b/boot/boot.c index 462243c..02af068 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -742,7 +742,8 @@ main (int argc, char **argv, char **envp) FD_SET (0, &rmask); if (select (1, &rmask, 0, 0, 0) == 1) read_reply (); - else /* We hosed */ + else if (errno != EINTR) + /* We hosed */ error (5, errno, "select"); } } diff --git a/console-client/trans.c b/console-client/trans.c index 224229e..4b9c92b 100644 --- a/console-client/trans.c +++ b/console-client/trans.c @@ -865,7 +865,6 @@ console_unregister_consnode (consnode_t cn) error_t console_setup_node (char *path) { - mach_port_t bootstrap; error_t err; struct stat ul_stat; file_t node; @@ -876,8 +875,7 @@ console_setup_node (char *path) node = file_name_lookup (path, O_CREAT|O_NOTRANS, 0664); if (node == MACH_PORT_NULL) return errno; - - task_get_bootstrap_port (mach_task_self (), &bootstrap); + netfs_init (); /* Create the root node (some attributes initialized below). */ diff --git a/daemons/Makefile b/daemons/Makefile index 9d32617..289fbf6 100644 --- a/daemons/Makefile +++ b/daemons/Makefile @@ -20,10 +20,10 @@ dir := daemons makemode := utilities -targets = rc getty mail.local console-run runttys runsystem -special-targets = rc runsystem +targets = rc getty mail.local console-run runttys runsystem runsystem.hurd +special-targets = rc runsystem runsystem.hurd SRCS = rc.sh runsystem.sh getty.c lmail.c console-run.c runttys.c \ - runsystem.hurd \ + runsystem.hurd.sh \ installationdir = $(libexecdir) @@ -45,3 +45,4 @@ runttys: runttys.o runttys-LDLIBS = -lutil runsystem: runsystem.sh +runsystem.hurd: runsystem.hurd.sh diff --git a/daemons/runsystem.hurd b/daemons/runsystem.hurd.sh similarity index 100% rename from daemons/runsystem.hurd rename to daemons/runsystem.hurd.sh diff --git a/eth-multiplexer/device_impl.c b/eth-multiplexer/device_impl.c index 7d82b8d..b15a009 100644 --- a/eth-multiplexer/device_impl.c +++ b/eth-multiplexer/device_impl.c @@ -51,8 +51,6 @@ ds_device_open (mach_port_t master_port, mach_port_t reply_port, mach_msg_type_name_t *devicetype) { struct vether_device *dev; - int openstat; - int right_mode = 1; struct protid *pi = ports_lookup_port (netfs_port_bucket, master_port, 0); if (pi == NULL) return D_NO_SUCH_DEVICE; @@ -85,18 +83,8 @@ ds_device_open (mach_port_t master_port, mach_port_t reply_port, } dev = (struct vether_device *) pi->po->np->nn->ln; - /* check the mode */ - openstat = pi->po->openstat; - if (mode & D_READ && !(openstat & O_READ)) - right_mode = 0; - if (mode & D_WRITE && !(openstat & O_WRITE)) - right_mode = 0; - ports_port_deref (pi); - if (dev) { - if (!right_mode) - return EBADF; *device = dev->dev_port; *devicetype = MACH_MSG_TYPE_MAKE_SEND; return 0; diff --git a/exec/exec.c b/exec/exec.c index ea352fa..d6dd5d8 100644 --- a/exec/exec.c +++ b/exec/exec.c @@ -109,19 +109,20 @@ load_section (void *section, struct execdata *u) vm_address_t mapstart = round_page (addr); /* Allocate space in the task and write CONTENTS into it. */ - void write_to_task (vm_address_t mapstart, vm_size_t size, + void write_to_task (vm_address_t * mapstart, vm_size_t size, vm_prot_t vm_prot, vm_address_t contents) { vm_size_t off = size % vm_page_size; /* Allocate with vm_map to set max protections. */ u->error = vm_map (u->task, - &mapstart, size, mask, anywhere, + mapstart, size, mask, anywhere, MACH_PORT_NULL, 0, 1, vm_prot|VM_PROT_WRITE, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, VM_INHERIT_COPY); + /* vm_write only works on integral multiples of vm_page_size */ if (! u->error && size >= vm_page_size) - u->error = vm_write (u->task, mapstart, contents, size - off); + u->error = vm_write (u->task, *mapstart, contents, size - off); if (! u->error && off != 0) { vm_address_t page = 0; @@ -135,14 +136,14 @@ load_section (void *section, struct execdata *u) (void *) (contents + (size - off)), off); if (! u->error) - u->error = vm_write (u->task, mapstart + (size - off), + u->error = vm_write (u->task, *mapstart + (size - off), page, vm_page_size); munmap ((caddr_t) page, vm_page_size); } } /* Reset the current protections to the desired state. */ if (! u->error && (vm_prot & VM_PROT_WRITE) == 0) - u->error = vm_protect (u->task, mapstart, size, 0, vm_prot); + u->error = vm_protect (u->task, *mapstart, size, 0, vm_prot); } if (mapstart - addr < filesz) @@ -154,7 +155,7 @@ load_section (void *section, struct execdata *u) #define SECTION_CONTENTS (u->file_data + filepos) if (SECTION_IN_MEMORY_P) /* Data is already in memory; write it into the task. */ - write_to_task (mapstart, filesz - (mapstart - addr), vm_prot, + write_to_task (&mapstart, filesz - (mapstart - addr), vm_prot, (vm_address_t) SECTION_CONTENTS + (mapstart - addr)); else if (u->filemap != MACH_PORT_NULL) @@ -173,7 +174,7 @@ load_section (void *section, struct execdata *u) const vm_size_t size = filesz - (mapstart - addr); void *buf = map (u, filepos + (mapstart - addr), size); if (buf) - write_to_task (mapstart, size, vm_prot, (vm_address_t) buf); + write_to_task (&mapstart, size, vm_prot, (vm_address_t) buf); } if (u->error) return 0; diff --git a/exec/hashexec.c b/exec/hashexec.c index e53d2ee..6337f0a 100644 --- a/exec/hashexec.c +++ b/exec/hashexec.c @@ -97,22 +97,24 @@ check_hashbang (struct execdata *e, mach_port_t port = ((which < nports && portarray[which] != MACH_PORT_NULL) ? portarray[which] : - (flags & EXEC_DEFAULTS) ? std_ports[which] - : MACH_PORT_NULL); + (flags & EXEC_DEFAULTS && which < std_nports) + ? std_ports[which] + : MACH_PORT_NULL); /* Reauthenticate dir ports if they are the defaults. */ switch (which) { case INIT_PORT_CRDIR: /* If secure, always use the default root. */ - if ((flags & EXEC_SECURE) || - port == std_ports[which]) + if ((which < std_nports && flags & EXEC_SECURE) || + (which < std_nports && port == std_ports[which])) return (reauthenticate (std_ports[which], &user_crdir) ?: (*operate) (user_crdir)); break; case INIT_PORT_CWDIR: /* If secure, reauthenticate cwd whether default or given. */ - if ((flags & EXEC_SECURE) || port == std_ports[which]) + if ((flags & EXEC_SECURE) || + (which < std_nports && port == std_ports[which])) return (reauthenticate (port, &user_cwdir) ?: (*operate) (user_cwdir)); break; diff --git a/ext2fs/ext2fs.c b/ext2fs/ext2fs.c index 03c9eed..1ead6d2 100644 --- a/ext2fs/ext2fs.c +++ b/ext2fs/ext2fs.c @@ -69,8 +69,11 @@ options[] = " (not compiled in)" #endif }, +#ifdef ALTERNATE_SBLOCK + /* XXX This is not implemented. */ {"sblock", 'S', "BLOCKNO", 0, "Use alternate superblock location (1kb blocks)"}, +#endif {0} }; @@ -83,7 +86,9 @@ parse_opt (int key, char *arg, struct argp_state *state) struct { int debug_flag; +#ifdef ALTERNATE_SBLOCK unsigned int sb_block; +#endif } *values = state->hook; switch (key) @@ -91,6 +96,7 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'D': values->debug_flag = 1; break; +#ifdef ALTERNATE_SBLOCK case 'S': values->sb_block = strtoul (arg, &arg, 0); if (!arg || *arg != '\0') @@ -99,6 +105,7 @@ parse_opt (int key, char *arg, struct argp_state *state) return EINVAL; } break; +#endif case ARGP_KEY_INIT: state->child_inputs[0] = state->input; @@ -107,7 +114,9 @@ parse_opt (int key, char *arg, struct argp_state *state) return ENOMEM; state->hook = values; memset (values, 0, sizeof *values); +#ifdef ALTERNATE_SBLOCK values->sb_block = SBLOCK_BLOCK; +#endif break; case ARGP_KEY_SUCCESS: diff --git a/ext2fs/ext2fs.h b/ext2fs/ext2fs.h index 070d5bd..afcd25c 100644 --- a/ext2fs/ext2fs.h +++ b/ext2fs/ext2fs.h @@ -271,7 +271,9 @@ extern pthread_cond_t disk_cache_reassociation; void *disk_cache_block_ref (block_t block); void disk_cache_block_ref_ptr (void *ptr); -void disk_cache_block_deref (void *ptr); +void _disk_cache_block_deref (void *ptr); +#define disk_cache_block_deref(PTR) \ + do { _disk_cache_block_deref (PTR); PTR = NULL; } while (0) int disk_cache_block_is_ref (block_t block); /* Our in-core copy of the super-block (pointer into the disk_cache). */ @@ -412,12 +414,14 @@ dino_ref (ino_t inum) } EXT2FS_EI void -dino_deref (struct ext2_inode *inode) +_dino_deref (struct ext2_inode *inode) { ext2_debug ("(%p)", inode); disk_cache_block_deref (inode); } #endif /* Use extern inlines. */ +#define dino_deref(INODE) \ + do { _dino_deref (INODE); INODE = NULL; } while (0) /* ---------------------------------------------------------------- */ /* inode.c */ @@ -481,11 +485,11 @@ record_global_poke (void *ptr) /* This syncs a modification to a non-file block. */ EXT2FS_EI void -sync_global_ptr (void *bptr, int wait) +sync_global_ptr (void *ptr, int wait) { - block_t block = boffs_block (bptr_offs (bptr)); + block_t block = boffs_block (bptr_offs (ptr)); void *block_ptr = bptr (block); - ext2_debug ("(%p -> %u)", bptr, block); + ext2_debug ("(%p -> %u)", ptr, block); global_block_modified (block); disk_cache_block_deref (block_ptr); pager_sync_some (diskfs_disk_pager, diff --git a/ext2fs/pager.c b/ext2fs/pager.c index 456b582..6a92682 100644 --- a/ext2fs/pager.c +++ b/ext2fs/pager.c @@ -1197,7 +1197,7 @@ disk_cache_block_ref_ptr (void *ptr) } void -disk_cache_block_deref (void *ptr) +_disk_cache_block_deref (void *ptr) { int index; diff --git a/ext2fs/pokel.c b/ext2fs/pokel.c index 3afb32e..53dc513 100644 --- a/ext2fs/pokel.c +++ b/ext2fs/pokel.c @@ -71,7 +71,7 @@ pokel_add (struct pokel *pokel, void *loc, vm_size_t length) { if (pokel->image == disk_cache) for (vm_offset_t i = offset; i < end; i += block_size) - disk_cache_block_deref (disk_cache + i); + _disk_cache_block_deref (disk_cache + i); break; } @@ -85,7 +85,7 @@ pokel_add (struct pokel *pokel, void *loc, vm_size_t length) vm_offset_t i_begin = p_offs > offset ? p_offs : offset; vm_offset_t i_end = p_end < end ? p_end : end; for (vm_offset_t i = i_begin; i < i_end; i += block_size) - disk_cache_block_deref (disk_cache + i); + _disk_cache_block_deref (disk_cache + i); } ext2_debug ("extended 0x%x[%ul] to 0x%x[%ul]", @@ -140,7 +140,7 @@ _pokel_exec (struct pokel *pokel, int sync, int wait) vm_offset_t begin = trunc_block (pl->offset); vm_offset_t end = round_block (pl->offset + pl->length); for (vm_offset_t i = begin; i != end; i += block_size) - disk_cache_block_deref (pokel->image + i); + _disk_cache_block_deref (pokel->image + i); } } diff --git a/hurd/auth_request.defs b/hurd/auth_request.defs index a1f9e27..54c156c 100644 --- a/hurd/auth_request.defs +++ b/hurd/auth_request.defs @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with the GNU Hurd; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -subsystem auth_reply 25000; /* must match auth.defs */ +subsystem auth_request 25000; /* must match auth.defs */ #include <hurd/hurd_types.defs> diff --git a/hurd/io_request.defs b/hurd/io_request.defs index 0d5e36d..b439a5c 100644 --- a/hurd/io_request.defs +++ b/hurd/io_request.defs @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with the GNU Hurd; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -subsystem io 21000; +subsystem io_request 21000; /* These functions are user-side stubs for the functions in io.defs; all the comments there apply exactly to here. */ diff --git a/hurd/process_request.defs b/hurd/process_request.defs index a8bf820..20e0ee1 100644 --- a/hurd/process_request.defs +++ b/hurd/process_request.defs @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with the GNU Hurd; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -subsystem process 24000; +subsystem process_request 24000; #include <hurd/hurd_types.defs> diff --git a/init/init.c b/init/init.c index fe230da..c8078dd 100644 --- a/init/init.c +++ b/init/init.c @@ -138,7 +138,7 @@ main (int argc, char **argv) sa.sa_flags |= SA_RESTART; sigaction (SIGCHLD, &sa, NULL); - char *args[] = { "/etc/hurd/runsystem.hurd", NULL }; + char *args[] = { "/libexec/runsystem.hurd", NULL }; switch (child_pid = fork ()) { diff --git a/libddekit/thread.c b/libddekit/thread.c index 8f7b3ed..17d553b 100644 --- a/libddekit/thread.c +++ b/libddekit/thread.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <string.h> #include <pthread.h> +#include <semaphore.h> #include <time.h> #include <error.h> #include <mach.h> @@ -11,7 +12,6 @@ #include "ddekit/memory.h" #include "ddekit/semaphore.h" #include "ddekit/condvar.h" -#include "list.h" #include "ddekit/thread.h" #define DDEKIT_THREAD_STACK_SIZE 0x2000 /* 8 KB */ @@ -19,11 +19,9 @@ //static struct ddekit_slab *ddekit_stack_slab = NULL; struct _ddekit_private_data { - struct list list; ddekit_condvar_t *sleep_cond; /* point to the thread who has the private data. */ struct ddekit_thread *thread; - mach_msg_header_t wakeupmsg; }; struct ddekit_thread { @@ -35,57 +33,20 @@ struct ddekit_thread { struct ddekit_sem { - pthread_spinlock_t lock; - /* A list of thread waiting for the semaphore. */ - struct list head; - int value; + sem_t sem; }; static __thread struct ddekit_thread *thread_self; static void _thread_cleanup () { - mach_port_destroy (mach_task_self (), - thread_self->private->wakeupmsg.msgh_remote_port); ddekit_condvar_deinit (thread_self->private->sleep_cond); ddekit_simple_free (thread_self->private); ddekit_simple_free (thread_self->name); ddekit_simple_free (thread_self); } -/* Prepare a wakeup message. */ -static error_t _create_wakeupmsg (struct _ddekit_private_data *data) -{ - kern_return_t err; - - /* Build wakeup message. */ - data->wakeupmsg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0); - data->wakeupmsg.msgh_size = 0; - - err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, - &data->wakeupmsg.msgh_remote_port); - if (err) - return EAGAIN; - - data->wakeupmsg.msgh_local_port = MACH_PORT_NULL; - data->wakeupmsg.msgh_seqno = 0; - data->wakeupmsg.msgh_id = 0; - - err = mach_port_insert_right (mach_task_self (), - data->wakeupmsg.msgh_remote_port, - data->wakeupmsg.msgh_remote_port, - MACH_MSG_TYPE_MAKE_SEND); - if (err) { - mach_port_destroy (mach_task_self (), - data->wakeupmsg.msgh_remote_port); - return EAGAIN; - } - - return 0; -} - static void setup_thread (struct ddekit_thread *t, const char *name) { - error_t err; struct _ddekit_private_data *private_data; if (name) { @@ -104,14 +65,8 @@ static void setup_thread (struct ddekit_thread *t, const char *name) { ddekit_simple_malloc (sizeof (*private_data)); private_data->sleep_cond = ddekit_condvar_init (); - private_data->list.prev = &private_data->list; - private_data->list.next = &private_data->list; private_data->thread = t; - err = _create_wakeupmsg (private_data); - if (err) - error (1, err, "_create_wakeupmsg"); - t->private = private_data; } @@ -267,114 +222,45 @@ void ddekit_init_threads() { * semaphore **********************************************************************/ -/* Block THREAD. */ -static error_t _timedblock (struct _ddekit_private_data *data, - const int timeout) -{ - error_t err; - mach_msg_header_t msg; - - assert (timeout > 0); - - err = mach_msg (&msg, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0, - sizeof msg, data->wakeupmsg.msgh_remote_port, - timeout, MACH_PORT_NULL); - if (err == EMACH_RCV_TIMED_OUT) - return ETIMEDOUT; - - assert_perror (err); - return 0; -} - -/* Block THREAD. */ -static void _block (struct _ddekit_private_data *data) +static int _sem_timedwait_internal (ddekit_sem_t *restrict sem, int timeout) { - mach_msg_header_t msg; - error_t err; - - err = mach_msg (&msg, MACH_RCV_MSG, 0, sizeof msg, - data->wakeupmsg.msgh_remote_port, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - assert_perror (err); -} - -static int _sem_timedwait_internal (ddekit_sem_t *restrict sem, - const int timeout) -{ - pthread_spin_lock (&sem->lock); - if (sem->value > 0) { - /* Successful down. */ - sem->value --; - pthread_spin_unlock (&sem->lock); - return 0; - } - - if (timeout < 0) { - pthread_spin_unlock (&sem->lock); - errno = EINVAL; - return -1; - } - - /* Add ourselves to the queue. */ - add_entry_head (&sem->head, &thread_self->private->list); - pthread_spin_unlock (&sem->lock); - - /* Block the thread. */ - if (timeout) { - error_t err; - - err = _timedblock (thread_self->private, timeout); - if (err) { - /* We timed out. We may need to disconnect ourself from the - waiter queue. - - FIXME: What do we do if we get a wakeup message before we - disconnect ourself? It may remain until the next time we - block. */ - assert (err == ETIMEDOUT); - - pthread_spin_lock (&sem->lock); - remove_entry (&thread_self->private->list); - pthread_spin_unlock (&sem->lock); - - errno = err; - return -1; + int ret; + if (timeout) + { + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + + ts.tv_nsec += (timeout%1000) * 1000000; + if (ts.tv_nsec >= 1000000000) { + ts.tv_nsec -= 1000000000; + ts.tv_sec += 1; } + ts.tv_sec += timeout/1000; + do + ret = sem_timedwait(&sem->sem, &ts); + while (ret == -1 && errno == EINTR); + return ret; } else - _block (thread_self->private); - - return 0; -} - -/* Wakeup THREAD. */ -static void _thread_wakeup (struct _ddekit_private_data *data) -{ - error_t err; - - err = mach_msg (&data->wakeupmsg, MACH_SEND_MSG, - sizeof (data->wakeupmsg), 0, MACH_PORT_NULL, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - assert_perror (err); + { + do + ret = sem_wait(&sem->sem); + while (ret == -1 && errno == EINTR); + return 0; + } } ddekit_sem_t *ddekit_sem_init(int value) { ddekit_sem_t *sem = (ddekit_sem_t *) ddekit_simple_malloc (sizeof (*sem)); - sem->lock = PTHREAD_SPINLOCK_INITIALIZER; - sem->head.prev = &sem->head; - sem->head.next = &sem->head; - sem->value = value; + sem_init(&sem->sem, 0, value); return sem; } void ddekit_sem_deinit(ddekit_sem_t *sem) { - if (!EMPTY_LIST (&sem->head)) { - error (0, EBUSY, "ddekit_sem_deinit"); - } - else - ddekit_simple_free(sem); + sem_destroy(&sem->sem); + ddekit_simple_free(sem); } void ddekit_sem_down(ddekit_sem_t *sem) { @@ -383,16 +269,7 @@ void ddekit_sem_down(ddekit_sem_t *sem) { /* returns 0 on success, != 0 when it would block */ int ddekit_sem_down_try(ddekit_sem_t *sem) { - pthread_spin_lock (&sem->lock); - if (sem->value > 0) { - /* Successful down. */ - sem->value --; - pthread_spin_unlock (&sem->lock); - return 0; - } - pthread_spin_unlock (&sem->lock); - - return -1; + return sem_trywait(&sem->sem); } /* returns 0 on success, != 0 on timeout */ @@ -402,33 +279,6 @@ int ddekit_sem_down_timed(ddekit_sem_t *sem, int timo) { } void ddekit_sem_up(ddekit_sem_t *sem) { - struct _ddekit_private_data *wakeup; - - pthread_spin_lock (&sem->lock); - if (sem->value > 0) { - /* Do a quick up. */ - assert (EMPTY_LIST (&sem->head)); - sem->value ++; - pthread_spin_unlock (&sem->lock); - return; - } - - if (EMPTY_LIST (&sem->head)) { - /* No one waiting. */ - sem->value = 1; - pthread_spin_unlock (&sem->lock); - return; - } - - /* Wake someone up. */ - - /* First dequeue someone. */ - wakeup = LIST_ENTRY (remove_entry_end (&sem->head), - struct _ddekit_private_data, list); - - /* Then drop the lock and transfer control. */ - pthread_spin_unlock (&sem->lock); - if (wakeup) - _thread_wakeup (wakeup); + sem_post(&sem->sem); } diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c index 6e1a61d..3238037 100644 --- a/libdiskfs/file-set-trans.c +++ b/libdiskfs/file-set-trans.c @@ -168,7 +168,20 @@ diskfs_S_file_set_translator (struct protid *cred, np->dn_stat.st_rdev = makedev (major, minor); } - diskfs_truncate (np, 0); + err = diskfs_truncate (np, 0); + if (err) + { + pthread_mutex_unlock (&np->lock); + return err; + } + + err = diskfs_set_translator (np, NULL, 0, cred); + if (err) + { + pthread_mutex_unlock (&np->lock); + return err; + } + if (newmode == S_IFLNK) { char *arg = passive + strlen (passive) + 1; diff --git a/libdiskfs/init-startup.c b/libdiskfs/init-startup.c index 14da003..c1407ed 100644 --- a/libdiskfs/init-startup.c +++ b/libdiskfs/init-startup.c @@ -223,5 +223,5 @@ _diskfs_init_completed () return; errout: - error (0, err, "Cannot request shutdown notification"); + error (0, err, "Warning: cannot request shutdown notification"); } diff --git a/libfshelp/fetch-control.c b/libfshelp/fetch-control.c index 26c12d8..91c65bb 100644 --- a/libfshelp/fetch-control.c +++ b/libfshelp/fetch-control.c @@ -19,13 +19,24 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "fshelp.h" +#include <assert.h> error_t fshelp_fetch_control (struct transbox *box, mach_port_t *control) { + error_t err = 0; *control = box->active; if (*control != MACH_PORT_NULL) - mach_port_mod_refs (mach_task_self (), *control, MACH_PORT_RIGHT_SEND, 1); - return 0; + err = mach_port_mod_refs (mach_task_self (), *control, + MACH_PORT_RIGHT_SEND, 1); + + if (err == KERN_INVALID_RIGHT) + { + err = mach_port_deallocate (mach_task_self (), *control); + assert_perror (err); + *control = box->active = MACH_PORT_NULL; + } + + return err; } diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c index c87bbaa..e043a67 100644 --- a/libfshelp/translator-list.c +++ b/libfshelp/translator-list.c @@ -53,8 +53,7 @@ translator_ihash_cleanup (void *element, void *arg) if (translator->pi) ports_port_deref (translator->pi); - /* No need to deallocate translator->active, we only keep the name of - the port, not a reference. */ + mach_port_deallocate (mach_task_self (), translator->active); free (translator->name); free (translator); } @@ -124,8 +123,10 @@ fshelp_set_active_translator (struct port_info *pi, t->pi = pi; } - /* No need to increment the reference count, we only keep the - name, not a reference. */ + if (MACH_PORT_VALID (t->active)) + mach_port_deallocate (mach_task_self (), t->active); + mach_port_mod_refs (mach_task_self (), active, + MACH_PORT_RIGHT_SEND, +1); t->active = active; } else diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c index 1588f63..576e767 100644 --- a/libports/manage-multithread.c +++ b/libports/manage-multithread.c @@ -68,6 +68,11 @@ adjust_priority (unsigned int totalthreads) goto error_pset_priv; err = thread_max_priority (self, pset_priv, 0); + /* If we are running in an unprivileged subhurd, we got a faked + privileged processor set port. This is indeed a kind of + permission problem, and we treat it as such. */ + if (err == KERN_INVALID_ARGUMENT) + err = EPERM; if (err) goto error_max_priority; diff --git a/proc/main.c b/proc/main.c index c4936f6..2c5ce55 100644 --- a/proc/main.c +++ b/proc/main.c @@ -80,6 +80,11 @@ increase_priority (void) goto out; err = thread_max_priority (mach_thread_self (), psetcntl, 0); + /* If we are running in an unprivileged subhurd, we got a faked + privileged processor set port. This is indeed a kind of + permission problem, and we treat it as such. */ + if (err == KERN_INVALID_ARGUMENT) + err = EPERM; if (err) goto out; @@ -155,7 +160,7 @@ main (int argc, char **argv, char **envp) /* Give ourselves good scheduling performance, because we are so important. */ err = increase_priority (); - if (err) + if (err && err != EPERM) error (0, err, "Increasing priority failed"); err = register_new_task_notification (_hurd_host_priv, diff --git a/procfs/rootdir.c b/procfs/rootdir.c index 8e7c659..748805e 100644 --- a/procfs/rootdir.c +++ b/procfs/rootdir.c @@ -272,27 +272,37 @@ rootdir_gc_meminfo (void *hook, char **contents, ssize_t *contents_len) struct vm_statistics vmstats; struct vm_cache_statistics cache_stats; default_pager_info_t swap; + FILE *m; error_t err; + m = open_memstream (contents, (size_t *) contents_len); + if (m == NULL) + { + err = ENOMEM; + goto out; + } + err = vm_statistics (mach_task_self (), &vmstats); if (err) - return EIO; + { + err = EIO; + goto out; + } err = vm_cache_statistics (mach_task_self (), &cache_stats); if (err) - return EIO; + { + err = EIO; + goto out; + } cnt = HOST_BASIC_INFO_COUNT; err = host_info (mach_host_self (), HOST_BASIC_INFO, (host_info_t) &hbi, &cnt); if (err) - return err; - - err = get_swapinfo (&swap); - if (err) - return err; + goto out; assert (cnt == HOST_BASIC_INFO_COUNT); - *contents_len = asprintf (contents, + fprintf (m, "MemTotal: %14lu kB\n" "MemFree: %14lu kB\n" "Buffers: %14lu kB\n" @@ -300,8 +310,6 @@ rootdir_gc_meminfo (void *hook, char **contents, ssize_t *contents_len) "Active: %14lu kB\n" "Inactive: %14lu kB\n" "Mlocked: %14lu kB\n" - "SwapTotal:%14lu kB\n" - "SwapFree: %14lu kB\n" , (long unsigned) hbi.memory_size / 1024, (long unsigned) vmstats.free_count * PAGE_SIZE / 1024, @@ -309,11 +317,23 @@ rootdir_gc_meminfo (void *hook, char **contents, ssize_t *contents_len) (long unsigned) cache_stats.cache_count * PAGE_SIZE / 1024, (long unsigned) vmstats.active_count * PAGE_SIZE / 1024, (long unsigned) vmstats.inactive_count * PAGE_SIZE / 1024, - (long unsigned) vmstats.wire_count * PAGE_SIZE / 1024, + (long unsigned) vmstats.wire_count * PAGE_SIZE / 1024); + + err = get_swapinfo (&swap); + if (err) + /* This is not fatal, we just omit the information. */ + err = 0; + else + fprintf (m, + "SwapTotal:%14lu kB\n" + "SwapFree: %14lu kB\n" + , (long unsigned) swap.dpi_total_space / 1024, (long unsigned) swap.dpi_free_space / 1024); - return 0; + out: + fclose (m); + return err; } static error_t diff --git a/random/gnupg-random.c b/random/gnupg-random.c index 3cf7812..a4df694 100644 --- a/random/gnupg-random.c +++ b/random/gnupg-random.c @@ -276,23 +276,21 @@ mix_pool(byte *pool) #if DIGESTLEN != 20 #error must have a digest length of 20 for ripe-md-160 #endif - /* loop over the pool */ + /* pool -> pool' */ pend = pool + POOLSIZE; memcpy(hashbuf, pend - DIGESTLEN, DIGESTLEN ); memcpy(hashbuf+DIGESTLEN, pool, BLOCKLEN-DIGESTLEN); rmd160_mixblock( &md, hashbuf); - memcpy(pool, hashbuf, 20 ); + memcpy(pool, hashbuf, DIGESTLEN); + /* Loop for the remaining iterations. */ p = pool; for( n=1; n < POOLBLOCKS; n++ ) { - memcpy(hashbuf, p, DIGESTLEN ); - - p += DIGESTLEN; - if( p+DIGESTLEN+BLOCKLEN < pend ) - memcpy(hashbuf+DIGESTLEN, p+DIGESTLEN, BLOCKLEN-DIGESTLEN); + if( p + BLOCKLEN < pend ) + memcpy(hashbuf, p, BLOCKLEN); else { - byte *pp = p+DIGESTLEN; - for(i=DIGESTLEN; i < BLOCKLEN; i++ ) { + byte *pp = p; + for(i=0; i < BLOCKLEN; i++ ) { if( pp >= pend ) pp = pool; hashbuf[i] = *pp++; @@ -300,7 +298,8 @@ mix_pool(byte *pool) } rmd160_mixblock( &md, hashbuf); - memcpy(p, hashbuf, 20 ); + p += DIGESTLEN; + memcpy(p, hashbuf, DIGESTLEN); } burn_stack (200); /* for the rmd160_mixblock() */ } diff --git a/random/random.c b/random/random.c index 8f76c5b..828e83a 100644 --- a/random/random.c +++ b/random/random.c @@ -639,7 +639,7 @@ main (int argc, char **argv) err = arrange_shutdown_notification (); if (err) - error (0, err, "Cannot request shutdown notification"); + error (0, err, "Warning: cannot request shutdown notification"); /* Launch. */ ports_manage_port_operations_multithread (fsys->pi.bucket, random_demuxer, diff --git a/startup/startup.c b/startup/startup.c index 49ba9ce..f54de5e 100644 --- a/startup/startup.c +++ b/startup/startup.c @@ -1202,6 +1202,8 @@ launch_something (const char *why) if (start_child (tries[try++], NULL) == 0) return; } + else + try++; } crash_system (); diff --git a/trans/crash.c b/trans/crash.c index 14783cf..f8e1658 100644 --- a/trans/crash.c +++ b/trans/crash.c @@ -30,6 +30,7 @@ #include <argz.h> #include <sys/mman.h> #include <assert.h> +#include <pthread.h> #include <version.h> @@ -71,6 +72,7 @@ enum crash_action static enum crash_action crash_how, crash_orphans_how; static char *corefile_template; +pthread_mutex_t corefile_template_lock = PTHREAD_MUTEX_INITIALIZER; @@ -336,12 +338,15 @@ S_crash_dump_task (mach_port_t port, if (!err) { file_t sink = core_file; + pthread_mutex_lock (&corefile_template_lock); if (corefile_template) { char *file_name; file_name = template_make_file_name (corefile_template, task, signo); + pthread_mutex_unlock (&corefile_template_lock); + if (file_name == NULL) error (0, errno, "template_make_file_name"); else @@ -356,6 +361,8 @@ S_crash_dump_task (mach_port_t port, free (file_name); } } + else + pthread_mutex_unlock (&corefile_template_lock); err = dump_core (task, sink, (off_t) -1, /* XXX should get core limit in RPC */ @@ -640,9 +647,26 @@ parse_opt (int opt, char *arg, struct argp_state *state) { char *errp; if (! template_valid (arg, &errp)) - error (1, 0, "Invalid template: ...'%s'", errp); + { + argp_error (state, "Invalid template: ...'%s'", errp); + return EINVAL; + } } - corefile_template = arg; + pthread_mutex_lock (&corefile_template_lock); + free (corefile_template); + if (strlen (arg) == 0) + corefile_template = NULL; + else + { + corefile_template = strdup (arg); + if (corefile_template == NULL) + { + pthread_mutex_unlock (&corefile_template_lock); + argp_failure (state, 1, errno, "strdup"); + return errno; + } + } + pthread_mutex_unlock (&corefile_template_lock); break; case ARGP_KEY_SUCCESS: @@ -686,6 +710,7 @@ trivfs_append_args (struct trivfs_control *fsys, err = argz_add (argz, argz_len, opt); } + pthread_mutex_lock (&corefile_template_lock); if (!err && corefile_template) { char *template; @@ -697,6 +722,7 @@ trivfs_append_args (struct trivfs_control *fsys, free (template); } } + pthread_mutex_unlock (&corefile_template_lock); return err; } diff --git a/trans/remap.c b/trans/remap.c index 5ee0189..5afbaa0 100644 --- a/trans/remap.c +++ b/trans/remap.c @@ -70,6 +70,7 @@ trivfs_S_dir_lookup (struct trivfs_protid *diruser, return EOPNOTSUPP; for (remap = remaps; remap; remap = remap->next) + /* FIXME: should match just prefix of filename too */ if (!strcmp (remap->from, filename)) { #ifdef DEBUG @@ -96,6 +97,12 @@ parse_opt (int key, char *arg, struct argp_state *state) switch (key) { case ARGP_KEY_ARG: + if (arg[0] != '/') + { + argp_error (state, "remap only works with absolute paths: %s", + arg); + return EINVAL; + } /* Skip heading slashes */ while (arg[0] == '/') diff --git a/utils/fakeroot.sh b/utils/fakeroot.sh index 7bc5dc7..daf18e7 100644 --- a/utils/fakeroot.sh +++ b/utils/fakeroot.sh @@ -54,6 +54,9 @@ if [ $# -eq 0 ]; then set -- ${SHELL:-/bin/sh} fi +FAKED_MODE="unknown-is-root" +export FAKED_MODE + # We exec settrans, which execs the "fakeauth" command in the chroot # context provided by /hurd/fakeroot. exec /bin/settrans \ diff --git a/utils/msgids.c b/utils/msgids.c index 4bc08de..d17f131 100644 --- a/utils/msgids.c +++ b/utils/msgids.c @@ -200,7 +200,10 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) case 'i': if (argz_add (&msgids_files_argz, &msgids_files_argz_len, arg) != 0) - error (1, errno, "argz_add"); + { + argp_failure (state, 1, errno, "argz_add"); + return errno; + } break; case 'I': -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hurd/hurd.git
