Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdmngr
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IOPSYS
mdmngr
Commits
0999bc21
Commit
0999bc21
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
improvements to dfs for device name
parent
ac41f384
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dongle_infrastructure.c
+32
-42
32 additions, 42 deletions
dongle_infrastructure.c
with
32 additions
and
42 deletions
dongle_infrastructure.c
+
32
−
42
View file @
0999bc21
...
...
@@ -200,7 +200,7 @@ fail:
char
*
get_device_name
(
char
*
dir_name
)
{
char
path
[
PATH_MAX
],
*
name
;
char
path
[
PATH_MAX
],
*
name
=
NULL
;
struct
directory
*
dr
,
*
sub_dr
;
struct
dirent
*
de
;
struct
stat
st
;
...
...
@@ -215,65 +215,55 @@ char *get_device_name(char *dir_name)
dr
->
path
=
strdup
(
dir_name
);
enqueue
(
dr
,
&
stack
);
while
(
!
list_empty
(
&
stack
))
{
while
(
!
list_empty
(
&
stack
)
&&
!
name
)
{
dr
=
dequeue
(
&
stack
);
dir
=
opendir
(
dr
->
path
);
if
(
!
dir
)
{
perror
(
"opendir"
);
goto
fail_opendir
;
}
if
(
!
dir
)
continue
;
if
(
!
search
(
dr
->
path
,
&
visited
))
{
enqueue
(
dr
,
&
visited
)
;
if
(
!
search
(
dr
->
path
,
&
visited
))
continue
;
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
enqueue
(
dr
,
&
visited
);
if
(
fstatat
(
dirfd
(
dir
),
de
->
d_name
,
&
st
,
AT_SYMLINK_NOFOLLOW
)
<
0
)
{
perror
(
"fstatat"
);
continue
;
}
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
if
(
!
S_ISDIR
(
st
.
st_mode
))
continue
;
if
(
fstatat
(
dirfd
(
dir
),
de
->
d_name
,
&
st
,
AT_SYMLINK_NOFOLLOW
)
<
0
)
{
perror
(
"fstatat"
);
continue
;
}
if
(
!
st
r
st
r
(
de
->
d_name
,
"eth"
)
&&
!
strstr
(
de
->
d_name
,
"usb"
))
{
snprintf
(
path
,
PATH_MAX
,
"%s%s/"
,
dr
->
path
,
de
->
d_name
)
;
if
(
!
S_ISDIR
(
st
.
st
_mode
))
continue
;
if
(
!
search
(
path
,
&
visited
))
{
sub_dr
=
malloc
(
sizeof
(
struct
directory
));
if
(
!
sub_dr
)
{
perror
(
"malloc"
);
goto
fail_malloc
;
}
if
(
!
strstr
(
dr
->
path
,
"net"
))
{
snprintf
(
path
,
PATH_MAX
,
"%s%s/"
,
dr
->
path
,
de
->
d_name
);
sub_dr
->
path
=
strdup
(
path
);
enqueue
(
sub_dr
,
&
stack
);
}
continue
;
sub_dr
=
malloc
(
sizeof
(
struct
directory
)
);
if
(
!
sub_dr
)
{
perror
(
"malloc"
);
goto
fail_malloc
;
}
if
(
strstr
(
dr
->
path
,
"net"
))
{
name
=
strdup
(
de
->
d_name
);
goto
success
;
}
sub_dr
->
path
=
strdup
(
path
);
enqueue
(
sub_dr
,
&
stack
);
continue
;
}
if
(
!
strstr
(
de
->
d_name
,
"eth"
)
&&
!
strstr
(
de
->
d_name
,
"usb"
))
break
;
name
=
strdup
(
de
->
d_name
);
break
;
}
closedir
(
dir
);
}
fail_malloc:
clear_list
(
&
visited
);
closedir
(
dir
);
fail_opendir:
clear_list
(
&
stack
);
fail:
return
NULL
;
success:
clear_list
(
&
visited
);
clear_list
(
&
stack
);
closedir
(
dir
);
return
name
;
}
...
...
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