[sys] unix: add IoctlSetString on all platforms

7 views
Skip to first unread message

Tobias Klauser (Gerrit)

unread,
Nov 13, 2025, 4:28:35 AM11/13/25
to Michael Pratt, Michael Knyszek, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Michael Knyszek and Michael Pratt

Tobias Klauser has uploaded the change for review

Tobias Klauser would like Michael Pratt and Michael Knyszek to review this change.

Commit message

unix: add IoctlSetString on all platforms

Currently, only solaris provides IoctlSetString. However, it might be
useful on other platforms too, e.g. for SIOCBRADDBR on linux.
Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506

Change diff

diff --git a/unix/ioctl_signed.go b/unix/ioctl_signed.go
index 5b0759b..be0f3fb 100644
--- a/unix/ioctl_signed.go
+++ b/unix/ioctl_signed.go
@@ -6,9 +6,7 @@

package unix

-import (
- "unsafe"
-)
+import "unsafe"

// ioctl itself should not be exposed directly, but additional get/set
// functions for specific types are permissible.
@@ -28,6 +26,13 @@
return ioctlPtr(fd, req, unsafe.Pointer(&v))
}

+// IoctlSetString performs an ioctl operation which sets a string value
+// on fd, using the specified request number.
+func IoctlSetString(fd int, req int, value string) error {
+ bs := append([]byte(value), 0)
+ return ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
+}
+
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
//
// To change fd's window size, the req argument should be TIOCSWINSZ.
diff --git a/unix/ioctl_unsigned.go b/unix/ioctl_unsigned.go
index 20f470b..f0c2821 100644
--- a/unix/ioctl_unsigned.go
+++ b/unix/ioctl_unsigned.go
@@ -6,9 +6,7 @@

package unix

-import (
- "unsafe"
-)
+import "unsafe"

// ioctl itself should not be exposed directly, but additional get/set
// functions for specific types are permissible.
@@ -28,6 +26,13 @@
return ioctlPtr(fd, req, unsafe.Pointer(&v))
}

+// IoctlSetString performs an ioctl operation which sets a string value
+// on fd, using the specified request number.
+func IoctlSetString(fd int, req uint, value string) error {
+ bs := append([]byte(value), 0)
+ return ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
+}
+
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
//
// To change fd's window size, the req argument should be TIOCSWINSZ.
diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go
index 18a3d9b..a6a2ea0 100644
--- a/unix/syscall_solaris.go
+++ b/unix/syscall_solaris.go
@@ -1052,14 +1052,6 @@
return ioctlRet(fd, req, uintptr(arg))
}

-func IoctlSetString(fd int, req int, val string) error {
- bs := make([]byte, len(val)+1)
- copy(bs[:len(bs)-1], val)
- err := ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
- runtime.KeepAlive(&bs[0])
- return err
-}
-
// Lifreq Helpers

func (l *Lifreq) SetName(name string) error {

Change information

Files:
  • M unix/ioctl_signed.go
  • M unix/ioctl_unsigned.go
  • M unix/syscall_solaris.go
Change size: S
Delta: 3 files changed, 16 insertions(+), 14 deletions(-)
Open in Gerrit

Related details

Attention is currently required from:
  • Michael Knyszek
  • Michael Pratt
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
Gerrit-Change-Number: 720200
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
Gerrit-Attention: Michael Pratt <mpr...@google.com>
Gerrit-Attention: Michael Knyszek <mkny...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ingo Oeser (Gerrit)

unread,
Nov 13, 2025, 5:45:19 AM11/13/25
to Tobias Klauser, goph...@pubsubhelper.golang.org, Go LUCI, Michael Knyszek, Michael Pratt, golang-co...@googlegroups.com
Attention needed from Michael Knyszek, Michael Pratt and Tobias Klauser

Ingo Oeser added 1 comment

File unix/ioctl_signed.go
Line 32, Patchset 1 (Latest): bs := append([]byte(value), 0)
Ingo Oeser . unresolved

Wouldn't a new string use a bit less memory here and be simpler code?
Same in the other file as well.


```suggestion
bs := value + "\x00"
```
Open in Gerrit

Related details

Attention is currently required from:
  • Michael Knyszek
  • Michael Pratt
  • Tobias Klauser
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
    Gerrit-Change-Number: 720200
    Gerrit-PatchSet: 1
    Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-CC: Ingo Oeser <night...@googlemail.com>
    Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Michael Pratt <mpr...@google.com>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Comment-Date: Thu, 13 Nov 2025 10:45:11 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Tobias Klauser (Gerrit)

    unread,
    Nov 14, 2025, 4:19:33 AM11/14/25
    to goph...@pubsubhelper.golang.org, Ingo Oeser, Go LUCI, Michael Knyszek, Michael Pratt, golang-co...@googlegroups.com
    Attention needed from Ingo Oeser, Michael Knyszek and Michael Pratt

    Tobias Klauser added 1 comment

    File unix/ioctl_signed.go
    Line 32, Patchset 1 (Latest): bs := append([]byte(value), 0)
    Ingo Oeser . resolved

    Wouldn't a new string use a bit less memory here and be simpler code?
    Same in the other file as well.


    ```suggestion
    bs := value + "\x00"
    ```
    Tobias Klauser

    I'm not sure how this will use less memory as we'd still create a new string.

    As I see it, NULL-terminated byte slices/arrays are more natural for interactions with syscalls as strings are just NULL-terminated byte arrays in C APIs. So I think I'd prefer to keep it that way unless there is a strong reason to use a Go string here.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ingo Oeser
    • Michael Knyszek
    • Michael Pratt
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
      Gerrit-Change-Number: 720200
      Gerrit-PatchSet: 1
      Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
      Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
      Gerrit-CC: Ingo Oeser <night...@googlemail.com>
      Gerrit-Attention: Michael Pratt <mpr...@google.com>
      Gerrit-Attention: Ingo Oeser <night...@googlemail.com>
      Gerrit-Attention: Michael Knyszek <mkny...@google.com>
      Gerrit-Comment-Date: Fri, 14 Nov 2025 09:19:25 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Ingo Oeser <night...@googlemail.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Tobias Klauser (Gerrit)

      unread,
      Nov 26, 2025, 7:05:49 AM11/26/25
      to goph...@pubsubhelper.golang.org, Cherry Mui, Ingo Oeser, Go LUCI, Michael Knyszek, Michael Pratt, golang-co...@googlegroups.com
      Attention needed from Cherry Mui, Ingo Oeser, Michael Knyszek and Michael Pratt

      Tobias Klauser voted

      Auto-Submit+1
      Commit-Queue+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      • Ingo Oeser
      • Michael Knyszek
      • Michael Pratt
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
          Gerrit-Change-Number: 720200
          Gerrit-PatchSet: 2
          Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
          Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
          Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
          Gerrit-CC: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Cherry Mui <cher...@google.com>
          Gerrit-Attention: Michael Pratt <mpr...@google.com>
          Gerrit-Attention: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Michael Knyszek <mkny...@google.com>
          Gerrit-Comment-Date: Wed, 26 Nov 2025 12:05:42 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          unsatisfied_requirement
          satisfied_requirement
          open
          diffy

          Ian Lance Taylor (Gerrit)

          unread,
          Jan 14, 2026, 6:15:41 PM (3 days ago) Jan 14
          to Tobias Klauser, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Go LUCI, Cherry Mui, Ingo Oeser, Michael Knyszek, Michael Pratt, golang-co...@googlegroups.com
          Attention needed from Cherry Mui, Ingo Oeser, Michael Knyszek, Michael Pratt and Tobias Klauser

          Ian Lance Taylor voted and added 1 comment

          Votes added by Ian Lance Taylor

          Code-Review+2

          1 comment

          Patchset-level comments
          File-level comment, Patchset 3 (Latest):
          Ian Lance Taylor . resolved

          Thanks.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Cherry Mui
          • Ingo Oeser
          • Michael Knyszek
          • Michael Pratt
          • Tobias Klauser
          Submit Requirements:
          • requirement satisfiedCode-Review
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
          Gerrit-Change-Number: 720200
          Gerrit-PatchSet: 3
          Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
          Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
          Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
          Gerrit-CC: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Cherry Mui <cher...@google.com>
          Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Attention: Michael Pratt <mpr...@google.com>
          Gerrit-Attention: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Michael Knyszek <mkny...@google.com>
          Gerrit-Comment-Date: Wed, 14 Jan 2026 23:15:36 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Florian Lehner (Gerrit)

          unread,
          Jan 15, 2026, 7:35:03 AM (2 days ago) Jan 15
          to Tobias Klauser, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Go LUCI, Cherry Mui, Ingo Oeser, Michael Knyszek, Michael Pratt, golang-co...@googlegroups.com
          Attention needed from Cherry Mui, Ingo Oeser, Michael Knyszek, Michael Pratt and Tobias Klauser

          Florian Lehner voted Code-Review+1

          Code-Review+1
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Cherry Mui
          • Ingo Oeser
          • Michael Knyszek
          • Michael Pratt
          • Tobias Klauser
          Submit Requirements:
          • requirement satisfiedCode-Review
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
          Gerrit-Change-Number: 720200
          Gerrit-PatchSet: 3
          Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Florian Lehner <lehner.f...@gmail.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
          Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
          Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
          Gerrit-CC: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Cherry Mui <cher...@google.com>
          Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Attention: Michael Pratt <mpr...@google.com>
          Gerrit-Attention: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Michael Knyszek <mkny...@google.com>
          Gerrit-Comment-Date: Thu, 15 Jan 2026 12:34:56 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Cherry Mui (Gerrit)

          unread,
          Jan 15, 2026, 4:59:30 PM (2 days ago) Jan 15
          to Tobias Klauser, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Go LUCI, Ingo Oeser, Michael Knyszek, Michael Pratt, golang-co...@googlegroups.com
          Attention needed from Ingo Oeser, Michael Knyszek, Michael Pratt and Tobias Klauser

          Cherry Mui voted Code-Review+1

          Code-Review+1
          Open in Gerrit

          Related details

          Attention is currently required from:
          Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
          Gerrit-Attention: Michael Pratt <mpr...@google.com>
          Gerrit-Attention: Ingo Oeser <night...@googlemail.com>
          Gerrit-Attention: Michael Knyszek <mkny...@google.com>
          Gerrit-Comment-Date: Thu, 15 Jan 2026 21:59:26 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Michael Pratt (Gerrit)

          unread,
          Jan 16, 2026, 5:09:14 PM (yesterday) Jan 16
          to Tobias Klauser, goph...@pubsubhelper.golang.org, Michael Pratt, Cherry Mui, Ian Lance Taylor, Go LUCI, Ingo Oeser, Michael Knyszek, golang-co...@googlegroups.com
          Attention needed from Ingo Oeser, Michael Knyszek and Tobias Klauser

          Michael Pratt voted Code-Review+1

          Code-Review+1
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Ingo Oeser
          • Michael Knyszek
          • Tobias Klauser
          Submit Requirements:
            • requirement satisfiedCode-Review
            • requirement satisfiedNo-Unresolved-Comments
            • requirement satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: sys
            Gerrit-Branch: master
            Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
            Gerrit-Change-Number: 720200
            Gerrit-PatchSet: 3
            Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
            Gerrit-Reviewer: Cherry Mui <cher...@google.com>
            Gerrit-Reviewer: Florian Lehner <lehner.f...@gmail.com>
            Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
            Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
            Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
            Gerrit-CC: Ingo Oeser <night...@googlemail.com>
            Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
            Gerrit-Attention: Ingo Oeser <night...@googlemail.com>
            Gerrit-Attention: Michael Knyszek <mkny...@google.com>
            Gerrit-Comment-Date: Fri, 16 Jan 2026 22:09:11 +0000
            Gerrit-HasComments: No
            Gerrit-Has-Labels: Yes
            satisfied_requirement
            open
            diffy

            Gopher Robot (Gerrit)

            unread,
            Jan 16, 2026, 5:09:52 PM (yesterday) Jan 16
            to Tobias Klauser, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Michael Pratt, Cherry Mui, Ian Lance Taylor, Go LUCI, Ingo Oeser, Michael Knyszek, golang-co...@googlegroups.com

            Gopher Robot submitted the change

            Change information

            Commit message:
            unix: add IoctlSetString on all platforms

            Currently, only solaris provides IoctlSetString. However, it might be
            useful on other platforms too, e.g. for SIOCBRADDBR on linux.
            Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
            Reviewed-by: Michael Pratt <mpr...@google.com>
            Reviewed-by: Ian Lance Taylor <ia...@golang.org>
            Reviewed-by: Florian Lehner <lehner.f...@gmail.com>
            Auto-Submit: Tobias Klauser <tobias....@gmail.com>
            Reviewed-by: Cherry Mui <cher...@google.com>
            Files:
            • M unix/ioctl_signed.go
            • M unix/ioctl_unsigned.go
            • M unix/syscall_solaris.go
            Change size: S
            Delta: 3 files changed, 16 insertions(+), 14 deletions(-)
            Branch: refs/heads/master
            Submit Requirements:
            • requirement satisfiedCode-Review: +1 by Michael Pratt, +1 by Florian Lehner, +1 by Cherry Mui, +2 by Ian Lance Taylor
            • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
            Open in Gerrit
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: merged
            Gerrit-Project: sys
            Gerrit-Branch: master
            Gerrit-Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506
            Gerrit-Change-Number: 720200
            Gerrit-PatchSet: 4
            Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
            Gerrit-Reviewer: Cherry Mui <cher...@google.com>
            Gerrit-Reviewer: Florian Lehner <lehner.f...@gmail.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            open
            diffy
            satisfied_requirement
            Reply all
            Reply to author
            Forward
            0 new messages