Commit baaf2496 authored by platypro's avatar platypro

Fixed high CPU usage when /dev/null passed as stdin

parent 0b2bdebb
......@@ -3,6 +3,8 @@ Quiz Grinder TODO
General
* [X] Command-line interface for backend
* [ ] Built-in exercise types
* [ ] Persistent users
Generation Modes
* [X] Random
......@@ -21,10 +23,12 @@ Widgets
* [X] NumberInput
* [X] TextInput
* [ ] ChoiceInput
* [ ] Answer options
* [ ] Custom widgets
Docs
* [ ] Building and deploying
* [ ] RESTful API
* [ ] Comand-line usage
* [ ] Command-line usage
* [ ] Creating problems
* [ ] Web front-end
* [ ] Widget, Lua API, and Exercise reference
Subproject commit af7977f368164ea7d64ae3e5723a1b6476f86270
Subproject commit 45493414a796fb57d7b23cebe128dd9b45c45198
......@@ -27,6 +27,11 @@ bool daemon_run(PG_STATE* state)
exercise_loadAll(state);
pcg32_srandom(time(NULL), (intptr_t)&printf);
char link[256];
ssize_t rval;
rval = readlink("/proc/self/fd/1", link, sizeof(link));
link[rval] = '\0';
//Change term settings
if (tcgetattr( STDIN_FILENO, &term) == 0)
{
......@@ -37,6 +42,11 @@ bool daemon_run(PG_STATE* state)
while((c = getchar()) != 'q')
{
if(c == -1)
{
daemon_http_join(state);
break;
}
switch(c)
{
case 'r':
......
......@@ -383,6 +383,12 @@ bool daemon_http_start(PG_STATE* state)
return true;
}
bool daemon_http_join(PG_STATE* state)
{
pthread_join(state->http.thread, NULL);
return true;
}
bool daemon_http_stop(PG_STATE* state)
{
pthread_cancel(state->http.thread);
......
......@@ -75,6 +75,7 @@ typedef enum RequestType
} REQUESTTYPE;
extern bool daemon_http_start(struct PG_State* state);
extern bool daemon_http_join(struct PG_State* state);
extern bool daemon_http_stop(struct PG_State* state);
#endif /*INCLUDE_SESSION_H*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment