>From 4358795cf083449ab499b5b05f50198bd116b8b5 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Sun, 10 Aug 2014 19:15:06 +0200 Subject: [PATCH] fix demonstrator and provide a different patch for ci --- src/ci.c | 26 +++------------------ src/z.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 39 deletions(-) diff --git a/src/ci.c b/src/ci.c index 72ddccd..3207133 100644 --- a/src/ci.c +++ b/src/ci.c @@ -1069,8 +1069,7 @@ ci_main (const char *cmd, int argc, char **argv) SAME_AFTER (from, bud.target->text); bud.d.pretty_log = getlogmsg (&reason, &bud); - /* "Rewind" ‘work.fro’ before feeding it to diff(1). */ - fro_bob (work.fro); + /* "Rewind" wfd before feeding it to diff(1). */ if (PROB (lseek (wfd, 0, SEEK_SET))) Ierror (); @@ -1086,27 +1085,8 @@ ci_main (const char *cmd, int argc, char **argv) if (DIFF_TROUBLE == runv (wfd, diffname, diffv)) RFATAL ("diff failed"); -#if 0 /* "tiny change" contributed by Achim Gratz: - - - status: on track to be installed, pending: - - configure-time check - - selection of appropriate #define name (to replace ‘#if 0’) - - ChangeLog entry - */ - - /* Re-open the work file to sync the notion of the - file position and the memory buffer. These may - have drifted apart due to sharing the fd with the - diff subprocess. */ - fro_zclose (&work.fro); - if (!(work.fro = fro_open (mani_filename, FOPEN_R_WORK, &work.st))) - { - syserror_errno (mani_filename); - continue; - } - -#endif + /* "Rewind" ‘work.fro’ after feeding it to diff(1). */ + fro_bob (work.fro); if (newhead) { diff --git a/src/z.c b/src/z.c index bef5bc2..41134f7 100644 --- a/src/z.c +++ b/src/z.c @@ -28,7 +28,7 @@ 1 -- unused 2 -- syscall failed 3 -- child problem - 4 -- unused + 4 -- parent doesn't read the whole file 5 -- parent sees EOF from child Results (platform, exit value, output): @@ -75,8 +75,37 @@ |cgot[29]: 0 => 114688 |status: 0 - * "cygwin" -- ??? (we would expect 5) - | ??? + * "cygwin" -- 4 + |argc: 1 + |argv[0]: ./z + |fd: 3 + |pgot[1]: 8192 => 8192 + |pgot[2]: 8192 => 16384 + |pgot[3]: 8192 => 24576 + |pgot[4]: 8192 => 32768 + |pgot[5]: 8192 => 40960 + |argc: 2 + |argv[0]: ./z + |argv[1]: child + |cgot[1]: 8192 => 8192 + |cgot[2]: 8192 => 16384 + |cgot[3]: 8192 => 24576 + |cgot[4]: 8192 => 32768 + |cgot[5]: 8192 => 40960 + |cgot[6]: 8192 => 49152 + |cgot[7]: 8192 => 57344 + |cgot[8]: 8192 => 65536 + |cgot[9]: 8192 => 73728 + |status: 0 + |pgot[1]: 8192 => 8192 + |pgot[2]: 8192 => 16384 + |pgot[3]: 8192 => 24576 + |pgot[4]: 8192 => 32768 + |pgot[5]: 8192 => 40960 + |pgot[6]: 8192 => 49152 + |pgot[7]: 1024 => 50176 + |truncated read! + */ #include @@ -99,7 +128,7 @@ child has produced. */ -#define BUF_SIZE 4096 /* fixme */ +#define BUF_SIZE 8192 /* fixme */ int fd; @@ -118,7 +147,7 @@ parent (void) pid_t pid; FILE *st; char buf[BUF_SIZE]; - size_t got; + off_t fend, sofar = 0; fd = open ("z.data", O_RDWR); if (0 > fd) @@ -128,16 +157,22 @@ parent (void) st = fdopen (fd, "r+"); if (! st) pbad ("fdopen"); + fseek (st, 0, SEEK_END); + fend = ftello (st); + fseek (st, 0, SEEK_SET); - for (int i = 1; i < 5; i++) + for (int i = 1; i < 6; i++) { - got = fread (buf, 1, sizeof (buf), st); - fprintf (stderr, "pgot[%d]: %zu\n", i, got); + off_t got = fread (buf, 1, sizeof (buf), st); + sofar += got; + fprintf (stderr, "pgot[%d]: %zu => %zu\n", i, got, sofar); } + fseeko (st, 0, SEEK_SET); + sofar = 0; - pid = fork (); + pid = vfork (); if (0 > pid) - pbad ("fork"); + pbad ("vfork"); if (! pid) /* child */ @@ -148,10 +183,10 @@ parent (void) if (0 > res) pbad ("dup2"); - res = execve (cmd[0], cmd, NULL); + res = execv (cmd[0], cmd); /* should not get here */ fprintf (stderr, "res: %d\nerrno: %d\n", res, errno); - pbad ("execve"); + pbad ("execv"); } else /* parent */ @@ -162,12 +197,26 @@ parent (void) if (pid != same) pbad ("stray child!"); + //fseeko (st, 0, SEEK_SET); + fprintf (stderr, "status: %d\n", status); if (feof (st)) { fprintf (stderr, "st at EOF!\n"); exit (5); } + for (int i = 1; ! feof (st); i++) + { + off_t got = fread (buf, 1, sizeof (buf), st); + + sofar += got; + fprintf (stderr, "pgot[%d]: %zu => %zu\n", i, got, sofar); + } + } + if (fend != sofar) + { + fprintf (stderr, "truncated read!\n"); + exit (4); } return EXIT_SUCCESS; @@ -184,7 +233,7 @@ int child (void) { char buf[BUF_SIZE]; - size_t sofar = 0; + off_t sofar = 0; FILE *st; if (0 != fd) @@ -193,14 +242,14 @@ child (void) cbad ("unepected fd"); } st = fdopen (fd, "r"); - for (int i = 1; ! feof (st); i++) + //for (int i = 1; ! feof (st); i++) + for (int i = 1; i < 10; i++) { - size_t got = fread (buf, 1, sizeof (buf), st); + off_t got = fread (buf, 1, sizeof (buf), st); sofar += got; fprintf (stderr, "cgot[%d]: %zu => %zu\n", i, got, sofar); } - return EXIT_SUCCESS; } -- 2.0.4