Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redoxer
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
Container 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
mattmadeofpasta
redoxer
Commits
0ed605d4
Verified
Commit
0ed605d4
authored
5 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Update daemon to improve reliability
parent
5d52989e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
daemon/src/main.rs
+26
-9
26 additions, 9 deletions
daemon/src/main.rs
with
26 additions
and
9 deletions
daemon/src/main.rs
+
26
−
9
View file @
0ed605d4
...
...
@@ -14,7 +14,7 @@ fn syscall_error(error: syscall::Error) -> io::Error {
io
::
Error
::
from_raw_os_error
(
error
.errno
)
}
pub
fn
handle
(
event_file
:
&
mut
File
,
master_fd
:
RawFd
,
process
:
&
mut
Child
)
->
io
::
Result
<
ExitStatus
>
{
pub
fn
handle
(
event_file
:
&
mut
File
,
master_fd
:
RawFd
,
timeout_fd
:
RawFd
,
process
:
&
mut
Child
)
->
io
::
Result
<
ExitStatus
>
{
let
handle_event
=
|
event_id
:
RawFd
|
->
io
::
Result
<
bool
>
{
if
event_id
==
master_fd
{
let
mut
packet
=
[
0
;
4096
];
...
...
@@ -30,6 +30,14 @@ pub fn handle(event_file: &mut File, master_fd: RawFd, process: &mut Child) -> i
Pio
::
<
u8
>
::
new
(
0xe9
)
.write
(
packet
[
i
]);
}
}
}
else
if
event_id
==
timeout_fd
{
let
mut
timespec
=
syscall
::
TimeSpec
::
default
();
syscall
::
read
(
timeout_fd
as
usize
,
&
mut
timespec
)
.map_err
(
syscall_error
)
?
;
timespec
.tv_sec
+=
1
;
syscall
::
write
(
timeout_fd
as
usize
,
&
mut
timespec
)
.map_err
(
syscall_error
)
?
;
Ok
(
true
)
}
else
{
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
InvalidData
,
...
...
@@ -38,14 +46,8 @@ pub fn handle(event_file: &mut File, master_fd: RawFd, process: &mut Child) -> i
}
};
if
handle_event
(
master_fd
)
?
{
if
handle_event
(
master_fd
)
?
&&
handle_event
(
timeout_fd
)
?
{
'events
:
loop
{
let
mut
sys_event
=
syscall
::
Event
::
default
();
event_file
.read
(
&
mut
sys_event
)
?
;
if
!
handle_event
(
sys_event
.id
as
RawFd
)
?
{
break
'events
;
}
match
process
.try_wait
()
{
Ok
(
status_opt
)
=>
match
status_opt
{
Some
(
status
)
=>
return
Ok
(
status
),
...
...
@@ -56,6 +58,12 @@ pub fn handle(event_file: &mut File, master_fd: RawFd, process: &mut Child) -> i
_
=>
return
Err
(
err
),
}
}
let
mut
sys_event
=
syscall
::
Event
::
default
();
event_file
.read
(
&
mut
sys_event
)
?
;
if
!
handle_event
(
sys_event
.id
as
RawFd
)
?
{
break
'events
;
}
}
}
...
...
@@ -89,6 +97,9 @@ fn inner() -> io::Result<()> {
let
(
columns
,
lines
)
=
(
DEFAULT_COLS
,
DEFAULT_LINES
);
let
(
master_fd
,
pty
)
=
getpty
(
columns
,
lines
)
?
;
let
timeout_fd
=
syscall
::
open
(
"time:4"
,
syscall
::
O_CLOEXEC
|
syscall
::
O_RDWR
|
syscall
::
O_NONBLOCK
)
.map_err
(
syscall_error
)
?
as
RawFd
;
let
mut
event_file
=
OpenOptions
::
new
()
.read
(
true
)
.write
(
true
)
...
...
@@ -100,6 +111,12 @@ fn inner() -> io::Result<()> {
data
:
0
})
?
;
event_file
.write
(
&
syscall
::
Event
{
id
:
timeout_fd
as
usize
,
flags
:
syscall
::
flag
::
EVENT_READ
,
data
:
0
})
?
;
let
slave_stdin
=
OpenOptions
::
new
()
.read
(
true
)
.open
(
&
pty
)
?
;
let
slave_stdout
=
OpenOptions
::
new
()
.write
(
true
)
.open
(
&
pty
)
?
;
let
slave_stderr
=
OpenOptions
::
new
()
.write
(
true
)
.open
(
&
pty
)
?
;
...
...
@@ -121,7 +138,7 @@ fn inner() -> io::Result<()> {
}
let
mut
process
=
command
.spawn
()
?
;
let
status
=
handle
(
&
mut
event_file
,
master_fd
,
&
mut
process
)
?
;
let
status
=
handle
(
&
mut
event_file
,
master_fd
,
timeout_fd
,
&
mut
process
)
?
;
if
status
.success
()
{
Ok
(())
}
else
{
...
...
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