diff options
Diffstat (limited to 'sd_login/util_syscall.go')
-rw-r--r-- | sd_login/util_syscall.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sd_login/util_syscall.go b/sd_login/util_syscall.go new file mode 100644 index 0000000..f3d12a8 --- /dev/null +++ b/sd_login/util_syscall.go @@ -0,0 +1,51 @@ +// Copyright (C) 2015-2017 Luke Shumaker <lukeshu@sbcglobal.net> +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package sd_login + +import ( + "net" + + "golang.org/x/sys/unix" +) + +const ( + // from <linux/magic.h> + magic_TMPFS = 0x01021994 + magic_CGROUP_SUPER = 0x0027e0eb + magic_CGROUP2_SUPER = 0x63677270 // "cgrp" +) + +const ( + // POSIX says at least 255, but Linux isn't POSIX. + host_name_max = 64 +) + +// I borrowed this from libnslcd.git/nslcd_systemd (of which I am the +// author) -- lukeshu +func getpeercred(conn *net.UnixConn) (cred unix.Ucred, err error) { + file, err := conn.File() + if err != nil { + return + } + defer file.Close() + _cred, err := unix.GetsockoptUcred(int(file.Fd()), unix.SOL_SOCKET, unix.SO_PEERCRED) + cred = *_cred + return +} + +func statfs(fspath string) (fs unix.Statfs_t, err error) { + err = unix.Statfs(fspath, &fs) + return +} |