MCPcopy
hub / github.com/lxc/incus / proxyConnection

Function proxyConnection

cmd/incus-user/proxy.go:52–136  ·  view source on GitHub ↗
(conn *net.UnixConn, serverUnixPath string)

Source from the content-addressed store, hash-verified

50}
51
52func proxyConnection(conn *net.UnixConn, serverUnixPath string) {
53 defer func() {
54 _ = conn.Close()
55
56 mu.Lock()
57 connections -= 1
58 mu.Unlock()
59 }()
60
61 // Increase counters.
62 mu.Lock()
63 transactions += 1
64 connections += 1
65 mu.Unlock()
66
67 // Get credentials.
68 creds, err := linux.GetUcred(conn)
69 if err != nil {
70 log.Errorf("Unable to get user credentials: %s", err)
71 return
72 }
73
74 // Setup logging context.
75 logger := log.WithFields(log.Fields{
76 "uid": creds.Uid,
77 "gid": creds.Gid,
78 "pid": creds.Pid,
79 })
80
81 logger.Debug("Connected")
82 defer logger.Debug("Disconnected")
83
84 // Check if the user was setup.
85 if !util.PathExists(internalUtil.VarPath("users", fmt.Sprintf("%d", creds.Uid))) || !slices.Contains(projectNames, fmt.Sprintf("user-%d", creds.Uid)) {
86 log.Infof("Setting up for uid %d", creds.Uid)
87 err := serverSetupUser(creds.Uid)
88 if err != nil {
89 log.Errorf("Failed to setup new user: %v", err)
90 return
91 }
92 }
93
94 // Connect to the daemon.
95 unixAddr, err := net.ResolveUnixAddr("unix", serverUnixPath)
96 if err != nil {
97 log.Errorf("Unable to resolve the target server: %v", err)
98 return
99 }
100
101 client, err := net.DialUnix("unix", nil, unixAddr)
102 if err != nil {
103 log.Errorf("Unable to connect to target server: %v", err)
104 return
105 }
106
107 defer incusLogger.WarnOnError(client.Close, "Failed to close connection")
108
109 // Get the TLS configuration

Callers 1

runMethod · 0.85

Calls 12

GetUcredFunction · 0.92
DebugFunction · 0.92
PathExistsFunction · 0.92
SafeCopyFunction · 0.92
serverSetupUserFunction · 0.85
tlsConfigFunction · 0.85
ErrorfMethod · 0.80
WithFieldsMethod · 0.80
InfofMethod · 0.80
CloseMethod · 0.65
ContainsMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…