summaryrefslogtreecommitdiff
path: root/debian/patches/0008-startup-bind-the-startup-server-to-servers-startup.patch
blob: d3633eb0aa999dedadf2b0a1d00ffdf07a546484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
From ccce2ecc7426fc65d05db387b5d8390644c17dc5 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Thu, 19 Sep 2013 09:15:02 +0200
Subject: [PATCH 8/8] startup: bind the startup server to /servers/startup

Previously, the Hurd (ab)used the fact that the startup server speaks
all protocols on its message port.  Any server that wished to register
for shutdown notifications would use XXX to get a port to the startup
server.

This hardcodes the PID of /hurd/startup, and does not allow one to
point a server to ones own startup server (e.g. using remap).

Bind the startup server to /servers/startup instead.  Use this to
contact the startup server.

* exec/main.c (S_exec_init): Use /servers/startup.  Fall back to the
old method so that the system still boots when the node
/servers/startup is missing.
* hurd/paths.h (_SERVERS_STARTUP): New macro.
* libdiskfs/boot-start.c (diskfs_S_fsys_init): Use /servers/startup.
* libdiskfs/init-startup.c (_diskfs_init_completed): Likewise.
* pfinet/main.c (arrange_shutdown_notification): Likewise.
* startup/Makefile (OBJS): Add fsysServer.o.
* startup/startup.c (demuxer): Handle the fsys protocol.
(main): Bind to /servers/startup.
(S_fsys_getroot): Implement fsys_getroot.  Stub out the rest.
---
 exec/main.c              |  11 ++++-
 hurd/paths.h             |   1 +
 libdiskfs/boot-start.c   |   9 ++--
 libdiskfs/init-startup.c |  13 ++++--
 pfinet/main.c            |  12 ++---
 startup/Makefile         |   2 +-
 startup/startup.c        | 119 +++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 146 insertions(+), 21 deletions(-)

diff --git a/exec/main.c b/exec/main.c
index 78faebd..664f150 100644
--- a/exec/main.c
+++ b/exec/main.c
@@ -251,8 +251,15 @@ S_exec_init (struct trivfs_protid *protid,
 
   proc_register_version (procserver, host_priv, "exec", "", HURD_VERSION);
 
-  err = proc_getmsgport (procserver, HURD_PID_STARTUP, &startup);
-  assert_perror (err);
+  startup = file_name_lookup (_SERVERS_STARTUP, 0, 0);
+  if (startup == MACH_PORT_NULL)
+    {
+      error (0, errno, "%s", _SERVERS_STARTUP);
+
+      /* Fall back to abusing the message port lookup.  */
+      err = proc_getmsgport (procserver, HURD_PID_STARTUP, &startup);
+      assert_perror (err);
+    }
   mach_port_deallocate (mach_task_self (), procserver);
 
   /* Call startup_essential task last; init assumes we are ready to
diff --git a/hurd/paths.h b/hurd/paths.h
index 489da57..568e45f 100644
--- a/hurd/paths.h
+++ b/hurd/paths.h
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define	_SERVERS		"/servers/"
 #define	_SERVERS_CRASH		_SERVERS "crash"
 #define	_SERVERS_EXEC		_SERVERS "exec"
+#define _SERVERS_STARTUP	_SERVERS "startup"
 #define _SERVERS_PROC		_SERVERS "proc"
 #define _SERVERS_PASSWORD	_SERVERS "password"
 #define _SERVERS_DEFPAGER	_SERVERS "default-pager"
diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c
index 42e991e..cfe2303 100644
--- a/libdiskfs/boot-start.c
+++ b/libdiskfs/boot-start.c
@@ -33,7 +33,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <string.h>
 #include <argz.h>
 #include <error.h>
-#include <pids.h>
 #include "exec_S.h"
 #include "exec_startup_S.h"
 #include "fsys_S.h"
@@ -602,9 +601,12 @@ diskfs_S_fsys_init (struct diskfs_control *pt,
 
   proc_register_version (procserver, host, diskfs_server_name, "",
 			 diskfs_server_version);
+  mach_port_deallocate (mach_task_self (), procserver);
 
-  err = proc_getmsgport (procserver, HURD_PID_STARTUP, &startup);
-  if (!err)
+  startup = file_name_lookup (_SERVERS_STARTUP, 0, 0);
+  if (startup == MACH_PORT_NULL)
+    error (0, errno, "%s", _SERVERS_STARTUP);
+  else
     {
       startup_essential_task (startup, mach_task_self (), MACH_PORT_NULL,
 			      diskfs_server_name, host);
@@ -612,7 +614,6 @@ diskfs_S_fsys_init (struct diskfs_control *pt,
     }
 
   mach_port_deallocate (mach_task_self (), host);
-  mach_port_deallocate (mach_task_self (), procserver);
 
   _diskfs_init_completed ();
 
diff --git a/libdiskfs/init-startup.c b/libdiskfs/init-startup.c
index d10c964..3a588e1 100644
--- a/libdiskfs/init-startup.c
+++ b/libdiskfs/init-startup.c
@@ -25,8 +25,8 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <fcntl.h>
 #include <error.h>
 #include <hurd/fsys.h>
+#include <hurd/paths.h>
 #include <hurd/startup.h>
-#include <pids.h>
 
 #include "startup_S.h"
 
@@ -195,15 +195,18 @@ _diskfs_init_completed ()
 
   /* Mark us as important.  */
   err = proc_mark_important (proc);
+  mach_port_deallocate (mach_task_self (), proc);
   /* This might fail due to permissions or because the old proc server
      is still running, ignore any such errors.  */
   if (err && err != EPERM && err != EMIG_BAD_ID)
     goto errout;
 
-  err = proc_getmsgport (proc, HURD_PID_STARTUP, &init);
-  mach_port_deallocate (mach_task_self (), proc);
-  if (err)
-    goto errout;
+  init = file_name_lookup (_SERVERS_STARTUP, 0, 0);
+  if (init == MACH_PORT_NULL)
+    {
+      err = errno;
+      goto errout;
+    }
 
   notify = ports_get_send_right (pi);
   ports_port_deref (pi);
diff --git a/pfinet/main.c b/pfinet/main.c
index 5b0262f..3cd5f13 100644
--- a/pfinet/main.c
+++ b/pfinet/main.c
@@ -24,11 +24,11 @@
 #include <arpa/inet.h>
 #include <error.h>
 #include <argp.h>
+#include <hurd/paths.h>
 #include <hurd/startup.h>
 #include <string.h>
 #include <fcntl.h>
 #include <version.h>
-#include <pids.h>
 
 /* Include Hurd's errno.h file, but don't include glue-include/hurd/errno.h,
    since it #undef's the errno macro. */
@@ -154,7 +154,6 @@ arrange_shutdown_notification ()
 {
   error_t err;
   mach_port_t initport, notify;
-  process_t procserver;
   struct port_info *pi;
 
   shutdown_notify_class = ports_create_class (0, 0);
@@ -169,13 +168,8 @@ arrange_shutdown_notification ()
   if (err)
     return;
 
-  procserver = getproc ();
-  if (!procserver)
-    return;
-
-  err = proc_getmsgport (procserver, HURD_PID_STARTUP, &initport);
-  mach_port_deallocate (mach_task_self (), procserver);
-  if (err)
+  initport = file_name_lookup (_SERVERS_STARTUP, 0, 0);
+  if (initport == MACH_PORT_NULL)
     return;
 
   notify = ports_get_send_right (pi);
diff --git a/startup/Makefile b/startup/Makefile
index 277fee4..23d35cb 100644
--- a/startup/Makefile
+++ b/startup/Makefile
@@ -21,7 +21,7 @@ makemode := server
 SRCS = startup.c
 OBJS = $(SRCS:.c=.o) \
        startupServer.o notifyServer.o startup_replyUser.o msgServer.o \
-       startup_notifyUser.o
+       startup_notifyUser.o fsysServer.o
 target = startup
 HURDLIBS = shouldbeinlibc
 
diff --git a/startup/startup.c b/startup/startup.c
index fe8471d..ff58270 100644
--- a/startup/startup.c
+++ b/startup/startup.c
@@ -504,9 +504,11 @@ demuxer (mach_msg_header_t *inp,
   extern int notify_server (mach_msg_header_t *, mach_msg_header_t *);
   extern int startup_server (mach_msg_header_t *, mach_msg_header_t *);
   extern int msg_server (mach_msg_header_t *, mach_msg_header_t *);
+  extern int fsys_server (mach_msg_header_t *, mach_msg_header_t *);
 
   return (notify_server (inp, outp) ||
 	  msg_server (inp, outp) ||
+	  fsys_server (inp, outp) ||
 	  startup_server (inp, outp));
 }
 
@@ -583,6 +585,18 @@ main (int argc, char **argv, char **envp)
   /* Crash if the boot filesystem task dies.  */
   request_dead_name (fstask);
 
+  file_t node = file_name_lookup (_SERVERS_STARTUP, O_NOTRANS, 0);
+  if (node == MACH_PORT_NULL)
+    error (0, errno, "%s", _SERVERS_STARTUP);
+  else
+    {
+      file_set_translator (node,
+			   0, FS_TRANS_SET, 0,
+			   NULL, 0,
+			   startup, MACH_MSG_TYPE_COPY_SEND);
+      mach_port_deallocate (mach_task_self (), node);
+    }
+
   /* Set up the set of ports we will pass to the programs we exec.  */
   for (i = 0; i < INIT_PORT_MAX; i++)
     switch (i)
@@ -1544,3 +1558,108 @@ S_msg_report_wait (mach_port_t process, thread_t thread,
   *rpc = 0;
   return 0;
 }
+
+/* fsys */
+error_t
+S_fsys_getroot (mach_port_t fsys_t,
+		mach_port_t dotdotnode,
+		uid_t *uids, size_t nuids,
+		uid_t *gids, size_t ngids,
+		int flags,
+		retry_type *do_retry,
+		char *retry_name,
+		mach_port_t *ret,
+		mach_msg_type_name_t *rettype)
+{
+  int is_root = 0;
+  size_t i;
+
+  for (i = 0; i < nuids; i++)
+    if (uids[i] == 0)
+      {
+        is_root = 1;
+        break;
+      }
+
+  if (! is_root)
+    return EPERM;
+
+  *do_retry = FS_RETRY_NORMAL;
+  *retry_name = '\0';
+  *ret = startup;
+  *rettype = MACH_MSG_TYPE_COPY_SEND;
+  return 0;
+}
+
+error_t
+S_fsys_goaway (mach_port_t control, int flags)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_startup (mach_port_t bootstrap, int flags, mach_port_t control,
+		mach_port_t *real, mach_msg_type_name_t *realtype)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_syncfs (mach_port_t control,
+	       int wait,
+	       int recurse)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_set_options (mach_port_t control,
+		    char *data, mach_msg_type_number_t len,
+		    int do_children)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_get_options (mach_port_t control,
+		    char **data, mach_msg_type_number_t *len)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_getfile (mach_port_t control,
+		uid_t *uids, size_t nuids,
+		uid_t *gids, size_t ngids,
+		char *handle, size_t handllen,
+		mach_port_t *pt,
+		mach_msg_type_name_t *pttype)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_getpriv (mach_port_t control,
+		mach_port_t *host_priv, mach_msg_type_name_t *host_priv_type,
+		mach_port_t *dev_master, mach_msg_type_name_t *dev_master_type,
+		task_t *fs_task, mach_msg_type_name_t *fs_task_type)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_init (mach_port_t control,
+	   mach_port_t reply,
+	   mach_msg_type_name_t replytype,
+	   mach_port_t proc,
+	   auth_t auth)
+{
+  return EOPNOTSUPP;
+}
+
+error_t
+S_fsys_forward (mach_port_t server, mach_port_t requestor,
+		char *argz, size_t argz_len)
+{
+  return EOPNOTSUPP;
+}
-- 
2.1.0