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
bbf5cf35
Unverified
Commit
bbf5cf35
authored
Jul 03, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: mv lxc_make_abstract_socket_name()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
92e35018
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
63 deletions
+71
-63
commands.c
src/lxc/commands.c
+1
-0
commands_utils.c
src/lxc/commands_utils.c
+64
-0
commands_utils.h
src/lxc/commands_utils.h
+5
-0
start.c
src/lxc/start.c
+1
-0
utils.c
src/lxc/utils.c
+0
-59
utils.h
src/lxc/utils.h
+0
-4
No files found.
src/lxc/commands.c
View file @
bbf5cf35
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include "utils.h"
#include "utils.h"
#include "cgroup.h"
#include "cgroup.h"
#include "commands.h"
#include "commands.h"
#include "commands_utils.h"
#include "console.h"
#include "console.h"
#include "confile.h"
#include "confile.h"
#include "lxclock.h"
#include "lxclock.h"
...
...
src/lxc/commands_utils.c
View file @
bbf5cf35
...
@@ -18,8 +18,11 @@
...
@@ -18,8 +18,11 @@
*/
*/
#define _GNU_SOURCE
#define _GNU_SOURCE
#define __STDC_FORMAT_MACROS
/* Required for PRIu64 to work. */
#include <errno.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/socket.h>
...
@@ -30,6 +33,7 @@
...
@@ -30,6 +33,7 @@
#include "log.h"
#include "log.h"
#include "monitor.h"
#include "monitor.h"
#include "state.h"
#include "state.h"
#include "utils.h"
lxc_log_define
(
lxc_commands_utils
,
lxc
);
lxc_log_define
(
lxc_commands_utils
,
lxc
);
...
@@ -89,3 +93,63 @@ int lxc_cmd_sock_get_state(const char *name, const char *lxcpath,
...
@@ -89,3 +93,63 @@ int lxc_cmd_sock_get_state(const char *name, const char *lxcpath,
close
(
state_client_fd
);
close
(
state_client_fd
);
return
ret
;
return
ret
;
}
}
int
lxc_make_abstract_socket_name
(
char
*
path
,
int
len
,
const
char
*
lxcname
,
const
char
*
lxcpath
,
const
char
*
hashed_sock_name
,
const
char
*
suffix
)
{
const
char
*
name
;
char
*
tmppath
;
size_t
tmplen
;
uint64_t
hash
;
int
ret
;
name
=
lxcname
;
if
(
!
name
)
name
=
""
;
if
(
hashed_sock_name
!=
NULL
)
{
ret
=
snprintf
(
path
,
len
,
"lxc/%s/%s"
,
hashed_sock_name
,
suffix
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
return
0
;
}
if
(
!
lxcpath
)
{
lxcpath
=
lxc_global_config_value
(
"lxc.lxcpath"
);
if
(
!
lxcpath
)
{
ERROR
(
"Failed to allocate memory"
);
return
-
1
;
}
}
ret
=
snprintf
(
path
,
len
,
"%s/%s/%s"
,
lxcpath
,
name
,
suffix
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
if
(
ret
<
len
)
return
0
;
/* ret >= len; lxcpath or name is too long. hash both */
tmplen
=
strlen
(
name
)
+
strlen
(
lxcpath
)
+
2
;
tmppath
=
alloca
(
tmplen
);
ret
=
snprintf
(
tmppath
,
tmplen
,
"%s/%s"
,
lxcpath
,
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
tmplen
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
hash
=
fnv_64a_buf
(
tmppath
,
ret
,
FNV1A_64_INIT
);
ret
=
snprintf
(
path
,
len
,
"lxc/%016"
PRIx64
"/%s"
,
hash
,
suffix
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
return
0
;
}
src/lxc/commands_utils.h
View file @
bbf5cf35
...
@@ -24,6 +24,11 @@
...
@@ -24,6 +24,11 @@
#include "state.h"
#include "state.h"
int
lxc_make_abstract_socket_name
(
char
*
path
,
int
len
,
const
char
*
lxcname
,
const
char
*
lxcpath
,
const
char
*
hashed_sock_name
,
const
char
*
suffix
);
/* lxc_cmd_sock_get_state Register a new state client fd in the container's
/* lxc_cmd_sock_get_state Register a new state client fd in the container's
* in-memory handler and retrieve the requested
* in-memory handler and retrieve the requested
* states.
* states.
...
...
src/lxc/start.c
View file @
bbf5cf35
...
@@ -67,6 +67,7 @@
...
@@ -67,6 +67,7 @@
#include "caps.h"
#include "caps.h"
#include "cgroup.h"
#include "cgroup.h"
#include "commands.h"
#include "commands.h"
#include "commands_utils.h"
#include "conf.h"
#include "conf.h"
#include "console.h"
#include "console.h"
#include "error.h"
#include "error.h"
...
...
src/lxc/utils.c
View file @
bbf5cf35
...
@@ -2338,62 +2338,3 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
...
@@ -2338,62 +2338,3 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
return
fret
;
return
fret
;
}
}
int
lxc_make_abstract_socket_name
(
char
*
path
,
int
len
,
const
char
*
lxcname
,
const
char
*
lxcpath
,
const
char
*
hashed_sock_name
,
const
char
*
suffix
)
{
const
char
*
name
;
char
*
tmppath
;
size_t
tmplen
;
uint64_t
hash
;
int
ret
;
name
=
lxcname
;
if
(
!
name
)
name
=
""
;
if
(
hashed_sock_name
!=
NULL
)
{
ret
=
snprintf
(
path
,
len
,
"lxc/%s/%s"
,
hashed_sock_name
,
suffix
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
return
0
;
}
if
(
!
lxcpath
)
{
lxcpath
=
lxc_global_config_value
(
"lxc.lxcpath"
);
if
(
!
lxcpath
)
{
ERROR
(
"Failed to allocate memory"
);
return
-
1
;
}
}
ret
=
snprintf
(
path
,
len
,
"%s/%s/%s"
,
lxcpath
,
name
,
suffix
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
if
(
ret
<
len
)
return
0
;
/* ret >= len; lxcpath or name is too long. hash both */
tmplen
=
strlen
(
name
)
+
strlen
(
lxcpath
)
+
2
;
tmppath
=
alloca
(
tmplen
);
ret
=
snprintf
(
tmppath
,
tmplen
,
"%s/%s"
,
lxcpath
,
name
);
if
(
ret
<
0
||
ret
>=
tmplen
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
hash
=
fnv_64a_buf
(
tmppath
,
ret
,
FNV1A_64_INIT
);
ret
=
snprintf
(
path
,
len
,
"lxc/%016"
PRIx64
"/%s"
,
hash
,
suffix
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create abstract socket name"
);
return
-
1
;
}
return
0
;
}
src/lxc/utils.h
View file @
bbf5cf35
...
@@ -374,9 +374,5 @@ int lxc_unstack_mountpoint(const char *path, bool lazy);
...
@@ -374,9 +374,5 @@ int lxc_unstack_mountpoint(const char *path, bool lazy);
* @param[in] args Arguments to be passed to child_fn.
* @param[in] args Arguments to be passed to child_fn.
*/
*/
int
run_command
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
void
*
args
);
int
run_command
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
void
*
args
);
int
lxc_make_abstract_socket_name
(
char
*
path
,
int
len
,
const
char
*
lxcname
,
const
char
*
lxcpath
,
const
char
*
hashed_sock_name
,
const
char
*
suffix
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_H */
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