summaryrefslogtreecommitdiff
path: root/trans/ifsock.c
diff options
context:
space:
mode:
Diffstat (limited to 'trans/ifsock.c')
-rw-r--r--trans/ifsock.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/trans/ifsock.c b/trans/ifsock.c
index 2e53ea96..092bb40d 100644
--- a/trans/ifsock.c
+++ b/trans/ifsock.c
@@ -1,5 +1,5 @@
/* Server for S_IFSOCK nodes
- Copyright (C) 1994, 1995 Free Software Foundation
+ Copyright (C) 1994, 1995, 2001, 02, 2006 Free Software Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -23,11 +23,27 @@
#include <hurd/socket.h>
#include <hurd/fsys.h>
#include <stdio.h>
+#include <stdlib.h>
#include <error.h>
#include <fcntl.h>
+#include <argp.h>
+
+#include <sys/cdefs.h>
+#ifndef __XSTRING /* Could / should (?) be provided by glibc. */
+#define __XSTRING(x) __STRING(x) /* Expand x, then stringify. */
+#endif
+
+#include <version.h>
#include "ifsock_S.h"
+const char *argp_program_version = STANDARD_HURD_VERSION (ifsock);
+
+static const char doc[] = "A translator to provide Unix domain sockets."
+"\vThis translator acts as a hook for Unix domain sockets."
+" The pflocal translator on " _SERVERS_SOCKET "/" __XSTRING(PF_LOCAL)
+" implements the sockets.";
+
mach_port_t address_port;
struct port_class *control_class;
@@ -62,6 +78,9 @@ main (int argc, char **argv)
mach_port_t pflocal;
mach_port_t bootstrap;
char buf[512];
+ const struct argp argp = { 0, 0, 0, doc };
+
+ argp_parse (&argp, argc, argv, 0, 0, 0);
control_class = ports_create_class (trivfs_clean_cntl, 0);
node_class = ports_create_class (trivfs_clean_protid, 0);
@@ -72,10 +91,11 @@ main (int argc, char **argv)
task_get_bootstrap_port (mach_task_self (), &bootstrap);
if (bootstrap == MACH_PORT_NULL)
error(1, 0, "Must be started as a translator");
-
+
/* Reply to our parent */
err = trivfs_startup (bootstrap, 0, control_class, port_bucket,
node_class, port_bucket, NULL);
+ mach_port_deallocate (mach_task_self (), bootstrap);
if (err)
error(2, err, "Contacting parent");
@@ -87,8 +107,8 @@ main (int argc, char **argv)
address_port = MACH_PORT_NULL;
else
{
- errno = socket_fabricate_address (pflocal, AF_LOCAL, &address_port);
- if (errno)
+ err = socket_fabricate_address (pflocal, AF_LOCAL, &address_port);
+ if (err)
address_port = MACH_PORT_NULL;
mach_port_deallocate (mach_task_self (), pflocal);
}
@@ -97,7 +117,7 @@ main (int argc, char **argv)
ports_manage_port_operations_one_thread (port_bucket, demuxer, 0);
return 0;
}
-
+
void
trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
{
@@ -114,18 +134,18 @@ error_t
S_ifsock_getsockaddr (file_t sockfile,
mach_port_t *address)
{
- struct trivfs_protid *cred = ports_lookup_port (port_bucket, sockfile,
+ struct trivfs_protid *cred = ports_lookup_port (port_bucket, sockfile,
node_class);
int perms;
error_t err;
-
+
if (!cred)
return EOPNOTSUPP;
-
+
err = file_check_access (cred->realnode, &perms);
if (!err && !(perms & O_READ))
err = EACCES;
-
+
if (!err)
*address = address_port;
ports_port_deref (cred);