Difference between revisions of "Watchdog"

From AwkwardTV
Jump to: navigation, search
m
Line 1: Line 1:
[http://dir.rigour.info/calciatori-nudi/ calciatori nudi] [http://it.rigour.info/topic/audiostar-fm/ audiostar fm] [http://uve.rigour.info/blog/infrazione-stradale.htm infrazione stradale] [http://online.rigour.info/populorum-progressio/ populorum progressio] [http://here.rigour.info/blog/malattie-mentale.htm malattie mentale buffet] [http://pagina.rigour.info/malnatt/ malnatt] [http://speed.rigour.info/chitarra-romana.htm chitarra romana di lazzaro] [http://it.rigour.info/topic/silent-cristmas/ silent cristmas] [http://paga.rigour.info/locandina-film/ locandina film the rock] [http://all.rigour.info/f-/ f 55 nikon] [http://up.rigour.info/description/lib/ovan-i.htm ovan i delfin] [http://dir.rigour.info/king-of/ king of convience] [http://here.rigour.info/blog/loghi-olimpionici.htm loghi olimpionici] [http://pagina.rigour.info/guadagna-da/ guadagna da casa] [http://speed.rigour.info/elemental-gimmick.htm elemental gimmick gear] [http://here.rigour.info/blog/albergo-aurora.htm albergo aurora nord] [http://it.rigour.info/topic/elisabetta-gardini/ elisabetta gardini] [http://up.rigour.info/description/lib/lusaka.htm lusaka] [http://dir.rigour.info/driver-c/ driver c385] [http://web.rigour.info/saint-john/ saint john (isola delle picco...] [http://web.rigour.info/rischio-di/ rischio di cambio e tecniche] [http://guest.rigour.info/library/html/subah-ho/ subah ho gayi] [http://online.rigour.info/nike/ nike 2004-2005] [http://content.rigour.info/html/tieta-do/ tieta do brasil] [http://dir.rigour.info/tendenze-dell/ tendenze dell architettura contemporanea] [http://gratis.rigour.info/content/view/ariete-macchina.htm ariete macchina da caffe] [http://it.rigour.info/topic/scoobydoo-e/ scooby-doo e il lupo mannaro] [http://paga.rigour.info/lamb-gabriel/ lamb gabriel] [http://gratis.rigour.info/content/view/giacche-pelle.htm giacche pelle] [http://pagina.rigour.info/creare-collana/ creare collana] [http://note.rigour.info/content/view/trucchi-gta.htm trucchi gta san andreas] [http://note.rigour.info/content/view/quinta-estacion.htm quinta estacion] [http://speed.rigour.info/bomberman-ds.htm bomberman ds videogiochi] [http://online.rigour.info/pamela-anderson/ pamela anderson porno video] [http://milano.rigour.info/mp-vera.htm mp3 vera sal da vinci] [http://gratis.rigour.info/content/view/affinita-nomi.htm affinita nomi] [http://note.rigour.info/content/view/don-chisciotte.htm don chisciotte film dvd] [http://load.rigour.info/view/new/sony-dcr.htm sony dcr dvd202] [http://pagina.rigour.info/sento-le/ sento le campane] [http://pagina.rigour.info/she-weel/ she weel be love] [http://uve.rigour.info/blog/plafoniere-casa.htm plafoniere casa] [http://online.rigour.info/puta-con/ puta con] [http://guest.rigour.info/library/html/sfondata/ sfondata] [http://speed.rigour.info/la-banda.htm la banda di jesse james] [http://italy.rigour.info/blog/amanti-nelle.htm amanti nelle tenebre] [http://pagina.rigour.info/hit-mania/ hit mania dance 006] [http://speed.rigour.info/keith-m.htm keith m maupin kill] [http://gratis.rigour.info/content/view/pulitore-polaris.htm pulitore polaris] [http://here.rigour.info/blog/duke-nuken.htm duke nuken] [http://web.rigour.info/wifi-access/ wifi access point adsl] [http://load.rigour.info/view/new/quattro-scatti.htm quattro scatti e una data per il nuovo singles] [http://paga.rigour.info/lee-yeongae/ lee yeong-ae] [http://dir.rigour.info/sonietta/ sonietta] [http://note.rigour.info/content/view/garmin-gps.htm garmin gps quest] [http://speed.rigour.info/sorella-mia.htm sorella mia] [http://guest.rigour.info/library/html/vacanze-italia/ vacanze italia] [http://load.rigour.info/view/new/piscine-fuori.htm piscine fuori terra in legno] [http://all.rigour.info/camicie-coreana/ camicie coreana] [http://note.rigour.info/content/view/frisk.htm frisk] [http://load.rigour.info/view/new/dvd-recorder.htm dvd recorder daewoo 7100] [http://uve.rigour.info/blog/figurine.htm figurine] [http://pagina.rigour.info/adidas-mei/ adidas mei] [http://speed.rigour.info/maggio-si.htm maggio si tu] [http://gratis.rigour.info/content/view/donne-incinte.htm donne incinte porche] [http://online.rigour.info/discoteche-del/ discoteche del veneto] [http://paga.rigour.info/darna/ darna] [http://up.rigour.info/description/lib/frasi-per.htm frasi per innamorati] [http://gratis.rigour.info/content/view/obie-bermudez.htm obie bermudez] [http://here.rigour.info/blog/tempesta-su.htm tempesta su washington] [http://web.rigour.info/nina-badric/ nina badric] [http://pagina.rigour.info/assicurazione-generali/ assicurazione generali] [http://dir.rigour.info/batterie-alcaline/ batterie alcaline] [http://web.rigour.info/fimati-erotici/ fimati erotici] [http://content.rigour.info/html/asus-car/ asus car kit] [http://note.rigour.info/content/view/albergo-trapani.htm albergo trapani] [http://guest.rigour.info/library/html/mutuo-prima/ mutuo prima casa sardegna] [http://pagina.rigour.info/sony-acvqp/ sony ac-vqp10] [http://uve.rigour.info/blog/immobiliare-banche.htm immobiliare banche] [http://italy.rigour.info/blog/temptation-island.htm temptation island] [http://paga.rigour.info/patente-c/ patente c] [http://down.rigour.info/blog/scale-elicoidali.htm scale elicoidali] [http://gratis.rigour.info/content/view/winny-thepooh.htm winny thepooh] [http://here.rigour.info/blog/monitor-.htm monitor 20 apple cinema] [http://online.rigour.info/dizionario-della/ dizionario della lingua italiana] [http://load.rigour.info/view/new/lamore-nasce.htm lamore nasce a roma] [http://blog.rigour.info/web/nikon-/ nikon 55-200 dx] [http://milano.rigour.info/mensaje-de.htm mensaje de texto de telefonica] [http://all.rigour.info/ambulatori-veterinari/ ambulatori veterinari grosseto] [http://web.rigour.info/thierry-cham/ thierry cham] [http://down.rigour.info/blog/dragos-team.htm dragos team] [http://blog.rigour.info/web/kt-tunstall/ kt tunstall eye telescope] [http://online.rigour.info/compositor-dale/ compositor dale don nokia] [http://guest.rigour.info/library/html/amd-ane/ amd a8n-e] [http://italy.rigour.info/blog/guardaroba-.htm guardaroba 2 ante] [http://online.rigour.info/perez-prado/ perez prado] [http://pagina.rigour.info/dimage-z/ dimage z5 nera] [http://load.rigour.info/view/new/orario-di.htm orario di lavoro negli ospedali] [http://all.rigour.info/bart-wars/ bart wars] [http://milano.rigour.info/gs.htm gs 500] [http://online.rigour.info/casio-exilim/ casio exilim ex- z750] [http://guest.rigour.info/library/html/nora-j/ nora j sunrise] [http://blog.rigour.info/web/dosatore-latte/ dosatore latte] [http://milano.rigour.info/albergo-bolzano.htm albergo bolzano] [http://paga.rigour.info/tylko-czarne/ tylko czarne oczy] [http://gratis.rigour.info/content/view/obiettivi-canon.htm obiettivi canon 90 -300] [http://gratis.rigour.info/content/view/wosvagen.htm wosvagen] [http://content.rigour.info/html/biglietto-di/ biglietto di pasqua] [http://content.rigour.info/html/lacie-gb/ lacie 200gb usb2] [http://it.rigour.info/topic/winni-the/ winni the pooh] [http://here.rigour.info/blog/fornitore-creta.htm fornitore creta] [http://online.rigour.info/prove-d/ prove d esame] [http://gratis.rigour.info/content/view/nokia-cnt.htm nokia cnt] [http://dir.rigour.info/olimpiadi-programma/ olimpiadi programma 15 08] [http://online.rigour.info/hotel-costa/ hotel costa del sol] [http://paga.rigour.info/lettore-dvd/ lettore dvd con tv] [http://down.rigour.info/blog/foto-di.htm foto di linda batista] [http://uve.rigour.info/blog/jinotega.htm jinotega] [http://blog.rigour.info/web/coldplay-video/ coldplay video] [http://down.rigour.info/blog/bowlinggames.htm bowlinggames] [http://blog.rigour.info/web/ian-brown/ ian brown] [http://blog.rigour.info/web/toner-scx/ toner scx-4720] [http://note.rigour.info/content/view/tema-guerra.htm tema guerra in iraq] [http://pagina.rigour.info/i-belong/ i belong to myself] [http://up.rigour.info/description/lib/magnetic-readers.htm magnetic readers] [http://paga.rigour.info/pantaloni-sci/ pantaloni sci] [http://down.rigour.info/blog/il-terribile.htm il terribile ispettore] [http://milano.rigour.info/the-sims.htm the sims - fuori tutti] [http://blog.rigour.info/web/hifi-united/ hifi united piacenza] [http://all.rigour.info/magari-rnato/ magari rnato zero] [http://note.rigour.info/content/view/manic-street.htm manic street teachers] [http://guest.rigour.info/library/html/federica/ federica] [http://uve.rigour.info/blog/recorder-dvdvhs.htm recorder dvd-vhs] [http://blog.rigour.info/web/txp-l/ t2xp l] [http://speed.rigour.info/hard-disk.htm hard disk 40 gb] [http://blog.rigour.info/web/soluzzioni-giochi/ soluzzioni giochi] [http://paga.rigour.info/pioneer-ns/ pioneer ns f10] [http://web.rigour.info/e-cellulari/ e-630 cellulari samsung] [http://blog.rigour.info/web/tv-upskirt/ tv upskirt] [http://content.rigour.info/html/in-the/ in the sahdow] [http://it.rigour.info/topic/gioiellerie-vercelli/ gioiellerie vercelli] [http://web.rigour.info/phillips-stephen/ phillips, stephen] [http://dir.rigour.info/fiera-ottica/ fiera ottica mido] [http://it.rigour.info/topic/contatori-pagina/ contatori pagina web] [http://content.rigour.info/html/il-gatto/ il gatto e la volpe midi] [http://guest.rigour.info/library/html/tv-con/ tv con ddt] [http://paga.rigour.info/turn-me/ turn me on de kevin little] [http://guest.rigour.info/library/html/la-terribile/ la terribile armata] [http://paga.rigour.info/dvd-cinema/ dvd cinema] [http://dir.rigour.info/francesca-duranti/ francesca duranti] [http://uve.rigour.info/blog/midi-file.htm midi file lo strano percorso] [http://gratis.rigour.info/content/view/grand-theft.htm grand theft auto diventa una serie anche su psp] [http://note.rigour.info/content/view/braun-combimax.htm braun combimax] [http://pagina.rigour.info/xbox-ps/ xbox ps2] [http://here.rigour.info/blog/midland-alan.htm midland alan 37] [http://milano.rigour.info/video-gratis.htm video gratis nolin] [http://pagina.rigour.info/olimpia-splendid/ olimpia splendid 20 hp] [http://up.rigour.info/description/lib/crea-il.htm crea il tuo personaggio e quello del tuo nemico e poi lotta] [http://dir.rigour.info/microsoft-guarda/ microsoft guarda avanti (dieci anni) in giappone] [http://here.rigour.info/blog/palmari-gps.htm palmari gps acer n30] [http://guest.rigour.info/library/html/castle-cat/ castle cat] [http://blog.rigour.info/web/tastiera-retro/ tastiera retro illuminata] [http://all.rigour.info/www-bustybabydolls/ www bustybabydolls com] [http://milano.rigour.info/googol.htm googol] [http://blog.rigour.info/web/le-coniche/ le coniche] [http://guest.rigour.info/library/html/canzoni-della/ canzoni della fiction noi] [http://it.rigour.info/topic/polti/ polti 800] [http://it.rigour.info/topic/la-fine/ la fine] [http://paga.rigour.info/vatican-anthem/ vatican anthem] [http://milano.rigour.info/joypad-ps.htm joypad ps2 usb] [http://it.rigour.info/topic/il-diavolo/ il diavolo con le ali] [http://note.rigour.info/content/view/sigma-per.htm sigma per nikon] [http://milano.rigour.info/insonnia-d.htm insonnia d amore film dvd] [http://here.rigour.info/blog/barcellona-p.htm barcellona p g] [http://paga.rigour.info/da-rpg/ da rpg] [http://blog.rigour.info/web/copertina-album/ copertina album keane] [http://blog.rigour.info/web/pensione-a/ pensione a catania] [http://paga.rigour.info/royal-oak/ royal oak] [http://up.rigour.info/description/lib/condono-edilizio.htm condono edilizio oblazione] [http://paga.rigour.info/nikon-es/ nikon es e28] [http://paga.rigour.info/sito-telefonia/ sito telefonia] [http://blog.rigour.info/web/zoom-nikkor/ zoom nikkor] [http://uve.rigour.info/blog/audi-km.htm audi km zero] [http://here.rigour.info/blog/agenzia-pubblicitaria.htm agenzia pubblicitaria] [http://uve.rigour.info/blog/tutti-gli.htm tutti gli hotel di rimini] [http://web.rigour.info/foto-pink/ foto pink floyd] [http://load.rigour.info/view/new/coppia-enne.htm coppia 19enne] [http://up.rigour.info/description/lib/gps-pda.htm gps pda mio] [http://load.rigour.info/view/new/case-a.htm case a fosdinovo] [http://all.rigour.info/cartina-politica/ cartina politica spagna] [http://web.rigour.info/gli-appuntamenti/ gli appuntamenti nintendo per il nuovo anno] [http://pagina.rigour.info/michelle-buswell/ michelle buswell] [http://all.rigour.info/perizoma-in/ perizoma in vista] [http://web.rigour.info/zena-gang/ zena gang bang] [http://up.rigour.info/description/lib/mujer-enamorada.htm mujer enamorada] [http://note.rigour.info/content/view/immagini-di.htm immagini di gente e lavoro] [http://content.rigour.info/html/usb-/ usb 2 0 digital photo bank] [http://web.rigour.info/una-rockstar/ una rockstar in cerca damore] [http://here.rigour.info/blog/tatouage-sexy.htm tatouage sexy] [http://here.rigour.info/blog/carmen-villani.htm carmen villani] [http://here.rigour.info/blog/warren-earl.htm warren, earl] ===What is Watchdog===
+
===What is Watchdog===
  
Watchdog is a service monitoring daemon responsible for rebooting the Apple TV if its GUI application is not running. Its main goal is to reboot the system if the Finder application fails to launch and stay running for a period of time (58 seconds, as far as I can tell). It keeps track of the number of times  
+
Watchdog is a service monitoring daemon responsible for rebooting the Apple TV if its GUI application is not running. Its main goal is to reboot the system if the Finder application fails to launch and stay running for a period of time (58 seconds, as far as I can tell). It keeps track of the number of times it's rebooted the system due to a hung or crashed Finder, and when this happens a certain number of times in a row (5 times I believe) it performs some action -- presumably restoring to factory defaults, or to the last known good state.
5A8
 
it's rebooted the system due to a hung or crashed Finder, and when this happens a certain number of times in a row (5 times I believe) it performs some action -- presumably restoring to factory defaults, or to the last known good state.
 
  
 
There's a kext called <tt>AppleTCOWatchdog.kext</tt> in the <tt>/System/Library/Extensions/</tt> folder.
 
There's a kext called <tt>AppleTCOWatchdog.kext</tt> in the <tt>/System/Library/Extensions/</tt> folder.
Line 21: Line 19:
  
 
* com.apple.riptide.heartbeat
 
* com.apple.riptide.heartbeat
* co
+
* com.apple.riptide.start
B50
 
m.apple.riptide.start
 
 
* com.apple.riptide.stop
 
* com.apple.riptide.stop
 
* com.apple.ripstop.query
 
* com.apple.ripstop.query
Line 32: Line 28:
 
This is essentially the 'keepalive' notification used to inform the watchdog that everything is hunky-dory.
 
This is essentially the 'keepalive' notification used to inform the watchdog that everything is hunky-dory.
  
Upon launch, ripstop switches to the Frontrow user
+
Upon launch, ripstop switches to the Frontrow user & group ID, then opens a COM interface to the watchdog service, and creates a notification port with a CFMachPortRef wrapper which it then runs via a CFRunLoop. In the main function, it makes the following calls into the watchdog service:
 +
(*service)->tcoWdSetTimer( service, 500 );
 +
(*service)->tcoWdLoadTImer( service );
 +
 
 +
These are the actions performed for each notification:
 +
 
 +
com.apple.riptide.heartbeat:
 +
(*service)->tcoWdLoadTimer( service );
 +
 
 +
com.apple.riptide.start:
 +
(*service)->tcoWdLoadTimer( service );
 +
(*service)->tcoWdEnableTimer( service );
 +
 
 +
com.apple.riptide.stop:
 +
(*service)->tcoWdDisableTimer( service );
 +
 
 +
com.apple.ripstop.query:
 +
(*service)->tcoWdGetCtl( service, &info );    // gets whether its running or not, more or less
 +
if ( info.counterIsRunning )
 +
    notify_post( com.apple.tcowd.ison );
 +
else
 +
    notify_post( com.apple.tcowd.isoff );
 +
 
 +
com.apple.ripstop.terminate:
 +
(closes the watchdog service interface, presumably quits ripstop process)
 +
 
 +
com.apple.ripstop.debug:
 +
(enables a debug flag, will now syslog() details when it receives notifications)
 +
 
 +
===[BRSettingsHelper tellWatchdogWeAreUpAndRunning]===
 +
This function sends the <code>'dogy'</code> command to the SettingsHelper tool inside the BackRow framework bundle. It essentially resets the Watchdog's failure counters in NVRAM, since the Watchdog is only interested in failures to launch the interface. Once the interface launches successfully, this function is called and the data is cleared.
 +
 
 +
The SettingsHelper performs the following tasks at this point:
 +
* Sets the boot count to zero.
 +
* Sets the maximum boot count to five.
 +
* Clears the system reset reason.
 +
* Clears the remote state.
 +
 
 +
===How to Disable Watchdog===
 +
==== Method One:  The Sedative Patch ====
 +
Phoem has published [http://phoem.com/TCOWatchDog-sedative.c source code for sedative], a patch for AppleTCOWatchdog application.
 +
==== Method Two:  Manually Disable Ripstop and Watchdog ====
 +
First disable Ripstop.  Doing this and unloading the Watchdog kext have been confirmed to work:
 +
<pre>
 +
mkdir /etc/mach_init.disabled
 +
mv /etc/mach_init.d/ripstop.plist /etc/mach_init.disabled
 +
</pre>
 +
 
 +
Reboot using the following command.
 +
<pre>
 +
shutdown -r now
 +
</pre>
 +
 
 +
Ripstop is now disabled.  To disable Watchdog, unload AppleTCOWatchdog.kext:
 +
<pre>
 +
kextunload -b com.apple.driver.AppleTCOWatchdog
 +
</pre>
 +
 
 +
To unload the AppleTCOWWatchdog.kext automatically at startup. add the command to your local startup script.  This is recommended as it is best to have Ripstop and Watchdog either both enabled or both disabled. In some cases the rc.local file doesn't exist. A way around it is to use su. (su is a rather dangerous command as it effectively allows you to log in as root so use it wisely!)
 +
 
 +
Copy /usr/bin/su from your local OS X installation to the same location on the AppleTV.
 +
 
 +
Then issue these commands
 +
 
 +
<pre>
 +
sudo su -
 +
touch /etc/rc.local
 +
</pre>
 +
 
 +
Then, after you verified that rc.local exists...
 +
 
 +
<pre>
 +
echo "/sbin/kextunload -b com.apple.driver.AppleTCOWatchdog" >> /etc/rc.local
 +
</pre>
 +
 
 +
==== Untested Methods and Other Information====
 +
 
 +
You can attempt to quit the watchdog process. Watchdog is (or at least used to be) "quit" in a special way. Locate the watchdog process and send it a 'SIGTERM' term.
 +
 
 +
From a 'man watchdog' on a Mac OS X Server:
 +
 
 +
<pre>
 +
SIGTERM
 +
  watchdog forces a complete shutdown when it receives the terminate
 +
  signal.  The automatic reboot timer will be disabled and all exe-
 +
  cuting children will be terminated, forcibly (with SIGKILL) if nec-
 +
  essary.  After all children have terminated, watchdog itself exits.
 +
  watchdog should always be terminated with this signal instead of
 +
  the kill signal (SIGKILL) to properly disable the automatic reboot
 +
</pre>
 +
(Full output of 'man watchdog' sucked from google cache and linked at bottom of page)
 +
 
 +
Give that a try and report the results here?
 +
 
 +
 
 +
 
 +
Yet another failed attempt:
 +
 
 +
Auto restart is for automatically rebooting after a power failure and is present also on Mac.
 +
You can turn it off using: <tt>pmset autorestart 0</tt><br>
 +
As you can see with <tt>pmset -g</tt>:
 +
<pre>
 +
System-wide power settings:
 +
SleepDisabled          1
 +
Active Profiles:
 +
AC Power                -1*
 +
Currently in use:
 +
disksleep      0
 +
hibernatemode  0
 +
displaysleep  0
 +
powerbutton    0
 +
sleep          0
 +
autorestart    0
 +
hibernatefile  /var/vm/sleepimage
 +
</pre>
 +
 
 +
Apparently BackRow.framework tells Watchdog that "we are up and running":
 +
strings /System/Library/PrivateFrameworks/BackRow.framework/Versions/A/BackRow
 +
(...)
 +
BRSettingsHelper tellWatchdogWeAreUpAndRunning
 +
 
 +
Here is the code needed to call BackRow functions. Note you must add the BackRow framework to your project.
 +
<pre>
 +
//BRSettingsHelper.h
 +
#import <Cocoa/Cocoa.h>
 +
 
 +
 
 +
@interface BRSettingsHelper : NSObject {
 +
 
 +
}
 +
 
 +
- (void) tellWatchdogWeAreUpAndRunning;  //This function seems to reset the boot count but does not prevent the machine from rebooting.
 +
- (void) reboot;
 +
 
 +
@end
 +
</pre>
 +
And now to test it:
 +
<pre>
 +
#import <Cocoa/Cocoa.h>
 +
#include "BRSettingsHelper.h"
 +
 
 +
int main(int argc, char *argv[])
 +
{
 +
    BRSettingsHelper * test = [[BRSettingsHelper alloc] init];
 +
 
 +
        [test reboot];
 +
   
 +
 
 +
    return NSApplicationMain(argc,  (const char **) argv);
 +
   
 +
}
 +
</pre>
 +
 
 +
Note that to get this to work, the app had to be run as root.
 +
<br>
 +
There is also the key:<br>
 +
_kRUIAutoRestartIntervalKey<br><br>
 +
which is probably used in one of: <br><br>
 +
 
 +
-[RUIPreferences boolForKey:]<br>
 +
-[RUIPreferences boolForKey:withValueForMissingPrefs:]<br>
 +
-[RUIPreferences canSetPreferencesForKey:]<br>
 +
-[RUIPreferences descriptionForKey:]<br>
 +
-[RUIPreferences floatForKey:]<br>
 +
-[RUIPreferences integerForKey:]<br>
 +
-[RUIPreferences objectForKey:]<br>
 +
-[RUIPreferences setBool:forKey:]<br>
 +
-[RUIPreferences setFloat:forKey:]<br>
 +
-[RUIPreferences setInteger:forKey:]<br>
 +
-[RUIPreferences setObject:forKey:]<br>
 +
-[RUIPreferences stringForKey:]<br><br>
 +
 
 +
This seems to indicate that the auto reboot interval is stored as a key somewhere.  I don't know if this is simply used for the Finder.app or if there is something else on the system that will use this.
 +
 
 +
 
 +
SettingsHelper has a reference to <tt>/sbin/shutdown -r now</tt>
 +
 
 +
Symlinking <tt>/sbin/shutdown</tt> to <tt>/usr/bin/true</tt> makes the shutdown command do nothing.
 +
 
 +
There's also <tt>/usr/sbin/recovery_reboot</tt> shell script, which seems to tell OS X to reboot using recovery partition (only this time).
 +
Perhaps (pretty doubtful) it is called when watchdog sniffs something bad. Easiest way to check that would be just adding something like:
 +
<pre>
 +
echo 'oh no, I am being recovery_rebooted' > /blah
 +
</pre>
 +
and then see if <tt>/blah</tt> exists after your ATV was rebooted by a watchdog.
 +
 
 +
===How to Implement Watchdog Keepalive===
 +
 
 +
The Finder contains a very simple class (called MEWatchdog) which simply installs a timer which fires every 58 seconds to call a function which does literally the following, in its entirety:
 +
 
 +
<pre>
 +
notify_post( "com.apple.riptide.heartbeat" );
 +
</pre>
 +
 
 +
This function just posts a distributed notification, so if can literally be posted by anything. Unless the Watchdog inspects the interval between notifications, it's likely that any application can perform the same test, along with the Finder, if started by something like launchd. This way, the watchdog would not reboot the machine, even if the Finder quits, and we don't have any potential side-effects arising from stopping a system process.
 +
 
 +
As an aside, 'Riptide' appears to be a codename of sorts for the AppleTV software system. Various elements within BackRow print out debug statements including file/line information, which begin with <tt>/SourceCache/Riptide-xxx/</tt>.
 +
 
 +
===Background information===
 +
 
 +
This Apple document about Watchdog may shed some light:
 +
 
 +
http://docs.info.apple.com/article.html?artnum=106588&coll=cp (However, on the Apple TV, there is no /etc/watchdog.conf, other than what this document is saying)
 +
 
 +
Watchdog is not used in Mac OS X 10.4: look at [http://developer.apple.com/macosx/launchd.html launchd].  This is referring to a software watchdog and is probably unrelated to the rebooting problem.
 +
 
 +
Link to a Google cache (possibly old) output of 'man watchdog' with possibly useful information in it:
 +
 
 +
http://72.14.253.104/search?q=cache:J8bC2hERg9YJ:www.hmug.org/man/8/watchdog.html+Mac+OS+X+Server+Watchdog&hl=en&ct=clnk&cd=16&gl=us
 +
 
 +
[[Category:Software]][[Category:How-to]]

Revision as of 13:49, 23 August 2007

What is Watchdog

Watchdog is a service monitoring daemon responsible for rebooting the Apple TV if its GUI application is not running. Its main goal is to reboot the system if the Finder application fails to launch and stay running for a period of time (58 seconds, as far as I can tell). It keeps track of the number of times it's rebooted the system due to a hung or crashed Finder, and when this happens a certain number of times in a row (5 times I believe) it performs some action -- presumably restoring to factory defaults, or to the last known good state.

There's a kext called AppleTCOWatchdog.kext in the /System/Library/Extensions/ folder.

Brief Watchdog Background

Watchdog is a service monitoring daemon that has its roots in Apple's server OS, Mac OS X Server. Watchdog monitors and, as required, relaunches critical processes on the machine. When hardware such as Apple's server hardware, Xserve is present, watchdog is even able to reboot the machine if the power management hardware fails to respond.

This should not be confused with the "watchdog" program from OS X 10.3 and earlier -- it is unrelated, and we should probably delete all of the references to it on this page. :/

The Ripstop Daemon

Ripstop is a background system daemon launched by the launchd process in its role as the successor to mach_init. Ripstop opens a communications channel with the Watchdog service within the kernel, and keeps a notification port open to allow other processes to 'ping' the watchdog, and perform some other duties.

Ripstop Details

Ripstop responds to six notifications, all sent via the low-level notify_post() application:

  • com.apple.riptide.heartbeat
  • com.apple.riptide.start
  • com.apple.riptide.stop
  • com.apple.ripstop.query
  • com.apple.ripstop.debug

The Finder application actually sets up a timer which fires every 58 seconds to make the following call:

notify_post( "com.apple.riptide.heartbeat" );

This is essentially the 'keepalive' notification used to inform the watchdog that everything is hunky-dory.

Upon launch, ripstop switches to the Frontrow user & group ID, then opens a COM interface to the watchdog service, and creates a notification port with a CFMachPortRef wrapper which it then runs via a CFRunLoop. In the main function, it makes the following calls into the watchdog service:

(*service)->tcoWdSetTimer( service, 500 );
(*service)->tcoWdLoadTImer( service );

These are the actions performed for each notification:

com.apple.riptide.heartbeat:

(*service)->tcoWdLoadTimer( service );

com.apple.riptide.start:

(*service)->tcoWdLoadTimer( service );
(*service)->tcoWdEnableTimer( service );

com.apple.riptide.stop:

(*service)->tcoWdDisableTimer( service );

com.apple.ripstop.query:

(*service)->tcoWdGetCtl( service, &info );    // gets whether its running or not, more or less
if ( info.counterIsRunning )
    notify_post( com.apple.tcowd.ison );
else
    notify_post( com.apple.tcowd.isoff );

com.apple.ripstop.terminate:

(closes the watchdog service interface, presumably quits ripstop process)

com.apple.ripstop.debug:

(enables a debug flag, will now syslog() details when it receives notifications)

[BRSettingsHelper tellWatchdogWeAreUpAndRunning]

This function sends the 'dogy' command to the SettingsHelper tool inside the BackRow framework bundle. It essentially resets the Watchdog's failure counters in NVRAM, since the Watchdog is only interested in failures to launch the interface. Once the interface launches successfully, this function is called and the data is cleared.

The SettingsHelper performs the following tasks at this point:

  • Sets the boot count to zero.
  • Sets the maximum boot count to five.
  • Clears the system reset reason.
  • Clears the remote state.

How to Disable Watchdog

Method One: The Sedative Patch

Phoem has published source code for sedative, a patch for AppleTCOWatchdog application.

Method Two: Manually Disable Ripstop and Watchdog

First disable Ripstop. Doing this and unloading the Watchdog kext have been confirmed to work:

mkdir /etc/mach_init.disabled
mv /etc/mach_init.d/ripstop.plist /etc/mach_init.disabled

Reboot using the following command.

shutdown -r now

Ripstop is now disabled. To disable Watchdog, unload AppleTCOWatchdog.kext:

kextunload -b com.apple.driver.AppleTCOWatchdog

To unload the AppleTCOWWatchdog.kext automatically at startup. add the command to your local startup script. This is recommended as it is best to have Ripstop and Watchdog either both enabled or both disabled. In some cases the rc.local file doesn't exist. A way around it is to use su. (su is a rather dangerous command as it effectively allows you to log in as root so use it wisely!)

Copy /usr/bin/su from your local OS X installation to the same location on the AppleTV.

Then issue these commands

sudo su -
touch /etc/rc.local

Then, after you verified that rc.local exists...

echo "/sbin/kextunload -b com.apple.driver.AppleTCOWatchdog" >> /etc/rc.local

Untested Methods and Other Information

You can attempt to quit the watchdog process. Watchdog is (or at least used to be) "quit" in a special way. Locate the watchdog process and send it a 'SIGTERM' term.

From a 'man watchdog' on a Mac OS X Server:

SIGTERM
	   watchdog forces a complete shutdown when it receives the terminate
	   signal.  The automatic reboot timer will be disabled and all exe-
	   cuting children will be terminated, forcibly (with SIGKILL) if nec-
	   essary.  After all children have terminated, watchdog itself exits.
	   watchdog should always be terminated with this signal instead of
	   the kill signal (SIGKILL) to properly disable the automatic reboot

(Full output of 'man watchdog' sucked from google cache and linked at bottom of page)

Give that a try and report the results here?


Yet another failed attempt:

Auto restart is for automatically rebooting after a power failure and is present also on Mac. You can turn it off using: pmset autorestart 0
As you can see with pmset -g:

System-wide power settings:
SleepDisabled          1
Active Profiles:
AC Power                -1*
Currently in use:
 disksleep      0 
 hibernatemode  0
 displaysleep   0
 powerbutton    0
 sleep          0
 autorestart    0
 hibernatefile  /var/vm/sleepimage

Apparently BackRow.framework tells Watchdog that "we are up and running":

strings /System/Library/PrivateFrameworks/BackRow.framework/Versions/A/BackRow
(...)
BRSettingsHelper tellWatchdogWeAreUpAndRunning

Here is the code needed to call BackRow functions. Note you must add the BackRow framework to your project.

//BRSettingsHelper.h
#import <Cocoa/Cocoa.h>


@interface BRSettingsHelper : NSObject {

}

- (void) tellWatchdogWeAreUpAndRunning;  //This function seems to reset the boot count but does not prevent the machine from rebooting.
- (void) reboot;

@end

And now to test it:

#import <Cocoa/Cocoa.h>
#include "BRSettingsHelper.h"

int main(int argc, char *argv[])
{
    BRSettingsHelper * test = [[BRSettingsHelper alloc] init];

        [test reboot]; 
    
   
    return NSApplicationMain(argc,  (const char **) argv);
    
}

Note that to get this to work, the app had to be run as root.
There is also the key:
_kRUIAutoRestartIntervalKey

which is probably used in one of:

-[RUIPreferences boolForKey:]
-[RUIPreferences boolForKey:withValueForMissingPrefs:]
-[RUIPreferences canSetPreferencesForKey:]
-[RUIPreferences descriptionForKey:]
-[RUIPreferences floatForKey:]
-[RUIPreferences integerForKey:]
-[RUIPreferences objectForKey:]
-[RUIPreferences setBool:forKey:]
-[RUIPreferences setFloat:forKey:]
-[RUIPreferences setInteger:forKey:]
-[RUIPreferences setObject:forKey:]
-[RUIPreferences stringForKey:]

This seems to indicate that the auto reboot interval is stored as a key somewhere. I don't know if this is simply used for the Finder.app or if there is something else on the system that will use this.


SettingsHelper has a reference to /sbin/shutdown -r now

Symlinking /sbin/shutdown to /usr/bin/true makes the shutdown command do nothing.

There's also /usr/sbin/recovery_reboot shell script, which seems to tell OS X to reboot using recovery partition (only this time). Perhaps (pretty doubtful) it is called when watchdog sniffs something bad. Easiest way to check that would be just adding something like:

echo 'oh no, I am being recovery_rebooted' > /blah

and then see if /blah exists after your ATV was rebooted by a watchdog.

How to Implement Watchdog Keepalive

The Finder contains a very simple class (called MEWatchdog) which simply installs a timer which fires every 58 seconds to call a function which does literally the following, in its entirety:

notify_post( "com.apple.riptide.heartbeat" );

This function just posts a distributed notification, so if can literally be posted by anything. Unless the Watchdog inspects the interval between notifications, it's likely that any application can perform the same test, along with the Finder, if started by something like launchd. This way, the watchdog would not reboot the machine, even if the Finder quits, and we don't have any potential side-effects arising from stopping a system process.

As an aside, 'Riptide' appears to be a codename of sorts for the AppleTV software system. Various elements within BackRow print out debug statements including file/line information, which begin with /SourceCache/Riptide-xxx/.

Background information

This Apple document about Watchdog may shed some light:

http://docs.info.apple.com/article.html?artnum=106588&coll=cp (However, on the Apple TV, there is no /etc/watchdog.conf, other than what this document is saying)

Watchdog is not used in Mac OS X 10.4: look at launchd. This is referring to a software watchdog and is probably unrelated to the rebooting problem.

Link to a Google cache (possibly old) output of 'man watchdog' with possibly useful information in it:

http://72.14.253.104/search?q=cache:J8bC2hERg9YJ:www.hmug.org/man/8/watchdog.html+Mac+OS+X+Server+Watchdog&hl=en&ct=clnk&cd=16&gl=us