Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Graceful loop end
  • Loading branch information
bryan-hoyle committed Oct 2, 2017
commit bace087155e7c54293d44341fa552fb229d588ac
10 changes: 6 additions & 4 deletions src/logkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ std::string execute(const char* cmd)
}

std::vector<int> input_fds;
bool reading = true;

void signal_handler(int signal)
{
for(int i = 0; i < input_fds.size(); i++){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed int here raises a compilation warning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I'll change that sometime in the afternoon in the next week or so. If you want to make the change, it should be an unsigned long i.

close(input_fds[i]); // closing input file will break the infinite while loop
close(input_fds[i]); // closing input files safely
}
exit(0);
reading = false; // End while loop

}

void set_utf8_locale()
Expand Down Expand Up @@ -503,8 +505,8 @@ int main(int argc, char **argv)
}
}

// infinite loop: exit gracefully by receiving SIGHUP, SIGINT or SIGTERM (of which handler closes input_fd)
while (1) {
// infinite loop: exit gracefully by receiving SIGHUP, SIGINT or SIGTERM (of which handler closes input_fds)
while (reading) {
int x = select(maxfd+1, &read_fds, NULL, NULL, NULL);
for(unsigned long i = 0; i < input_fds.size() && x > 0; i++){
int input_fd = input_fds[i];
Expand Down