diff options
Diffstat (limited to 'utils/devprobe.c')
-rw-r--r-- | utils/devprobe.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/utils/devprobe.c b/utils/devprobe.c index e29e1e32..d7020322 100644 --- a/utils/devprobe.c +++ b/utils/devprobe.c @@ -1,6 +1,6 @@ /* Check the existence of mach devices - Copyright (C) 1996 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> @@ -20,11 +20,13 @@ #include <stdio.h> #include <argp.h> -#include <error.h> #include <hurd.h> #include <mach.h> #include <device/device.h> +#include <version.h> + +const char *argp_program_version = STANDARD_HURD_VERSION (devprobe); static const struct argp_option options[] = { {"silent", 's', 0, 0, "Don't print devices found"}, @@ -33,19 +35,19 @@ static const struct argp_option options[] = { {0} }; static const char *args_doc = "DEVNAME..."; -static const char *doc = "The exit status is 0 if any devices were found."; +static const char *doc = "Test for the existence of mach device DEVNAME..." + "\vThe exit status is 0 if any devices were found."; int main (int argc, char **argv) { - error_t err; - mach_port_t device_master; /* Print devices found? (otherwise only exit status matters) */ int print = 1; /* If printing, print all devices on the command line that are found. Otherwise, just the first one found is printed. */ int all = 1; int found_one = 0; + mach_port_t device_master = MACH_PORT_NULL; /* Parse our options... */ error_t parse_opt (int key, char *arg, struct argp_state *state) @@ -65,10 +67,19 @@ main (int argc, char **argv) all = 0; break; case ARGP_KEY_ARG: - err = device_open (device_master, 0, arg, &device); + if (device_master == MACH_PORT_NULL) + { + err = get_privileged_ports (0, &device_master); + if (err) + argp_failure (state, 3, err, "Can't get device master port"); + } + + err = device_open (device_master, D_READ, arg, &device); if (err == 0) /* Got it. */ { + device_close (device); + /* Free the device port we got. */ mach_port_deallocate (mach_task_self (), device); @@ -84,7 +95,7 @@ main (int argc, char **argv) } else if (err != ED_NO_SUCH_DEVICE) /* Complain about unexpected errors. */ - error (0, err, "%s", arg); + argp_failure (state, 0, err, "%s", arg); break; default: @@ -94,10 +105,6 @@ main (int argc, char **argv) } const struct argp argp = { options, parse_opt, args_doc, doc }; - err = get_privileged_ports (0, &device_master); - if (err) - error (3, err, "Can't get device master port"); - /* Parse our arguments. */ argp_parse (&argp, argc, argv, 0, 0, 0); |