Skip to content

Commit

Permalink
tools: move lxc-attach to API symbols only
Browse files Browse the repository at this point in the history
Closes #2073.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 6, 2018
1 parent 3fb8253 commit 9267beb
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 57 deletions.
6 changes: 4 additions & 2 deletions src/lxc/Makefile.am
Expand Up @@ -4,7 +4,6 @@ pkginclude_HEADERS = \
version.h

noinst_HEADERS = \
tools/arguments.h \
attach.h \
storage/storage.h \
storage/aufs.h \
Expand All @@ -18,6 +17,9 @@ noinst_HEADERS = \
storage/rsync.h \
storage/zfs.h \
storage/storage_utils.h \
tools/arguments.h \
tools/tool_utils.h \
tools/tool_list.h \
cgroups/cgroup.h \
cgroups/cgroup_utils.h \
caps.h \
Expand Down Expand Up @@ -266,7 +268,7 @@ AM_LDFLAGS += -Wl,-rpath -Wl,$(libdir)
endif
LDADD=liblxc.la @CAP_LIBS@ @SELINUX_LIBS@ @SECCOMP_LIBS@

lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c
lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c tools/tool_utils.c
lxc_autostart_SOURCES = tools/lxc_autostart.c tools/arguments.c
lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c
lxc_config_SOURCES = tools/lxc_config.c tools/arguments.c
Expand Down
41 changes: 0 additions & 41 deletions src/lxc/confile.c
Expand Up @@ -2409,47 +2409,6 @@ signed long lxc_config_parse_arch(const char *arch)
return -1;
}

int lxc_fill_elevated_privileges(char *flaglist, int *flags)
{
char *token, *saveptr = NULL;
int i, aflag;
struct {
const char *token;
int flag;
} all_privs[] = {
{ "CGROUP", LXC_ATTACH_MOVE_TO_CGROUP },
{ "CAP", LXC_ATTACH_DROP_CAPABILITIES },
{ "LSM", LXC_ATTACH_LSM_EXEC },
{ NULL, 0 }
};

if (!flaglist) {
/* For the sake of backward compatibility, drop all privileges
* if none is specified.
*/
for (i = 0; all_privs[i].token; i++)
*flags |= all_privs[i].flag;

return 0;
}

token = strtok_r(flaglist, "|", &saveptr);
while (token) {
aflag = -1;
for (i = 0; all_privs[i].token; i++)
if (!strcmp(all_privs[i].token, token))
aflag = all_privs[i].flag;
if (aflag < 0)
return -1;

*flags |= aflag;

token = strtok_r(NULL, "|", &saveptr);
}

return 0;
}

/* Write out a configuration file. */
void write_config(FILE *fout, struct lxc_conf *c)
{
Expand Down
2 changes: 0 additions & 2 deletions src/lxc/confile.h
Expand Up @@ -92,8 +92,6 @@ extern int lxc_config_define_load(struct lxc_list *defines,
/* needed for lxc-attach */
extern signed long lxc_config_parse_arch(const char *arch);

extern int lxc_fill_elevated_privileges(char *flaglist, int *flags);

extern int lxc_clear_config_item(struct lxc_conf *c, const char *key);

extern void write_config(FILE *fout, struct lxc_conf *c);
Expand Down
9 changes: 8 additions & 1 deletion src/lxc/tools/arguments.c
Expand Up @@ -182,6 +182,13 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args,
return 0;
}

void remove_trailing_slashes(char *p)
{
int l = strlen(p);
while (--l >= 0 && (p[l] == '/' || p[l] == '\n'))
p[l] = '\0';
}

extern int lxc_arguments_parse(struct lxc_arguments *args, int argc,
char *const argv[])
{
Expand Down Expand Up @@ -250,7 +257,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc,
/* If no lxcpaths were given, use default */
if (!args->lxcpath_cnt) {
ret = lxc_arguments_lxcpath_add(
args, lxc_global_config_value("lxc.lxcpath"));
args, lxc_get_global_config_item("lxc.lxcpath"));
if (ret < 0)
return ret;
}
Expand Down
12 changes: 2 additions & 10 deletions src/lxc/tools/lxc_attach.c
Expand Up @@ -27,6 +27,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
Expand All @@ -36,16 +37,8 @@

#include <lxc/lxccontainer.h>

#include "attach.h"
#include "arguments.h"
#include "caps.h"
#include "conf.h"
#include "confile.h"
#include "console.h"
#include "log.h"
#include "list.h"
#include "mainloop.h"
#include "utils.h"
#include "tool_utils.h"

static const struct option my_longopts[] = {
{"elevated-privileges", optional_argument, 0, 'e'},
Expand Down Expand Up @@ -290,7 +283,6 @@ int main(int argc, char *argv[])
r = lxc_log_init(&log);
if (r)
exit(EXIT_FAILURE);
lxc_log_options_no_override();

if (geteuid()) {
if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
Expand Down
1 change: 0 additions & 1 deletion src/lxc/tools/lxc_autostart.c
Expand Up @@ -24,7 +24,6 @@
#include <lxc/lxccontainer.h>

#include "arguments.h"
#include "list.h"
#include "log.h"
#include "utils.h"

Expand Down

0 comments on commit 9267beb

Please sign in to comment.