Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nora Puchreiner
Nix
Commits
db1d4503
Unverified
Commit
db1d4503
authored
7 years ago
by
Eelco Dolstra
Browse files
Options
Downloads
Patches
Plain Diff
Handle SIGWINCH
parent
ec9e0c03
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/libutil/util.cc
+28
-0
28 additions, 0 deletions
src/libutil/util.cc
src/libutil/util.hh
+10
-0
10 additions, 0 deletions
src/libutil/util.hh
src/nix/progress-bar.cc
+1
-8
1 addition, 8 deletions
src/nix/progress-bar.cc
with
39 additions
and
8 deletions
src/libutil/util.cc
+
28
−
0
View file @
db1d4503
...
...
@@ -17,6 +17,7 @@
#include
<fcntl.h>
#include
<limits.h>
#include
<pwd.h>
#include
<sys/ioctl.h>
#include
<sys/types.h>
#include
<sys/wait.h>
#include
<unistd.h>
...
...
@@ -1254,6 +1255,26 @@ void callFailure(const std::function<void(std::exception_ptr exc)> & failure, st
}
static
Sync
<
std
::
pair
<
unsigned
short
,
unsigned
short
>>
windowSize
{{
0
,
0
}};
static
void
updateWindowSize
()
{
struct
winsize
ws
;
if
(
ioctl
(
1
,
TIOCGWINSZ
,
&
ws
)
==
0
)
{
auto
windowSize_
(
windowSize
.
lock
());
windowSize_
->
first
=
ws
.
ws_row
;
windowSize_
->
second
=
ws
.
ws_col
;
}
}
std
::
pair
<
unsigned
short
,
unsigned
short
>
getWindowSize
()
{
return
*
windowSize
.
lock
();
}
static
Sync
<
std
::
list
<
std
::
function
<
void
()
>>>
_interruptCallbacks
;
static
void
signalHandlerThread
(
sigset_t
set
)
...
...
@@ -1264,6 +1285,10 @@ static void signalHandlerThread(sigset_t set)
if
(
signal
==
SIGINT
||
signal
==
SIGTERM
||
signal
==
SIGHUP
)
triggerInterrupt
();
else
if
(
signal
==
SIGWINCH
)
{
updateWindowSize
();
}
}
}
...
...
@@ -1287,6 +1312,8 @@ static sigset_t savedSignalMask;
void
startSignalHandlerThread
()
{
updateWindowSize
();
if
(
sigprocmask
(
SIG_BLOCK
,
nullptr
,
&
savedSignalMask
))
throw
SysError
(
"quering signal mask"
);
...
...
@@ -1296,6 +1323,7 @@ void startSignalHandlerThread()
sigaddset
(
&
set
,
SIGTERM
);
sigaddset
(
&
set
,
SIGHUP
);
sigaddset
(
&
set
,
SIGPIPE
);
sigaddset
(
&
set
,
SIGWINCH
);
if
(
pthread_sigmask
(
SIG_BLOCK
,
&
set
,
nullptr
))
throw
SysError
(
"blocking signals"
);
...
...
This diff is collapsed.
Click to expand it.
src/libutil/util.hh
+
10
−
0
View file @
db1d4503
...
...
@@ -349,6 +349,12 @@ bool hasSuffix(const string & s, const string & suffix);
std
::
string
toLower
(
const
std
::
string
&
s
);
/* Escape a string that contains octal-encoded escape codes such as
used in /etc/fstab and /proc/mounts (e.g. "foo\040bar" decodes to
"foo bar"). */
string
decodeOctalEscaped
(
const
string
&
s
);
/* Exception handling in destructors: print an error message, then
ignore the exception. */
void
ignoreException
();
...
...
@@ -470,4 +476,8 @@ struct MaintainCount
};
/* Return the number of rows and columns of the terminal. */
std
::
pair
<
unsigned
short
,
unsigned
short
>
getWindowSize
();
}
This diff is collapsed.
Click to expand it.
src/nix/progress-bar.cc
+
1
−
8
View file @
db1d4503
...
...
@@ -6,8 +6,6 @@
#include
<map>
#include
<atomic>
#include
<sys/ioctl.h>
namespace
nix
{
static
std
::
string
getS
(
const
std
::
vector
<
Logger
::
Field
>
&
fields
,
size_t
n
)
...
...
@@ -99,15 +97,10 @@ private:
Sync
<
State
>
state_
;
int
width
=
0
;
public
:
ProgressBar
()
{
struct
winsize
ws
;
if
(
ioctl
(
1
,
TIOCGWINSZ
,
&
ws
)
==
0
)
width
=
ws
.
ws_col
;
}
~
ProgressBar
()
...
...
@@ -270,7 +263,7 @@ public:
}
}
writeToStderr
(
"
\r
"
+
ansiTruncate
(
line
,
width
)
+
"\e[K"
);
writeToStderr
(
"
\r
"
+
ansiTruncate
(
line
,
getWindowSize
().
second
)
+
"\e[K"
);
}
std
::
string
getStatus
(
State
&
state
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment