From 9f057f691fbfcd8ee36d8fdd306d391480713baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 16 Jul 2018 18:09:24 +0000 Subject: [PATCH] Fix funkiness with EOF --- lewdfingerd.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lewdfingerd.c b/lewdfingerd.c index 8a80ce8..6fd4ae9 100644 --- a/lewdfingerd.c +++ b/lewdfingerd.c @@ -1,4 +1,5 @@ #define _GNU_SOURCE +#include #include #include #include @@ -138,16 +139,20 @@ void handle_userlist(int sock) { // Go over users' home dirs and see if .finger-response is present FILE *passwd = fopen("/etc/passwd", "r"); - while(!feof(passwd)) { + for(;;) { char *line = NULL; size_t line_length; - // FIXME: Funkiness with eof + errno = 0; if(getline(&line, &line_length, passwd) < 0) { - // Bail out on error - perror("getline"); - free(line); - return; + if(errno == 0) { + // EOF reached + break; + } else { + perror("getline"); + free(line); + return; + } } printf("%s", line); //debg