[RISU,v5,10/13] risu: handle trace through stdin/stdout

Message ID 20170619104655.31104-11-alex.bennee@linaro.org
State Superseded
Headers show
Series
  • RISU record/replay patches
Related show

Commit Message

Alex Bennée June 19, 2017, 10:46 a.m.
Trace files can get quite large so it would be useful to be able to
just capture the trace stream with stdin/stdout for processing in a
pipe line. The sort of case where this is useful is for building
static binaries where zlib support is missing for whatever reason.

It can also be used in testing pipelines.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 risu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

-- 
2.13.0

Comments

Peter Maydell June 20, 2017, 2:14 p.m. | #1
On 19 June 2017 at 11:46, Alex Bennée <alex.bennee@linaro.org> wrote:
> Trace files can get quite large so it would be useful to be able to

> just capture the trace stream with stdin/stdout for processing in a

> pipe line. The sort of case where this is useful is for building

> static binaries where zlib support is missing for whatever reason.

>

> It can also be used in testing pipelines.

>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  risu.c | 12 ++++++++++--

>  1 file changed, 10 insertions(+), 2 deletions(-)

>

> diff --git a/risu.c b/risu.c

> index 93c274b..e94b54b 100644

> --- a/risu.c

> +++ b/risu.c

> @@ -312,7 +312,11 @@ int main(int argc, char **argv)

>

>      if (ismaster) {

>          if (trace) {

> -            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);

> +            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {


Why not just strcmp() ?

> +                master_fd = fileno(stdout);


   = STDOUT_FILENO;

> +            } else {

> +                master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);

> +            }

>          } else {

>              fprintf(stderr, "master port %d\n", port);

>              master_fd = master_connect(port);

> @@ -320,7 +324,11 @@ int main(int argc, char **argv)

>          return master();

>      } else {

>          if (trace) {

> -            apprentice_fd = open(trace_fn, O_RDONLY);

> +            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {

> +                apprentice_fd = fileno(stdin);


 = STDIN_FILENO;

> +            } else {

> +                apprentice_fd = open(trace_fn, O_RDONLY);

> +            }

>          } else {

>              fprintf(stderr, "apprentice host %s port %d\n", hostname, port);

>              apprentice_fd = apprentice_connect(hostname, port);

> --

> 2.13.0

>


thanks
-- PMM
Alex Bennée June 20, 2017, 2:58 p.m. | #2
Peter Maydell <peter.maydell@linaro.org> writes:

> On 19 June 2017 at 11:46, Alex Bennée <alex.bennee@linaro.org> wrote:

>> Trace files can get quite large so it would be useful to be able to

>> just capture the trace stream with stdin/stdout for processing in a

>> pipe line. The sort of case where this is useful is for building

>> static binaries where zlib support is missing for whatever reason.

>>

>> It can also be used in testing pipelines.

>>

>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>> ---

>>  risu.c | 12 ++++++++++--

>>  1 file changed, 10 insertions(+), 2 deletions(-)

>>

>> diff --git a/risu.c b/risu.c

>> index 93c274b..e94b54b 100644

>> --- a/risu.c

>> +++ b/risu.c

>> @@ -312,7 +312,11 @@ int main(int argc, char **argv)

>>

>>      if (ismaster) {

>>          if (trace) {

>> -            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);

>> +            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {

>

> Why not just strcmp() ?


Years of habit...

>

>> +                master_fd = fileno(stdout);

>

>    = STDOUT_FILENO;


heh , the original version used that. I'll put it back.

>

>> +            } else {

>> +                master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);

>> +            }

>>          } else {

>>              fprintf(stderr, "master port %d\n", port);

>>              master_fd = master_connect(port);

>> @@ -320,7 +324,11 @@ int main(int argc, char **argv)

>>          return master();

>>      } else {

>>          if (trace) {

>> -            apprentice_fd = open(trace_fn, O_RDONLY);

>> +            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {

>> +                apprentice_fd = fileno(stdin);

>

>  = STDIN_FILENO;

>

>> +            } else {

>> +                apprentice_fd = open(trace_fn, O_RDONLY);

>> +            }

>>          } else {

>>              fprintf(stderr, "apprentice host %s port %d\n", hostname, port);

>>              apprentice_fd = apprentice_connect(hostname, port);

>> --

>> 2.13.0

>>

>

> thanks

> -- PMM



--
Alex Bennée

Patch hide | download patch | download mbox

diff --git a/risu.c b/risu.c
index 93c274b..e94b54b 100644
--- a/risu.c
+++ b/risu.c
@@ -312,7 +312,11 @@  int main(int argc, char **argv)
 
     if (ismaster) {
         if (trace) {
-            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {
+                master_fd = fileno(stdout);
+            } else {
+                master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            }
         } else {
             fprintf(stderr, "master port %d\n", port);
             master_fd = master_connect(port);
@@ -320,7 +324,11 @@  int main(int argc, char **argv)
         return master();
     } else {
         if (trace) {
-            apprentice_fd = open(trace_fn, O_RDONLY);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {
+                apprentice_fd = fileno(stdin);
+            } else {
+                apprentice_fd = open(trace_fn, O_RDONLY);
+            }
         } else {
             fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
             apprentice_fd = apprentice_connect(hostname, port);