io_windows.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // +build windows
  2. /*
  3. Copyright The containerd Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package runc
  15. // NewPipeIO creates pipe pairs to be used with runc
  16. func NewPipeIO(opts ...IOOpt) (i IO, err error) {
  17. option := defaultIOOption()
  18. for _, o := range opts {
  19. o(option)
  20. }
  21. var (
  22. pipes []*pipe
  23. stdin, stdout, stderr *pipe
  24. )
  25. // cleanup in case of an error
  26. defer func() {
  27. if err != nil {
  28. for _, p := range pipes {
  29. p.Close()
  30. }
  31. }
  32. }()
  33. if option.OpenStdin {
  34. if stdin, err = newPipe(); err != nil {
  35. return nil, err
  36. }
  37. pipes = append(pipes, stdin)
  38. }
  39. if option.OpenStdout {
  40. if stdout, err = newPipe(); err != nil {
  41. return nil, err
  42. }
  43. pipes = append(pipes, stdout)
  44. }
  45. if option.OpenStderr {
  46. if stderr, err = newPipe(); err != nil {
  47. return nil, err
  48. }
  49. pipes = append(pipes, stderr)
  50. }
  51. return &pipeIO{
  52. in: stdin,
  53. out: stdout,
  54. err: stderr,
  55. }, nil
  56. }