Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jun 2004 02:13:54 +0200
From:      Cyrille Lefevre <cyrille.lefevre@laposte.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/68437: conscontrol DEVDIR -> _PATH_DEV fix and more
Message-ID:  <20040628001353.GA30844@gits.dyndns.org>
Resent-Message-ID: <200406280020.i5S0KFdU020862@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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 <paths.h>, 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 <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040628001353.GA30844>