Difference between revisions of "Watchdog"

From AwkwardTV
Jump to: navigation, search
m
m (reverting spammed page)
Line 1: Line 1:
[http://kinunia.cn/leccami.htm leccami] [http://helmed.info/topic/www-mls/ www mls com] [http://ashythro.info/library/html/zafferano-bicchieri/ zafferano bicchieri] [http://ustall.org/web/zoran-jelenkovic.htm zoran jelenkovic] [http://amohseni.info/img/styles/tv-studio/ tv studio pctv] [http://bloprofeldi.info/lib/ati-fire.htm ati fire] [http://chaba.info/incanto-classic/ incanto classic saeco] [http://bloprofeldi.info/lib/risultati-motomondiale.htm risultati motomondiale 2004] [http://chaba.info/km-mitsubishi/ km0 mitsubishi pajero sport auto km 0] [http://bloprofeldi.info/lib/schede-madri.htm schede madri asus p4p800s] [http://saibso.org/sigma.htm sigma 12-24] [http://nobinters.org/sn-una.htm sn una tettona] [http://saibso.org/cittadinanza.htm cittadinanza] [http://psisemiya.com/images/small/canon-lbp/ canon lbp 2000 toner] [http://davte.info/library/html/microfono-ps.htm microfono ps2] [http://saibso.org/chi-ha.htm chi ha vinto piu coppe al mondo calcio] [http://ustall.org/web/dinotopia.htm dinotopia] [http://chaba.info/tablet-pc/ tablet pc 12 1 hp] [http://psisemiya.com/images/small/manifesto-ringraziamenti/ manifesto ringraziamenti] [http://chaba.info/fiat-coupe/ fiat coupe 1 8 turbo] [http://nobinters.org/nh-hotel.htm nh hotel] [http://bloprofeldi.info/lib/chacker.htm chacker] [http://ustall.org/web/soho-square.htm soho square] [http://ashythro.info/library/html/erikson-e/ erikson e la crisi psico sociale] [http://ustall.org/web/gioco-all.htm gioco all aperto bambino] [http://davte.info/library/html/minolta-toner.htm minolta toner] [http://nobinters.org/cuffie-wireless.htm cuffie wireless dolby digital] [http://helmed.info/topic/il-libro/ il libro della] [http://chaba.info/aldo-giovanni/ aldo giovanni e giacomo] [http://psisemiya.com/images/small/volo-aereo/ volo aereo palermo lampedusa] [http://helmed.info/topic/iraq/ iraq] [http://ustall.org/web/fotos-ivy.htm fotos ivy queen] [http://ustall.org/web/loona-bailando.htm loona bailando] [http://chaba.info/pulitore-vapore/ pulitore vapore] [http://psisemiya.com/images/small/smallville-kristin/ smallville kristin kreuk nuda] [http://psisemiya.com/images/small/fax-l/ fax 3310l] [http://saibso.org/prestito-bruxelles.htm prestito bruxelles] [http://kinunia.cn/bepi-koelliker.htm bepi koelliker] [http://saibso.org/regali-per.htm regali per casa] [http://amohseni.info/img/styles/dpr-/ dpr 686 del 3 5 1957] [http://helmed.info/topic/yety-sport/ yety sport 5] [http://helmed.info/topic/rrufeja/ rrufeja] [http://bloprofeldi.info/lib/toyota-mantova.htm toyota mantova] [http://nobinters.org/velodyne-vx.htm velodyne vx10] [http://saibso.org/camera-villorba.htm camera villorba] [http://ashythro.info/library/html/www-canzoni/ www canzoni di leone di lernia it] [http://kinunia.cn/foto-camera.htm foto camera digitale online] [http://amohseni.info/img/styles/olimpia-splendid/ olimpia splendid deumidificatore] [http://amohseni.info/img/styles/batterie-samsung/ batterie samsung e800] [http://kinunia.cn/ecco.htm ecco] [http://helmed.info/topic/i-cieli/ i cieli del mito libri] [http://bloprofeldi.info/lib/casper-slide.htm casper slide] [http://ustall.org/web/la-macchina.htm la macchina nera] [http://bloprofeldi.info/lib/kingston-ddr.htm kingston ddr sodimm] [http://helmed.info/topic/fromage-frais/ fromage frais] [http://nobinters.org/invernali.htm invernali] [http://nobinters.org/ninne-nanne.htm ninne nanne in italiano] [http://amohseni.info/img/styles/esce-il/ esce il drago entra la tigre] [http://psisemiya.com/images/small/peretta/ peretta] [http://chaba.info/volkswagen-fox/ volkswagen fox diesel] [http://kinunia.cn/dori-ghezzi.htm dori ghezzi wess] [http://psisemiya.com/images/small/cantautore/ cantautore] [http://saibso.org/garmin-gps.htm garmin gps iii] [http://ustall.org/web/seks-vidoe.htm seks vidoe] [http://helmed.info/topic/corpi/ corpi] [http://davte.info/library/html/vogliamoci-tanto.htm vogliamoci tanto bene] [http://ustall.org/web/lalbero-delle.htm lalbero delle pere] [http://amohseni.info/img/styles/the-biggest/ the biggest black cock] [http://saibso.org/un-grande.htm un grande amore] [http://amohseni.info/img/styles/picrite/ picrite] [http://bloprofeldi.info/lib/star-wars.htm star wars. clone wars. vol. 01] [http://kinunia.cn/jogos-da.htm jogos da playboy] [http://saibso.org/nike-calcio.htm nike calcio] [http://chaba.info/ecco-la/ ecco la demo di age of empires iii] [http://amohseni.info/img/styles/la-camera/ la camera della morte] [http://ustall.org/web/terratec-aureon.htm terratec aureon universe 7 1] [http://saibso.org/dvdrw-.htm dvd-rw 9 4 gb] [http://psisemiya.com/images/small/internet-a/ internet a passo di lumaca] [http://ashythro.info/library/html/piastra-per/ piastra per bistecchiera] [http://saibso.org/piscina-di.htm piscina di antegnate] [http://amohseni.info/img/styles/appendici-carrelli/ appendici carrelli] [http://nobinters.org/www-lady.htm www lady web it] [http://ashythro.info/library/html/guri-quarta/ guri quarta serie speciale 13 dicembre 2] [http://psisemiya.com/images/small/hub-/ hub 5 porte ethernet] [http://davte.info/library/html/rod.htm rod] [http://bloprofeldi.info/lib/usted-de.htm usted de diego torres] [http://psisemiya.com/images/small/olivetti-logos/ olivetti logos 682 s] [http://helmed.info/topic/piatti-in/ piatti in vetro] [http://psisemiya.com/images/small/trottolino/ trottolino] [http://helmed.info/topic/hp/ hp 200] [http://chaba.info/todo-lo/ todo lo que hago lo hago por ti] [http://kinunia.cn/sale-marino.htm sale marino integrale] [http://chaba.info/testo-voglia/ testo voglia di dance all night] [http://nobinters.org/kit-cp.htm kit cp 100] [http://psisemiya.com/images/small/film-erotici/ film erotici] [http://bloprofeldi.info/lib/helena-figo.htm helena figo sexy] [http://helmed.info/topic/orbs/ orbs] [http://psisemiya.com/images/small/athlon/ athlon 64 939 3000] [http://ashythro.info/library/html/pieces-de/ pieces de rechange] [http://chaba.info/processori-intel/ processori intel pentium 4 prescott] [http://davte.info/library/html/foto-naziskin.htm foto naziskin] [http://kinunia.cn/tocuh.htm tocuh] [http://ashythro.info/library/html/santo-antonio/ santo antonio] [http://saibso.org/pisa-san.htm pisa san francisco biglietti aerei] [http://davte.info/library/html/gamepad-pc.htm gamepad pc saitek] [http://bloprofeldi.info/lib/tarantelle-pugliesi.htm tarantelle pugliesi] [http://davte.info/library/html/breezin.htm breezin] [http://kinunia.cn/gamepad-joystick.htm gamepad joystick] [http://davte.info/library/html/hotel-centrale.htm hotel centrale jesolo] [http://bloprofeldi.info/lib/fotos-garotas.htm fotos garotas nuas] [http://kinunia.cn/navigatore-gps.htm navigatore gps blaupunkt] [http://davte.info/library/html/grimaudo.htm grimaudo] [http://helmed.info/topic/piastre-intercambiabili/ piastre intercambiabili] [http://saibso.org/cranberries-zombi.htm cranberries zombi] [http://davte.info/library/html/chat-gay.htm chat gay roma gratis] [http://kinunia.cn/bey.htm bey] [http://amohseni.info/img/styles/usb-sharp/ usb sharp gx30] [http://kinunia.cn/extremo.htm extremo] [http://psisemiya.com/images/small/mina-in/ mina in studio] [http://kinunia.cn/audi-a.htm audi a3 1.6] [http://ashythro.info/library/html/calciatore-nudo/ calciatore nudo] [http://psisemiya.com/images/small/lampade-risparmio/ lampade risparmio energetico] [http://helmed.info/topic/handel-cd/ handel cd] [http://chaba.info/logitech-premium/ logitech premium usb headset 350] [http://amohseni.info/img/styles/kuman/ kuman] [http://nobinters.org/mi-manchi.htm mi manchi pooh] [http://davte.info/library/html/dvd-x.htm dvd 8x princo] [http://ashythro.info/library/html/yonis/ yonis] [http://davte.info/library/html/musica-per.htm musica per i tuoi sogni] [http://ustall.org/web/pirandello-l.htm pirandello l esclusa] [http://amohseni.info/img/styles/piscine-montichiari/ piscine montichiari] [http://psisemiya.com/images/small/rex-rd/ rex rd 185 dx] [http://saibso.org/wwwpetardas-con.htm wwwpetardas con] [http://davte.info/library/html/cardim-fernao.htm cardim, fernao] [http://saibso.org/set-lettino.htm set lettino] [http://bloprofeldi.info/lib/bando-straordinario.htm bando straordinario 19 12 2005 servizio civile] [http://kinunia.cn/silke.htm silke] [http://nobinters.org/www-google.htm www google ro] [http://davte.info/library/html/europa-grecia.htm europa grecia isola] [http://kinunia.cn/ibm-t.htm ibm t43] [http://chaba.info/foto-di/ foto di pantere] [http://chaba.info/www-robertobaggio/ www robertobaggio it] [http://davte.info/library/html/zorro-alla.htm zorro alla corte di spagna] [http://amohseni.info/img/styles/drow/ drow] [http://kinunia.cn/wavelenght.htm wavelenght] [http://saibso.org/schema-fattura.htm schema fattura] [http://bloprofeldi.info/lib/infradito-sandali.htm infradito sandali] [http://nobinters.org/dichiarazione-dei.htm dichiarazione dei rediti] [http://amohseni.info/img/styles/sia-di/ sia di fornaci] [http://psisemiya.com/images/small/frankfurt-an/ frankfurt an der oder] [http://saibso.org/fz.htm fz 61 1] [http://davte.info/library/html/primi-denunciati.htm primi denunciati] [http://psisemiya.com/images/small/tu-soltanto/ tu soltanto tu] [http://davte.info/library/html/delta-v.htm delta v via da qui mp3] [http://amohseni.info/img/styles/preromanticismo/ preromanticismo] [http://saibso.org/il-pingpong.htm il pingpong] [http://psisemiya.com/images/small/arctic-cooling/ arctic cooling nv silencer 5] [http://helmed.info/topic/heroin/ heroin] [http://ashythro.info/library/html/labtec-mouse/ labtec mouse optical] [http://nobinters.org/big-girls.htm big girls] [http://nobinters.org/www-canzoni.htm www canzoni da scaricare it] [http://nobinters.org/grandmaster-flash.htm grandmaster flash] [http://nobinters.org/belle-di.htm belle di notre dame de paris] [http://nobinters.org/ocktoberfest.htm ocktoberfest] [http://nobinters.org/un-emozione.htm un emozione da poco anna oxa] [http://nobinters.org/love-lina.htm love lina] [http://davte.info/library/html/modem-.htm modem 56 interno xp] [http://kinunia.cn/crimsom-rooom.htm crimsom rooom] [http://ustall.org/web/dvd-rip.htm dvd rip] [http://ashythro.info/library/html/numer/ numer] [http://helmed.info/topic/barzallette-cattive/ barzallette cattive] [http://chaba.info/colin-mcrea/ colin mcrea rally 2] [http://kinunia.cn/classiche-napoletane.htm classiche napoletane] [http://chaba.info/byblos-terra/ byblos terra] [http://nobinters.org/stampante-epson.htm stampante epson stylus pro 4000] [http://saibso.org/chu-mei.htm chu mei] [http://amohseni.info/img/styles/andrews-virginia/ andrews virginia libri] [http://chaba.info/fliston/ fliston] [http://saibso.org/fortuna-slim.htm fortuna slim bluetooth] [http://nobinters.org/la-canzone.htm la canzone dei vecchi amanti] [http://nobinters.org/photos-colocataires.htm photos colocataires m6] [http://helmed.info/topic/ef-/ ef 100 macro] [http://amohseni.info/img/styles/grow/ grow2] [http://kinunia.cn/kaoma-video.htm kaoma video lambada] [http://davte.info/library/html/a-scuola.htm a scuola dallo sciamano] [http://chaba.info/harrrdito/ harrrdito] [http://bloprofeldi.info/lib/duello-nel.htm duello nel ventre della terra] [http://amohseni.info/img/styles/samira-saeed/ samira saeed] [http://amohseni.info/img/styles/aspirapolvere/ aspirapolvere 1400] [http://ustall.org/web/notebook-toshiba.htm notebook toshiba libretto u100] [http://davte.info/library/html/la-tani.htm la tani] [http://davte.info/library/html/free-sheet.htm free sheet music everybody is changing] [http://nobinters.org/cafe.htm cafe1930] [http://kinunia.cn/telefonia-fissa.htm telefonia fissa] [http://saibso.org/essenza-si.htm essenza si zegna] [http://chaba.info/romani/ romani] [http://bloprofeldi.info/lib/acer-dlp.htm acer dlp] [http://nobinters.org/adobe-acrobat.htm adobe acrobat 6 0 professional] [http://kinunia.cn/sunstech-dvp.htm sunstech dvp] [http://nobinters.org/sound-blaster.htm sound blaster zs notebook] ===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 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.
 
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.
Line 28: 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 01:03, 19 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