|
| 1 | +//go:build !windows |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright The containerd Authors. |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package sys |
| 20 | + |
| 21 | +import "golang.org/x/sys/unix" |
| 22 | + |
| 23 | +// The following contents were copied from Go 1.18.2. |
| 24 | +// Use of this source code is governed by the following |
| 25 | +// BSD-style license: |
| 26 | +// |
| 27 | +// Copyright (c) 2009 The Go Authors. All rights reserved. |
| 28 | +// |
| 29 | +// Redistribution and use in source and binary forms, with or without |
| 30 | +// modification, are permitted provided that the following conditions are |
| 31 | +// met: |
| 32 | +// |
| 33 | +// * Redistributions of source code must retain the above copyright |
| 34 | +// notice, this list of conditions and the following disclaimer. |
| 35 | +// * Redistributions in binary form must reproduce the above |
| 36 | +// copyright notice, this list of conditions and the following disclaimer |
| 37 | +// in the documentation and/or other materials provided with the |
| 38 | +// distribution. |
| 39 | +// * Neither the name of Google Inc. nor the names of its |
| 40 | +// contributors may be used to endorse or promote products derived from |
| 41 | +// this software without specific prior written permission. |
| 42 | +// |
| 43 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 44 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 45 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 46 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 47 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 48 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 49 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 50 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 51 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 52 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 53 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 54 | + |
| 55 | +// IgnoringEINTR makes a function call and repeats it if it returns an |
| 56 | +// EINTR error. This appears to be required even though we install all |
| 57 | +// signal handlers with SA_RESTART: see #22838, #38033, #38836, #40846. |
| 58 | +// Also #20400 and #36644 are issues in which a signal handler is |
| 59 | +// installed without setting SA_RESTART. None of these are the common case, |
| 60 | +// but there are enough of them that it seems that we can't avoid |
| 61 | +// an EINTR loop. |
| 62 | +func IgnoringEINTR(fn func() error) error { |
| 63 | + for { |
| 64 | + err := fn() |
| 65 | + if err != unix.EINTR { |
| 66 | + return err |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments