| 81 | |
| 82 | |
| 83 | int start_logger(const char* app_name) { |
| 84 | tag = app_name; |
| 85 | |
| 86 | /* make stdout line-buffered and stderr unbuffered */ |
| 87 | setvbuf(stdout, 0, _IOLBF, 0); |
| 88 | setvbuf(stderr, 0, _IONBF, 0); |
| 89 | |
| 90 | /* create the pipe and redirect stdout and stderr */ |
| 91 | pipe(pfd); |
| 92 | dup2(pfd[1], 1); |
| 93 | dup2(pfd[1], 2); |
| 94 | |
| 95 | /* spawn the logging thread */ |
| 96 | if (pthread_create(&thr, 0, thread_func, 0) == -1) { return -1; } |
| 97 | pthread_detach(thr); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | #endif |
| 102 |