From: Mike Lowis Date: Tue, 26 Apr 2016 20:24:21 +0000 (-0400) Subject: Added warning message function to util.h X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=48e93b7c1a3abd2d7e24ed7b3d1fad83f7338813;p=proto%2Falbase.git Added warning message function to util.h --- diff --git a/include/util.h b/include/util.h index d5689cea..cae12905 100644 --- a/include/util.h +++ b/include/util.h @@ -47,6 +47,18 @@ static void die(const char* msgfmt, ...) exit(EXIT_FAILURE); } +/* Generic Warning Function + *****************************************************************************/ +static void warn(const char* msgfmt, ...) +{ + va_list args; + va_start(args, msgfmt); + fprintf(stderr, "Warning: "); + vfprintf(stderr, msgfmt, args); + fprintf(stderr, "\n"); + va_end(args); +} + /* Signal Handling *****************************************************************************/ static void esignal(int sig, void (*func)(int)) diff --git a/source/getty.c b/source/getty.c index 1499129b..f0d79323 100644 --- a/source/getty.c +++ b/source/getty.c @@ -28,7 +28,7 @@ static int opentty(void) { if (isatty(fd) == 0) die("%s is not a tty\n", TTY); if (ioctl(fd, TIOCSCTTY, (void *)1) != 0) - fprintf(stderr, "Warning: TIOCSCTTY: could not set controlling tty\n"); + warn("TIOCSCTTY: could not set controlling tty\n"); vhangup(); close(fd); /* Now open it for real */ @@ -85,9 +85,9 @@ int main(int argc, char *argv[]) { dup2(fd, 1); // Make stdout the TTY dup2(fd, 2); // Make stderr the TTY if (fchown(fd, 0, 0) < 0) - fprintf(stderr, "fchown %s:", TTY); + warn("fchown %s:", TTY); if (fchmod(fd, 0600) < 0) - fprintf(stderr, "fchmod %s:", TTY); + warn("fchmod %s:", TTY); if (fd > 2) close(fd); sigignore(SIGHUP, 0); // stop ignoring SIGHUP