]> git.mdlowis.com Git - proto/albase.git/commitdiff
Added warning message function to util.h
authorMike Lowis <mike.lowis@gentex.com>
Tue, 26 Apr 2016 20:24:21 +0000 (16:24 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 26 Apr 2016 20:24:21 +0000 (16:24 -0400)
include/util.h
source/getty.c

index d5689cea71b8d9088b79f78e57ceb2f9e8c48e97..cae129050018b64a4f2567f0784e980664b24107 100644 (file)
@@ -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))
index 1499129b5167fc277d052c35b2f1731700d94007..f0d79323b66a23b89f5acd195f5e24419407dfe9 100644 (file)
@@ -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