Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elbestream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
misc
elbestream
Commits
e1abc639
Unverified
Commit
e1abc639
authored
May 13, 2024
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to specify the directory for temporary files
parent
c9e7718d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
5 deletions
+54
-5
README.rst
README.rst
+8
-3
elbestream.c
elbestream.c
+26
-2
test.sh
test.sh
+20
-0
No files found.
README.rst
View file @
e1abc639
...
...
@@ -14,6 +14,7 @@ SYNOPSIS
::
./elbestream
[-d <directory>]
[-i <input buffer size> (default: 1048576 bytes)]
[-o <output buffer size> (default: 1048576 bytes)]
[-m <minimum output size>]
...
...
@@ -81,9 +82,13 @@ on the remainder of `stdin(3)`, with its output being sent to
`stdout(3)` as if only *try command* was run to begin with.
If, however, *try command* is considered to have failed, the input
buffer and the rest of `stdin(3)` are written to a temporary
file. Then, the ``%f`` argument of *fin command* is replaced with the
name of that file and *fin command* is run.
buffer and the rest of `stdin(3)` are written to a temporary file
created in the directory specified by the ``-d`` argument or, if it is
not given, the current working directory. Then, the ``%f`` argument of
*fin command* is replaced with the name of that file and *fin command*
is run.
The ``-d`` argument can not be the empty string.
IMPLEMENTATION DETAILS
======================
...
...
elbestream.c
View file @
e1abc639
...
...
@@ -66,6 +66,15 @@
#define closefif(fd) if (fd >= 0) closef(fd)
// from varnish-cache
/* Safe printf into a fixed-size buffer */
#define bprintf(buf, fmt, ...) \
do { \
int ibprintf; \
ibprintf = snprintf(buf, sizeof buf, fmt, __VA_ARGS__); \
assert(ibprintf >= 0 && ibprintf < (int)sizeof buf); \
} while (0)
static
void
blockf
(
int
fd
)
{
...
...
@@ -81,6 +90,7 @@ static void
usage
(
char
*
const
argv
[])
{
fprintf
(
stderr
,
"Usage: %s
\n
"
"
\t
[-d <directory>]
\n
"
"
\t
[-i <input buffer size> (default: %d bytes)]
\n
"
"
\t
[-o <output buffer size> (default: %d bytes)]
\n
"
"
\t
[-m <minimum output size>]
\n
"
...
...
@@ -362,6 +372,7 @@ main(int argc, char *argv[], char * const envp[])
{
size_t
ibufsz
=
DEF_IBUF
,
obufsz
=
DEF_OBUF
,
min
=
0
,
isz
=
0
,
tryisz
,
osz
;
char
*
dir
=
"."
;
ssize_t
r
=
0
;
char
*
ibufr
;
int
icompl
,
i
,
opt
,
finc
;
...
...
@@ -372,7 +383,7 @@ main(int argc, char *argv[], char * const envp[])
pid_t
pid
;
pthread_t
thr
;
while
((
opt
=
getopt
(
argc
,
argv
,
"i:o:m:"
))
!=
-
1
)
{
while
((
opt
=
getopt
(
argc
,
argv
,
"i:o:m:
d:
"
))
!=
-
1
)
{
ep
=
NULL
;
switch
(
opt
)
{
case
'i'
:
...
...
@@ -390,6 +401,9 @@ main(int argc, char *argv[], char * const envp[])
if
(
*
ep
!=
'\0'
)
argerr
(
argv
,
"-m"
,
ep
);
break
;
case
'd'
:
dir
=
optarg
;
break
;
default:
/* '?' */
usage
(
argv
);
exit
(
EXIT_FAILURE
);
...
...
@@ -408,6 +422,10 @@ main(int argc, char *argv[], char * const envp[])
fprintf
(
stderr
,
"-o argument can not be zero
\n
"
);
exit
(
EXIT_FAILURE
);
}
if
(
*
dir
==
'\0'
)
{
fprintf
(
stderr
,
"-d argument can not be empty
\n
"
);
exit
(
EXIT_FAILURE
);
}
tryv
=
&
argv
[
optind
];
...
...
@@ -488,8 +506,14 @@ main(int argc, char *argv[], char * const envp[])
closefif
(
readfd
);
closefif
(
writefd
);
strcpy
(
fn
,
"elbebuf.XXXXXX"
);
bprintf
(
fn
,
"%s/elbebuf.XXXXXX"
,
dir
);
writefd
=
mkstemp
(
fn
);
if
(
writefd
<
0
)
{
fprintf
(
stderr
,
"mkstemp(%s) failed: %s (%d)
\n\n
"
,
fn
,
strerror
(
errno
),
errno
);
cleanup
();
exit
(
EXIT_FAILURE
);
}
assert
(
writefd
>=
0
);
if
(
isz
>
0
)
{
r
=
write
(
writefd
,
ibuf
,
isz
);
...
...
test.sh
View file @
e1abc639
...
...
@@ -22,3 +22,23 @@ for i in 1 4 10 29 30 31 40 ; do
fi
done
done
# empty -d argument
if
./elbestream
-d
''
-i
$i
-o
$o
-m
1
--
$false
----
$cat
%f
;
then
echo
>
&2 FAIL
exit
9
fi
# -d OK
if
!
echo
"
${
t
}
"
| ./elbestream
-d
/tmp
-i
$i
-o
$o
-m
1
--
$false
\
----
$cat
%f
;
then
echo
>
&2 FAIL
exit
9
fi
# -d does not exist
if
echo
"
${
t
}
"
| ./elbestream
-d
xxx
-i
$i
-o
$o
-m
1
--
$false
\
----
$cat
%f
;
then
echo
>
&2 FAIL
exit
9
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment