-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuse: parse socket control message using the standard library
make mount procedure cleaner by using standard library to parse socker control message Change-Id: Ic52f5a0e2ddda40e680e341e35fb9b4158ba3324
- Loading branch information
Showing
3 changed files
with
48 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package fuse | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func getConnection(local *os.File) (int, error) { | ||
conn, err := net.FileConn(local) | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer conn.Close() | ||
unixConn := conn.(*net.UnixConn) | ||
|
||
var data [4]byte | ||
control := make([]byte, 4*256) | ||
|
||
_, oobn, _, _, err := unixConn.ReadMsgUnix(data[:], control[:]) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
messages, err := syscall.ParseSocketControlMessage(control[:oobn]) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if len(messages) != 1 { | ||
return 0, fmt.Errorf("getConnection: expect 1 control message, got %#v", messages) | ||
} | ||
message := messages[0] | ||
|
||
fds, err := syscall.ParseUnixRights(&message) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if len(fds) != 1 { | ||
return 0, fmt.Errorf("getConnection: expect 1 fd, got %#v", fds) | ||
} | ||
fd := fds[0] | ||
|
||
if fd < 0 { | ||
return 0, fmt.Errorf("getConnection: fd < 0: %d", fd) | ||
} | ||
return fd, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters