jonls / redshift

Redshift adjusts the color temperature of your screen according to your surroundings. This may help your eyes hurt less if you are working in front of the screen at night.
http://jonls.dk/redshift
GNU General Public License v3.0
5.92k stars 429 forks source link

8d5cf30b: Does not start with error message "CRTC 2 does not exist. Only CRTC 0 exists." #157

Closed christian-burger closed 9 years ago

christian-burger commented 9 years ago

All began with 8d5cf30b4d47eb326a844ad11c15dac1bf040561 crashing on me. I bisected the problem to commit f9c2a1568c308ec69970662a8f5ceb8726e8d8cc. The actual error message when HEAD was compiled with -g -Og: CRTC 2 does not exist. Only CRTC 0 exists. Though f9c2a1568c308ec69970662a8f5ceb8726e8d8cc just crashes when compiled with -g -Og:

Program received signal SIGSEGV, Segmentation fault.
0x15799fd4 in randr_set_temperature_for_crtc (state=state@entry=0xb87d694c, crtc_num=crtc_num@entry=0, setting=setting@entry=0xb87d696c) at gamma-randr.c:316
316             xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc;
(gdb) print state->crtcs[crtc_num]
Cannot access memory at address 0x1
(gdb) print state
$1 = (randr_state_t *) 0xbe1a049c
(gdb) print state->crtcs
$2 = (randr_crtc_state_t *) 0x1

Looking at the changes in f9c2a1568c308ec69970662a8f5ceb8726e8d8cc, I am a bit at a loss about why. It just looks like there is just code movement?! My assumption for the moment is, that the problem existed before -- I tried v1.10 and it works. The problem is just being brought to daylight by moving the function. Looks to me that state->crtcs is not being correctly initialized?

Here is what I did to figure out why it crashed (minus the bisect), in case it is needed. I was debugging HEAD:

$ gdb ./redshift
GNU gdb (Gentoo 7.7.1 p1) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./redshift...done.
(gdb) run
Starting program: /home/christian/workbench/display/redshift.2/src/redshift 
warning: Cannot call inferior functions, Linux kernel PaX protection forbids return to non-executable pages!
Unknown configuration setting `#brightness-night'.
Using method `randr'.

Program received signal SIGSEGV, Segmentation fault.
0x1f6b5833 in randr_set_temperature_for_crtc (state=0xb4a0e544, crtc_num=<optimized out>, setting=0xb4a0e584) at gamma-randr.c:323
323             xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc;
(gdb) list
318                     }
319
320                     return -1;
321             }
322
323             xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc;
324             unsigned int ramp_size = state->crtcs[crtc_num].ramp_size;
325
326             /* Create new gamma ramps */
327             uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t));
(gdb) print state
$1 = (randr_state_t *) 0xb4a0e544
(gdb) print crtc_num
$2 = <optimized out>
(gdb) print state->crtcs[crtc_num].crtc
value has been optimized out

Okay, "optimized out"? However that happened, seems kinda important. I remade redshift with make CFLAGS="-g -Og". Let's try that again:

$ gdb ./redshift
GNU gdb (Gentoo 7.7.1 p1) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./redshift...done.
(gdb) run
Starting program: /home/christian/workbench/display/redshift.2/src/redshift 
warning: Cannot call inferior functions, Linux kernel PaX protection forbids return to non-executable pages!
Unknown configuration setting `#brightness-night'.
Using method `randr'.
CRTC 2 does not exist. Only CRTC 0 exists.
Temperature adjustment failed.
[Inferior 1 (process 4010) exited with code 01]

If you wonder about Unknown configuration setting '#brightness-night', I use # to comment out configurations. I re-did the last test with this simpler configuration file, just in case, same results:

$ cat ~/.config/redshift.conf
[redshift]
location-provider=manual

[manual]
lat=52.5
lon=13.4
jonls commented 9 years ago

Thanks, I'll take a look and see if can figure it out. Perhaps Valgrind would be helpful? By the way, you can use ; to indicate a comment in the configuration file.