diff -urN mythtv/programs/mythfrontend/main.cpp mythtv.new/programs/mythfrontend/main.cpp
old
|
new
|
|
9 | 9 | #include <qwidget.h> |
10 | 10 | #include <fcntl.h> |
11 | 11 | #include <signal.h> |
| 12 | #include <cerrno> |
12 | 13 | #include <pthread.h> |
13 | 14 | |
14 | 15 | #include <iostream> |
… |
… |
|
53 | 54 | |
54 | 55 | ThemedMenu *menu; |
55 | 56 | XBox *xbox = NULL; |
| 57 | QString logfile = ""; |
56 | 58 | |
57 | 59 | void startGuide(void) |
58 | 60 | { |
… |
… |
|
735 | 737 | query.exec(); |
736 | 738 | } |
737 | 739 | |
| 740 | int log_rotate(int report_error) |
| 741 | { |
| 742 | int new_logfd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0664); |
| 743 | |
| 744 | if (new_logfd < 0) { |
| 745 | /* If we can't open the new logfile, send data to /dev/null */ |
| 746 | if (report_error) { |
| 747 | cerr << "cannot open logfile " << logfile << endl; |
| 748 | return -1; |
| 749 | } |
| 750 | |
| 751 | new_logfd = open("/dev/null", O_WRONLY); |
| 752 | |
| 753 | if (new_logfd < 0) { |
| 754 | /* There's not much we can do, so punt. */ |
| 755 | return -1; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | while (dup2(new_logfd, 1) < 0 && errno == EINTR); |
| 760 | while (dup2(new_logfd, 2) < 0 && errno == EINTR); |
| 761 | while (close(new_logfd) < 0 && errno == EINTR); |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | void log_rotate_handler(int) |
| 767 | { |
| 768 | log_rotate(0); |
| 769 | } |
| 770 | |
738 | 771 | int main(int argc, char **argv) |
739 | 772 | { |
740 | 773 | QString geometry = ""; |
… |
… |
|
752 | 787 | #endif |
753 | 788 | QApplication a(argc, argv); |
754 | 789 | |
755 | | QString logfile = ""; |
756 | | |
757 | 790 | QString pluginname = ""; |
758 | 791 | |
759 | 792 | QFileInfo finfo(a.argv()[0]); |
… |
… |
|
871 | 904 | } |
872 | 905 | } |
873 | 906 | |
874 | | int logfd = -1; |
875 | | |
876 | 907 | if (logfile != "") |
877 | 908 | { |
878 | | logfd = open(logfile.ascii(), O_WRONLY|O_CREAT|O_APPEND, 0664); |
879 | | |
880 | | if (logfd < 0) |
881 | | { |
882 | | perror("open(logfile)"); |
883 | | return FRONTEND_EXIT_OPENING_LOGFILE_ERROR; |
884 | | } |
885 | | } |
886 | | |
887 | | if (logfd != -1) |
888 | | { |
889 | | // Send stdout and stderr to the logfile |
890 | | dup2(logfd, 1); |
891 | | dup2(logfd, 2); |
892 | | |
893 | | // Close the unduplicated logfd |
894 | | if (logfd != 1 && logfd != 2) |
895 | | close(logfd); |
| 909 | if (log_rotate(1) < 0) |
| 910 | cerr << "cannot open logfile; using stdout/stderr" << endl; |
| 911 | else |
| 912 | signal(SIGHUP, &log_rotate_handler); |
896 | 913 | } |
897 | 914 | |
898 | 915 | if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) |
… |
… |
|
1081 | 1098 | pthread_join(priv_thread, &value); |
1082 | 1099 | } |
1083 | 1100 | |
| 1101 | signal(SIGHUP, SIG_DFL); |
| 1102 | |
1084 | 1103 | if (networkControl) |
1085 | 1104 | delete networkControl; |