summaryrefslogtreecommitdiff
path: root/sd_login/util_syscall.go
blob: f3d12a8f0081eae8ea864cbfa9a76fd8c9a8a4c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
}