diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | README | 25 | ||||
| -rw-r--r-- | lib.c | 59 | ||||
| -rw-r--r-- | persistent-hello.c | 13 | ||||
| -rw-r--r-- | reincarnation.c | 59 | ||||
| -rw-r--r-- | reincarnation.h | 8 | ||||
| -rw-r--r-- | stubs.c | 55 |
7 files changed, 165 insertions, 61 deletions
@@ -22,7 +22,7 @@ dir := reincarnation makemode := servers -SRCS = reincarnation.c persistent-hello.c +SRCS = reincarnation.c persistent-hello.c lib.c stubs.c OBJS = $(SRCS:.c=.o) \ notifyServer.o \ reincarnationServer.o \ @@ -33,7 +33,8 @@ HURDLIBS = fshelp trivfs ihash shouldbeinlibc include ../Makeconf -reincarnation: notifyServer.o reincarnationServer.o ../libfshelp/libfshelp.a +reincarnation: stubs.o notifyServer.o reincarnationServer.o \ + ../libfshelp/libfshelp.a persistent-hello: reincarnationUser.o ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a ../libihash/libihash.a -$(targets): %: %.o +$(targets): %: %.o lib.o @@ -0,0 +1,25 @@ +A reincarnation prototype for the Hurd +====================================== + +% ./reincarnation -c hi ./persistent-hello --content="hi there :) +" & +% cat hi +hi there :) +% pkill persistent-hell ; cat hi +hi there :) + +!!! run as root, libtrivfs allows only root to do this atm :( +# fsysopts hi "--contents=something else +" + +% cat hi +something else +% pkill persistent-hell ; cat hi +something else + +Whoa, persistent-hello got reincarnated and retained its +state. Unfortunately any client related state is currently lost, +including the ports: + +% ( pkill persistent-hell ; cat ) < hi +[1] 14400 resource lost ( pkill persistent-hell; cat; ) < hi @@ -0,0 +1,59 @@ +/* Reincarnation services for translators. + + Copyright (C) 2013 Free Software Foundation, Inc. + + Written by Justus Winter <4winter@informatik.uni-hamburg.de> + + This file might one day be a part of the GNU Hurd. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <mach/mach_param.h> +#include "reincarnation.h" + +error_t +reincarnation_set_port (task_t task, mach_port_t port) +{ + error_t err; + + mach_port_t *ports; + size_t ports_len; + err = mach_ports_lookup (task, + &ports, &ports_len); + if (err) + return err; + + ports[TASK_PORT_REGISTER_REINCARNATION] = port; + + err = mach_ports_register (task, + ports, + TASK_PORT_REGISTER_MAX); + return err; +} + +error_t +reincarnation_get_port (task_t task, mach_port_t *port) +{ + error_t err; + + mach_port_t *ports = NULL; + size_t ports_len = 0; + err = mach_ports_lookup (task, + &ports, &ports_len); + if (err) + return err; + + *port = ports[TASK_PORT_REGISTER_REINCARNATION]; + return 0; +} diff --git a/persistent-hello.c b/persistent-hello.c index 0efc60f..6274e99 100644 --- a/persistent-hello.c +++ b/persistent-hello.c @@ -302,16 +302,13 @@ main (int argc, char **argv) if (err) error (3, err, "trivfs_startup"); - /* Get reincarnation image. */ - mach_port_t *registered_ports = NULL; - size_t registered_ports_len = 0; - err = mach_ports_lookup (mach_task_self (), - ®istered_ports, ®istered_ports_len); + /* Get reincarnation port. */ + err = reincarnation_get_port (mach_task_self (), + &reincarnation); if (err) - error (5, err, "mach_port_lookup"); - - reincarnation = registered_ports[0]; + error (5, err, "reincarnation_get_port"); + /* Get reincarnation image. */ char *image = NULL; size_t image_len = 0; err = reincarnate (reincarnation, &image, &image_len); diff --git a/reincarnation.c b/reincarnation.c index 8f333cf..29b3505 100644 --- a/reincarnation.c +++ b/reincarnation.c @@ -70,7 +70,7 @@ int excl = 0; int timeout = DEFAULT_TIMEOUT * 1000; /* ms */ /* child stuff */ -mach_port_t ports[INIT_PORT_REINCARNATION + 1]; +mach_port_t ports[INIT_PORT_MAX]; mach_port_t fds[STDERR_FILENO + 1]; int ints[INIT_INT_MAX]; @@ -154,7 +154,7 @@ demuxer (mach_msg_header_t *inp, error_t prepare_child (void) { - for (int i = 0; i < INIT_PORT_REINCARNATION; i++) + for (int i = 0; i < INIT_PORT_MAX; i++) ports[i] = MACH_PORT_NULL; for (int i = 0; i < STDERR_FILENO + 1; i++) @@ -165,7 +165,6 @@ prepare_child (void) ports[INIT_PORT_CWDIR] = getcwdir (); ports[INIT_PORT_CRDIR] = getcrdir (); ports[INIT_PORT_AUTH] = getauth (); - ports[INIT_PORT_REINCARNATION] = reincarnation_port; fds[STDERR_FILENO] = getdport (STDERR_FILENO); return 0; @@ -183,22 +182,18 @@ main (int argc, char **argv) if (err) error (5, err, "mach_port_allocate"); - mach_msg_type_name_t acquired_type; - err = mach_port_extract_right (mach_task_self (), - reincarnation_port, - MACH_MSG_TYPE_MAKE_SEND, - &reincarnation_port, - &acquired_type); + err = mach_port_insert_right (mach_task_self (), + reincarnation_port, + reincarnation_port, + MACH_MSG_TYPE_MAKE_SEND); if (err) - error (3, err, "mach_port_extract_right"); + error (3, err, "mach_port_insert_right"); prepare_child (); - mach_port_t registered_ports[] = { reincarnation_port, }; - err = mach_ports_register (mach_task_self (), - ®istered_ports, 1); + err = reincarnation_set_port (mach_task_self (), reincarnation_port); if (err) - error (5, err, "mach_port_register"); + error (5, err, "reincarnation_set_port"); err = start_child (); if (err) @@ -259,7 +254,7 @@ start_child (void) fds, MACH_MSG_TYPE_COPY_SEND, STDERR_FILENO + 1, ports, MACH_MSG_TYPE_COPY_SEND, - INIT_PORT_REINCARNATION, + INIT_PORT_MAX, ints, INIT_INT_MAX, geteuid (), timeout, &active_control); @@ -336,38 +331,4 @@ S_checkpoint(mach_port_t server, stored_image_len = imageCnt; return 0; } - -/* Stubs for unused notification RPCs. */ - -kern_return_t -do_mach_notify_port_destroyed (mach_port_t notify, - mach_port_t rights) -{ - return EOPNOTSUPP; -} - -kern_return_t -do_mach_notify_send_once (mach_port_t notify) -{ - return EOPNOTSUPP; -} - -kern_return_t -do_mach_notify_no_senders (mach_port_t port, mach_port_mscount_t mscount) -{ - return EOPNOTSUPP; -} - -kern_return_t -do_mach_notify_port_deleted (mach_port_t notify, - mach_port_t name) -{ - return EOPNOTSUPP; -} -kern_return_t -do_mach_notify_msg_accepted (mach_port_t notify, - mach_port_t name) -{ - return EOPNOTSUPP; -} diff --git a/reincarnation.h b/reincarnation.h index 19a3a8d..7e1b16e 100644 --- a/reincarnation.h +++ b/reincarnation.h @@ -24,6 +24,12 @@ #include <hurd.h> -#define INIT_PORT_REINCARNATION INIT_PORT_MAX +#define TASK_PORT_REGISTER_REINCARNATION 0 + +error_t +reincarnation_set_port (task_t task, mach_port_t port); + +error_t +reincarnation_get_port (task_t task, mach_port_t *port); #endif /* __REINCARNATION_H__ */ @@ -0,0 +1,55 @@ +/* Stubs for unused notification RPCs. + + Copyright (C) 2013 Free Software Foundation, Inc. + + Written by Justus Winter <4winter@informatik.uni-hamburg.de> + + This file might one day be a part of the GNU Hurd. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <hurd.h> + +kern_return_t +do_mach_notify_port_destroyed (mach_port_t notify, + mach_port_t rights) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_send_once (mach_port_t notify) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_no_senders (mach_port_t port, mach_port_mscount_t mscount) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_port_deleted (mach_port_t notify, + mach_port_t name) +{ + return EOPNOTSUPP; +} + +kern_return_t +do_mach_notify_msg_accepted (mach_port_t notify, + mach_port_t name) +{ + return EOPNOTSUPP; +} |
