Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steamrt
steam-runtime-tools
Commits
ecc78375
Commit
ecc78375
authored
4 years ago
by
Simon McVittie
Browse files
Options
Downloads
Patches
Plain Diff
inspect-library: Use gcc cleanup attribute for cleanup
Signed-off-by:
Simon McVittie
<
smcv@collabora.com
>
parent
400f2496
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!131
Refactor inspect-library
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
helpers/inspect-library.c
+46
-32
46 additions, 32 deletions
helpers/inspect-library.c
with
46 additions
and
32 deletions
helpers/inspect-library.c
+
46
−
32
View file @
ecc78375
...
...
@@ -46,7 +46,6 @@
#define BASE "Base"
static
void
print_json_string_content
(
const
char
*
s
);
static
void
clean_exit
(
void
*
handle
);
static
bool
has_symbol
(
void
*
handle
,
const
char
*
symbol
);
static
bool
has_versioned_symbol
(
void
*
handle
,
const
char
*
symbol
,
...
...
@@ -72,6 +71,44 @@ do { \
oom (); \
} while (0)
static
inline
void
*
steal_pointer
(
void
*
pp
)
{
typedef
void
*
__attribute__
((
may_alias
))
voidp_alias
;
voidp_alias
*
pointer_to_pointer
=
pp
;
void
*
ret
=
*
pointer_to_pointer
;
*
pointer_to_pointer
=
NULL
;
return
ret
;
}
static
void
clear_with_free
(
void
*
pp
)
{
free
(
steal_pointer
(
pp
));
}
static
void
clear_with_dlclose
(
void
*
pp
)
{
void
*
handle
=
steal_pointer
(
pp
);
if
(
handle
!=
NULL
)
dlclose
(
handle
);
}
static
void
clear_with_fclose
(
void
*
pp
)
{
FILE
*
fh
=
steal_pointer
(
pp
);
if
(
fh
!=
NULL
)
fclose
(
fh
);
}
#define autodlclose __attribute__((__cleanup__(clear_with_dlclose)))
#define autofclose __attribute__((__cleanup__(clear_with_fclose)))
#define autofree __attribute__((__cleanup__(clear_with_free)))
enum
{
OPTION_HELP
=
1
,
...
...
@@ -152,15 +189,15 @@ main (int argc,
const
char
*
soname
;
const
char
*
version
;
const
char
*
symbol
;
void
*
handle
=
NULL
;
autodlclose
void
*
handle
=
NULL
;
struct
link_map
*
dep_map
=
NULL
;
struct
link_map
*
the_library
=
NULL
;
FILE
*
fp
;
char
*
missing_symbols
=
NULL
;
char
*
misversioned_symbols
=
NULL
;
autofclose
FILE
*
fp
=
NULL
;
autofree
char
*
missing_symbols
=
NULL
;
autofree
char
*
misversioned_symbols
=
NULL
;
size_t
missing_n
=
0
;
size_t
misversioned_n
=
0
;
char
*
line
=
NULL
;
autofree
char
*
line
=
NULL
;
size_t
len
=
0
;
ssize_t
chars
;
bool
first
;
...
...
@@ -242,7 +279,6 @@ main (int argc,
if
(
dlopen
(
hidden_deps
[
i
],
RTLD_NOW
|
RTLD_GLOBAL
)
==
NULL
)
{
fprintf
(
stderr
,
"Unable to find the dependency library: %s
\n
"
,
dlerror
());
clean_exit
(
handle
);
return
1
;
}
}
...
...
@@ -251,7 +287,6 @@ main (int argc,
if
(
handle
==
NULL
)
{
fprintf
(
stderr
,
"Unable to find the library: %s
\n
"
,
dlerror
());
clean_exit
(
handle
);
return
1
;
}
/* Using RTLD_DI_LINKMAP insted of RTLD_DI_ORIGIN we don't need to worry
...
...
@@ -259,7 +294,6 @@ main (int argc,
if
(
dlinfo
(
handle
,
RTLD_DI_LINKMAP
,
&
the_library
)
!=
0
||
the_library
==
NULL
)
{
fprintf
(
stderr
,
"Unable to obtain the path: %s
\n
"
,
dlerror
());
clean_exit
(
handle
);
return
1
;
}
...
...
@@ -301,7 +335,6 @@ main (int argc,
fprintf
(
stderr
,
"Error reading
\"
%s
\"
: %s
\n
"
,
argv
[
optind
+
1
],
strerror
(
saved_errno
));
clean_exit
(
handle
);
return
1
;
}
...
...
@@ -368,10 +401,6 @@ main (int argc,
if
(
symbol
==
NULL
)
{
fprintf
(
stderr
,
"Probably the symbol@version pair is mispelled."
);
free
(
line
);
free
(
missing_symbols
);
free
(
misversioned_symbols
);
clean_exit
(
handle
);
return
1
;
}
...
...
@@ -390,20 +419,17 @@ main (int argc,
}
else
if
(
!
has_versioned_symbol
(
handle
,
symbol
,
version
))
{
char
*
merged_string
;
autofree
char
*
merged_string
=
NULL
;
asprintf_or_die
(
&
merged_string
,
"%s@%s"
,
symbol
,
version
);
if
(
has_symbol
(
handle
,
symbol
))
argz_add_or_die
(
&
misversioned_symbols
,
&
misversioned_n
,
merged_string
);
else
argz_add_or_die
(
&
missing_symbols
,
&
missing_n
,
merged_string
);
free
(
merged_string
);
}
}
}
}
free
(
line
);
fclose
(
fp
);
if
(
deb_symbols
&&
!
found_our_soname
)
{
...
...
@@ -442,9 +468,6 @@ main (int argc,
printf
(
"
\"
"
);
}
printf
(
"
\n
]"
);
free
(
missing_symbols
);
free
(
misversioned_symbols
);
}
dep_map
=
the_library
;
...
...
@@ -473,7 +496,7 @@ main (int argc,
}
printf
(
"
\n
]
\n
}"
);
clean_exit
(
handle
);
printf
(
"
\n
}
\n
"
);
return
0
;
}
...
...
@@ -492,15 +515,6 @@ print_json_string_content (const char *s)
}
}
static
void
clean_exit
(
void
*
handle
)
{
if
(
handle
!=
NULL
)
dlclose
(
handle
);
printf
(
"
\n
}
\n
"
);
}
static
bool
has_symbol
(
void
*
handle
,
const
char
*
symbol
)
...
...
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