Skip to content

Commit

Permalink
cffdump: pager-close
Browse files Browse the repository at this point in the history
At the end of output, close stdout and hang around until pager process
goes away.  This lets pager realize it is end of input instead of just
trying to wait forever for more output if you try to scroll to the
bottom.
  • Loading branch information
robclark committed Aug 6, 2015
1 parent 96244b2 commit 971491e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions util/cffdump.c
Expand Up @@ -28,10 +28,12 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <errno.h>

#include "redump.h"
#include "disasm.h"
Expand Down Expand Up @@ -1631,6 +1633,24 @@ static void pager_open(void)
}
}

static int pager_close(void)
{
siginfo_t status;

close(STDOUT_FILENO);

while (true) {
memset(&status, 0, sizeof(status));
if (waitid(P_PID, pager_pid, &status, WEXITED) < 0) {
if (errno == EINTR)
continue;
return -errno;
}

return 0;
}
}

int main(int argc, char **argv)
{
int ret, n = 1;
Expand Down Expand Up @@ -1762,6 +1782,10 @@ int main(int argc, char **argv)

script_finish();

if (interactive) {
pager_close();
}

return 0;
}

Expand Down

0 comments on commit 971491e

Please sign in to comment.