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
5c4d0247
Commit
5c4d0247
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
some refactoring regarding getting device name
parent
3af8f3e9
No related branches found
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
+17
-35
17 additions, 35 deletions
dongle_infrastructure.c
with
17 additions
and
35 deletions
dongle_infrastructure.c
+
17
−
35
View file @
5c4d0247
...
@@ -219,7 +219,7 @@ fail:
...
@@ -219,7 +219,7 @@ fail:
char
*
get_device_name
(
char
*
dir_name
)
char
*
get_device_name
(
char
*
dir_name
)
{
{
char
*
path
,
*
name
,
tmp_
path
[
PATH_MAX
];
char
path
[
PATH_MAX
]
,
*
name
;
struct
directory
*
dr
,
*
sub_dr
;
struct
directory
*
dr
,
*
sub_dr
;
struct
dirent
*
de
;
struct
dirent
*
de
;
struct
stat
st
;
struct
stat
st
;
...
@@ -232,7 +232,6 @@ char *get_device_name(char *dir_name)
...
@@ -232,7 +232,6 @@ char *get_device_name(char *dir_name)
goto
fail
;
goto
fail
;
}
}
dr
->
path
=
strdup
(
dir_name
);
dr
->
path
=
strdup
(
dir_name
);
//snprintf(dr->path, PATH_MAX, "%s", dir_name); //remain allocated?
enqueue
(
dr
,
&
stack
);
enqueue
(
dr
,
&
stack
);
while
(
!
list_empty
(
&
stack
))
{
while
(
!
list_empty
(
&
stack
))
{
...
@@ -258,24 +257,18 @@ char *get_device_name(char *dir_name)
...
@@ -258,24 +257,18 @@ char *get_device_name(char *dir_name)
continue
;
continue
;
if
(
!
strstr
(
de
->
d_name
,
"eth"
)
&&
!
strstr
(
de
->
d_name
,
"usb"
))
{
if
(
!
strstr
(
de
->
d_name
,
"eth"
)
&&
!
strstr
(
de
->
d_name
,
"usb"
))
{
path_len
=
strlen
(
dr
->
path
)
+
strlen
(
de
->
d_name
)
+
2
;
path
=
calloc
(
path_len
,
1
);
if
(
!
path
)
{
perror
(
"calloc"
);
goto
fail_calloc
;
}
snprintf
(
path
,
PATH_MAX
,
"%s%s/"
,
dr
->
path
,
de
->
d_name
);
snprintf
(
path
,
PATH_MAX
,
"%s%s/"
,
dr
->
path
,
de
->
d_name
);
if
(
!
search
(
path
,
&
visited
))
{
if
(
!
search
(
path
,
&
visited
))
{
sub_dr
=
malloc
(
sizeof
(
struct
directory
));
sub_dr
=
malloc
(
sizeof
(
struct
directory
));
if
(
!
sub_dr
)
{
if
(
!
sub_dr
)
{
perror
(
"malloc"
);
perror
(
"malloc"
);
goto
fail_
dir
;
goto
fail_
malloc
;
}
}
sub_dr
->
path
=
path
;
sub_dr
->
path
=
strdup
(
path
);
enqueue
(
sub_dr
,
&
stack
);
enqueue
(
sub_dr
,
&
stack
);
}
else
}
free
(
path
);
continue
;
continue
;
}
}
...
@@ -288,44 +281,30 @@ char *get_device_name(char *dir_name)
...
@@ -288,44 +281,30 @@ char *get_device_name(char *dir_name)
}
}
closedir
(
dir
);
closedir
(
dir
);
}
}
fail_dir:
//free(path);
fail_malloc:
fail_calloc:
clear_list
(
&
visited
);
clear_list
(
&
visited
);
fail_opendir:
fail_opendir:
//
clear_list(&stack);
clear_list
(
&
stack
);
fail:
fail:
return
NULL
;
return
NULL
;
success:
success:
printf
(
"name %s
\n
"
,
name
);
clear_list
(
&
visited
);
clear_list
(
&
visited
);
printf
(
"name %s
\n
"
,
name
);
clear_list
(
&
stack
);
clear_list
(
&
stack
);
printf
(
"name %s
\n
"
,
name
);
closedir
(
dir
);
closedir
(
dir
);
return
name
;
return
name
;
}
}
char
*
get_interface_name
(
char
*
usb_path
,
char
*
sub_dir_name
)
{
char
path
[
PATH_MAX
];
snprintf
(
path
,
PATH_MAX
,
"%s/%s/"
,
usb_path
,
sub_dir_name
);
return
get_device_name
(
path
);
}
int
get_devices
(
void
)
int
get_devices
(
void
)
{
{
char
usb_path
[
PATH_MAX
]
=
{
0
}
,
product_path
[
PATH_MAX
]
=
{
0
}
,
*
name
;
char
usb_path
[
PATH_MAX
],
product_path
[
PATH_MAX
]
,
path
[
PATH_MAX
]
,
*
name
;
struct
dirent
*
de
;
struct
dirent
*
de
;
DIR
*
dir
;
DIR
*
dir
;
struct
stat
st
;
struct
stat
st
;
struct
device
*
node
;
struct
device
*
node
;
int
rv
;
int
rv
;
printf
(
"hello
\n
"
);
strncpy
(
usb_path
,
"/sys/bus/usb/devices/"
,
PATH_MAX
);
strncpy
(
usb_path
,
"/sys/bus/usb/devices"
,
PATH_MAX
);
if
((
dir
=
opendir
(
usb_path
))
!=
NULL
)
{
if
((
dir
=
opendir
(
usb_path
))
!=
NULL
)
{
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
...
@@ -333,16 +312,19 @@ int get_devices(void)
...
@@ -333,16 +312,19 @@ int get_devices(void)
if
(
strstr
(
de
->
d_name
,
":"
)
||
strstr
(
de
->
d_name
,
"usb"
))
if
(
strstr
(
de
->
d_name
,
":"
)
||
strstr
(
de
->
d_name
,
"usb"
))
continue
;
continue
;
snprintf
(
product_path
,
PATH_MAX
,
"%s
/
%s/product"
,
usb_path
,
de
->
d_name
);
snprintf
(
product_path
,
PATH_MAX
,
"%s%s/product"
,
usb_path
,
de
->
d_name
);
printf
(
"product_path %s
\n
"
,
product_path
);
printf
(
"product_path %s
\n
"
,
product_path
);
memset
(
&
st
,
0
,
sizeof
(
struct
stat
));
memset
(
&
st
,
0
,
sizeof
(
struct
stat
));
rv
=
stat
(
product_path
,
&
st
);
rv
=
stat
(
product_path
,
&
st
);
if
(
rv
<
0
){
if
(
rv
<
0
){
perror
(
"stat"
);
perror
(
"stat"
);
continue
;
continue
;
}
}
name
=
get_interface_name
(
usb_path
,
de
->
d_name
);
printf
(
"returned name %s!
\n
"
,
name
);
snprintf
(
path
,
PATH_MAX
,
"%s%s/"
,
usb_path
,
de
->
d_name
);
name
=
get_device_name
(
path
);
if
(
!
name
)
if
(
!
name
)
continue
;
continue
;
...
...
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