bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

zealous use of error


From: James A Morrison
Subject: zealous use of error
Date: Sun, 24 Mar 2002 10:04:57 -0500 (EST)

Hi,

  Here is my patch that is overzealous in the use of error ;)
I didn't touch any code that was copyrighted UC Berkeley or CMU, nor did
I touch any code that didn't compile already.

  This patch includes the previous patch because they are related.

  I changed symlink so that it checks the number of arguments it has
before checking to see if it started as a translator to match the behaviour
of other translators.

2002-03-23  James A. Morrison  <ja2morri@uwaterloo.ca>

boot:   
        * boot.c (main): Use error, not perror and exit.

console:
        * main.c (main): Use error, not fprintf, to stderr, and exit.

daemons:
        * console-run.c (open_console): Use err, not errno.

fstests:
        * fstests.c (main): Use error, not perror.
        * timertest.c (main): Use error, not perror and exit.

init:
        * init.c (reboot_mach): Use err, not errno.
        (run): Likewise.
        (lauch_core_servers): Likewise.
        (run_for_real): Check against MACH_PORT_NULL instead of not(!) for 
        failure.
        (start_child): Likewise.

libdiskfs:
        * init-startup.c (_diskfs_init_completed): Use error, not fprintf to
        stderr.

libnetfs:
        * make-protid.c (netfs_make_protid): Use err, not errno.

nfs:
        * main.c (main): Use error, not perror and exit.  Use err, not errno.
        * mount.c (mount_root): Likewise.
        * rpc.c (rpc_receive_thread): Use error, not perror.

nfsd:
        * fsys.c (init_filesystems): Use error, not fprintf to stderr.
        (write_filesystems): Use error, not fprintf to stderr.  Use err, not
        errno.
        * main.c (main): Use error, not perror and exit.

sutils:
        * halt.c (main): Use error, not perror.
        * reboot.c (main): Likewise.
        * update.c (main): Use error, not perror and exit.

term:
        * main.c (main): Use error, not fprintf, to stderr, and exit or perror
        and exit.  Use err, not errno.  Check against MACH_PORT_NULL instead
        of not(!) for failure.
        * users.c (init_users): Use err, not errno.  Use error, not perror and
        exit.

trans:
        * ifsock.c (main): Use err, not errno.
        * symlink.c (main): Use error, not fprintf, to stderr, and exit.  Use
        error, not perror and exit.  Use err, not error.
        Check for proper usage of symlink before checking if symlink is started
        as a translator.

utils:
        * rpctrace.c (parse_msgid_list): Use err, not errno.
        * shd.c (reap): Use error, not perror.
        (run): Use error, not perror.  Use err, not errno.
        (command): Use error, not perror.
        (main): Use error, not perror.
        Index: boot/boot.c
===================================================================
RCS file: /cvsroot/hurd/hurd/boot/boot.c,v
retrieving revision 1.102
diff -u -p -r1.102 boot.c
--- boot/boot.c 7 Oct 2001 20:01:35 -0000       1.102
+++ boot/boot.c 24 Mar 2002 14:52:44 -0000
@@ -1,6 +1,6 @@
 /* Load a task using the single server, and then run it
    as if we were the kernel.
-   Copyright (C) 1993,94,95,96,97,98,99,2000,01 Free Software Foundation, Inc.
+   Copyright (C) 1993,94,95,96,97,98,99,2000,01,02 Free Software Foundation, 
Inc.
 
 This file is part of the GNU Hurd.
 
@@ -670,11 +670,8 @@ main (int argc, char **argv, char **envp
       FD_SET (0, &rmask);
       if (select (1, &rmask, 0, 0, 0) == 1)
        read_reply ();
-      else
-       {                       /* We hosed */
-         perror ("select");
-         exit (5);
-       }
+      else /* We hosed */
+       error (5, errno, "select");
     }
 
 /*  mach_msg_server (request_server, __vm_page_size * 2, receive_set); */
Index: console/main.c
===================================================================
RCS file: /cvsroot/hurd/hurd/console/main.c,v
retrieving revision 1.2
diff -u -p -r1.2 main.c
--- console/main.c      18 Mar 2002 06:57:51 -0000      1.2
+++ console/main.c      24 Mar 2002 14:52:44 -0000
@@ -129,10 +129,7 @@ main (int argc, char **argv)
 
   task_get_bootstrap_port (mach_task_self (), &bootstrap);
   if (bootstrap == MACH_PORT_NULL)
-    {
-      fprintf (stderr, "Must be started as a translator\n");
-      exit (1);
-    }
+    error (1, 0, "Must be started as a translator");
 
   /* Set our node */
   err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &fsys);
Index: daemons/console-run.c
===================================================================
RCS file: /cvsroot/hurd/hurd/daemons/console-run.c,v
retrieving revision 1.4
diff -u -p -r1.4 console-run.c
--- daemons/console-run.c       30 Jan 2001 23:45:31 -0000      1.4
+++ daemons/console-run.c       24 Mar 2002 14:52:45 -0000
@@ -1,5 +1,5 @@
 /* Run a program on the console, trying hard to get the console open.
-   Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001,02 Free Software Foundation, Inc.
 
    This file is part of the GNU Hurd.
 
@@ -141,21 +141,21 @@ open_console (char **namep)
          termname = terminal + strlen (terminal) + 1; /* first arg is name */
 
          /* The callback to start_translator opens TERM as a side effect.  */
-         errno =
+         err =
            fshelp_start_translator (open_node, NULL, terminal, terminal,
                                     argz_len, 3000, &control);
-         if (errno)
+         if (err)
            {
-             error (0, errno, "%s", terminal);
+             error (0, err, "%s", terminal);
              continue;
            }
 
-         errno = file_set_translator (term, 0, FS_TRANS_SET, 0, 0, 0,
+         err = file_set_translator (term, 0, FS_TRANS_SET, 0, 0, 0,
                                       control, MACH_MSG_TYPE_COPY_SEND);
          mach_port_deallocate (mach_task_self (), control);
-         if (errno)
+         if (err)
            {
-             error (0, errno, "%s", termname);
+             error (0, err, "%s", termname);
              continue;
            }
          mach_port_deallocate (mach_task_self (), term);
@@ -167,10 +167,10 @@ open_console (char **namep)
              error (0, errno, "%s", termname);
              continue;
            }
-         errno = io_stat (term, &st);
-         if (errno)
+         err = io_stat (term, &st);
+         if (err)
            {
-             error (0, errno, "%s", termname);
+             error (0, err, "%s", termname);
              term = MACH_PORT_NULL;
              continue;
            }
Index: fstests/fstests.c
===================================================================
RCS file: /cvsroot/hurd/hurd/fstests/fstests.c,v
retrieving revision 1.24
diff -u -p -r1.24 fstests.c
--- fstests/fstests.c   5 Mar 2002 01:28:59 -0000       1.24
+++ fstests/fstests.c   24 Mar 2002 14:52:46 -0000
@@ -1,5 +1,5 @@
 /* Test filesystem behavior
-   Copyright (C) 1993,94,2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1993,94,2000,01,02 Free Software Foundation, Inc.
 
 This file is part of the GNU Hurd.
 
@@ -27,6 +27,7 @@ the Free Software Foundation, 675 Mass A
 #include <hurd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <error.h>
 #include <unistd.h>
 
 int check_refs (mach_port_t port) /* To call from gdb */
@@ -42,48 +43,48 @@ int
 main ()
 {
   mach_port_t root;
-#if 0
+#if HURDISH_TESTS
   extern file_t *_hurd_init_dtable;
   char string[] = "Did this get into the file?\n";
   file_t filetowrite;
   retry_type retry;
   char pathbuf[1024];
   int written;
-  int err;
+  error_t err;
 #endif
 
   root = getcrdir ();
 
   printf ("fstests running...\n");
 
-#if 0
+#if HURDISH_TESTS
   if ((err = dir_unlink (root, "CREATED")) && err != ENOENT)
-    printf ("Error on unlink: %d\n", err);
+    error (0, err, "Error on unlink");
   else if (err = dir_lookup (root, "CREATED", O_WRITE | O_CREAT, 0666,
                             &retry, pathbuf, &filetowrite))
-    printf ("Error on lookup: %d\n", err);
+    error (0, err, "Error on lookup");
   else if (err = io_write (filetowrite, string, strlen (string), -1, &written))
-    printf ("Error on write: %d\n", err);
+    error (0, err, "Error on write");
   else if (written != strlen (string))
-    printf ("Short write: %d\n", written);
+    error (0, 0, "Short write: %d\n", written);
   else if (err = file_syncfs (filetowrite, 1, 0))
-    printf ("Error on sync: %d\n", err);
+    error (0, err, "Error on sync");
 #else
 
   if (unlink ("/newdir"))
-    perror ("unlink");
+    error (0, errno, "unlink");
   if (rmdir ("/newdir"))
-    perror ("1st rmdir");
+    error (0, errno, "1st rmdir");
   if (mkdir ("/newdir", 0777))
-    perror ("1st mkdir");
+    error (0, errno, "1st mkdir");
   if (rename ("/newdir", "/newdir2"))
-    perror ("1st rename");
+    error (0, errno, "1st rename");
   if (rmdir ("/foo"))
-    perror ("2nd rmdir");
+    error (0, errno, "2nd rmdir");
   if (mkdir ("/foo", 0777))
-    perror ("2nd mkdir");
+    error (0, errno, "2nd mkdir");
   if (rename ("/newdir2", "/foo"))
-    perror ("2nd rename");
+    error (0, errno, "2nd rename");
   sync ();
 #endif
 
Index: fstests/timertest.c
===================================================================
RCS file: /cvsroot/hurd/hurd/fstests/timertest.c,v
retrieving revision 1.4
diff -u -p -r1.4 timertest.c
--- fstests/timertest.c 26 Feb 2001 04:14:34 -0000      1.4
+++ fstests/timertest.c 24 Mar 2002 14:52:46 -0000
@@ -1,5 +1,5 @@
-/*
-   Copyright (C) 1994, 2001 Free Software Foundation, Inc.
+/* A test for the Hurd timer and getchar
+   Copyright (C) 1994,2001,02 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -19,6 +19,8 @@
 #include <sys/time.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
+#include <error.h>
 
 void
 alarm_handler (int signo)
@@ -28,22 +30,19 @@ alarm_handler (int signo)
 }
 
 int
-main()
+main(int argc, char *argv[])
 {
   struct itimerval real_timer;
 
   real_timer.it_interval.tv_usec = 0;
   real_timer.it_interval.tv_sec = 1;
   real_timer.it_value.tv_usec = 0;
-  real_timer.it_value.tv_sec = 1;
+  real_timer.it_value.tv_sec = 4;
 
   signal (SIGALRM, alarm_handler);
 
   if (setitimer (ITIMER_REAL, &real_timer, 0) < 0)
-    {
-      perror ("Setting timer");
-      exit (1);
-    }
+    error (1, errno, "Setting timer");
 
   while (1)
     {
@@ -52,10 +51,7 @@ main()
       fflush (stdout);
       c = getchar ();
       if (ferror (stdin))
-       {
-         perror ("getchar");
-         exit (1);
-       }
+       error (1, errno, "getchar");
       if (c == EOF)
        {
          puts ("Saw EOF.  Pausing (no input)...");
Index: init/init.c
===================================================================
RCS file: /cvsroot/hurd/hurd/init/init.c,v
retrieving revision 1.127
diff -u -p -r1.127 init.c
--- init/init.c 2 Jan 2002 11:21:41 -0000       1.127
+++ init/init.c 24 Mar 2002 14:52:47 -0000
@@ -171,12 +171,13 @@ reboot_mach (int flags)
     }
   else
     {
+      error_t err;
       printf ("%s: %sing Mach (flags %#x)...\n",
              program_invocation_short_name, BOOT (flags), flags);
       fflush (stdout);
       sleep (5);
-      while ((errno = host_reboot (host_priv, flags)))
-       error (0, errno, "reboot");
+      while ((err = host_reboot (host_priv, flags)))
+       error (0, err, "reboot");
       for (;;);
     }
 }
@@ -357,6 +358,7 @@ run (const char *server, mach_port_t *po
   while (1)
     {
       file_t file;
+      error_t err;
 
       file = file_name_lookup (prog, O_EXEC, 0);
       if (file == MACH_PORT_NULL)
@@ -373,17 +375,17 @@ run (const char *server, mach_port_t *po
              printf ("Pausing for %s\n", prog);
              getchar ();
            }
-         errno = file_exec (file, *task, 0,
-                            (char *)prog, strlen (prog) + 1, /* Args.  */
-                            startup_envz, startup_envz_len,
-                            default_dtable, MACH_MSG_TYPE_COPY_SEND, 3,
-                            ports, MACH_MSG_TYPE_COPY_SEND, INIT_PORT_MAX,
-                            default_ints, INIT_INT_MAX,
-                            NULL, 0, NULL, 0);
-         if (!errno)
+         err = file_exec (file, *task, 0,
+                          (char *)prog, strlen (prog) + 1, /* Args.  */
+                          startup_envz, startup_envz_len,
+                          default_dtable, MACH_MSG_TYPE_COPY_SEND, 3,
+                          ports, MACH_MSG_TYPE_COPY_SEND, INIT_PORT_MAX,
+                          default_ints, INIT_INT_MAX,
+                          NULL, 0, NULL, 0);
+         if (!err)
            break;
 
-         error (0, errno, "%s", prog);
+         error (0, err, "%s", prog);
        }
 
       printf ("File name for server %s (or nothing to reboot): ", server);
@@ -426,13 +428,13 @@ run_for_real (char *filename, char *args
       if (getstring (buf, sizeof (buf)) && *buf)
        filename = buf;
       file = file_name_lookup (filename, O_EXEC, 0);
-      if (!file)
+      if (file == MACH_PORT_NULL)
        error (0, errno, "%s", filename);
     }
-  while (!file);
+  while (file == MACH_PORT_NULL);
 #else
   file = file_name_lookup (filename, O_EXEC, 0);
-  if (!file)
+  if (file == MACH_PORT_NULL)
     {
       error (0, errno, "%s", filename);
       return 0;
@@ -692,10 +694,10 @@ launch_core_servers (void)
     mach_port_deallocate (mach_task_self (), old);
 
   /* Give the bootstrap FS its proc and auth ports.  */
-  errno = fsys_init (bootport, fsproc, MACH_MSG_TYPE_COPY_SEND, authserver);
+  err = fsys_init (bootport, fsproc, MACH_MSG_TYPE_COPY_SEND, authserver);
   mach_port_deallocate (mach_task_self (), fsproc);
-  if (errno)
-    error (0, errno, "fsys_init"); /* Not necessarily fatal.  */
+  if (err)
+    error (0, err, "fsys_init"); /* Not necessarily fatal.  */
 }
 
 /* Set up the initial value of the standard exec data. */
@@ -1029,7 +1031,7 @@ start_child (const char *prog, char **pr
   assert_perror (err);
 
   file = file_name_lookup (args, O_EXEC, 0);
-  if (!file)
+  if (file == MACH_PORT_NULL)
     {
       error (0, errno, "%s", args);
       free (args);
Index: libdiskfs/init-startup.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/init-startup.c,v
retrieving revision 1.28
diff -u -p -r1.28 init-startup.c
--- libdiskfs/init-startup.c    15 Apr 2001 22:44:00 -0000      1.28
+++ libdiskfs/init-startup.c    24 Mar 2002 14:52:47 -0000
@@ -201,6 +201,5 @@ _diskfs_init_completed ()
   return;
 
  errout:
-  fprintf (stderr, "Cannot request shutdown notification: %s\n",
-          strerror (err));
+  error (0, err, "Cannot request shutdown notification");
 }
Index: libnetfs/make-protid.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/make-protid.c,v
retrieving revision 1.6
diff -u -p -r1.6 make-protid.c
--- libnetfs/make-protid.c      18 Nov 1996 23:51:10 -0000      1.6
+++ libnetfs/make-protid.c      24 Mar 2002 14:52:48 -0000
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -23,18 +23,22 @@
 struct protid *
 netfs_make_protid (struct peropen *po, struct iouser *cred)
 {
+  error_t err;
   struct protid *pi;
 
   if (cred)
-    errno = ports_create_port (netfs_protid_class, netfs_port_bucket, 
-                              sizeof (struct protid), &pi);
+    err = ports_create_port (netfs_protid_class, netfs_port_bucket, 
+                            sizeof (struct protid), &pi);
   else
-    errno = ports_create_port_noinstall (netfs_protid_class,
-                                        netfs_port_bucket, 
-                                        sizeof (struct protid), &pi);
+    err = ports_create_port_noinstall (netfs_protid_class,
+                                      netfs_port_bucket, 
+                                      sizeof (struct protid), &pi);
     
-  if (errno)
-    return 0;
+  if (err)
+    {
+      errno = err;
+      return 0;
+    }
 
   po->refcnt++;
   pi->po = po;
@@ -43,3 +47,4 @@ netfs_make_protid (struct peropen *po, s
   pi->mapped = 0;
   return pi;
 }
+
Index: nfs/main.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/main.c,v
retrieving revision 1.29
diff -u -p -r1.29 main.c
--- nfs/main.c  30 Jan 2001 00:38:45 -0000      1.29
+++ nfs/main.c  24 Mar 2002 14:52:50 -0000
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -345,6 +345,7 @@ parse_startup_opt (int key, char *arg, s
 int
 main (int argc, char **argv)
 {
+  error_t err;
   struct argp common_argp = { common_options, parse_common_opt };
   const struct argp_child argp_children[] =
     { {&common_argp}, {&netfs_std_startup_argp}, {0} };
@@ -378,14 +379,11 @@ main (int argc, char **argv)
     }
   while ((ret == -1) && (errno == EADDRINUSE));
   if (ret == -1)
-    {
-      perror ("binding main udp socket");
-      exit (1);
-    }
+    error (1, errno, "binding main udp socket");
 
-  errno = maptime_map (0, 0, &mapped_time);
-  if (errno)
-    error (2, errno, "mapping time");
+  err = maptime_map (0, 0, &mapped_time);
+  if (err)
+    error (2, err, "mapping time");
 
   cthread_detach (cthread_fork ((cthread_fn_t) timeout_service_thread, 0));
   cthread_detach (cthread_fork ((cthread_fn_t) rpc_receive_thread, 0));
Index: nfs/mount.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/mount.c,v
retrieving revision 1.24
diff -u -p -r1.24 mount.c
--- nfs/mount.c 29 Dec 2001 00:40:09 -0000      1.24
+++ nfs/mount.c 24 Mar 2002 14:52:50 -0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 1995,96,97,98,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,2001,02 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -101,6 +101,7 @@ mount_root (char *name, char *host)
   int *p;
   void *rpcbuf;
   int port;
+  error_t err;
   struct node *np;
   short pmapport;
 
@@ -145,14 +146,14 @@ mount_root (char *name, char *host)
       if (connect (main_udp_socket, (struct sockaddr *)&addr,
                   sizeof (struct sockaddr_in)) == -1)
        {
-         perror ("server mount program");
+         error (0, errno, "server mount program");
          return 0;
        }
 
       p = pmap_initialize_rpc (PMAPPROC_GETPORT, &rpcbuf);
       if (! p)
        {
-         perror ("creating rpc packet");
+         error (0, errno, "creating rpc packet");
          return 0;
        }
 
@@ -160,8 +161,8 @@ mount_root (char *name, char *host)
       *p++ = htonl (MOUNTVERS);
       *p++ = htonl (IPPROTO_UDP);
       *p++ = htonl (0);
-      errno = conduct_rpc (&rpcbuf, &p);
-      if (!errno)
+      err = conduct_rpc (&rpcbuf, &p);
+      if (!err)
        {
          port = ntohl (*p++);
          addr.sin_port = htons (port);
@@ -170,7 +171,7 @@ mount_root (char *name, char *host)
        addr.sin_port = htons (mount_port);
       else
        {
-         perror ("portmap of mount");
+         error (0, err, "portmap of mount");
          goto error_with_rpcbuf;
        }
       free (rpcbuf);
@@ -181,31 +182,31 @@ mount_root (char *name, char *host)
   if (connect (main_udp_socket, (struct sockaddr *) &addr,
               sizeof (struct sockaddr_in)) == -1)
     {
-      perror ("connect");
+      error (0, errno, "connect");
       goto error_with_rpcbuf;
     }
 
   p = mount_initialize_rpc (MOUNTPROC_MNT, &rpcbuf);
   if (! p)
     {
-      perror ("rpc");
+      error (0, errno, "rpc");
       goto error_with_rpcbuf;
     }
 
   p = xdr_encode_string (p, name);
-  errno = conduct_rpc (&rpcbuf, &p);
-  if (errno)
+  err = conduct_rpc (&rpcbuf, &p);
+  if (err)
     {
-      perror (name);
+      error (0, err, name);
       goto error_with_rpcbuf;
     }
   /* XXX Protocol spec says this should be a "unix error code"; we'll
      pretend that an NFS error code is what's meant; the numbers match
      anyhow.  */
-  errno = nfs_error_trans (htonl (*p++));
-  if (errno)
+  err = nfs_error_trans (htonl (*p++));
+  if (err)
     {
-      perror (name);
+      error (0, err, name);
       goto error_with_rpcbuf;
     }
 
@@ -223,28 +224,28 @@ mount_root (char *name, char *host)
       if (connect (main_udp_socket, (struct sockaddr *) &addr,
                   sizeof (struct sockaddr_in)) == -1)
        {
-         perror ("connect");
+         error (0, errno, "connect");
          return 0;
        }
 
       p = pmap_initialize_rpc (PMAPPROC_GETPORT, &rpcbuf);
       if (! p)
        {
-         perror ("rpc");
+         error (0, errno, "rpc");
          goto error_with_rpcbuf;
        }
       *p++ = htonl (NFS_PROGRAM);
       *p++ = htonl (NFS_VERSION);
       *p++ = htonl (IPPROTO_UDP);
       *p++ = htonl (0);
-      errno = conduct_rpc (&rpcbuf, &p);
-      if (!errno)
+      err = conduct_rpc (&rpcbuf, &p);
+      if (!err)
        port = ntohl (*p++);
       else if (nfs_port)
        port = nfs_port;
       else
        {
-         perror ("portmap of nfs server");
+         error (0, err, "portmap of nfs server");
          goto error_with_rpcbuf;
        }
       free (rpcbuf);
@@ -254,7 +255,7 @@ mount_root (char *name, char *host)
   if (connect (main_udp_socket, (struct sockaddr *) &addr,
               sizeof (struct sockaddr_in)) == -1)
     {
-      perror ("connect");
+      error (0, errno, "connect");
       return 0;
     }
 
Index: nfs/rpc.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/rpc.c,v
retrieving revision 1.10
diff -u -p -r1.10 rpc.c
--- nfs/rpc.c   30 Jan 2001 00:38:45 -0000      1.10
+++ nfs/rpc.c   24 Mar 2002 14:52:50 -0000
@@ -1,5 +1,5 @@
 /* SunRPC management for NFS client
-   Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation
+   Copyright (C) 1994, 1995, 1996, 1997, 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
@@ -33,6 +33,7 @@
 #include <netinet/in.h>
 #include <assert.h>
 #include <errno.h>
+#include <error.h>
 #include <unistd.h>
 #include <stdio.h>
 
@@ -370,7 +371,7 @@ rpc_receive_thread ()
       int cc = read (main_udp_socket, buf, 1024 + read_size);
       if (cc == -1)
         {
-          perror ("nfs read");
+          error (0, errno, "nfs read");
           continue;
         }
       else
Index: nfsd/fsys.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfsd/fsys.c,v
retrieving revision 1.2
diff -u -p -r1.2 fsys.c
--- nfsd/fsys.c 7 Aug 1996 19:03:28 -0000       1.2
+++ nfsd/fsys.c 24 Mar 2002 14:52:50 -0000
@@ -1,5 +1,5 @@
 /* Filesystem management for NFS server
-   Copyright (C) 1996 Free Software Foundation, Inc.
+   Copyright (C) 1996, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -65,8 +65,7 @@ init_filesystems (void)
   index_file = fopen (index_file_name, "r");
   if (!index_file)
     {
-      fprintf (stderr, "%s: Cannot open `%s': %s\n",
-              program_invocation_name, index_file_name, strerror (errno));
+      error (0, errno, "Cannot open `%s'", index_file_name);
       return;
     }
 
@@ -81,17 +80,15 @@ init_filesystems (void)
       
       if (nitems != 2)
        {
-         fprintf (stderr, "%s:%s:%d Bad syntax\n",
-                  program_invocation_name, index_file_name, line);
+         error (0, 0, "%s:%d Bad syntax", index_file_name, line);
          continue;
        }
 
       root = file_name_lookup (name, 0, 0);
-      if (!root)
+      if (root == MACH_PORT_NULL)
        {
-         fprintf (stderr, "%s:%s:%d Filesystem `%s': %s\n",
-                  program_invocation_name, index_file_name, line,
-                  name, strerror (errno));
+         error (0, errno, "%s:%d Filesystem `%s'", 
+                index_file_name, line, name);
          free (name);
          continue;
        }
@@ -123,6 +120,7 @@ write_filesystems (void)
 {
   file_t newindex;
   FILE *f;
+  error_t err;
   int i;
 
   if (!index_file_name)
@@ -133,19 +131,17 @@ write_filesystems (void)
       index_file_dir = file_name_split (index_file_name, &index_file_compname);
       if (index_file_dir == MACH_PORT_NULL)
        {
-         fprintf (stderr, "%s: `%s': %s\n",
-                  program_invocation_name, index_file_name, strerror (errno));
+         error (0, errno, "`%s'", index_file_name);
          index_file_name = 0;
          return;
        }
     }
 
   /* Create an anonymous file in the same directory */
-  errno = dir_mkfile (index_file_dir, O_WRONLY, 0666, &newindex);
-  if (errno)
+  err = dir_mkfile (index_file_dir, O_WRONLY, 0666, &newindex);
+  if (err)
     {
-      fprintf (stderr, "%s: `%s': %s\n",
-              program_invocation_name, index_file_name, strerror (errno));
+      error (0, err, "`%s'", index_file_name);
       index_file_name = 0;
       mach_port_deallocate (mach_task_self (), index_file_dir);
       index_file_dir = MACH_PORT_NULL;
@@ -159,10 +155,9 @@ write_filesystems (void)
       fprintf (f, "%d %s\n", i, fsystable[i].name);
 
   /* Link it in */
-  errno = dir_link (index_file_dir, newindex, index_file_compname, 0);
-  if (errno)
-    fprintf (stderr, "%s: `%s': %s\n",
-            program_invocation_name, index_file_name, strerror (errno));
+  err = dir_link (index_file_dir, newindex, index_file_compname, 0);
+  if (err)
+    error (0, err, "`%s'", index_file_name);
   fflush (f);
   file_sync (newindex, 1, 0);
   fclose (f);
Index: nfsd/main.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfsd/main.c,v
retrieving revision 1.4
diff -u -p -r1.4 main.c
--- nfsd/main.c 12 Aug 1996 18:30:28 -0000      1.4
+++ nfsd/main.c 24 Mar 2002 14:52:50 -0000
@@ -63,17 +63,12 @@ main (int argc, char **argv)
   fail = bind (main_udp_socket, (struct sockaddr *)&main_address,
               sizeof (struct sockaddr_in));
   if (fail)
-    {
-      perror ("Binding NFS socket");
-      exit (1);
-    }
+    error (1, errno, "Binding NFS socket");
+    
   fail = bind (pmap_udp_socket, (struct sockaddr *)&pmap_address,
               sizeof (struct sockaddr_in));
   if (fail)
-    {
-      perror ("Binding PMAP socket");
-      exit (1);
-    }
+    error (1, errno, "Binding PMAP socket");
 
   init_filesystems ();
 
Index: sutils/halt.c
===================================================================
RCS file: /cvsroot/hurd/hurd/sutils/halt.c,v
retrieving revision 1.6
diff -u -p -r1.6 halt.c
--- sutils/halt.c       20 Feb 1997 04:19:48 -0000      1.6
+++ sutils/halt.c       24 Mar 2002 14:52:56 -0000
@@ -1,5 +1,5 @@
 /* Halt the system
-   Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1994, 1996, 1997, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -34,6 +34,6 @@ main (int argc, char *argv[])
   struct argp argp = {0, 0, 0, "Halt the system"};
   argp_parse (&argp, argc, argv, 0, 0, 0);
   reboot (RB_HALT);
-  perror ("reboot");
+  error (1, errno, "reboot");
   return 1;
 }
Index: sutils/reboot.c
===================================================================
RCS file: /cvsroot/hurd/hurd/sutils/reboot.c,v
retrieving revision 1.6
diff -u -p -r1.6 reboot.c
--- sutils/reboot.c     20 Feb 1997 04:19:42 -0000      1.6
+++ sutils/reboot.c     24 Mar 2002 14:52:56 -0000
@@ -1,5 +1,5 @@
 /* Reboot the system
-   Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1994, 1996, 1997, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -34,6 +34,6 @@ main (int argc, char *argv[])
   struct argp argp = {0, 0, 0, "Reboot the system"};
   argp_parse (&argp, argc, argv, 0, 0, 0);
   reboot (0);
-  perror ("reboot");
+  error (1, errno, "reboot");
   return 1;
 }
Index: sutils/update.c
===================================================================
RCS file: /cvsroot/hurd/hurd/sutils/update.c,v
retrieving revision 1.4
diff -u -p -r1.4 update.c
--- sutils/update.c     1 Oct 1994 17:17:40 -0000       1.4
+++ sutils/update.c     24 Mar 2002 14:52:56 -0000
@@ -1,5 +1,5 @@
 /* Periodically call sync.
-   Copyright (C) 1994 Free Software Foundation, Inc.
+   Copyright (C) 1994, 2002 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -41,10 +41,7 @@ main (int argc, char **argv)
     }
   
   if (daemon (0, 0))
-    {
-      perror ("daemon");
-      exit (1);
-    }
+    error (1, errno, "daemon");
 
   for (;;)
     {
Index: term/main.c
===================================================================
RCS file: /cvsroot/hurd/hurd/term/main.c,v
retrieving revision 1.27
diff -u -p -r1.27 main.c
--- term/main.c 5 Mar 2002 02:17:04 -0000       1.27
+++ term/main.c 24 Mar 2002 14:52:56 -0000
@@ -26,6 +26,7 @@
 #include <argp.h>
 #include <hurd/fsys.h>
 #include <string.h>
+#include <error.h>
 
 #include <version.h>
 
@@ -148,6 +149,7 @@ main (int argc, char **argv)
   struct trivfs_control **ourcntl, **peercntl;
   mach_port_t bootstrap, right;
   struct stat st;
+  error_t err;
 
   term_bucket = ports_create_bucket ();
   
@@ -206,27 +208,20 @@ main (int argc, char **argv)
 
     default:
       /* Should not happen.  */
-      fprintf (stderr, "Unknown terminal type\n");
-      exit (1);
+      error (1, 0, "Unknown terminal type");
     }
   
   task_get_bootstrap_port (mach_task_self (), &bootstrap);
   
   if (bootstrap == MACH_PORT_NULL)
-    {
-      fprintf (stderr, "Must be started as a translator\n");
-      exit (1);
-    }
+    error (1, 0, "Must be started as a translator");
 
   /* Set our node.  */
-  errno = trivfs_startup (bootstrap, 0,
-                         ourcntlclass, term_bucket, ourclass, term_bucket,
-                         ourcntl);
-  if (errno)
-    {
-      perror ("Starting translator");
-      exit (1);
-    }
+  err = trivfs_startup (bootstrap, 0,
+                       ourcntlclass, term_bucket, ourclass, term_bucket,
+                       ourcntl);
+  if (err)
+    error (1, err, "Starting translator");
 
   /* For ptys, the nodename depends on which half is used.  For now just use
      the hook to store the nodename.  */
@@ -238,25 +233,22 @@ main (int argc, char **argv)
       char *peer_name = tty_arg;
       file_t file = file_name_lookup (peer_name, O_CREAT|O_NOTRANS, 0666);
 
-      if (file != MACH_PORT_NULL)
-       errno = 0;
+      if (file == MACH_PORT_NULL)
+       err = errno;
 
-      if (! errno)
-       errno = trivfs_create_control (file, peercntlclass, term_bucket,
-                                      peerclass, term_bucket, peercntl);
-      if (! errno)
+      if (! err)
+       err = trivfs_create_control (file, peercntlclass, term_bucket,
+                                    peerclass, term_bucket, peercntl);
+      if (! err)
        {
          right = ports_get_send_right (*peercntl);
-         errno = file_set_translator (file, 0, FS_TRANS_EXCL | FS_TRANS_SET,
+         err = file_set_translator (file, 0, FS_TRANS_EXCL | FS_TRANS_SET,
                                     0, 0, 0, right, MACH_MSG_TYPE_COPY_SEND);
          mach_port_deallocate (mach_task_self (), right);
        }
 
-      if (errno)
-       {
-         perror (peer_name);
-         exit (1);
-       }
+      if (err)
+         error (1, err, peer_name);
 
       (*peercntl)->hook = peer_name;
       ports_port_deref (*peercntl);
@@ -267,13 +259,13 @@ main (int argc, char **argv)
   mutex_init (&global_lock);
 
   /* Initialize status from underlying node.  */
-  errno = io_stat ((*ourcntl)->underlying, &st);
-  if (errno)
+  err = io_stat ((*ourcntl)->underlying, &st);
+  if (err)
     {
       /* We cannot stat the underlying node.  Fallback to the defaults.  */
       term_owner = term_group = 0;
       term_mode = (bottom == &ptyio_bottom ? DEFFILEMODE : S_IRUSR | S_IWUSR);
-      errno = 0;
+      err = 0;
     }
   else
     {
@@ -289,12 +281,9 @@ main (int argc, char **argv)
   
   outputq = create_queue (256, QUEUE_LOWAT, QUEUE_HIWAT);
   
-  errno = (*bottom->init) ();
-  if (errno)
-    {
-      perror ("Initializing bottom handler");
-      exit (1);
-    }
+  err = (*bottom->init) ();
+  if (err)
+    error (1, err, "Initializing bottom handler");
 
   condition_init (&carrier_alert);
   condition_init (&select_alert);
Index: term/users.c
===================================================================
RCS file: /cvsroot/hurd/hurd/term/users.c,v
retrieving revision 1.96
diff -u -p -r1.96 users.c
--- term/users.c        5 Mar 2002 02:17:04 -0000       1.96
+++ term/users.c        24 Mar 2002 14:52:56 -0000
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <hurd/iohelp.h>
 #include <hurd/fshelp.h>
+#include <error.h>
 #include "ourmsg_U.h"
 
 
@@ -84,13 +85,11 @@ struct protid_hook
 void
 init_users ()
 {
-  errno = ports_create_port (cttyid_class, term_bucket,
-                            sizeof (struct port_info), &cttyid);
-  if (errno)
-    {
-      perror ("Allocating cttyid");
-      exit (1);
-    }
+  error_t err;
+  err = ports_create_port (cttyid_class, term_bucket,
+                          sizeof (struct port_info), &cttyid);
+  if (err)
+    error (1, err, "Allocating cttyid");
 
   mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
                      &async_icky_id);
Index: trans/ifsock.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/ifsock.c,v
retrieving revision 1.9
diff -u -p -r1.9 ifsock.c
--- trans/ifsock.c      26 Feb 2001 04:16:01 -0000      1.9
+++ trans/ifsock.c      24 Mar 2002 14:52:56 -0000
@@ -1,5 +1,5 @@
 /* Server for S_IFSOCK nodes
-   Copyright (C) 1994, 1995, 2001 Free Software Foundation
+   Copyright (C) 1994, 1995, 2001, 02 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
@@ -89,8 +89,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);
     }
Index: trans/symlink.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/symlink.c,v
retrieving revision 1.11
diff -u -p -r1.11 symlink.c
--- trans/symlink.c     26 Feb 2001 04:16:01 -0000      1.11
+++ trans/symlink.c     24 Mar 2002 14:52:57 -0000
@@ -1,5 +1,5 @@
 /* Translator for S_IFLNK nodes
-   Copyright (C) 1994, 2000, 2001 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
@@ -21,6 +21,8 @@
 #include <string.h>
 #include <hurd/fsys.h>
 #include <fcntl.h>
+#include <errno.h>
+#include <error.h>
 #include "fsys_S.h"
 
 mach_port_t realnode;
@@ -38,14 +40,7 @@ main (int argc, char **argv)
 {
   mach_port_t bootstrap;
   mach_port_t control;
-  error_t error;
-
-  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);
-    }
+  error_t err;
 
   if (argc != 2)
     {
@@ -53,21 +48,24 @@ main (int argc, char **argv)
       exit (1);
     }
 
+  task_get_bootstrap_port (mach_task_self (), &bootstrap);
+  if (bootstrap == MACH_PORT_NULL)
+    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);
   mach_port_insert_right (mach_task_self (), control, control,
                          MACH_MSG_TYPE_MAKE_SEND);
-  error =
+  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 (error)
-    {
-      perror ("Starting up translator");
-      exit (1);
-    }
+  if (err)
+    error (1, err, "Starting up translator");
+
   io_restrict_auth (realnode, &realnodenoauth, 0, 0, 0, 0);
   mach_port_deallocate (mach_task_self (), realnode);
 
@@ -75,9 +73,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);
     }
 }
Index: utils/rpctrace.c
===================================================================
RCS file: /cvsroot/hurd/hurd/utils/rpctrace.c,v
retrieving revision 1.11
diff -u -p -r1.11 rpctrace.c
--- utils/rpctrace.c    30 Jan 2002 12:25:44 -0000      1.11
+++ utils/rpctrace.c    24 Mar 2002 14:52:57 -0000
@@ -79,6 +79,7 @@ parse_msgid_list (const char *filename)
   unsigned int lineno = 0;
   char *name, *subsystem;
   unsigned int msgid;
+  error_t err;
 
   fp = fopen (filename, "r");
   if (fp == 0)
@@ -103,9 +104,9 @@ parse_msgid_list (const char *filename)
            error (1, errno, "malloc");
          info->name = name;
          info->subsystem = subsystem;
-         errno = ihash_add (&msgid_ihash, msgid, info, NULL);
-         if (errno)
-           error (1, errno, "ihash_add");
+         err = ihash_add (&msgid_ihash, msgid, info, NULL);
+         if (err)
+           error (1, err, "ihash_add");
        }
     }
 
Index: utils/shd.c
===================================================================
RCS file: /cvsroot/hurd/hurd/utils/shd.c,v
retrieving revision 1.8
diff -u -p -r1.8 shd.c
--- utils/shd.c 2 Jan 2002 11:22:17 -0000       1.8
+++ utils/shd.c 24 Mar 2002 14:52:57 -0000
@@ -44,7 +44,7 @@ reap (pid_t waitfor)
       if (pid == -1)
        {
          if (errno != ECHILD && errno != EWOULDBLOCK)
-           perror ("waitpid");
+           error (0, errno, "waitpid");
          return;
        }
       else if (WIFEXITED (status))
@@ -69,6 +69,7 @@ run (char **argv, int fd0, int fd1)
 {
   file_t file;
   char *program;
+  error_t err;
 
   if (strchr (argv[0], '/') != NULL)
     program = argv[0];
@@ -84,7 +85,7 @@ run (char **argv, int fd0, int fd1)
   file = file_name_lookup (program, O_EXEC, 0);
   if (file == MACH_PORT_NULL)
     {
-      perror (program);
+      error (0, errno, program);
       return -1;
     }
   else
@@ -92,14 +93,14 @@ run (char **argv, int fd0, int fd1)
       task_t task;
       pid_t pid;
 
-      errno = task_create (mach_task_self (),
+      err = task_create (mach_task_self (),
 #ifdef KERN_INVALID_LEDGER
                           NULL, 0,     /* OSF Mach */
 #endif
                           0, &task);
-      if (errno)
+      if (err)
        {
-         perror ("task_create");
+         error (0, err, "task_create");
          pid = -1;
        }
       else
@@ -113,12 +114,12 @@ run (char **argv, int fd0, int fd1)
              *save = dup (to);
              if (*save < 0)
                {
-                 perror ("dup");
+                 error (0, errno, "dup");
                  return -1;
                }
              if (dup2 (from, to) != to)
                {
-                 perror ("dup2");
+                 error (0, errno, "dup2");
                  return -1;
                }
              close (from);
@@ -130,7 +131,7 @@ run (char **argv, int fd0, int fd1)
                return 0;
              if (dup2 (*save, to) != to)
                {
-                 perror ("dup2");
+                 error (0, errno, "dup2");
                  return -1;
                }
              close (*save);
@@ -139,10 +140,10 @@ run (char **argv, int fd0, int fd1)
 
          pid = task2pid (task);
          if (pid == -1)
-           perror ("task2pid"), pid = 0;
-         errno = proc_child (proc, task);
-         if (errno)
-           perror ("proc_child");
+           error (0, errno, "task2pid"), pid = 0;
+         err = proc_child (proc, task);
+         if (err)
+           error (0, err, "proc_child");
          if (pause_startup)
            {
              printf ("Pausing (child PID %d)...", pid);
@@ -154,24 +155,25 @@ run (char **argv, int fd0, int fd1)
              movefd (fd1, 1, &save1))
            return -1;
 
-         errno = _hurd_exec (task, file, argv, environ);
+         err = _hurd_exec (task, file, argv, environ);
 
          if (restorefd (fd0, 0, &save0) ||
              restorefd (fd1, 1, &save1))
            return -1;
 
-         if (errno)
+         if (err)
            {
-             perror ("_hurd_exec");
-             errno = task_terminate (task);
-             if (errno)
-               perror ("task_terminate");
+             error (0, err, "_hurd_exec");
+             err = task_terminate (task);
+             if (err)
+               error (0, err, "task_terminate");
            }
          mach_port_deallocate (mach_task_self (), task);
 
        }
       mach_port_deallocate (mach_task_self (), file);
 
+      errno = err;
       return pid;
     }
 }
@@ -196,7 +198,7 @@ command (int argc, char **argv)
        argv[i] = NULL;
        if (pipe (fds))
          {
-           perror ("pipe");
+           error (0, errno, "pipe");
            return;
          }
        pid = run (argv + start, fd0, fds[1]);
@@ -217,7 +219,7 @@ command (int argc, char **argv)
 
 
 int
-main ()
+main (int argc, char *argv[])
 {
   char *linebuf = NULL;
   size_t linebufsize = 0;
@@ -270,7 +272,7 @@ main ()
        {
          if (feof (stdin))
            return 0;
-         perror ("getline");
+         error (0, errno, "getline");
          continue;
        }
 
@@ -325,7 +327,7 @@ main ()
              if (argc != 2)
                fprintf (stderr, "Usage: cd DIRECTORY\n");
              else if (chdir (argv[1]))
-               perror ("chdir");
+               error (0, errno, "chdir");
            }
          else if (!strcmp (argv[0], "exec"))
            {
@@ -347,7 +349,7 @@ main ()
                  if (execv (program, &argv[1]) == 0)
                    fprintf (stderr, "execv (%s) returned 0!\n", program);
                  else
-                   perror ("execv");
+                   error (0, errno, "execv");
                }
            }
          else if (!strcmp (argv[0], "setenv"))
@@ -355,7 +357,7 @@ main ()
              if (argc != 3)
                fprintf (stderr, "Usage: setenv VAR VALUE\n");
              else if (setenv (argv[1], argv[2], 1))
-               perror ("setenv");
+               error (0, errno, "setenv");
            }
          else if (!strcmp (argv[0], "fork"))
            {
@@ -363,7 +365,7 @@ main ()
              switch (pid)
                {
                case -1:
-                 perror ("fork");
+                 error (0, errno, "fork");
                  break;
                case 0:
                  printf ("I am the child, PID %d.\n", (int) getpid ());



reply via email to

[Prev in Thread] Current Thread [Next in Thread]