summaryrefslogtreecommitdiff
path: root/trans/symlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'trans/symlink.c')
-rw-r--r--trans/symlink.c97
1 files changed, 62 insertions, 35 deletions
diff --git a/trans/symlink.c b/trans/symlink.c
index d8495f8b..03b51003 100644
--- a/trans/symlink.c
+++ b/trans/symlink.c
@@ -1,5 +1,5 @@
/* Translator for S_IFLNK nodes
- Copyright (C) 1994 Free Software Foundation
+ Copyright (C) 1994, 2000, 2001, 2002 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
@@ -17,8 +17,14 @@
#include <hurd.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <argp.h>
#include <hurd/fsys.h>
#include <fcntl.h>
+#include <errno.h>
+#include <error.h>
+#include <version.h>
#include "fsys_S.h"
mach_port_t realnode;
@@ -31,37 +37,64 @@ char *linktarget;
extern int fsys_server (mach_msg_header_t *, mach_msg_header_t *);
+const char *argp_program_version = STANDARD_HURD_VERSION (symlink);
+
+static const struct argp_option options[] =
+ {
+ { 0 }
+ };
+
+static const char args_doc[] = "TARGET";
+static const char doc[] = "A translator for symlinks."
+"\vA symlink is an alias for another node in the filesystem."
+"\n"
+"\nA symbolic link refers to its target `by name', and contains no actual"
+" reference to the target. The target referenced by the symlink is"
+" looked up in the namespace of the client.";
+
+/* Parse a single option/argument. */
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ if (key == ARGP_KEY_ARG && state->arg_num == 0)
+ linktarget = arg;
+ else if (key == ARGP_KEY_ARG || key == ARGP_KEY_NO_ARGS)
+ argp_usage (state);
+ else
+ return ARGP_ERR_UNKNOWN;
+ return 0;
+}
+
+static struct argp argp = { options, parse_opt, args_doc, doc };
+
+
int
main (int argc, char **argv)
{
mach_port_t bootstrap;
mach_port_t control;
- error_t error;
-
+ error_t err;
+
+ /* Parse our options... */
+ argp_parse (&argp, argc, argv, 0, 0, 0);
+
task_get_bootstrap_port (mach_task_self (), &bootstrap);
if (bootstrap == MACH_PORT_NULL)
- {
- fprintf (stderr, "%s must be started as a translator\n", argv[0]);
- exit (1);
- }
-
- if (argc != 2)
- {
- fprintf (stderr, "Usage: %s link-target\n", argv[0]);
- exit (1);
- }
+ error (1, 0, "Must be started as a translator");
linktarget = argv[1];
/* Reply to our parent */
mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &control);
- error =
- fsys_startup (bootstrap, 0, control, MACH_MSG_TYPE_MAKE_SEND, &realnode);
- if (error)
- {
- perror ("Starting up translator");
- exit (1);
- }
+ mach_port_insert_right (mach_task_self (), control, control,
+ MACH_MSG_TYPE_MAKE_SEND);
+ err =
+ fsys_startup (bootstrap, 0, control, MACH_MSG_TYPE_COPY_SEND, &realnode);
+ mach_port_deallocate (mach_task_self (), control);
+ mach_port_deallocate (mach_task_self (), bootstrap);
+ if (err)
+ error (1, err, "Starting up translator");
+
io_restrict_auth (realnode, &realnodenoauth, 0, 0, 0, 0);
mach_port_deallocate (mach_task_self (), realnode);
@@ -69,9 +102,9 @@ main (int argc, char **argv)
while (1)
{
/* The timeout here is 10 minutes */
- error = mach_msg_server_timeout (fsys_server, 0, control,
- MACH_RCV_TIMEOUT, 1000 * 60 * 10);
- if (error == MACH_RCV_TIMED_OUT)
+ err = mach_msg_server_timeout (fsys_server, 0, control,
+ MACH_RCV_TIMEOUT, 1000 * 60 * 10);
+ if (err == MACH_RCV_TIMED_OUT)
exit (0);
}
}
@@ -79,10 +112,8 @@ main (int argc, char **argv)
error_t
S_fsys_getroot (mach_port_t fsys_t,
mach_port_t dotdotnode,
- uid_t *uids,
- u_int nuids,
- uid_t *gids,
- u_int ngids,
+ uid_t *uids, size_t nuids,
+ uid_t *gids, size_t ngids,
int flags,
retry_type *do_retry,
char *retry_name,
@@ -126,8 +157,7 @@ S_fsys_startup (mach_port_t bootstrap, int flags, mach_port_t control,
}
error_t
-S_fsys_goaway (mach_port_t control,
- int flags)
+S_fsys_goaway (mach_port_t control, int flags)
{
exit (0);
}
@@ -157,12 +187,9 @@ S_fsys_get_options (mach_port_t control,
error_t
S_fsys_getfile (mach_port_t control,
- uid_t *uids,
- u_int nuids,
- uid_t *gids,
- u_int ngids,
- char *handle,
- u_int handllen,
+ 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)
{