internal/wayland: remove fd typecasts
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m21s
Test / Hakurei (push) Successful in 3m14s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m18s
Test / Hakurei (race detector) (push) Successful in 5m5s
Test / Flake checks (push) Successful in 1m24s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m21s
Test / Hakurei (push) Successful in 3m14s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m18s
Test / Hakurei (race detector) (push) Successful in 5m5s
Test / Flake checks (push) Successful in 1m24s
These are no longer necessary since RawConn is no longer used. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
61972d61f6
commit
00771efeb4
@ -49,7 +49,7 @@ func New(displayPath, bindPath *check.Absolute, appID, instanceID string) (*Secu
|
|||||||
_ = syscall.Close(fd)
|
_ = syscall.Close(fd)
|
||||||
return nil, &Error{RHostConnect, err}
|
return nil, &Error{RHostConnect, err}
|
||||||
} else {
|
} else {
|
||||||
closeFds, bindErr := bindSecurityContext(fd, bindPath, appID, instanceID)
|
closeFds, bindErr := securityContextBindPipe(fd, bindPath, appID, instanceID)
|
||||||
if bindErr != nil {
|
if bindErr != nil {
|
||||||
// do not leak the pipe and socket
|
// do not leak the pipe and socket
|
||||||
err = errors.Join(bindErr, // already wrapped
|
err = errors.Join(bindErr, // already wrapped
|
||||||
@ -62,11 +62,15 @@ func New(displayPath, bindPath *check.Absolute, appID, instanceID string) (*Secu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bindSecurityContext binds a socket associated to a security context created on serverFd,
|
// securityContextBindPipe binds a socket associated to a security context created on serverFd,
|
||||||
// returning the pipe file descriptors used for security-context-v1 close_fd.
|
// returning the pipe file descriptors used for security-context-v1 close_fd.
|
||||||
//
|
//
|
||||||
// A non-nil error unwraps to concrete type [Error].
|
// A non-nil error unwraps to concrete type [Error].
|
||||||
func bindSecurityContext(serverFd int, bindPath *check.Absolute, appID, instanceID string) ([2]int, error) {
|
func securityContextBindPipe(
|
||||||
|
serverFd int,
|
||||||
|
bindPath *check.Absolute,
|
||||||
|
appID, instanceID string,
|
||||||
|
) ([2]int, error) {
|
||||||
// write end passed to security-context-v1 close_fd
|
// write end passed to security-context-v1 close_fd
|
||||||
var closeFds [2]int
|
var closeFds [2]int
|
||||||
if err := syscall.Pipe2(closeFds[0:], syscall.O_CLOEXEC); err != nil {
|
if err := syscall.Pipe2(closeFds[0:], syscall.O_CLOEXEC); err != nil {
|
||||||
@ -74,7 +78,12 @@ func bindSecurityContext(serverFd int, bindPath *check.Absolute, appID, instance
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returned error is already wrapped
|
// returned error is already wrapped
|
||||||
if err := bindWaylandFd(bindPath.String(), uintptr(serverFd), appID, instanceID, uintptr(closeFds[1])); err != nil {
|
if err := securityContextBind(
|
||||||
|
bindPath.String(),
|
||||||
|
serverFd,
|
||||||
|
appID, instanceID,
|
||||||
|
closeFds[1],
|
||||||
|
); err != nil {
|
||||||
return closeFds, errors.Join(err,
|
return closeFds, errors.Join(err,
|
||||||
syscall.Close(closeFds[1]),
|
syscall.Close(closeFds[1]),
|
||||||
syscall.Close(closeFds[0]),
|
syscall.Close(closeFds[0]),
|
||||||
|
|||||||
@ -31,7 +31,7 @@ static const struct wl_registry_listener registry_listener = {
|
|||||||
.global_remove = registry_handle_global_remove,
|
.global_remove = registry_handle_global_remove,
|
||||||
};
|
};
|
||||||
|
|
||||||
hakurei_wayland_res hakurei_bind_wayland_fd(
|
hakurei_wayland_res hakurei_security_context_bind(
|
||||||
char *socket_path,
|
char *socket_path,
|
||||||
int server_fd,
|
int server_fd,
|
||||||
const char *app_id,
|
const char *app_id,
|
||||||
|
|||||||
@ -23,7 +23,7 @@ typedef enum {
|
|||||||
HAKUREI_WAYLAND_HOST_CONNECT,
|
HAKUREI_WAYLAND_HOST_CONNECT,
|
||||||
} hakurei_wayland_res;
|
} hakurei_wayland_res;
|
||||||
|
|
||||||
hakurei_wayland_res hakurei_bind_wayland_fd(
|
hakurei_wayland_res hakurei_security_context_bind(
|
||||||
char *socket_path,
|
char *socket_path,
|
||||||
int server_fd,
|
int server_fd,
|
||||||
const char *app_id,
|
const char *app_id,
|
||||||
|
|||||||
@ -117,19 +117,26 @@ func (e *Error) Error() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bindWaylandFd calls hakurei_bind_wayland_fd. A non-nil error has concrete type [Error].
|
// securityContextBind calls hakurei_security_context_bind.
|
||||||
func bindWaylandFd(socketPath string, fd uintptr, appID, instanceID string, syncFd uintptr) error {
|
//
|
||||||
|
// A non-nil error has concrete type [Error].
|
||||||
|
func securityContextBind(
|
||||||
|
socketPath string,
|
||||||
|
serverFd int,
|
||||||
|
appID, instanceID string,
|
||||||
|
closeFd int,
|
||||||
|
) error {
|
||||||
if hasNull(appID) || hasNull(instanceID) {
|
if hasNull(appID) || hasNull(instanceID) {
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
var e Error
|
var e Error
|
||||||
e.Cause, e.Errno = C.hakurei_bind_wayland_fd(
|
e.Cause, e.Errno = C.hakurei_security_context_bind(
|
||||||
C.CString(socketPath),
|
C.CString(socketPath),
|
||||||
C.int(fd),
|
C.int(serverFd),
|
||||||
C.CString(appID),
|
C.CString(appID),
|
||||||
C.CString(instanceID),
|
C.CString(instanceID),
|
||||||
C.int(syncFd),
|
C.int(closeFd),
|
||||||
)
|
)
|
||||||
|
|
||||||
if e.Cause == RSuccess {
|
if e.Cause == RSuccess {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user