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
db894c06
Unverified
Commit
db894c06
authored
Sep 19, 2018
by
2xsec
Committed by
Christian Brauner
Oct 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
af_unix: add function to remove duplicated codes for set sockaddr
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
8397a1e6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
29 deletions
+42
-29
af_unix.c
src/lxc/af_unix.c
+42
-29
No files found.
src/lxc/af_unix.c
View file @
db894c06
...
@@ -42,50 +42,70 @@
...
@@ -42,50 +42,70 @@
lxc_log_define
(
af_unix
,
lxc
);
lxc_log_define
(
af_unix
,
lxc
);
int
lxc_abstract_unix_open
(
const
char
*
path
,
int
type
,
int
flags
)
static
ssize_t
lxc_abstract_unix_set_sockaddr
(
struct
sockaddr_un
*
addr
,
const
char
*
path
)
{
{
int
fd
,
ret
;
size_t
len
;
size_t
len
;
struct
sockaddr_un
addr
;
fd
=
socket
(
PF_UNIX
,
type
,
0
);
if
(
!
addr
||
!
path
)
{
if
(
fd
<
0
)
errno
=
EINVAL
;
return
-
1
;
return
-
1
;
}
/* Clear address structure */
/* Clear address structure */
memset
(
&
addr
,
0
,
sizeof
(
addr
));
memset
(
addr
,
0
,
sizeof
(
*
addr
));
if
(
!
path
)
addr
->
sun_family
=
AF_UNIX
;
return
fd
;
addr
.
sun_family
=
AF_UNIX
;
len
=
strlen
(
&
path
[
1
]);
len
=
strlen
(
&
path
[
1
]);
/* do not enforce \0-termination */
/* do not enforce \0-termination */
if
(
len
>=
sizeof
(
addr
.
sun_path
))
{
if
(
len
>=
INT_MAX
||
len
>=
sizeof
(
addr
->
sun_path
))
{
close
(
fd
);
errno
=
ENAMETOOLONG
;
errno
=
ENAMETOOLONG
;
return
-
1
;
return
-
1
;
}
}
/* do not enforce \0-termination */
/* do not enforce \0-termination */
memcpy
(
&
addr
.
sun_path
[
1
],
&
path
[
1
],
len
);
memcpy
(
&
addr
->
sun_path
[
1
],
&
path
[
1
],
len
);
return
len
;
}
int
lxc_abstract_unix_open
(
const
char
*
path
,
int
type
,
int
flags
)
{
int
fd
,
ret
;
ssize_t
len
;
struct
sockaddr_un
addr
;
fd
=
socket
(
PF_UNIX
,
type
,
0
);
if
(
fd
<
0
)
return
-
1
;
if
(
!
path
)
return
fd
;
len
=
lxc_abstract_unix_set_sockaddr
(
&
addr
,
path
);
if
(
len
<
0
)
{
int
saved_errno
=
errno
;
close
(
fd
);
errno
=
saved_errno
;
return
-
1
;
}
ret
=
bind
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
ret
=
bind
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
int
saved_err
on
=
errno
;
int
saved_err
no
=
errno
;
close
(
fd
);
close
(
fd
);
errno
=
saved_err
on
;
errno
=
saved_err
no
;
return
-
1
;
return
-
1
;
}
}
if
(
type
==
SOCK_STREAM
)
{
if
(
type
==
SOCK_STREAM
)
{
ret
=
listen
(
fd
,
100
);
ret
=
listen
(
fd
,
100
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
int
saved_err
on
=
errno
;
int
saved_err
no
=
errno
;
close
(
fd
);
close
(
fd
);
errno
=
saved_err
on
;
errno
=
saved_err
no
;
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -101,28 +121,21 @@ void lxc_abstract_unix_close(int fd)
...
@@ -101,28 +121,21 @@ void lxc_abstract_unix_close(int fd)
int
lxc_abstract_unix_connect
(
const
char
*
path
)
int
lxc_abstract_unix_connect
(
const
char
*
path
)
{
{
int
fd
,
ret
;
int
fd
,
ret
;
size_t
len
;
s
s
ize_t
len
;
struct
sockaddr_un
addr
;
struct
sockaddr_un
addr
;
fd
=
socket
(
PF_UNIX
,
SOCK_STREAM
,
0
);
fd
=
socket
(
PF_UNIX
,
SOCK_STREAM
,
0
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
-
1
;
return
-
1
;
memset
(
&
addr
,
0
,
sizeof
(
addr
));
len
=
lxc_abstract_unix_set_sockaddr
(
&
addr
,
path
);
if
(
len
<
0
)
{
addr
.
sun_family
=
AF_UNIX
;
int
saved_errno
=
errno
;
len
=
strlen
(
&
path
[
1
]);
/* do not enforce \0-termination */
if
(
len
>=
sizeof
(
addr
.
sun_path
))
{
close
(
fd
);
close
(
fd
);
errno
=
ENAMETOOLONG
;
errno
=
saved_errno
;
return
-
1
;
return
-
1
;
}
}
/* do not enforce \0-termination */
memcpy
(
&
addr
.
sun_path
[
1
],
&
path
[
1
],
len
);
ret
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
ret
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
...
...
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