forked from containers/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/utils: Add an asynchronous cancellable version of askForConfirmation
A subsequent commit will use this to ensure that the user can still interact with the image download prompt while 'skopeo inspect' fetches the image size from the remote registry. Initially, the prompt will be shown without the image size. Once the size has been fetched, the older prompt will be cancelled and a new one will be shown that includes the size. Even though this code is only expected to be used to read from the standard input stream, when it's connected to a terminal device, the use of poll(2) here was tested with FIFOs or named pipes and regular files as well, in case they might be necessary in future. An eventfd(2) file descriptor expects a 8-byte or 64-bit integer value to be given to write(2) to increase its counter by that amount [1]. In C, it could be phrased as: uint64_t one = 1; write (eventfd, &one, sizeof(one)); However, Go's wrapper for write(2) expects a sequence of bytes (ie., []byte), and not an arbitrary memory address. Therefore the 'binary' package [3] is used to encode the integer into a byte sequence as a varint. Even though a varint-encoded 64-bit integer takes a maximum of 10 bytes, as defined by binary.MaxVarintLen64, 1 byte is enough to encode the number 1 as an unsigned 64-bit integer [3]. That's enough to fit into a byte sequence of length 8 to satisfy what an eventfd(2) file descriptor expects. Ultimately, it doesn't matter exactly what value the receiving end assigns to the number given to write(2), as long as it's not zero. [1] https://man7.org/linux/man-pages/man2/eventfd.2.html [2] https://pkg.go.dev/golang.org/x/sys/unix#Write [3] https://protobuf.dev/programming-guides/encoding/ containers#752 containers#1263
- Loading branch information
1 parent
44664c2
commit f3c62d4
Showing
1 changed file
with
196 additions
and
0 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