Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F149281453
D50398.1789813410.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D50398.1789813410.diff
View Options
diff --git a/usr.sbin/sndctl/sndctl.c b/usr.sbin/sndctl/sndctl.c
--- a/usr.sbin/sndctl/sndctl.c
+++ b/usr.sbin/sndctl/sndctl.c
@@ -664,30 +664,37 @@
size_t size;
int n, prev;
- n = strtol(arg, NULL, 10);
- if (errno == EINVAL || errno == ERANGE) {
- warn("strtol(%s)", arg);
- return (-1);
- }
-
size = sizeof(int);
/* Read current value. */
if (sysctlbyname(buf, &prev, &size, NULL, 0) < 0) {
warn("sysctlbyname(%s)", buf);
return (-1);
}
- /* Apply new value. */
- if (sysctlbyname(buf, NULL, 0, &n, size) < 0) {
- warn("sysctlbyname(%s, %d)", buf, n);
- return (-1);
+
+ /* Read-only. */
+ if (arg != NULL) {
+ errno = 0;
+ n = strtol(arg, NULL, 10);
+ if (errno == EINVAL || errno == ERANGE) {
+ warn("strtol(%s)", arg);
+ return (-1);
+ }
+
+ /* Apply new value. */
+ if (sysctlbyname(buf, NULL, 0, &n, size) < 0) {
+ warn("sysctlbyname(%s, %d)", buf, n);
+ return (-1);
+ }
}
+
/* Read back applied value for good measure. */
if (sysctlbyname(buf, &n, &size, NULL, 0) < 0) {
warn("sysctlbyname(%s)", buf);
return (-1);
}
- printf("%s: %d -> %d\n", buf, prev, n);
+ if (arg != NULL)
+ printf("%s: %d -> %d\n", buf, prev, n);
if (var != NULL)
*var = n;
@@ -708,17 +715,21 @@
return (-1);
}
- size = strlen(arg);
- /* Apply new value. */
- if (sysctlbyname(buf, NULL, 0, arg, size) < 0) {
- warn("sysctlbyname(%s, %s)", buf, arg);
- return (-1);
- }
- /* Get size of new string. */
- if (sysctlbyname(buf, NULL, &size, NULL, 0) < 0) {
- warn("sysctlbyname(%s)", buf);
- return (-1);
+ /* Read-only. */
+ if (arg != NULL) {
+ size = strlen(arg);
+ /* Apply new value. */
+ if (sysctlbyname(buf, NULL, 0, arg, size) < 0) {
+ warn("sysctlbyname(%s, %s)", buf, arg);
+ return (-1);
+ }
+ /* Get size of new string. */
+ if (sysctlbyname(buf, NULL, &size, NULL, 0) < 0) {
+ warn("sysctlbyname(%s)", buf);
+ return (-1);
+ }
}
+
if ((tmp = calloc(1, size)) == NULL)
err(1, "calloc");
/* Read back applied value for good measure. */
@@ -728,7 +739,8 @@
return (-1);
}
- printf("%s: %s -> %s\n", buf, prev, tmp);
+ if (arg != NULL)
+ printf("%s: %s -> %s\n", buf, prev, tmp);
if (var != NULL)
strlcpy(var, tmp, varsz);
free(tmp);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Sep 19, 10:23 AM (2 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29777774
Default Alt Text
D50398.1789813410.diff (2 KB)
Attached To
Mode
D50398: sndctl(8): Allow read-only sysctls
Attached
Detach File
Event Timeline
Log In to Comment