Use err[x]/warn[x] and improve error reporting
Submitted by: charnier
This commit is contained in:
parent
62e85934b8
commit
e1e9e15252
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=49376
@ -23,7 +23,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: pppctl.c,v 1.17 1999/01/31 12:24:29 brian Exp $
|
* $Id: pppctl.c,v 1.18 1999/04/26 08:53:52 brian Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -35,6 +35,7 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <histedit.h>
|
#include <histedit.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
@ -49,16 +50,16 @@
|
|||||||
static char Buffer[LINELEN], Command[LINELEN];
|
static char Buffer[LINELEN], Command[LINELEN];
|
||||||
|
|
||||||
static int
|
static int
|
||||||
Usage()
|
usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: pppctl [-v] [ -t n ] [ -p passwd ] "
|
fprintf(stderr, "usage: pppctl [-v] [-t n] [-p passwd] "
|
||||||
"Port|LocalSock [command[;command]...]\n");
|
"Port|LocalSock [command[;command]...]\n");
|
||||||
fprintf(stderr, " -v tells pppctl to output all"
|
fprintf(stderr, " -v tells pppctl to output all"
|
||||||
" conversation\n");
|
" conversation\n");
|
||||||
fprintf(stderr, " -t n specifies a timeout of n"
|
fprintf(stderr, " -t n specifies a timeout of n"
|
||||||
" seconds when connecting (default 2)\n");
|
" seconds when connecting (default 2)\n");
|
||||||
fprintf(stderr, " -p passwd specifies your password\n");
|
fprintf(stderr, " -p passwd specifies your password\n");
|
||||||
return 1;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int TimedOut = 0;
|
static int TimedOut = 0;
|
||||||
@ -198,7 +199,7 @@ main(int argc, char **argv)
|
|||||||
struct sockaddr *sock;
|
struct sockaddr *sock;
|
||||||
struct sockaddr_in ifsin;
|
struct sockaddr_in ifsin;
|
||||||
struct sockaddr_un ifsun;
|
struct sockaddr_un ifsun;
|
||||||
int socksz, arg, fd, len, verbose, err;
|
int socksz, arg, fd, len, verbose, save_errno;
|
||||||
unsigned TimeoutVal;
|
unsigned TimeoutVal;
|
||||||
char *DoneWord = "x", *next, *start;
|
char *DoneWord = "x", *next, *start;
|
||||||
struct sigaction act, oact;
|
struct sigaction act, oact;
|
||||||
@ -226,7 +227,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Usage();
|
usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -234,7 +235,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
if (argc < arg + 1)
|
if (argc < arg + 1)
|
||||||
return Usage();
|
usage();
|
||||||
|
|
||||||
if (*argv[arg] == '/') {
|
if (*argv[arg] == '/') {
|
||||||
sock = (struct sockaddr *)&ifsun;
|
sock = (struct sockaddr *)&ifsun;
|
||||||
@ -243,14 +244,14 @@ main(int argc, char **argv)
|
|||||||
memset(&ifsun, '\0', sizeof ifsun);
|
memset(&ifsun, '\0', sizeof ifsun);
|
||||||
ifsun.sun_len = strlen(argv[arg]);
|
ifsun.sun_len = strlen(argv[arg]);
|
||||||
if (ifsun.sun_len > sizeof ifsun.sun_path - 1) {
|
if (ifsun.sun_len > sizeof ifsun.sun_path - 1) {
|
||||||
fprintf(stderr, "%s: Path too long\n", argv[arg]);
|
warnx("%s: path too long", argv[arg]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ifsun.sun_family = AF_LOCAL;
|
ifsun.sun_family = AF_LOCAL;
|
||||||
strcpy(ifsun.sun_path, argv[arg]);
|
strcpy(ifsun.sun_path, argv[arg]);
|
||||||
|
|
||||||
if (fd = socket(AF_LOCAL, SOCK_STREAM, 0), fd < 0) {
|
if (fd = socket(AF_LOCAL, SOCK_STREAM, 0), fd < 0) {
|
||||||
fprintf(stderr, "Cannot create local domain socket\n");
|
warnx("cannot create local domain socket");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -273,11 +274,11 @@ main(int argc, char **argv)
|
|||||||
memset(&ifsin, '\0', sizeof ifsin);
|
memset(&ifsin, '\0', sizeof ifsin);
|
||||||
if (strspn(host, "0123456789.") == hlen) {
|
if (strspn(host, "0123456789.") == hlen) {
|
||||||
if (!inet_aton(host, &ifsin.sin_addr)) {
|
if (!inet_aton(host, &ifsin.sin_addr)) {
|
||||||
fprintf(stderr, "Cannot translate %s\n", host);
|
warnx("cannot translate %s", host);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if ((h = gethostbyname(host)) == 0) {
|
} else if ((h = gethostbyname(host)) == 0) {
|
||||||
fprintf(stderr, "Cannot resolve %s\n", host);
|
warnx("cannot resolve %s", host);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -289,8 +290,8 @@ main(int argc, char **argv)
|
|||||||
if (strspn(port, "0123456789") == strlen(port))
|
if (strspn(port, "0123456789") == strlen(port))
|
||||||
ifsin.sin_port = htons(atoi(port));
|
ifsin.sin_port = htons(atoi(port));
|
||||||
else if (s = getservbyname(port, "tcp"), !s) {
|
else if (s = getservbyname(port, "tcp"), !s) {
|
||||||
fprintf(stderr, "%s isn't a valid port or service!\n", port);
|
warnx("%s isn't a valid port or service!", port);
|
||||||
return Usage();
|
usage();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ifsin.sin_port = s->s_port;
|
ifsin.sin_port = s->s_port;
|
||||||
@ -299,7 +300,7 @@ main(int argc, char **argv)
|
|||||||
ifsin.sin_family = AF_INET;
|
ifsin.sin_family = AF_INET;
|
||||||
|
|
||||||
if (fd = socket(AF_INET, SOCK_STREAM, 0), fd < 0) {
|
if (fd = socket(AF_INET, SOCK_STREAM, 0), fd < 0) {
|
||||||
fprintf(stderr, "Cannot create internet socket\n");
|
warnx("cannot create internet socket");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,19 +315,20 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (connect(fd, sock, socksz) < 0) {
|
if (connect(fd, sock, socksz) < 0) {
|
||||||
err = errno;
|
|
||||||
if (TimeoutVal) {
|
if (TimeoutVal) {
|
||||||
|
save_errno = errno;
|
||||||
alarm(0);
|
alarm(0);
|
||||||
sigaction(SIGALRM, &oact, 0);
|
sigaction(SIGALRM, &oact, 0);
|
||||||
|
errno = save_errno;
|
||||||
}
|
}
|
||||||
if (TimedOut) {
|
if (TimedOut)
|
||||||
fputs("Timeout: ", stderr);
|
warnx("timeout: cannot connect to socket %s", argv[arg]);
|
||||||
err = 0;
|
else {
|
||||||
|
if (errno)
|
||||||
|
warn("cannot connect to socket %s", argv[arg]);
|
||||||
|
else
|
||||||
|
warnx("cannot connect to socket %s", argv[arg]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Cannot connect to socket %s", argv[arg]);
|
|
||||||
if (err)
|
|
||||||
fprintf(stderr, ": %s", strerror(err));
|
|
||||||
fputc('\n', stderr);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
@ -422,7 +424,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "ppp is not responding\n");
|
warnx("ppp is not responding");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user