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
5b46db1a
Unverified
Commit
5b46db1a
authored
Oct 12, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands_utils: improve code redundancy to make abstract unix socket name
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
2f126499
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
25 deletions
+26
-25
commands.c
src/lxc/commands.c
+4
-11
commands_utils.c
src/lxc/commands_utils.c
+20
-13
commands_utils.h
src/lxc/commands_utils.h
+2
-1
No files found.
src/lxc/commands.c
View file @
5b46db1a
...
...
@@ -1244,24 +1244,17 @@ out_close:
int
lxc_cmd_init
(
const
char
*
name
,
const
char
*
lxcpath
,
const
char
*
suffix
)
{
int
fd
,
len
,
ret
;
int
fd
,
ret
;
char
path
[
LXC_AUDS_ADDR_LEN
]
=
{
0
};
char
*
offset
=
&
path
[
1
];
/* -2 here because this is an abstract unix socket so it needs a
* leading \0, and we null terminate, so it needs a trailing \0.
* Although null termination isn't required by the API, we do it anyway
* because we print the sockname out sometimes.
*/
len
=
sizeof
(
path
)
-
2
;
ret
=
lxc_make_abstract_socket_name
(
offset
,
len
,
name
,
lxcpath
,
NULL
,
suffix
);
ret
=
lxc_make_abstract_socket_name
(
path
,
sizeof
(
path
),
name
,
lxcpath
,
NULL
,
suffix
);
if
(
ret
<
0
)
return
-
1
;
TRACE
(
"Creating abstract unix socket
\"
%s
\"
"
,
offset
);
TRACE
(
"Creating abstract unix socket
\"
%s
\"
"
,
&
path
[
1
]
);
fd
=
lxc_abstract_unix_open
(
path
,
SOCK_STREAM
,
0
);
if
(
fd
<
0
)
{
SYSERROR
(
"Failed to create command socket %s"
,
offset
);
SYSERROR
(
"Failed to create command socket %s"
,
&
path
[
1
]
);
if
(
errno
==
EADDRINUSE
)
ERROR
(
"Container
\"
%s
\"
appears to be already running"
,
name
);
...
...
src/lxc/commands_utils.c
View file @
5b46db1a
...
...
@@ -96,24 +96,38 @@ int lxc_cmd_sock_get_state(const char *name, const char *lxcpath,
return
ret
;
}
int
lxc_make_abstract_socket_name
(
char
*
path
,
int
len
,
const
char
*
lxcname
,
int
lxc_make_abstract_socket_name
(
char
*
path
,
size_t
pathlen
,
const
char
*
lxcname
,
const
char
*
lxcpath
,
const
char
*
hashed_sock_name
,
const
char
*
suffix
)
{
const
char
*
name
;
char
*
offset
;
char
*
tmppath
;
size_t
len
;
size_t
tmplen
;
uint64_t
hash
;
int
ret
;
if
(
!
path
)
return
-
1
;
offset
=
&
path
[
1
];
/* -2 here because this is an abstract unix socket so it needs a
* leading \0, and we null terminate, so it needs a trailing \0.
* Although null termination isn't required by the API, we do it anyway
* because we print the sockname out sometimes.
*/
len
=
pathlen
-
2
;
name
=
lxcname
;
if
(
!
name
)
name
=
""
;
if
(
hashed_sock_name
!=
NULL
)
{
ret
=
snprintf
(
path
,
len
,
"lxc/%s/%s"
,
hashed_sock_name
,
suffix
);
ret
=
snprintf
(
offset
,
len
,
"lxc/%s/%s"
,
hashed_sock_name
,
suffix
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
...
...
@@ -129,7 +143,7 @@ int lxc_make_abstract_socket_name(char *path, int len, const char *lxcname,
}
}
ret
=
snprintf
(
path
,
len
,
"%s/%s/%s"
,
lxcpath
,
name
,
suffix
);
ret
=
snprintf
(
offset
,
len
,
"%s/%s/%s"
,
lxcpath
,
name
,
suffix
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
...
...
@@ -147,7 +161,7 @@ int lxc_make_abstract_socket_name(char *path, int len, const char *lxcname,
}
hash
=
fnv_64a_buf
(
tmppath
,
ret
,
FNV1A_64_INIT
);
ret
=
snprintf
(
path
,
len
,
"lxc/%016"
PRIx64
"/%s"
,
hash
,
suffix
);
ret
=
snprintf
(
offset
,
len
,
"lxc/%016"
PRIx64
"/%s"
,
hash
,
suffix
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
...
...
@@ -161,15 +175,8 @@ int lxc_cmd_connect(const char *name, const char *lxcpath,
{
int
ret
,
client_fd
;
char
path
[
LXC_AUDS_ADDR_LEN
]
=
{
0
};
char
*
offset
=
&
path
[
1
];
/* -2 here because this is an abstract unix socket so it needs a
* leading \0, and we null terminate, so it needs a trailing \0.
* Although null termination isn't required by the API, we do it anyway
* because we print the sockname out sometimes.
*/
size_t
len
=
sizeof
(
path
)
-
2
;
ret
=
lxc_make_abstract_socket_name
(
offset
,
len
,
name
,
lxcpath
,
ret
=
lxc_make_abstract_socket_name
(
path
,
sizeof
(
path
),
name
,
lxcpath
,
hashed_sock_name
,
suffix
);
if
(
ret
<
0
)
return
-
1
;
...
...
src/lxc/commands_utils.h
View file @
5b46db1a
...
...
@@ -25,7 +25,8 @@
#include "state.h"
#include "commands.h"
int
lxc_make_abstract_socket_name
(
char
*
path
,
int
len
,
const
char
*
lxcname
,
int
lxc_make_abstract_socket_name
(
char
*
path
,
size_t
pathlen
,
const
char
*
lxcname
,
const
char
*
lxcpath
,
const
char
*
hashed_sock_name
,
const
char
*
suffix
);
...
...
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