cmd, pkg/utils: Split out the code to get the initialization stamp path
This will prevent any silly bug in getting the initialization stamp path from breaking the communication protocol between the 'enter' or 'run' commands on the host and the Toolbx container's entry point process. https://github.com/containers/toolbox/pull/1633
This commit is contained in:
parent
63309e4666
commit
2956ecacb4
|
|
@ -342,14 +342,12 @@ func initContainer(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
logrus.Debug("Finished initializing container")
|
logrus.Debug("Finished initializing container")
|
||||||
|
|
||||||
toolboxRuntimeDirectory, err := utils.GetRuntimeDirectory(targetUser)
|
pid := os.Getpid()
|
||||||
|
initializedStamp, err := utils.GetInitializedStamp(pid, targetUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pid := os.Getpid()
|
|
||||||
initializedStamp := fmt.Sprintf("%s/container-initialized-%d", toolboxRuntimeDirectory, pid)
|
|
||||||
|
|
||||||
logrus.Debugf("Creating initialization stamp %s", initializedStamp)
|
logrus.Debugf("Creating initialization stamp %s", initializedStamp)
|
||||||
|
|
||||||
initializedStampFile, err := os.Create(initializedStamp)
|
initializedStampFile, err := os.Create(initializedStamp)
|
||||||
|
|
|
||||||
|
|
@ -592,13 +592,11 @@ func constructExecArgs(container, preserveFDs string,
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureContainerIsInitialized(container string, entryPointPID int, timestamp time.Time) error {
|
func ensureContainerIsInitialized(container string, entryPointPID int, timestamp time.Time) error {
|
||||||
toolboxRuntimeDirectory, err := utils.GetRuntimeDirectory(currentUser)
|
initializedStamp, err := utils.GetInitializedStamp(entryPointPID, currentUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
initializedStampBase := fmt.Sprintf("container-initialized-%d", entryPointPID)
|
|
||||||
initializedStamp := filepath.Join(toolboxRuntimeDirectory, initializedStampBase)
|
|
||||||
logrus.Debugf("Checking if initialization stamp %s exists", initializedStamp)
|
logrus.Debugf("Checking if initialization stamp %s exists", initializedStamp)
|
||||||
|
|
||||||
shouldUsePolling := isUsePollingSet()
|
shouldUsePolling := isUsePollingSet()
|
||||||
|
|
@ -648,6 +646,11 @@ func ensureContainerIsInitialized(container string, entryPointPID int, timestamp
|
||||||
if watcherForStamp != nil {
|
if watcherForStamp != nil {
|
||||||
defer watcherForStamp.Close()
|
defer watcherForStamp.Close()
|
||||||
|
|
||||||
|
toolboxRuntimeDirectory, err := utils.GetRuntimeDirectory(currentUser)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := watcherForStamp.Add(toolboxRuntimeDirectory); err != nil {
|
if err := watcherForStamp.Add(toolboxRuntimeDirectory); err != nil {
|
||||||
if errors.Is(err, unix.ENOMEM) || errors.Is(err, unix.ENOSPC) {
|
if errors.Is(err, unix.ENOMEM) || errors.Is(err, unix.ENOSPC) {
|
||||||
logrus.Debugf("Setting up watches for file system events: failed to add path: %s",
|
logrus.Debugf("Setting up watches for file system events: failed to add path: %s",
|
||||||
|
|
|
||||||
|
|
@ -503,6 +503,17 @@ func getHostVersionID() (string, error) {
|
||||||
return osRelease["VERSION_ID"], nil
|
return osRelease["VERSION_ID"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetInitializedStamp(entryPointPID int, targetUser *user.User) (string, error) {
|
||||||
|
toolbxRuntimeDirectory, err := GetRuntimeDirectory(targetUser)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
initializedStampBase := fmt.Sprintf("container-initialized-%d", entryPointPID)
|
||||||
|
initializedStamp := filepath.Join(toolbxRuntimeDirectory, initializedStampBase)
|
||||||
|
return initializedStamp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetMountPoint returns the mount point of a target.
|
// GetMountPoint returns the mount point of a target.
|
||||||
func GetMountPoint(target string) (string, error) {
|
func GetMountPoint(target string) (string, error) {
|
||||||
var stdout strings.Builder
|
var stdout strings.Builder
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue