From a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3 Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 2 Feb 2008 23:58:48 +0000 Subject: Add vty-checker, a tool to check to make sure VTY devices are properly configured. git-svn-id: svn://creme-brulee.marcuscom.com/ports/trunk@10326 df743ca5-7f9a-e211-a948-0013205c9059 --- sysutils/vty-checker/Makefile | 34 +++++++++++++ sysutils/vty-checker/pkg-descr | 4 ++ sysutils/vty-checker/src/Makefile | 6 +++ sysutils/vty-checker/src/vty-checker.c | 90 ++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 sysutils/vty-checker/Makefile create mode 100644 sysutils/vty-checker/pkg-descr create mode 100644 sysutils/vty-checker/src/Makefile create mode 100644 sysutils/vty-checker/src/vty-checker.c (limited to 'sysutils') diff --git a/sysutils/vty-checker/Makefile b/sysutils/vty-checker/Makefile new file mode 100644 index 000000000..8d86c87a4 --- /dev/null +++ b/sysutils/vty-checker/Makefile @@ -0,0 +1,34 @@ +# New ports collection makefile for: vty-checker +# Date created: 02 February 2008 +# Whom: Joe Marcus Clarke +# +# $FreeBSD$ +# $MCom$ +# +# This port is self contained in the src directory. +# + +PORTNAME= vty-checker +PORTVERSION= 1.0 +CATEGORIES= sysutils +MASTER_SITES= # none +DISTFILES= # none + +MAINTAINER= gnome@FreeBSD.org +COMMENT= A small tool to verify all VTY lines have been configured + +WRKSRC= ${WRKDIR}/src +SRC= ${.CURDIR}/src + +PLIST_FILES= bin/vty-checker + +do-fetch: + @${DO_NADA} + +pre-patch: + @${CP} -R ${SRC} ${WRKDIR} + +do-install: + ${INSTALL_PROGRAM} ${WRKSRC}/vty-checker ${PREFIX}/bin/vty-checker + +.include diff --git a/sysutils/vty-checker/pkg-descr b/sysutils/vty-checker/pkg-descr new file mode 100644 index 000000000..1a1ce2f3a --- /dev/null +++ b/sysutils/vty-checker/pkg-descr @@ -0,0 +1,4 @@ +vty-checker is a small tool which tries to open each configured VTY line to +make sure the device is configured. The idea is to run this program prior to +starting an application which will bind to a particular VTY. This is +especially important for programs starting out of rc.d. diff --git a/sysutils/vty-checker/src/Makefile b/sysutils/vty-checker/src/Makefile new file mode 100644 index 000000000..7fc3de652 --- /dev/null +++ b/sysutils/vty-checker/src/Makefile @@ -0,0 +1,6 @@ +PROG= vty-checker +SRCS= vty-checker.c + +MAN= + +.include diff --git a/sysutils/vty-checker/src/vty-checker.c b/sysutils/vty-checker/src/vty-checker.c new file mode 100644 index 000000000..866997018 --- /dev/null +++ b/sysutils/vty-checker/src/vty-checker.c @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2008 Joe Marcus Clarke + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int debug; + char *debugstr; + struct ttyent *t; + char ttydev[PATH_MAX]; + int res, ret; + + ret = 0; + + debugstr = getenv("VTY_CHECKER_DEBUG"); + if (debugstr != NULL) { + debug = atoi(debugstr); + } else { + debug = 0; + } + + res = setttyent(); + if (res == 0) { + /* We cannot get a list of VTYs. Return TRUE, and let the + * caller sort things out. + */ + if (debug) { + (void)fprintf(stderr, "Failed to get TTY entries: %s\n", + strerror(errno)); + } + return (0); + } + + (void)sprintf(ttydev, "/dev/"); + + while ((t = getttyent()) != NULL) { + if (t->ty_status & TTY_ON && strncmp(t->ty_name, "ttyv", 4) == 0) { + char *ty_devptr; + int fd; + + ty_devptr = ttydev + 6; + (void)strlcat(ty_devptr, t->ty_name, PATH_MAX); + + if ((fd = open(ttydev, O_RDONLY)) < 0) { + if (debug) { + (void)fprintf(stderr, + "Failed to open %s: %s\n", + ttydev, strerror(errno)); + } + ret = 1; + break; + } + (void)close(fd); + } + } + + endttyent(); + + return (ret); +} -- cgit v1.2.3