Improve error/help messages

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26992 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2008-10-30 14:22:19 +00:00
parent c8a82362f5
commit 09efb07075
2 changed files with 39 additions and 21 deletions

View file

@ -1,3 +1,8 @@
2008-10-30 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdomap.c: Improve error messages and information about
the -a option.
2008-10-29 Richard Frith-Macdonald <rfm@gnu.org> 2008-10-29 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSException.m: Fix stacktrace to be available when built * Source/NSException.m: Fix stacktrace to be available when built

View file

@ -97,6 +97,18 @@
#include <syslog.h> #include <syslog.h>
#endif #endif
#if HAVE_STRERROR
#define lastErr() strerror(errno)
#else
#ifdef __MINGW32__
static errbuf[BUFSIZ];
#define lastErr() (sprintf(errbuf, "WSAGetLastError()=%d", WSAGetLastError()), errbuf)
#else
static errbuf[BUFSIZ];
#define lastErr() (sprintf(errbuf, "%m"), errbuf)
#endif
#endif
#include "gdomap.h" #include "gdomap.h"
/* /*
* ABOUT THIS PROGRAM * ABOUT THIS PROGRAM
@ -1233,7 +1245,7 @@ init_iface()
int res = errno; int res = errno;
sprintf(ebuf, sprintf(ebuf,
"SIOCGIFCONF for init_iface found no active interfaces; %m"); "SIOCGIFCONF for init_iface found no active interfaces; %s", lastErr());
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
if (res == EINVAL) if (res == EINVAL)
@ -1242,7 +1254,8 @@ init_iface()
"Either you have too many network interfaces on your machine (in which case\n" "Either you have too many network interfaces on your machine (in which case\n"
"you need to change the 'MAX_IFACE' constant in gdomap.c and rebuild it), or\n" "you need to change the 'MAX_IFACE' constant in gdomap.c and rebuild it), or\n"
"your system is buggy, and you need to use the '-a' command line flag for\n" "your system is buggy, and you need to use the '-a' command line flag for\n"
"gdomap to manually set the interface addresses and masks to be used.\n"); "gdomap to manually set the interface addresses and masks to be used.\n"
"Try 'gdomap -C' for more information.\n");
gdomap_log(LOG_INFO); gdomap_log(LOG_INFO);
} }
close(desc); close(desc);
@ -1274,7 +1287,7 @@ init_iface()
if (ioctl(desc, SIOCGIFFLAGS, (char *)&ifreq) < 0) if (ioctl(desc, SIOCGIFFLAGS, (char *)&ifreq) < 0)
{ {
sprintf(ebuf, "SIOCGIFFLAGS: %m"); sprintf(ebuf, "SIOCGIFFLAGS: %s", lastErr());
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
} }
else if (ifreq.ifr_flags & IFF_UP) else if (ifreq.ifr_flags & IFF_UP)
@ -1301,7 +1314,7 @@ init_iface()
#endif #endif
if (ioctl(desc, SIOCGIFADDR, (char *)&ifreq) < 0) if (ioctl(desc, SIOCGIFADDR, (char *)&ifreq) < 0)
{ {
sprintf(ebuf, "SIOCGIFADDR: %m"); sprintf(ebuf, "SIOCGIFADDR: %s", lastErr());
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
} }
else if (ifreq.ifr_addr.sa_family == AF_INET) else if (ifreq.ifr_addr.sa_family == AF_INET)
@ -1312,7 +1325,8 @@ init_iface()
"You have too many network interfaces on your machine (in which case you need\n" "You have too many network interfaces on your machine (in which case you need\n"
"to change the 'MAX_IFACE' constant in gdomap.c and rebuild it), or your\n" "to change the 'MAX_IFACE' constant in gdomap.c and rebuild it), or your\n"
"system is buggy, and you need to use the '-a' command line flag for\n" "system is buggy, and you need to use the '-a' command line flag for\n"
"gdomap to manually set the interface addresses and masks to be used."); "gdomap to manually set the interface addresses and masks to be used.\n"
"Try 'gdomap -C' for more information.\n");
gdomap_log(LOG_INFO); gdomap_log(LOG_INFO);
close(desc); close(desc);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1325,7 +1339,7 @@ init_iface()
{ {
if (ioctl(desc, SIOCGIFDSTADDR, (char*)&ifreq) < 0) if (ioctl(desc, SIOCGIFDSTADDR, (char*)&ifreq) < 0)
{ {
sprintf(ebuf, "SIOCGIFADDR: %m"); sprintf(ebuf, "SIOCGIFADDR: %s", lastErr());
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
bcok[interfaces] = 0; bcok[interfaces] = 0;
} }
@ -1338,10 +1352,10 @@ init_iface()
else else
#endif #endif
{ {
if (!loopback && if (!loopback
ioctl(desc, SIOCGIFBRDADDR, (char*)&ifreq) < 0) && ioctl(desc, SIOCGIFBRDADDR, (char*)&ifreq) < 0)
{ {
sprintf(ebuf, "SIOCGIFBRDADDR: %m"); sprintf(ebuf, "SIOCGIFBRDADDR: %s", lastErr());
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
bcok[interfaces] = 0; bcok[interfaces] = 0;
} }
@ -1353,7 +1367,7 @@ init_iface()
} }
if (ioctl(desc, SIOCGIFNETMASK, (char *)&ifreq) < 0) if (ioctl(desc, SIOCGIFNETMASK, (char *)&ifreq) < 0)
{ {
sprintf(ebuf, "SIOCGIFNETMASK: %m"); sprintf(ebuf, "SIOCGIFNETMASK: %s", lastErr());
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
/* /*
* If we can't get a netmask - assume a class-c * If we can't get a netmask - assume a class-c
@ -1385,7 +1399,8 @@ init_iface()
if (interfaces == 0) if (interfaces == 0)
{ {
sprintf(ebuf, "I can't find any network interfaces on this platform - " sprintf(ebuf, "I can't find any network interfaces on this platform - "
"use the '-a' flag to load interface details from a file instead."); "use the '-a' flag to load interface details from a file instead.\n"
"Try 'gdomap -C' for more information.\n");
gdomap_log(LOG_CRIT); gdomap_log(LOG_CRIT);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -2506,12 +2521,7 @@ handle_recv()
{ {
if (debug) if (debug)
{ {
sprintf(ebuf, "recvfrom returned %d - " sprintf(ebuf, "recvfrom returned %d - %s", r, lastErr());
#ifdef __MINGW32__
"WSAGetLastError() = %d\n", r, WSAGetLastError());
#else
"%m", r);
#endif
gdomap_log(LOG_DEBUG); gdomap_log(LOG_DEBUG);
} }
clear_chan(udp_desc); clear_chan(udp_desc);
@ -4156,7 +4166,7 @@ static void do_help(int argc, char **argv, char *options)
} }
printf("%s -[%s]\n", argv[0], options); printf("%s -[%s]\n", argv[0], options);
printf("GNU Distributed Objects name server\n"); printf("GNU Distributed Objects name server\n");
printf("-C help about configuration\n"); printf("-C help about interfaces and configuration\n");
printf("-H general help\n"); printf("-H general help\n");
printf("-I pid file to write pid\n"); printf("-I pid file to write pid\n");
printf("-L name perform lookup for name then quit.\n"); printf("-L name perform lookup for name then quit.\n");
@ -4365,10 +4375,12 @@ printf(
"systems, this facility is not available (or is broken), so you must tell\n" "systems, this facility is not available (or is broken), so you must tell\n"
"gdomap the addresses and masks of the interfaces using the '-a' command line\n" "gdomap the addresses and masks of the interfaces using the '-a' command line\n"
"option. The file named with '-a' should contain a series of lines with\n" "option. The file named with '-a' should contain a series of lines with\n"
"space separated pairs of addresses and masks in 'dot' notation.\n" "space separated pairs of addresses and masks in 'dot' notation, eg.\n"
"192.168.1.2 255.255.255.0\n"
"You must NOT include loopback interfaces in this list.\n" "You must NOT include loopback interfaces in this list.\n"
"If you want to support broadcasting of probe information on a network,\n" "If you want to support broadcasting of probe information on a network,\n"
"you may supply the broadcast address as a third item on the line.\n" "you may supply the broadcast address as a third item on the line, eg.\n"
"192.168.1.9 255.255.255.0 192.168.1.255\n"
"If your operating system has some other method of giving you a list of\n" "If your operating system has some other method of giving you a list of\n"
"network interfaces and masks, please send me example code so that I can\n" "network interfaces and masks, please send me example code so that I can\n"
"implement it in gdomap.\n"); "implement it in gdomap.\n");
@ -4697,7 +4709,8 @@ printf(
sprintf(ebuf, "I can't find the loopback interface on this machine."); sprintf(ebuf, "I can't find the loopback interface on this machine.");
gdomap_log(LOG_ERR); gdomap_log(LOG_ERR);
sprintf(ebuf, sprintf(ebuf,
"Perhaps you should correct your machine configuration or use the -a flag."); "Perhaps you should correct your machine configuration or use the -a flag.\n"
"Try 'gdomap -C' for more information.\n");
gdomap_log(LOG_INFO); gdomap_log(LOG_INFO);
if (interfaces < MAX_IFACE) if (interfaces < MAX_IFACE)
{ {