Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libbpf-bootstrap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luis Gerhorst
libbpf-bootstrap
Commits
30d9d149
Commit
30d9d149
authored
Jul 13, 2021
by
Luis Gerhorst
Browse files
Options
Downloads
Patches
Plain Diff
task_find: print_libc option
parent
b2a4fab2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/task_find.c
+32
-15
32 additions, 15 deletions
src/task_find.c
with
32 additions
and
15 deletions
src/task_find.c
+
32
−
15
View file @
30d9d149
...
@@ -235,7 +235,8 @@ struct linux_dirent64 {
...
@@ -235,7 +235,8 @@ struct linux_dirent64 {
#define BUF_SIZE (32*1024)
#define BUF_SIZE (32*1024)
static
int
do_user_find
(
unsigned
char
d_type
,
int
parent_dfd
,
const
char
*
name
,
static
int
do_user_find
(
unsigned
char
d_type
,
int
parent_dfd
,
const
char
*
name
,
const
char
*
search_name
,
int
search_type
,
bool
debug
)
{
const
char
*
search_name
,
int
search_type
,
bool
debug
,
bool
print_libc
)
{
int
err
=
0
;
int
err
=
0
;
size_t
namelen
=
strlen
(
name
);
size_t
namelen
=
strlen
(
name
);
...
@@ -243,13 +244,16 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
...
@@ -243,13 +244,16 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
return
0
;
return
0
;
}
}
bool
match
=
bool
match
=
(
search_type
!=
-
1
&&
d_type
==
search_type
)
search_type
!=
-
1
&&
d_type
==
search_type
||
(
search_name
!=
NULL
&&
strcmp
(
search_name
,
name
)
==
0
);
||
search_name
!=
NULL
&&
strcmp
(
search_name
,
name
)
==
0
;
if
(
match
)
{
if
(
match
)
{
if
(
print_libc
)
{
printf
(
"%s
\n
"
,
name
);
}
else
{
write
(
STDOUT_FILENO
,
name
,
namelen
);
write
(
STDOUT_FILENO
,
name
,
namelen
);
write
(
STDOUT_FILENO
,
"
\n
"
,
1
);
write
(
STDOUT_FILENO
,
"
\n
"
,
1
);
}
}
}
if
(
d_type
!=
DT_DIR
)
{
if
(
d_type
!=
DT_DIR
)
{
return
0
;
return
0
;
...
@@ -261,8 +265,12 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
...
@@ -261,8 +265,12 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
return
0
;
return
0
;
}
}
if
(
print_libc
)
{
printf
(
"%s/
\n
"
,
name
);
}
else
{
write
(
STDOUT_FILENO
,
name
,
namelen
);
write
(
STDOUT_FILENO
,
name
,
namelen
);
write
(
STDOUT_FILENO
,
"/
\n
"
,
2
);
write
(
STDOUT_FILENO
,
"/
\n
"
,
2
);
}
while
(
true
)
{
while
(
true
)
{
char
buf
[
BUF_SIZE
];
char
buf
[
BUF_SIZE
];
...
@@ -277,7 +285,8 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
...
@@ -277,7 +285,8 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
for
(
int
bpos
=
0
;
bpos
<
nread
;)
{
for
(
int
bpos
=
0
;
bpos
<
nread
;)
{
struct
linux_dirent64
*
d
=
(
struct
linux_dirent64
*
)
(
buf
+
bpos
);
struct
linux_dirent64
*
d
=
(
struct
linux_dirent64
*
)
(
buf
+
bpos
);
err
=
do_user_find
(
d
->
d_type
,
dfd
,
d
->
d_name
,
search_name
,
search_type
,
debug
);
err
=
do_user_find
(
d
->
d_type
,
dfd
,
d
->
d_name
,
search_name
,
search_type
,
debug
,
print_libc
);
if
(
err
)
{
if
(
err
)
{
goto
close
;
goto
close
;
}
}
...
@@ -286,20 +295,25 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
...
@@ -286,20 +295,25 @@ static int do_user_find(unsigned char d_type, int parent_dfd, const char *name,
}
}
close:
close:
if
(
print_libc
)
{
printf
(
"..
\n
"
);
}
else
{
write
(
STDOUT_FILENO
,
"..
\n
"
,
3
);
write
(
STDOUT_FILENO
,
"..
\n
"
,
3
);
}
close
(
dfd
);
close
(
dfd
);
return
err
;
return
err
;
}
}
static
int
user_find
(
const
char
*
path
,
const
char
*
search_name
,
static
int
user_find
(
const
char
*
path
,
const
char
*
search_name
,
bool
debug
,
int
search_type
)
{
bool
debug
,
int
search_type
,
bool
print_libc
)
{
return
do_user_find
(
DT_DIR
,
AT_FDCWD
,
path
,
search_name
,
search_type
,
debug
);
return
do_user_find
(
DT_DIR
,
AT_FDCWD
,
path
,
search_name
,
search_type
,
debug
,
print_libc
);
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
bool
debug
=
false
;
bool
debug
=
false
;
bool
variant_bpf
=
true
;
bool
variant_bpf
=
true
;
bool
print_libc
=
true
;
const
char
*
path
;
const
char
*
path
;
const
char
*
name
=
NULL
;
const
char
*
name
=
NULL
;
...
@@ -308,7 +322,7 @@ int main(int argc, char **argv)
...
@@ -308,7 +322,7 @@ int main(int argc, char **argv)
int
optc
;
int
optc
;
opterr
=
0
;
opterr
=
0
;
while
((
optc
=
getopt
(
argc
,
argv
,
"D"
"v:"
"n:"
"t:"
))
!=
-
1
)
{
while
((
optc
=
getopt
(
argc
,
argv
,
"D"
"v:"
"n:"
"t:"
"p:"
))
!=
-
1
)
{
switch
(
optc
)
{
switch
(
optc
)
{
case
'D'
:
case
'D'
:
debug
=
true
;
debug
=
true
;
...
@@ -322,8 +336,11 @@ int main(int argc, char **argv)
...
@@ -322,8 +336,11 @@ int main(int argc, char **argv)
case
't'
:
case
't'
:
type_str
=
optarg
;
type_str
=
optarg
;
break
;
break
;
case
'p'
:
print_libc
=
strcmp
(
"libc"
,
optarg
)
==
0
;
break
;
default:
default:
fprintf
(
stderr
,
"error: invalid option
\n
"
);
fprintf
(
stderr
,
"error: invalid option
%c
\n
"
,
optc
);
print_usage
(
argv
);
print_usage
(
argv
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
@@ -381,7 +398,7 @@ int main(int argc, char **argv)
...
@@ -381,7 +398,7 @@ int main(int argc, char **argv)
if
(
variant_bpf
)
{
if
(
variant_bpf
)
{
ret
=
bpf_find
(
path
,
name
,
debug
,
type
);
ret
=
bpf_find
(
path
,
name
,
debug
,
type
);
}
else
{
}
else
{
ret
=
user_find
(
path
,
name
,
debug
,
type
);
ret
=
user_find
(
path
,
name
,
debug
,
type
,
print_libc
);
}
}
return
ret
;
return
ret
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment