summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Hieber <r.hieber@pengutronix.de>2017-07-20 11:47:22 +0200
committerRoland Hieber <r.hieber@pengutronix.de>2017-07-25 21:26:09 +0200
commitd2398162c13915d8ca28f7f1fa582638bb90c678 (patch)
tree1736e0dfbe7cdb304fc12408543dabaf17ef5516
parent6acaeeb143e2b4a43a1366f672bdc87404ea50e6 (diff)
downloadurshd-d2398162c13915d8ca28f7f1fa582638bb90c678.tar.gz
urshd-d2398162c13915d8ca28f7f1fa582638bb90c678.tar.xz
urshd: prevent warnings when building debug version
When building on GCC 5.4.0 with --enable-debug, -Werror is in effect: make[2]: Entering directory 'urshd-1.0.2/src' arm-v7a-linux-gnueabi-gcc -DHAVE_CONFIG_H -I. -I../include -Wall -Wsign-compare -Wfloat-equal -Wformat-security -Werror -g -O1 -MT urshd.o -MD -MP -MF .deps/urshd.Tpo -c -o urshd.o urshd.c urshd.c: In function 'mainloop': urshd.c:582:1: error: no return statement in function returning non-void [-Werror=return-type] urshd.c:541:3: error: ignoring return value of 'daemon', declared with attribute warn_unused_result [-Werror=unused-result] urshd.c: In function 'doit': urshd.c:340:3: error: ignoring return value of 'chdir', declared with attribute warn_unused_result [-Werror=unused-result] urshd.c:352:2: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result] urshd.c: In function 'error': urshd.c:203:5: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result] urshd.c: In function 'stderr_parent': urshd.c:277:3: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result] cc1: all warnings being treated as errors GNUmakefile:231: recipe for target 'urshd.o' failed make[2]: *** [urshd.o] Error 1 make[2]: Leaving directory 'urshd-1.0.2/src' Use this opportunity to improve error handling. Signed-off-by: Roland Hieber <r.hieber@pengutronix.de>
-rw-r--r--src/urshd.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/urshd.c b/src/urshd.c
index 0877113..a8eb868 100644
--- a/src/urshd.c
+++ b/src/urshd.c
@@ -201,7 +201,9 @@ error(const char *fmt, ...)
vsnprintf(bp, sizeof(buf) - 1, fmt, ap);
va_end(ap);
- write(2, buf, strlen(buf));
+ if (write(2, buf, strlen(buf)) != 0) {
+ fatal("error: write: %m");
+ }
}
static void
@@ -274,8 +276,11 @@ stderr_parent(int sock, int pype, int pid)
shutdown(sock, 2);
FD_CLR(pype, &readfrom);
guys--;
- } else
- write(sock, buf, cc);
+ } else {
+ if (write(sock, buf, cc) != 0) {
+ fatal("stderr_parent: %m");
+ }
+ }
}
}
@@ -338,11 +343,10 @@ doit(struct sockaddr_in *fromp)
}
if (chdir(pwd->pw_dir) < 0) {
- chdir("/");
- /*
- * error("No remote directory.\n");
- * exit(1);
- */
+ if (chdir("/") != 0) {
+ error("No remote directory.\n");
+ exit(1);
+ }
}
if (pwd->pw_uid != 0 && !access(_PATH_NOLOGIN, F_OK)) {
@@ -350,7 +354,9 @@ doit(struct sockaddr_in *fromp)
exit(1);
}
- (void) write(2, "\0", 1);
+ if (write(2, "\0", 1) != 0) {
+ fatal("Unable to write: %m");
+ }
sent_null = 1;
if (port) {
@@ -502,7 +508,7 @@ network_init(int fd, struct sockaddr_in *fromp)
#endif
}
-static int
+static void
mainloop(char *port)
{
int s;
@@ -536,8 +542,11 @@ mainloop(char *port)
sn.sin_port = sp->s_port;
}
- if (opt_daemon)
- daemon(0, 0);
+ if (opt_daemon) {
+ if (daemon(0, 0) != 0) {
+ fatal("Could not fork: %s", strerror(errno));
+ }
+ }
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {