• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-artifact / 1612715840

06 Jan 2025 09:59AM UTC coverage: 77.109% (-0.02%) from 77.125%
1612715840

Pull #659

gitlab-ci

bahaa-ghazal
fix: fixed singing artifact via symlink

Changelog: Title
Ticket: MEN-3410
Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #659: fix: fixed singing artifact via symlink

8 of 14 new or added lines in 1 file covered. (57.14%)

3 existing lines in 1 file now uncovered.

5804 of 7527 relevant lines covered (77.11%)

134.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cli/util/tty.go
1
// Copyright 2021 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
//go:build linux || aix || darwin || dragonfly || freebsd || netbsd || opbenbsd
16
// +build linux aix darwin dragonfly freebsd netbsd opbenbsd
17

18
package util
19

20
import (
21
        "context"
22
        "os"
23

24
        "github.com/pkg/errors"
25
        "golang.org/x/sys/unix"
26
)
27

28
// Disable TTY echo of stdin.
29
func DisableEcho(fd int) (*unix.Termios, error) {
×
30
        term, err := unix.IoctlGetTermios(fd, ioctlGetTermios)
×
31
        if err != nil {
×
32
                return nil, err
×
33
        }
×
34

35
        newTerm := *term
×
36
        newTerm.Lflag &^= unix.ECHO
×
37
        newTerm.Lflag |= unix.ICANON | unix.ISIG
×
38
        newTerm.Iflag |= unix.ICRNL
×
39
        if err := unix.IoctlSetTermios(fd, ioctlSetTermios, &newTerm); err != nil {
×
40
                return nil, err
×
41
        }
×
42
        return term, nil
×
43
}
44

45
// Signal handler to re-enable tty echo on interrupt. The signal handler is
46
// transparent with system default, and immedeately releases the channel and
47
// calling the system sighandler after termios is set.
48
func EchoSigHandler(
49
        ctx context.Context,
50
        sigChan chan os.Signal,
51
        errChan chan error,
52
        term *unix.Termios) {
×
53
        for {
×
54
                var (
×
55
                        sig       os.Signal
×
56
                        sigRecved bool
×
57
                )
×
58
                select {
×
59
                case <-ctx.Done():
×
60
                        errChan <- nil
×
61
                        return
×
62
                case sig, sigRecved = <-sigChan:
×
63
                }
UNCOV
64
                if sig == unix.SIGWINCH || sig == unix.SIGURG {
×
65
                        // Though SIGCHLD is ignored by default, in this context
×
66
                        // we want to restore echo state.
×
67
                        continue
×
68
                }
69
                // Restore Termios
UNCOV
70
                _ = unix.IoctlSetTermios(int(os.Stdin.Fd()), ioctlSetTermios, term)
×
71
                if sigRecved {
×
72
                        switch sig {
×
73
                        case unix.SIGCHLD:
×
74
                                // SIGCHLD is expected when ssh terminates.
×
75
                                errChan <- nil
×
76
                        default:
×
77
                                errChan <- errors.Errorf("Received signal: %s",
×
78
                                        unix.SignalName(sig.(unix.Signal)))
×
79
                                // Relay signal to default handler
×
80
                                _ = unix.Kill(os.Getpid(), sig.(unix.Signal))
×
81
                        }
UNCOV
82
                } else {
×
83
                        errChan <- nil
×
84
                        return
×
85
                }
×
86
        }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc