diff options
author | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2008-02-03 07:58:48 +0800 |
---|---|---|
committer | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2008-02-03 07:58:48 +0800 |
commit | a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3 (patch) | |
tree | 656a9d39b3c2248137636b8f966ded70e3c19613 /sysutils | |
parent | b36ef1f4546c752e61a234962c40ef1af43db05e (diff) | |
download | marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.tar marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.tar.gz marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.tar.bz2 marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.tar.lz marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.tar.xz marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.tar.zst marcuscom-ports-a5aaa9f7f2cebce80ce260499ced95a4dd0a92d3.zip |
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
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/vty-checker/Makefile | 34 | ||||
-rw-r--r-- | sysutils/vty-checker/pkg-descr | 4 | ||||
-rw-r--r-- | sysutils/vty-checker/src/Makefile | 6 | ||||
-rw-r--r-- | sysutils/vty-checker/src/vty-checker.c | 90 |
4 files changed, 134 insertions, 0 deletions
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 <marcus@FreeBSD.org> +# +# $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 <bsd.port.mk> 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 <bsd.prog.mk> 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 <marcus@FreeBSD.org> + * + * 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 <sys/param.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ttyent.h> +#include <unistd.h> + +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); +} |