Import package work effort from Nikolas Poniros <edhunter@sidux.com>.
[debian/lxdm.git] / debian / patches / stderr_stdout_to_log.patch
1 --- a/src/lxdm.c
2 +++ b/src/lxdm.c
3 @@ -176,6 +176,15 @@ void lxdm_quit_self(void)
4         exit(0);
5  }
6  
7 +void log_clear(void)
8 +{
9 +       FILE *log;
10 +       log=fopen("/var/log/lxdm.log","w");
11 +       if(!log)
12 +               return;
13 +       fclose(log);
14 +}
15 +
16  void log_print(char *fmt,...)
17  {
18         static FILE *log;
19 @@ -189,9 +198,14 @@ void log_print(char *fmt,...)
20         }
21         if(!log)
22         {
23 -               log=fopen("/var/log/lxdm.log","w");
24 +               log=fopen("/var/log/lxdm.log","a");
25                 if(!log)
26                         return;
27 +               fclose(log);
28 +               log=freopen("/var/log/lxdm.log","a",stdout);
29 +               setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
30 +               freopen("/var/log/lxdm.log","a",stderr);
31 +               setvbuf(stderr, NULL, _IONBF, BUFSIZ);
32         }
33         va_start(ap,fmt);
34         vfprintf(log,fmt,ap);
35 @@ -490,6 +504,7 @@ void startx(void)
36         if(!getenv("DISPLAY"))
37                 putenv("DISPLAY=:0");
38                 
39 +       log_print("%s\n","start X");
40         create_server_auth();
41                 
42         arg=g_key_file_get_string(config,"server","arg",0);
43 @@ -502,6 +517,8 @@ void startx(void)
44         switch(server){
45         case 0:
46                 setpgid(0,getpid());
47 +               // required to catch output
48 +               log_print("%s\n", "lxdm forked");
49                 execvp(args[0], args);
50                 break;
51         case -1:
52 @@ -909,6 +926,7 @@ int main(int arc,char *arg[])
53         
54         set_signal();
55         lxdm_get_tty();
56 +       log_clear();
57         startx();
58  
59         for(tmp=0;tmp<200;tmp++)
60