* Exit non-zero error code when flushroute() fails operating on the

routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
  diagnostic output (stdout).  The error diagnostic is still written
  to stderr.  [from FreeBSD]

* Use warn(3) in place of perror(3).
This commit is contained in:
ginsbach 2005-07-15 21:29:54 +00:00
parent 0df4f0ca31
commit d313757b82

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.82 2005/06/26 21:28:15 christos Exp $ */ /* $NetBSD: route.c,v 1.83 2005/07/15 21:29:54 ginsbach Exp $ */
/* /*
* Copyright (c) 1983, 1989, 1991, 1993 * Copyright (c) 1983, 1989, 1991, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1991, 1993\n\
#if 0 #if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else #else
__RCSID("$NetBSD: route.c,v 1.82 2005/06/26 21:28:15 christos Exp $"); __RCSID("$NetBSD: route.c,v 1.83 2005/07/15 21:29:54 ginsbach Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -329,7 +329,7 @@ bad: usage(*argv);
rlen = write(sock, next, rtm->rtm_msglen); rlen = write(sock, next, rtm->rtm_msglen);
if (rlen < (int)rtm->rtm_msglen) { if (rlen < (int)rtm->rtm_msglen) {
warn("write to routing socket, got %d for rlen", rlen); warn("write to routing socket, got %d for rlen", rlen);
break; return 1;
} }
seqno++; seqno++;
if (qflag) if (qflag)
@ -992,8 +992,8 @@ newroute(int argc, char **argv)
} }
if (*cmd == 'g') if (*cmd == 'g')
return rv; return rv;
oerrno = errno;
if (!qflag) { if (!qflag) {
oerrno = errno;
(void) printf("%s %s %s", cmd, ishost? "host" : "net", dest); (void) printf("%s %s %s", cmd, ishost? "host" : "net", dest);
if (*gateway) { if (*gateway) {
(void) printf(": gateway %s", gateway); (void) printf(": gateway %s", gateway);
@ -1003,26 +1003,25 @@ newroute(int argc, char **argv)
} }
if (ret == 0) if (ret == 0)
(void) printf("\n"); (void) printf("\n");
} else {
if (ret != 0) { switch (oerrno) {
switch (oerrno) { case ESRCH:
case ESRCH: error = "not in table";
error = "not in table"; break;
break; case EBUSY:
case EBUSY: error = "entry in use";
error = "entry in use"; break;
break; case ENOBUFS:
case ENOBUFS: error = "routing table overflow";
error = "routing table overflow"; break;
break; default:
default: error = strerror(oerrno);
error = strerror(oerrno); break;
break; }
(void) printf(": %s\n", error);
} }
(void) printf(": %s\n", error);
return 1;
} }
return 0; return (ret != 0);
} }
static void static void
@ -1552,7 +1551,7 @@ rtmsg(int cmd, int flags)
if (debugonly) if (debugonly)
return (0); return (0);
if ((rlen = write(sock, (char *)&m_rtmsg, l)) < 0) { if ((rlen = write(sock, (char *)&m_rtmsg, l)) < 0) {
perror("writing to routing socket"); warn("writing to routing socket");
return (-1); return (-1);
} }
#ifndef SMALL #ifndef SMALL