From owner-freebsd-bugs@FreeBSD.ORG Mon Jun 28 00:20:15 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5D0DA16A4CE for ; Mon, 28 Jun 2004 00:20:15 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 401F243D3F for ; Mon, 28 Jun 2004 00:20:15 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i5S0KF3P020863 for ; Mon, 28 Jun 2004 00:20:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i5S0KFdU020862; Mon, 28 Jun 2004 00:20:15 GMT (envelope-from gnats) Resent-Date: Mon, 28 Jun 2004 00:20:15 GMT Resent-Message-Id: <200406280020.i5S0KFdU020862@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Cyrille Lefevre Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BA6C316A4CE for ; Mon, 28 Jun 2004 00:14:51 +0000 (GMT) Received: from ioskeha.hittite.isp.9tel.net (ioskeha.hittite.isp.9tel.net [62.62.156.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id B89E543D2F for ; Mon, 28 Jun 2004 00:14:50 +0000 (GMT) (envelope-from cyrille.lefevre@laposte.net) Received: from mail.gits.dyndns.org (unknown [84.97.140.172]) by ioskeha.hittite.isp.9tel.net (Postfix) with ESMTP id 38AC714B655 for ; Mon, 28 Jun 2004 02:15:17 +0200 (CEST) Received: from gits.invalid (IDENT:wihfked9omrkqzl1@localhost [127.0.0.1]) i5S0EMpH052867 for ; Mon, 28 Jun 2004 02:14:41 +0200 (CEST) (envelope-from cyrille.lefevre@laposte.net) Received: by gits.invalid (tmda-sendmail, from uid 0); Mon, 28 Jun 2004 02:14:06 +0200 (CEST) Message-Id: <20040628001353.GA30844@gits.dyndns.org> Date: Mon, 28 Jun 2004 02:13:54 +0200 From: Cyrille Lefevre To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/68437: conscontrol DEVDIR -> _PATH_DEV fix and more X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Cyrille Lefevre List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2004 00:20:15 -0000 >Number: 68437 >Category: bin >Synopsis: conscontrol DEVDIR -> _PATH_DEV fix and more >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jun 28 00:20:14 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Cyrille Lefevre >Release: FreeBSD 5.2-CURRENT i386 >Organization: ACME >Environment: System: FreeBSD gits.invalid 5.2-CURRENT FreeBSD 5.2-CURRENT #35: Sun Jun 20 01:53:37 CEST 2004 root@gits:/disk3/freebsd/current/obj/disk3/freebsd/current/src/sys/CUSTOM i386 >Description: * required fix: - includes , replaces DEVDIR by _PATH_DEV and _PATH_CONSOLE. * optional fix: - adds ctty_oid (kern.console) and mute_oid (kern.consmute) constants. - adds a check for the trailing comma removing (who says if sysctlbyname will not change in the future ?) >How-To-Repeat: n/a >Fix: Index: conscontrol.c =================================================================== RCS file: /home/ncvs/src/sbin/conscontrol/conscontrol.c,v retrieving revision 1.4 diff -u -I$Id.*$ -I$.+BSD.*$ -r1.4 conscontrol.c --- conscontrol.c 18 Jun 2004 06:33:44 -0000 1.4 +++ conscontrol.c 28 Jun 2004 00:07:14 -0000 @@ -35,12 +35,14 @@ #include #include #include +#include #include #include #include #include -#define DEVDIR "/dev/" +static const char *ctty_oid = "kern.console"; +static const char *mute_oid = "kern.consmute"; static void __dead2 usage(void) @@ -62,23 +64,23 @@ char *buf, *p, *avail; len = sizeof(mute); - if (sysctlbyname("kern.consmute", &mute, &len, NULL, 0) == -1) - err(1, "kern.consmute retrieval failed"); - if (sysctlbyname("kern.console", NULL, &len, NULL, 0) == -1) - err(1, "kern.console estimate failed"); + if (sysctlbyname(mute_oid, &mute, &len, NULL, 0) == -1) + err(1, "%s retrieval failed", mute_oid); + if (sysctlbyname(ctty_oid, NULL, &len, NULL, 0) == -1) + err(1, "%s estimate failed", ctty_oid); if ((buf = malloc(len)) == NULL) - errx(1, "kern.console malloc failed"); - if (sysctlbyname("kern.console", buf, &len, NULL, 0) == -1) - err(1, "kern.console retrieval failed"); + errx(1, "%s malloc failed", ctty_oid); + if (sysctlbyname(ctty_oid, buf, &len, NULL, 0) == -1) + err(1, "%s retrieval failed", ctty_oid); if ((avail = strchr(buf, '/')) == NULL) - errx(1, "kern.console format not understood"); + errx(1, "%s format not understood", ctty_oid); p = avail; *avail++ = '\0'; - if (p != buf) - *--p = '\0'; /* remove trailing ',' */ + if (p != buf && *--p == ',') + *p = '\0'; /* remove trailing ',' */ p = avail + strlen(avail); - if (p != avail) - *--p = '\0'; /* remove trailing ',' */ + if (p != avail && *--p == ',') + *p = '\0'; /* remove trailing ',' */ printf("Configured: %s\n", buf); printf(" Available: %s\n", avail); printf(" Muting: %s\n", mute ? "on" : "off"); @@ -98,7 +100,7 @@ else usage(); len = sizeof(mute); - if (sysctlbyname("kern.consmute", NULL, NULL, &mute, len) == -1) + if (sysctlbyname(mute_oid, NULL, NULL, &mute, len) == -1) err(1, "could not change console muting"); } @@ -111,10 +113,10 @@ static char* stripdev(char *devnam) { - if (memcmp (devnam, DEVDIR, strlen(DEVDIR)) == 0) - return (&devnam[strlen(DEVDIR)]); /* remove /dev */ + if (memcmp (devnam, _PATH_DEV, strlen(_PATH_DEV)) == 0) + return (&devnam[strlen(_PATH_DEV)]); /* remove /dev */ else if (strchr (devnam, '/')) { - fprintf(stderr, "Not a device in /dev: %s\n", devnam); + fprintf(stderr, "Not a device in %s: %s\n", _PATH_DEV, devnam); return (NULL); /* end of string */ } else return (devnam); /* passed */ @@ -129,7 +131,7 @@ if (devnam == NULL) return; len = strlen(devnam); - if (sysctlbyname("kern.console", NULL, NULL, devnam, len) == -1) + if (sysctlbyname(ctty_oid, NULL, NULL, devnam, len) == -1) err(1, "could not add %s as a console", devnam); } @@ -147,7 +149,7 @@ errx(1, "malloc failed"); buf[0] = '-'; strcpy(buf + 1, devnam); - if (sysctlbyname("kern.console", NULL, NULL, buf, len) == -1) + if (sysctlbyname(ctty_oid, NULL, NULL, buf, len) == -1) err(1, "could not remove %s as a console", devnam); free(buf); } @@ -170,7 +172,7 @@ { int ttyfd, flag = 0; - ttyfd = open(DEVDIR "console", O_RDONLY); + ttyfd = open(_PATH_CONSOLE, O_RDONLY); if (ttyfd == -1) err(1, "opening virtual console"); if (ioctl(ttyfd, TIOCCONS, &flag) == -1) >Release-Note: >Audit-Trail: >Unformatted: