Skip to content

Commit

Permalink
fix: activation of multiple sockets fails on 64-bit platforms (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bored-engineer authored Dec 20, 2024
2 parents 2a2ea99 + fd3560c commit cb067ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# Go workspace file
go.work

example/example
4 changes: 2 additions & 2 deletions launchd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Files(name string) ([]*os.File, error) {
}
files := make([]*os.File, len(fds))
for idx, fd := range fds {
files[idx] = os.NewFile(uintptr(fd), "")
files[idx] = os.NewFile(fd, "")
}
return files, nil
}
Expand Down Expand Up @@ -44,7 +44,7 @@ func Activate(name string) (net.Listener, error) {
if err != nil {
return nil, err
} else if len(listeners) != 1 {
return nil, syscall.EINVAL
return nil, fmt.Errorf("too many sockets: %v: %w", len(listeners), syscall.EINVAL)
}
return listeners[0], nil
}
10 changes: 6 additions & 4 deletions libxpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var libxpc_launch_activate_socket_trampoline_addr uintptr
//go:cgo_import_dynamic libxpc_launch_activate_socket launch_activate_socket "/usr/lib/system/libxpc.dylib"

// invokes launch_activate_socket
func libxpc_launch_activate_socket(name string) ([]int, error) {
func libxpc_launch_activate_socket(name string) ([]uintptr, error) {
c_name_ptr, err := syscall.BytePtrFromString(name)
if err != nil {
return nil, err
Expand All @@ -45,8 +45,10 @@ func libxpc_launch_activate_socket(name string) ([]int, error) {
} else if c_cnt > maxFDs {
return nil, syscall.EINVAL
}
c_fds := (*[maxFDs]int)(unsafe.Pointer(c_fds_ptr))
fds := make([]int, c_cnt)
copy(fds, (*c_fds)[0:c_cnt])
c_fds := (*[maxFDs]int32)(unsafe.Pointer(c_fds_ptr))
fds := make([]uintptr, c_cnt)
for idx, fd := range c_fds[0:c_cnt] {
fds[idx] = uintptr(fd)
}
return fds, nil
}

0 comments on commit cb067ce

Please sign in to comment.