Skip to content
Snippets Groups Projects
Commit c92949c3 authored by Simon McVittie's avatar Simon McVittie
Browse files

capture-libs: Allow patterns to be read from a file


The pressure-vessel tool used in the Steam Runtime has an increasingly
long list of graphics libraries which might be better as a file
than on the command-line.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent e8079fed
Branches
Tags
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
...@@ -49,6 +49,19 @@ my $container = "${test_tempdir}/container"; ...@@ -49,6 +49,19 @@ my $container = "${test_tempdir}/container";
mkdir($container); mkdir($container);
my $libdir = "${test_tempdir}/libdir"; my $libdir = "${test_tempdir}/libdir";
{
open(my $fh, '>', "${test_tempdir}/empty");
close $fh;
}
{
open(my $fh, '>', "${test_tempdir}/libc");
print $fh "# comment\n";
print $fh "\n";
print $fh "soname:libc.so.6\n";
print $fh "soname:libc.so.6"; # deliberately no trailing newline
close $fh;
}
run_ok(['rm', '-fr', $libdir]); run_ok(['rm', '-fr', $libdir]);
mkdir($libdir); mkdir($libdir);
run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, 'soname:libc.so.6'], '>&2', run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, 'soname:libc.so.6'], '>&2',
...@@ -97,7 +110,9 @@ run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host, ...@@ -97,7 +110,9 @@ run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host,
qw(--dev-bind /dev /dev), qw(--dev-bind /dev /dev),
$CAPSULE_CAPTURE_LIBS_TOOL, $CAPSULE_CAPTURE_LIBS_TOOL,
"--dest=$libdir", "--dest=$libdir",
"--provider=$host", 'soname:libc.so.6'], '>&2'); "--provider=$host",
"from:$test_tempdir/empty",
"from:$test_tempdir/libc"], '>&2');
{ {
opendir(my $dir_iter, $libdir); opendir(my $dir_iter, $libdir);
my @links = sort grep { $_ ne '.' and $_ ne '..' } readdir $dir_iter; my @links = sort grep { $_ ne '.' and $_ ne '..' } readdir $dir_iter;
......
...@@ -246,6 +246,8 @@ static void usage (int code) ...@@ -246,6 +246,8 @@ static void usage (int code)
fprintf( fh, "\n" ); fprintf( fh, "\n" );
fprintf( fh, "Each PATTERN is one of:\n" ); fprintf( fh, "Each PATTERN is one of:\n" );
fprintf( fh, "\n" ); fprintf( fh, "\n" );
fprintf( fh, "from:FILE\n"
"\tRead PATTERNs from FILE, one per line.\n" );
fprintf( fh, "soname:SONAME\n" fprintf( fh, "soname:SONAME\n"
"\tCapture the library in ld.so.cache whose name is\n" "\tCapture the library in ld.so.cache whose name is\n"
"\texactly SONAME\n" ); "\texactly SONAME\n" );
...@@ -325,6 +327,9 @@ fail: ...@@ -325,6 +327,9 @@ fail:
return false; return false;
} }
static bool capture_pattern( const char *pattern, capture_flags flags,
int *code, char **message );
static bool capture_patterns( const char * const *patterns, static bool capture_patterns( const char * const *patterns,
capture_flags flags, capture_flags flags,
int *code, char **message ); int *code, char **message );
...@@ -823,6 +828,54 @@ capture_path_match( const char *pattern, capture_flags flags, ...@@ -823,6 +828,54 @@ capture_path_match( const char *pattern, capture_flags flags,
return ret; return ret;
} }
static bool
capture_lines( const char *filename, capture_flags flags,
int *code, char **message )
{
FILE *fp = NULL;
bool ret = true;
char *line = NULL;
size_t len = 0;
ssize_t chars;
if( strcmp( filename, "-" ) != 0 )
{
fp = fopen( filename, "re" );
if( fp == NULL )
{
_capsule_set_error( code, message, errno,
"Unable to open \"%s\": %s",
filename, strerror( errno ) );
return false;
}
}
while( ( chars = getline( &line, &len, fp ? fp : stdin ) ) > -1 )
{
/* Ignore blank lines and shell-style comments (which must
* currently be at the beginning of the line) */
if( chars == 0 || line[0] == '\0' || line[0] == '\n' || line[0] == '#' )
continue;
if( line[chars - 1] == '\n' )
line[chars - 1] = '\0';
if( !capture_pattern( line, flags, code, message ) )
{
ret = false;
break;
}
}
free( line );
if( fp != NULL )
fclose( fp );
return ret;
}
static bool static bool
capture_pattern( const char *pattern, capture_flags flags, capture_pattern( const char *pattern, capture_flags flags,
int *code, char **message ) int *code, char **message )
...@@ -1013,6 +1066,12 @@ capture_pattern( const char *pattern, capture_flags flags, ...@@ -1013,6 +1066,12 @@ capture_pattern( const char *pattern, capture_flags flags,
code, message ); code, message );
} }
if( strstarts( pattern, "from:" ) )
{
return capture_lines( pattern + strlen( "from:" ),
flags, code, message );
}
if( strchr( pattern, ':' ) != NULL ) if( strchr( pattern, ':' ) != NULL )
{ {
_capsule_set_error( code, message, EINVAL, _capsule_set_error( code, message, EINVAL,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment