Browse Source

Fix/clean up return values checking.

tags/ggatessh-v1.0.0
pjd 20 years ago
parent
commit
b74b98f9de
4 changed files with 31 additions and 31 deletions
  1. +9
    -9
      ggatec/ggatec.c
  2. +11
    -11
      ggated/ggated.c
  3. +3
    -3
      ggatel/ggatel.c
  4. +8
    -8
      shared/ggate.c

+ 9
- 9
ggatec/ggatec.c View File

@@ -103,7 +103,7 @@ handshake(void)
} }
serv.sin_port = htons(port); serv.sin_port = htons(port);
sfd = socket(AF_INET, SOCK_STREAM, 0); sfd = socket(AF_INET, SOCK_STREAM, 0);
if (sfd < 0)
if (sfd == -1)
g_gate_xlog("Can't open socket: %s.", strerror(errno)); g_gate_xlog("Can't open socket: %s.", strerror(errno));
/* /*
* Some trivial network optimalization. * Some trivial network optimalization.
@@ -113,23 +113,23 @@ handshake(void)
int on = 1; int on = 1;


if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &on, if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &on,
sizeof(on)) < 0) {
sizeof(on)) == -1) {
g_gate_xlog("setsockopt() error: %s.", strerror(errno)); g_gate_xlog("setsockopt() error: %s.", strerror(errno));
} }
} }
bsize = rcvbuf; bsize = rcvbuf;
if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)))
if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1)
g_gate_xlog("setsockopt() error: %s.", strerror(errno)); g_gate_xlog("setsockopt() error: %s.", strerror(errno));
bsize = sndbuf; bsize = sndbuf;
if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)))
if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)) == -1)
g_gate_xlog("setsockopt() error: %s.", strerror(errno)); g_gate_xlog("setsockopt() error: %s.", strerror(errno));
tv.tv_sec = timeout; tv.tv_sec = timeout;
tv.tv_usec = 0; tv.tv_usec = 0;
if (setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) ||
setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
if (setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1 ||
setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
g_gate_xlog("setsockopt() error: %s.", strerror(errno)); g_gate_xlog("setsockopt() error: %s.", strerror(errno));
} }
if (connect(sfd, (struct sockaddr *)&serv, sizeof(serv)) < 0) {
if (connect(sfd, (struct sockaddr *)&serv, sizeof(serv)) == -1) {
g_gate_log(LOG_ERR, "Can't connect to server: %s.", g_gate_log(LOG_ERR, "Can't connect to server: %s.",
strerror(errno)); strerror(errno));
return (-1); return (-1);
@@ -294,7 +294,7 @@ serve_loop(int sfd)
if (error != EAGAIN) if (error != EAGAIN)
g_gate_xlog("%s.", strerror(error)); g_gate_xlog("%s.", strerror(error));
sfd = handshake(); sfd = handshake();
if (sfd < 0) {
if (sfd == -1) {
sleep(2); sleep(2);
continue; continue;
} }
@@ -332,7 +332,7 @@ g_gatec_create(void)
int sfd; int sfd;


sfd = handshake(); sfd = handshake();
if (sfd < 0)
if (sfd == -1)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
ggioc.gctl_version = G_GATE_VERSION; ggioc.gctl_version = G_GATE_VERSION;
ggioc.gctl_mediasize = mediasize; ggioc.gctl_mediasize = mediasize;


+ 11
- 11
ggated/ggated.c View File

@@ -575,14 +575,14 @@ main(int argc, char *argv[])


if (!g_gate_verbose) { if (!g_gate_verbose) {
/* Run in daemon mode. */ /* Run in daemon mode. */
if (daemon(0, 0) < 0)
if (daemon(0, 0) == -1)
g_gate_xlog("Can't daemonize: %s", strerror(errno)); g_gate_xlog("Can't daemonize: %s", strerror(errno));
} }


signal(SIGCHLD, SIG_IGN); signal(SIGCHLD, SIG_IGN);


sfd = socket(AF_INET, SOCK_STREAM, 0); sfd = socket(AF_INET, SOCK_STREAM, 0);
if (sfd < 0)
if (sfd == -1)
g_gate_xlog("Can't open stream socket: %s.", strerror(errno)); g_gate_xlog("Can't open stream socket: %s.", strerror(errno));
bzero(&serv, sizeof(serv)); bzero(&serv, sizeof(serv));
serv.sin_family = AF_INET; serv.sin_family = AF_INET;
@@ -591,27 +591,27 @@ main(int argc, char *argv[])
on = 1; on = 1;
if (nagle) { if (nagle) {
if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &on, if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &on,
sizeof(on)) < 0) {
sizeof(on)) == -1) {
g_gate_xlog("setsockopt() error: %s.", strerror(errno)); g_gate_xlog("setsockopt() error: %s.", strerror(errno));
} }
} }
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
g_gate_xlog("setsockopt(): %s.", strerror(errno)); g_gate_xlog("setsockopt(): %s.", strerror(errno));
bsize = rcvbuf; bsize = rcvbuf;
if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) < 0)
if (setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1)
g_gate_xlog("setsockopt(): %s.", strerror(errno)); g_gate_xlog("setsockopt(): %s.", strerror(errno));
bsize = sndbuf; bsize = sndbuf;
if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)) < 0)
if (setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)) == -1)
g_gate_xlog("setsockopt(): %s.", strerror(errno)); g_gate_xlog("setsockopt(): %s.", strerror(errno));
tv.tv_sec = 10; tv.tv_sec = 10;
tv.tv_usec = 0; tv.tv_usec = 0;
if (setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) ||
setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
if (setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1 ||
setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
g_gate_xlog("setsockopt() error: %s.", strerror(errno)); g_gate_xlog("setsockopt() error: %s.", strerror(errno));
} }
if (bind(sfd, (struct sockaddr *)&serv, sizeof(serv)) < 0)
if (bind(sfd, (struct sockaddr *)&serv, sizeof(serv)) == -1)
g_gate_xlog("bind(): %s.", strerror(errno)); g_gate_xlog("bind(): %s.", strerror(errno));
if (listen(sfd, 5) < 0)
if (listen(sfd, 5) == -1)
g_gate_xlog("listen(): %s.", strerror(errno)); g_gate_xlog("listen(): %s.", strerror(errno));


g_gate_log(LOG_INFO, "Listen on port: %d.", port); g_gate_log(LOG_INFO, "Listen on port: %d.", port);
@@ -621,7 +621,7 @@ main(int argc, char *argv[])
for (;;) { for (;;) {
fromlen = sizeof(from); fromlen = sizeof(from);
tmpsfd = accept(sfd, &from, &fromlen); tmpsfd = accept(sfd, &from, &fromlen);
if (tmpsfd < 0)
if (tmpsfd == -1)
g_gate_xlog("accept(): %s.", strerror(errno)); g_gate_xlog("accept(): %s.", strerror(errno));


if (got_sighup) { if (got_sighup) {


+ 3
- 3
ggatel/ggatel.c View File

@@ -77,7 +77,7 @@ g_gatel_serve(int fd)
size_t bsize; size_t bsize;


if (g_gate_verbose == 0) { if (g_gate_verbose == 0) {
if (daemon(0, 0) < 0) {
if (daemon(0, 0) == -1) {
g_gate_destroy(unit, 1); g_gate_destroy(unit, 1);
err(EXIT_FAILURE, "Cannot daemonize"); err(EXIT_FAILURE, "Cannot daemonize");
} }
@@ -161,7 +161,7 @@ g_gatel_create(void)
int fd; int fd;


fd = open(path, g_gate_openflags(flags)); fd = open(path, g_gate_openflags(flags));
if (fd < 0)
if (fd == -1)
err(EXIT_FAILURE, "Cannot open %s", path); err(EXIT_FAILURE, "Cannot open %s", path);
ggioc.gctl_version = G_GATE_VERSION; ggioc.gctl_version = G_GATE_VERSION;
ggioc.gctl_unit = unit; ggioc.gctl_unit = unit;
@@ -186,7 +186,7 @@ g_gatel_attach(void)
int fd; int fd;


fd = open(path, g_gate_openflags(flags)); fd = open(path, g_gate_openflags(flags));
if (fd < 0)
if (fd == -1)
err(EXIT_FAILURE, "Cannot open %s", path); err(EXIT_FAILURE, "Cannot open %s", path);
g_gatel_serve(fd); g_gatel_serve(fd);
} }


+ 8
- 8
shared/ggate.c View File

@@ -133,10 +133,10 @@ g_gate_mediasize(int fd)
off_t mediasize; off_t mediasize;
struct stat sb; struct stat sb;


if (fstat(fd, &sb) < 0)
if (fstat(fd, &sb) == -1)
g_gate_xlog("fstat(): %s.", strerror(errno)); g_gate_xlog("fstat(): %s.", strerror(errno));
if (S_ISCHR(sb.st_mode)) { if (S_ISCHR(sb.st_mode)) {
if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) {
if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) == -1) {
g_gate_xlog("Can't get media size: %s.", g_gate_xlog("Can't get media size: %s.",
strerror(errno)); strerror(errno));
} }
@@ -154,10 +154,10 @@ g_gate_sectorsize(int fd)
size_t secsize; size_t secsize;
struct stat sb; struct stat sb;


if (fstat(fd, &sb) < 0)
if (fstat(fd, &sb) == -1)
g_gate_xlog("fstat(): %s.", strerror(errno)); g_gate_xlog("fstat(): %s.", strerror(errno));
if (S_ISCHR(sb.st_mode)) { if (S_ISCHR(sb.st_mode)) {
if (ioctl(fd, DIOCGSECTORSIZE, &secsize) < 0) {
if (ioctl(fd, DIOCGSECTORSIZE, &secsize) == -1) {
g_gate_xlog("Can't get sector size: %s.", g_gate_xlog("Can't get sector size: %s.",
strerror(errno)); strerror(errno));
} }
@@ -174,7 +174,7 @@ g_gate_open_device(void)
{ {


g_gate_devfd = open("/dev/" G_GATE_CTL_NAME, O_RDWR, 0); g_gate_devfd = open("/dev/" G_GATE_CTL_NAME, O_RDWR, 0);
if (g_gate_devfd < 0)
if (g_gate_devfd == -1)
err(EXIT_FAILURE, "open(/dev/%s)", G_GATE_CTL_NAME); err(EXIT_FAILURE, "open(/dev/%s)", G_GATE_CTL_NAME);
} }


@@ -189,7 +189,7 @@ void
g_gate_ioctl(unsigned long req, void *data) g_gate_ioctl(unsigned long req, void *data)
{ {


if (ioctl(g_gate_devfd, req, data) < 0) {
if (ioctl(g_gate_devfd, req, data) == -1) {
g_gate_xlog("%s: ioctl(/dev/%s): %s.", getprogname(), g_gate_xlog("%s: ioctl(/dev/%s): %s.", getprogname(),
G_GATE_CTL_NAME, strerror(errno)); G_GATE_CTL_NAME, strerror(errno));
} }
@@ -221,9 +221,9 @@ void
g_gate_load_module(void) g_gate_load_module(void)
{ {


if (modfind("g_gate") < 0) {
if (modfind("g_gate") == -1) {
/* Not present in kernel, try loading it. */ /* Not present in kernel, try loading it. */
if (kldload("geom_gate") < 0 || modfind("g_gate") < 0) {
if (kldload("geom_gate") == -1 || modfind("g_gate") == -1) {
if (errno != EEXIST) { if (errno != EEXIST) {
errx(EXIT_FAILURE, errx(EXIT_FAILURE,
"geom_gate module not available!"); "geom_gate module not available!");


Loading…
Cancel
Save