github.com/singularityware/singularity@v3.1.1+incompatible/internal/app/singularity/oci_state_linux.go (about)

     1  // Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package singularity
     7  
     8  import (
     9  	"encoding/json"
    10  	"fmt"
    11  
    12  	"github.com/sylabs/singularity/pkg/util/unix"
    13  )
    14  
    15  // OciState query container state
    16  func OciState(containerID string, args *OciArgs) error {
    17  	// query instance files and returns state
    18  	state, err := getState(containerID)
    19  	if err != nil {
    20  		return err
    21  	}
    22  	if args.SyncSocketPath != "" {
    23  		data, err := json.Marshal(state)
    24  		if err != nil {
    25  			return fmt.Errorf("failed to marshal state data: %s", err)
    26  		} else if err := unix.WriteSocket(args.SyncSocketPath, data); err != nil {
    27  			return err
    28  		}
    29  	} else {
    30  		c, err := json.MarshalIndent(state, "", "\t")
    31  		if err != nil {
    32  			return err
    33  		}
    34  		fmt.Println(string(c))
    35  	}
    36  	return nil
    37  }