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
d2ba12a8
Commit
d2ba12a8
authored
Jun 29, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-ls: share internal API symbols
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
469711c5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
7 deletions
+88
-7
Makefile.am
src/lxc/Makefile.am
+1
-1
lxc_ls.c
src/lxc/tools/lxc_ls.c
+87
-6
No files found.
src/lxc/Makefile.am
View file @
d2ba12a8
...
@@ -276,7 +276,7 @@ lxc_execute_SOURCES = tools/lxc_execute.c tools/arguments.c tools/tool_utils.c
...
@@ -276,7 +276,7 @@ lxc_execute_SOURCES = tools/lxc_execute.c tools/arguments.c tools/tool_utils.c
lxc_freeze_SOURCES
=
tools/lxc_freeze.c tools/arguments.c
lxc_freeze_SOURCES
=
tools/lxc_freeze.c tools/arguments.c
lxc_info_SOURCES
=
tools/lxc_info.c tools/arguments.c
lxc_info_SOURCES
=
tools/lxc_info.c tools/arguments.c
lxc_monitor_SOURCES
=
tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_monitor_SOURCES
=
tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_ls_SOURCES
=
tools/lxc_ls.c tools/arguments.c
tools/tool_utils.c
lxc_ls_SOURCES
=
tools/lxc_ls.c tools/arguments.c
lxc_copy_SOURCES
=
tools/lxc_copy.c tools/arguments.c tools/tool_utils.c
lxc_copy_SOURCES
=
tools/lxc_copy.c tools/arguments.c tools/tool_utils.c
lxc_start_SOURCES
=
tools/lxc_start.c tools/arguments.c
lxc_start_SOURCES
=
tools/lxc_start.c tools/arguments.c
lxc_stop_SOURCES
=
tools/lxc_stop.c tools/arguments.c
lxc_stop_SOURCES
=
tools/lxc_stop.c tools/arguments.c
...
...
src/lxc/tools/lxc_ls.c
View file @
d2ba12a8
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
*/
*/
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <dirent.h>
#include <getopt.h>
#include <getopt.h>
#include <limits.h>
#include <limits.h>
#include <regex.h>
#include <regex.h>
...
@@ -35,7 +36,10 @@
...
@@ -35,7 +36,10 @@
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "arguments.h"
#include "tool_utils.h"
#include "log.h"
#include "utils.h"
lxc_log_define
(
lxc_ls
,
lxc
);
/* Per default we only allow five levels of recursion to protect the stack at
/* Per default we only allow five levels of recursion to protect the stack at
* least a little bit. */
* least a little bit. */
...
@@ -156,6 +160,8 @@ static int ls_remove_lock(const char *path, const char *name,
...
@@ -156,6 +160,8 @@ static int ls_remove_lock(const char *path, const char *name,
static
int
ls_serialize
(
int
wpipefd
,
struct
ls
*
n
);
static
int
ls_serialize
(
int
wpipefd
,
struct
ls
*
n
);
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
int
rm_r
(
char
*
dirname
);
static
const
struct
option
my_longopts
[]
=
{
static
const
struct
option
my_longopts
[]
=
{
{
"line"
,
no_argument
,
0
,
'1'
},
{
"line"
,
no_argument
,
0
,
'1'
},
{
"fancy"
,
no_argument
,
0
,
'f'
},
{
"fancy"
,
no_argument
,
0
,
'f'
},
...
@@ -203,6 +209,7 @@ int main(int argc, char *argv[])
...
@@ -203,6 +209,7 @@ int main(int argc, char *argv[])
{
{
int
ret
=
EXIT_FAILURE
;
int
ret
=
EXIT_FAILURE
;
struct
lxc_log
log
;
struct
lxc_log
log
;
/*
/*
* The lxc parser requires that my_args.name is set. So let's satisfy
* The lxc parser requires that my_args.name is set. So let's satisfy
* that condition by setting a dummy name which is never used.
* that condition by setting a dummy name which is never used.
...
@@ -248,6 +255,7 @@ int main(int argc, char *argv[])
...
@@ -248,6 +255,7 @@ int main(int argc, char *argv[])
struct
ls
*
ls_arr
=
NULL
;
struct
ls
*
ls_arr
=
NULL
;
size_t
ls_size
=
0
;
size_t
ls_size
=
0
;
/* &(char *){NULL} is no magic. It's just a compound literal which
/* &(char *){NULL} is no magic. It's just a compound literal which
* avoids having a pointless variable in main() that serves no purpose
* avoids having a pointless variable in main() that serves no purpose
* here. */
* here. */
...
@@ -259,6 +267,7 @@ int main(int argc, char *argv[])
...
@@ -259,6 +267,7 @@ int main(int argc, char *argv[])
goto
out
;
goto
out
;
ls_field_width
(
ls_arr
,
ls_size
,
&
max_len
);
ls_field_width
(
ls_arr
,
ls_size
,
&
max_len
);
if
(
my_args
.
ls_fancy
&&
!
my_args
.
ls_fancy_format
)
{
if
(
my_args
.
ls_fancy
&&
!
my_args
.
ls_fancy_format
)
{
ls_print_table
(
ls_arr
,
&
max_len
,
ls_size
);
ls_print_table
(
ls_arr
,
&
max_len
,
ls_size
);
}
else
if
(
my_args
.
ls_fancy
&&
my_args
.
ls_fancy_format
)
{
}
else
if
(
my_args
.
ls_fancy
&&
my_args
.
ls_fancy_format
)
{
...
@@ -283,6 +292,7 @@ static void ls_free(struct ls *l, size_t size)
...
@@ -283,6 +292,7 @@ static void ls_free(struct ls *l, size_t size)
{
{
size_t
i
;
size_t
i
;
struct
ls
*
m
=
NULL
;
struct
ls
*
m
=
NULL
;
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
free
(
m
->
groups
);
free
(
m
->
groups
);
free
(
m
->
interface
);
free
(
m
->
interface
);
...
@@ -319,8 +329,10 @@ static char *ls_get_config_item(struct lxc_container *c, const char *item,
...
@@ -319,8 +329,10 @@ static char *ls_get_config_item(struct lxc_container *c, const char *item,
static
void
ls_free_arr
(
char
**
arr
,
size_t
size
)
static
void
ls_free_arr
(
char
**
arr
,
size_t
size
)
{
{
size_t
i
;
size_t
i
;
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
free
(
arr
[
i
]);
free
(
arr
[
i
]);
free
(
arr
);
free
(
arr
);
}
}
...
@@ -372,18 +384,21 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
...
@@ -372,18 +384,21 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
struct
ls
*
l
=
NULL
;
struct
ls
*
l
=
NULL
;
struct
lxc_container
*
c
=
NULL
;
struct
lxc_container
*
c
=
NULL
;
size_t
i
;
size_t
i
;
for
(
i
=
0
;
i
<
(
size_t
)
num
;
i
++
)
{
for
(
i
=
0
;
i
<
(
size_t
)
num
;
i
++
)
{
char
*
name
=
containers
[
i
];
char
*
name
=
containers
[
i
];
/* Filter container names by regex the user gave us. */
/* Filter container names by regex the user gave us. */
if
(
args
->
ls_filter
||
args
->
argc
==
1
)
{
if
(
args
->
ls_filter
||
args
->
argc
==
1
)
{
regex_t
preg
;
regex_t
preg
;
tmp
=
args
->
ls_filter
?
args
->
ls_filter
:
args
->
argv
[
0
];
tmp
=
args
->
ls_filter
?
args
->
ls_filter
:
args
->
argv
[
0
];
check
=
regcomp
(
&
preg
,
tmp
,
REG_NOSUB
|
REG_EXTENDED
);
check
=
regcomp
(
&
preg
,
tmp
,
REG_NOSUB
|
REG_EXTENDED
);
if
(
check
==
REG_ESPACE
)
/* we're out of memory */
if
(
check
==
REG_ESPACE
)
/* we're out of memory */
goto
out
;
goto
out
;
else
if
(
check
!=
0
)
else
if
(
check
!=
0
)
continue
;
continue
;
check
=
regexec
(
&
preg
,
name
,
0
,
NULL
,
0
);
check
=
regexec
(
&
preg
,
name
,
0
,
NULL
,
0
);
regfree
(
&
preg
);
regfree
(
&
preg
);
if
(
check
!=
0
)
if
(
check
!=
0
)
...
@@ -397,9 +412,8 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
...
@@ -397,9 +412,8 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
else
if
(
!
c
)
else
if
(
!
c
)
continue
;
continue
;
if
(
args
->
ls_defined
&&
!
c
->
is_defined
(
c
))
{
if
(
args
->
ls_defined
&&
!
c
->
is_defined
(
c
))
goto
put_and_next
;
goto
put_and_next
;
}
/* This does not allocate memory so no worries about freeing it
/* This does not allocate memory so no worries about freeing it
* when we goto next or out. */
* when we goto next or out. */
...
@@ -508,6 +522,7 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
...
@@ -508,6 +522,7 @@ static int ls_get(struct ls **m, size_t *size, const struct lxc_arguments *args,
* all other information we need. */
* all other information we need. */
if
(
args
->
ls_nesting
&&
running
)
{
if
(
args
->
ls_nesting
&&
running
)
{
struct
wrapargs
wargs
=
(
struct
wrapargs
){.
args
=
NULL
};
struct
wrapargs
wargs
=
(
struct
wrapargs
){.
args
=
NULL
};
/* Open a socket so that the child can communicate with us. */
/* Open a socket so that the child can communicate with us. */
check
=
socketpair
(
AF_UNIX
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
,
wargs
.
pipefd
);
check
=
socketpair
(
AF_UNIX
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
,
wargs
.
pipefd
);
if
(
check
==
-
1
)
if
(
check
==
-
1
)
...
@@ -588,6 +603,7 @@ put_and_next:
...
@@ -588,6 +603,7 @@ put_and_next:
out:
out:
ls_free_arr
(
containers
,
num
);
ls_free_arr
(
containers
,
num
);
free
(
path
);
free
(
path
);
/* lockpath is shared amongst all non-fork()ing recursive calls to
/* lockpath is shared amongst all non-fork()ing recursive calls to
* ls_get() so only free it on the uppermost level. */
* ls_get() so only free it on the uppermost level. */
if
(
lvl
==
0
)
if
(
lvl
==
0
)
...
@@ -634,6 +650,7 @@ static char *ls_get_groups(struct lxc_container *c, bool running)
...
@@ -634,6 +650,7 @@ static char *ls_get_groups(struct lxc_container *c, bool running)
if
(
val
)
{
if
(
val
)
{
char
*
tmp
;
char
*
tmp
;
if
((
tmp
=
strrchr
(
val
,
'\n'
)))
if
((
tmp
=
strrchr
(
val
,
'\n'
)))
*
tmp
=
'\0'
;
*
tmp
=
'\0'
;
...
@@ -648,7 +665,9 @@ static char *ls_get_groups(struct lxc_container *c, bool running)
...
@@ -648,7 +665,9 @@ static char *ls_get_groups(struct lxc_container *c, bool running)
static
char
*
ls_get_ips
(
struct
lxc_container
*
c
,
const
char
*
inet
)
static
char
*
ls_get_ips
(
struct
lxc_container
*
c
,
const
char
*
inet
)
{
{
char
*
ips
=
NULL
;
char
*
ips
=
NULL
;
char
**
iptmp
=
c
->
get_ips
(
c
,
NULL
,
inet
,
0
);
char
**
iptmp
;
iptmp
=
c
->
get_ips
(
c
,
NULL
,
inet
,
0
);
if
(
iptmp
)
if
(
iptmp
)
ips
=
lxc_string_join
(
", "
,
(
const
char
**
)
iptmp
,
false
);
ips
=
lxc_string_join
(
", "
,
(
const
char
**
)
iptmp
,
false
);
...
@@ -712,6 +731,7 @@ out:
...
@@ -712,6 +731,7 @@ out:
static
unsigned
int
ls_get_term_width
(
void
)
static
unsigned
int
ls_get_term_width
(
void
)
{
{
struct
winsize
ws
;
struct
winsize
ws
;
if
(((
ioctl
(
STDOUT_FILENO
,
TIOCGWINSZ
,
&
ws
)
==
-
1
)
&&
if
(((
ioctl
(
STDOUT_FILENO
,
TIOCGWINSZ
,
&
ws
)
==
-
1
)
&&
(
ioctl
(
STDERR_FILENO
,
TIOCGWINSZ
,
&
ws
)
==
-
1
)
&&
(
ioctl
(
STDERR_FILENO
,
TIOCGWINSZ
,
&
ws
)
==
-
1
)
&&
(
ioctl
(
STDIN_FILENO
,
TIOCGWINSZ
,
&
ws
)
==
-
1
))
||
(
ioctl
(
STDIN_FILENO
,
TIOCGWINSZ
,
&
ws
)
==
-
1
))
||
...
@@ -745,6 +765,7 @@ static bool ls_has_all_grps(const char *has, char **must, size_t must_len)
...
@@ -745,6 +765,7 @@ static bool ls_has_all_grps(const char *has, char **must, size_t must_len)
if
(
j
==
tmp_has_len
)
if
(
j
==
tmp_has_len
)
break
;
break
;
}
}
if
(
i
==
must_len
)
if
(
i
==
must_len
)
bret
=
true
;
bret
=
true
;
...
@@ -780,11 +801,13 @@ static void ls_print_names(struct ls *l, struct lengths *lht,
...
@@ -780,11 +801,13 @@ static void ls_print_names(struct ls *l, struct lengths *lht,
size_t
i
,
len
=
0
;
size_t
i
,
len
=
0
;
struct
ls
*
m
=
NULL
;
struct
ls
*
m
=
NULL
;
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
if
(
list
)
{
if
(
list
)
{
printf
(
"%s
\n
"
,
m
->
name
?
m
->
name
:
"-"
);
printf
(
"%s
\n
"
,
m
->
name
?
m
->
name
:
"-"
);
}
else
{
}
else
{
printf
(
"%-*s"
,
lht
->
name_length
,
m
->
name
?
m
->
name
:
"-"
);
printf
(
"%-*s"
,
lht
->
name_length
,
m
->
name
?
m
->
name
:
"-"
);
len
+=
lht
->
name_length
;
len
+=
lht
->
name_length
;
if
((
len
+
lht
->
name_length
)
>=
termwidth
)
{
if
((
len
+
lht
->
name_length
)
>=
termwidth
)
{
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -795,6 +818,7 @@ static void ls_print_names(struct ls *l, struct lengths *lht,
...
@@ -795,6 +818,7 @@ static void ls_print_names(struct ls *l, struct lengths *lht,
}
}
}
}
}
}
if
(
len
>
0
)
if
(
len
>
0
)
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
...
@@ -854,6 +878,7 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
...
@@ -854,6 +878,7 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
struct
ls
*
m
=
NULL
;
struct
ls
*
m
=
NULL
;
size_t
i
;
size_t
i
;
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
for
(
s
=
tmp
;
s
&&
*
s
;
s
++
)
{
for
(
s
=
tmp
;
s
&&
*
s
;
s
++
)
{
if
(
strcasecmp
(
*
s
,
"NAME"
)
==
0
)
{
if
(
strcasecmp
(
*
s
,
"NAME"
)
==
0
)
{
...
@@ -903,6 +928,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
...
@@ -903,6 +928,8 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
static
void
ls_print_table
(
struct
ls
*
l
,
struct
lengths
*
lht
,
static
void
ls_print_table
(
struct
ls
*
l
,
struct
lengths
*
lht
,
size_t
size
)
size_t
size
)
{
{
size_t
i
;
/* If list is empty do nothing. */
/* If list is empty do nothing. */
if
(
size
==
0
)
if
(
size
==
0
)
return
;
return
;
...
@@ -919,7 +946,6 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
...
@@ -919,7 +946,6 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
"UNPRIVILEGED"
);
printf
(
"%-*s "
,
lht
->
unprivileged_length
,
"UNPRIVILEGED"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
size_t
i
;
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
if
(
m
->
nestlvl
>
0
)
{
if
(
m
->
nestlvl
>
0
)
{
printf
(
"%*s"
,
m
->
nestlvl
,
"
\\
"
);
printf
(
"%*s"
,
m
->
nestlvl
,
"
\\
"
);
...
@@ -927,6 +953,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
...
@@ -927,6 +953,7 @@ static void ls_print_table(struct ls *l, struct lengths *lht,
}
else
{
}
else
{
printf
(
"%-*s "
,
lht
->
name_length
,
m
->
name
?
m
->
name
:
"-"
);
printf
(
"%-*s "
,
lht
->
name_length
,
m
->
name
?
m
->
name
:
"-"
);
}
}
printf
(
"%-*s "
,
lht
->
state_length
,
m
->
state
?
m
->
state
:
"-"
);
printf
(
"%-*s "
,
lht
->
state_length
,
m
->
state
?
m
->
state
:
"-"
);
printf
(
"%-*d "
,
lht
->
autostart_length
,
m
->
autostart
);
printf
(
"%-*d "
,
lht
->
autostart_length
,
m
->
autostart
);
printf
(
"%-*s "
,
lht
->
groups_length
,
m
->
groups
?
m
->
groups
:
"-"
);
printf
(
"%-*s "
,
lht
->
groups_length
,
m
->
groups
?
m
->
groups
:
"-"
);
...
@@ -941,6 +968,7 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
...
@@ -941,6 +968,7 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
{
{
char
*
invalid
;
char
*
invalid
;
unsigned
long
int
m
,
n
=
MAX_NESTLVL
;
unsigned
long
int
m
,
n
=
MAX_NESTLVL
;
switch
(
c
)
{
switch
(
c
)
{
case
'1'
:
case
'1'
:
args
->
ls_line
=
true
;
args
->
ls_line
=
true
;
...
@@ -1000,6 +1028,7 @@ static int ls_get_wrapper(void *wrap)
...
@@ -1000,6 +1028,7 @@ static int ls_get_wrapper(void *wrap)
size_t
len
=
0
;
size_t
len
=
0
;
struct
wrapargs
*
wargs
=
(
struct
wrapargs
*
)
wrap
;
struct
wrapargs
*
wargs
=
(
struct
wrapargs
*
)
wrap
;
struct
ls
*
m
=
NULL
,
*
n
=
NULL
;
struct
ls
*
m
=
NULL
,
*
n
=
NULL
;
size_t
i
;
/* close pipe */
/* close pipe */
close
(
wargs
->
pipefd
[
0
]);
close
(
wargs
->
pipefd
[
0
]);
...
@@ -1014,7 +1043,6 @@ static int ls_get_wrapper(void *wrap)
...
@@ -1014,7 +1043,6 @@ static int ls_get_wrapper(void *wrap)
if
(
lxc_write_nointr
(
wargs
->
pipefd
[
1
],
&
len
,
sizeof
(
len
))
<=
0
)
if
(
lxc_write_nointr
(
wargs
->
pipefd
[
1
],
&
len
,
sizeof
(
len
))
<=
0
)
goto
out
;
goto
out
;
size_t
i
;
for
(
i
=
0
,
n
=
m
;
i
<
len
;
i
++
,
n
++
)
{
for
(
i
=
0
,
n
=
m
;
i
<
len
;
i
++
,
n
++
)
{
if
(
ls_serialize
(
wargs
->
pipefd
[
1
],
n
)
==
-
1
)
if
(
ls_serialize
(
wargs
->
pipefd
[
1
],
n
)
==
-
1
)
goto
out
;
goto
out
;
...
@@ -1071,14 +1099,18 @@ out:
...
@@ -1071,14 +1099,18 @@ out:
static
int
ls_send_str
(
int
fd
,
const
char
*
buf
)
static
int
ls_send_str
(
int
fd
,
const
char
*
buf
)
{
{
size_t
slen
=
0
;
size_t
slen
=
0
;
if
(
buf
)
if
(
buf
)
slen
=
strlen
(
buf
);
slen
=
strlen
(
buf
);
if
(
lxc_write_nointr
(
fd
,
&
slen
,
sizeof
(
slen
))
!=
sizeof
(
slen
))
if
(
lxc_write_nointr
(
fd
,
&
slen
,
sizeof
(
slen
))
!=
sizeof
(
slen
))
return
-
1
;
return
-
1
;
if
(
slen
>
0
)
{
if
(
slen
>
0
)
{
if
(
lxc_write_nointr
(
fd
,
buf
,
slen
)
!=
(
ssize_t
)
slen
)
if
(
lxc_write_nointr
(
fd
,
buf
,
slen
)
!=
(
ssize_t
)
slen
)
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
...
@@ -1242,6 +1274,7 @@ static void ls_field_width(const struct ls *l, const size_t size,
...
@@ -1242,6 +1274,7 @@ static void ls_field_width(const struct ls *l, const size_t size,
{
{
const
struct
ls
*
m
;
const
struct
ls
*
m
;
size_t
i
,
len
=
0
;
size_t
i
,
len
=
0
;
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
for
(
i
=
0
,
m
=
l
;
i
<
size
;
i
++
,
m
++
)
{
if
(
m
->
name
)
{
if
(
m
->
name
)
{
len
=
strlen
(
m
->
name
)
+
m
->
nestlvl
;
len
=
strlen
(
m
->
name
)
+
m
->
nestlvl
;
...
@@ -1290,3 +1323,51 @@ static void ls_field_width(const struct ls *l, const size_t size,
...
@@ -1290,3 +1323,51 @@ static void ls_field_width(const struct ls *l, const size_t size,
}
}
}
}
}
}
static
int
rm_r
(
char
*
dirname
)
{
int
ret
;
struct
dirent
*
direntp
;
DIR
*
dir
;
int
r
=
0
;
dir
=
opendir
(
dirname
);
if
(
!
dir
)
return
-
1
;
while
((
direntp
=
readdir
(
dir
)))
{
char
*
pathname
;
struct
stat
mystat
;
if
(
!
strcmp
(
direntp
->
d_name
,
"."
)
||
!
strcmp
(
direntp
->
d_name
,
".."
))
continue
;
pathname
=
must_make_path
(
dirname
,
direntp
->
d_name
,
NULL
);
ret
=
lstat
(
pathname
,
&
mystat
);
if
(
ret
<
0
)
{
r
=
-
1
;
goto
next
;
}
if
(
!
S_ISDIR
(
mystat
.
st_mode
))
goto
next
;
ret
=
rm_r
(
pathname
);
if
(
ret
<
0
)
r
=
-
1
;
next:
free
(
pathname
);
}
ret
=
rmdir
(
dirname
);
if
(
ret
<
0
)
r
=
-
1
;
ret
=
closedir
(
dir
);
if
(
ret
<
0
)
r
=
-
1
;
return
r
;
}
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