utils: add remove_trailing_newlines()

parent ccf8d128
...@@ -2685,15 +2685,6 @@ out: ...@@ -2685,15 +2685,6 @@ out:
return bret; return bret;
} }
static void strip_newline(char *p)
{
size_t len = strlen(p);
if (len < 1)
return;
if (p[len-1] == '\n')
p[len-1] = '\0';
}
void mod_all_rdeps(struct lxc_container *c, bool inc) void mod_all_rdeps(struct lxc_container *c, bool inc)
{ {
struct lxc_container *p; struct lxc_container *p;
...@@ -2716,8 +2707,10 @@ void mod_all_rdeps(struct lxc_container *c, bool inc) ...@@ -2716,8 +2707,10 @@ void mod_all_rdeps(struct lxc_container *c, bool inc)
ERROR("badly formatted file %s", path); ERROR("badly formatted file %s", path);
goto out; goto out;
} }
strip_newline(lxcpath);
strip_newline(lxcname); remove_trailing_newlines(lxcpath);
remove_trailing_newlines(lxcname);
if ((p = lxc_container_new(lxcname, lxcpath)) == NULL) { if ((p = lxc_container_new(lxcname, lxcpath)) == NULL) {
ERROR("Unable to find dependent container %s:%s", ERROR("Unable to find dependent container %s:%s",
lxcpath, lxcname); lxcpath, lxcname);
......
...@@ -65,16 +65,6 @@ static int parse_config_v1(FILE *f, struct lxc_conf *conf) ...@@ -65,16 +65,6 @@ static int parse_config_v1(FILE *f, struct lxc_conf *conf)
} }
#if HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH #if HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH
static void remove_trailing_newlines(char *l)
{
char *p = l;
while (*p)
p++;
while (--p >= l && *p == '\n')
*p = '\0';
}
static uint32_t get_v2_default_action(char *line) static uint32_t get_v2_default_action(char *line)
{ {
uint32_t ret_action = -1; uint32_t ret_action = -1;
......
...@@ -2533,3 +2533,14 @@ int lxc_set_death_signal(int signal) ...@@ -2533,3 +2533,14 @@ int lxc_set_death_signal(int signal)
return 0; return 0;
} }
void remove_trailing_newlines(char *l)
{
char *p = l;
while (*p)
p++;
while (--p >= l && *p == '\n')
*p = '\0';
}
...@@ -453,6 +453,7 @@ extern void lxc_free_array(void **array, lxc_free_fn element_free_fn); ...@@ -453,6 +453,7 @@ extern void lxc_free_array(void **array, lxc_free_fn element_free_fn);
extern size_t lxc_array_len(void **array); extern size_t lxc_array_len(void **array);
extern void **lxc_append_null_to_array(void **array, size_t count); extern void **lxc_append_null_to_array(void **array, size_t count);
extern void remove_trailing_newlines(char *l);
/* initialize rand with urandom */ /* initialize rand with urandom */
extern int randseed(bool); extern int randseed(bool);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment