5 ms·
Hmm, it seems like you need to make sure the computer is on before calling this function, or else you run the risk of getting back undefined data. Seems like w
by eminence32 5y ago
Hmm, it seems like you need to make sure the computer is on before calling this function, or else you run the risk of getting back undefined data. Seems like we also need a function that can be used to tell if the computer is on...
- salawat 5y agoNah. Just bump that responsibility to the caller, and power supply manufacturer. Have the caller call power_on_computer() first always. This will ensure you always get defined state! ...What do you mean not every power supply manufacturer implements the power_on_computer() function as a NOOP if the computer is already on?!
- h2odragon 5y agoSome implement it that way, some it returns and error message or throws an NMI; then ya got the cheap clones that use it to frob a toggle without regard to the state it was in (which there's no way to read)... Then ya got the weird ones (HP) where it only works right if you call it twice with a 40ms delay between while streaming a sample from "Swan Lake" over their NDA'd 1wire thingy.
- marcodiego 5y agoI know that at least Solaris implemented SIGPWR signal to inform programs of a power failure: https://community.bmc.com/s/article/Inquira-KA334556 https://community.bmc.com/s/article/Inquira-KA334556
- marcodiego 5y agoTIL: linux also implements SIGPWR. Using "kill -PWR `pidof dd`" killed it with "power failure".
- ancode 5y agoThere's a syscall to check whether the computer is on so just call that before this and you'll be fine
- Someone 5y agoThat introduces a time-of-check to time-of-use bug (https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use).
- nvader 5y agoAh, good ole TOCTOU
- waterhouse 5y agoAha. If only the API was "Execute a user-provided function in a context where the computer is guaranteed to be on".
- bryan_w 5y agoYou need to halt this thinking at once