Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
dab1ce7f
Unverified
Commit
dab1ce7f
authored
Oct 19, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync: switch to new error helpers
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
8d3bcf63
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
35 deletions
+20
-35
sync.c
src/lxc/sync.c
+20
-35
No files found.
src/lxc/sync.c
View file @
dab1ce7f
...
@@ -23,30 +23,21 @@ static int __sync_wait(int fd, int sequence)
...
@@ -23,30 +23,21 @@ static int __sync_wait(int fd, int sequence)
ssize_t
ret
;
ssize_t
ret
;
ret
=
lxc_read_nointr
(
fd
,
&
sync
,
sizeof
(
sync
));
ret
=
lxc_read_nointr
(
fd
,
&
sync
,
sizeof
(
sync
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
SYSERROR
(
"Sync wait failure"
);
return
log_error_errno
(
-
1
,
errno
,
"Sync wait failure"
);
return
-
1
;
}
if
(
!
ret
)
if
(
!
ret
)
return
0
;
return
0
;
if
((
size_t
)
ret
!=
sizeof
(
sync
))
{
if
((
size_t
)
ret
!=
sizeof
(
sync
))
ERROR
(
"Unexpected sync size: %zu expected %zu"
,
(
size_t
)
ret
,
sizeof
(
sync
));
return
log_error
(
-
1
,
"Unexpected sync size: %zu expected %zu"
,
(
size_t
)
ret
,
sizeof
(
sync
));
return
-
1
;
}
if
(
sync
==
LXC_SYNC_ERROR
)
{
if
(
sync
==
LXC_SYNC_ERROR
)
ERROR
(
"An error occurred in another process "
return
log_error
(
-
1
,
"An error occurred in another process (expected sequence number %d)"
,
sequence
);
"(expected sequence number %d)"
,
sequence
);
return
-
1
;
if
(
sync
!=
sequence
)
}
return
log_error
(
-
1
,
"Invalid sequence number %d. Expected sequence number %d"
,
sync
,
sequence
);
if
(
sync
!=
sequence
)
{
ERROR
(
"Invalid sequence number %d. Expected sequence number %d"
,
sync
,
sequence
);
return
-
1
;
}
return
0
;
return
0
;
}
}
...
@@ -54,10 +45,9 @@ static int __sync_wake(int fd, int sequence)
...
@@ -54,10 +45,9 @@ static int __sync_wake(int fd, int sequence)
{
{
int
sync
=
sequence
;
int
sync
=
sequence
;
if
(
lxc_write_nointr
(
fd
,
&
sync
,
sizeof
(
sync
))
<
0
)
{
if
(
lxc_write_nointr
(
fd
,
&
sync
,
sizeof
(
sync
))
<
0
)
SYSERROR
(
"Sync wake failure"
);
return
log_error_errno
(
-
1
,
errno
,
"Sync wake failure"
);
return
-
1
;
}
return
0
;
return
0
;
}
}
...
@@ -65,6 +55,7 @@ static int __sync_barrier(int fd, int sequence)
...
@@ -65,6 +55,7 @@ static int __sync_barrier(int fd, int sequence)
{
{
if
(
__sync_wake
(
fd
,
sequence
))
if
(
__sync_wake
(
fd
,
sequence
))
return
-
1
;
return
-
1
;
return
__sync_wait
(
fd
,
sequence
+
1
);
return
__sync_wait
(
fd
,
sequence
+
1
);
}
}
...
@@ -103,31 +94,25 @@ int lxc_sync_init(struct lxc_handler *handler)
...
@@ -103,31 +94,25 @@ int lxc_sync_init(struct lxc_handler *handler)
int
ret
;
int
ret
;
ret
=
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
handler
->
sync_sock
);
ret
=
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
handler
->
sync_sock
);
if
(
ret
)
{
if
(
ret
)
SYSERROR
(
"failed to create synchronization socketpair"
);
return
log_error_errno
(
-
1
,
errno
,
"failed to create synchronization socketpair"
);
return
-
1
;
}
/* Be sure we don't inherit this after the exec */
/* Be sure we don't inherit this after the exec */
fcntl
(
handler
->
sync_sock
[
0
],
F_SETFD
,
FD_CLOEXEC
);
ret
=
fcntl
(
handler
->
sync_sock
[
0
],
F_SETFD
,
FD_CLOEXEC
);
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to make socket close-on-exec"
);
return
0
;
return
0
;
}
}
void
lxc_sync_fini_child
(
struct
lxc_handler
*
handler
)
void
lxc_sync_fini_child
(
struct
lxc_handler
*
handler
)
{
{
if
(
handler
->
sync_sock
[
0
]
!=
-
1
)
{
close_prot_errno_disarm
(
handler
->
sync_sock
[
0
]);
close
(
handler
->
sync_sock
[
0
]);
handler
->
sync_sock
[
0
]
=
-
1
;
}
}
}
void
lxc_sync_fini_parent
(
struct
lxc_handler
*
handler
)
void
lxc_sync_fini_parent
(
struct
lxc_handler
*
handler
)
{
{
if
(
handler
->
sync_sock
[
1
]
!=
-
1
)
{
close_prot_errno_disarm
(
handler
->
sync_sock
[
1
]);
close
(
handler
->
sync_sock
[
1
]);
handler
->
sync_sock
[
1
]
=
-
1
;
}
}
}
void
lxc_sync_fini
(
struct
lxc_handler
*
handler
)
void
lxc_sync_fini
(
struct
lxc_handler
*
handler
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment