1235368Sgnn#!/usr/sbin/dtrace -s 2235368Sgnn/* 3235368Sgnn * woof.d - Bark whenever new processes appear. Needs /dev/audio. 4235368Sgnn * Written in DTrace (Solaris 10 3/05). 5235368Sgnn * 6235368Sgnn * $Id: woof.d 3 2007-08-01 10:50:08Z brendan $ 7235368Sgnn * 8235368Sgnn * USAGE: woof.d & 9235368Sgnn * 10235368Sgnn * SEE ALSO: /usr/dt/bin/sdtaudiocontrol # to set volume 11235368Sgnn * 12235368Sgnn * COPYRIGHT: Copyright (c) 2006 Brendan Gregg. 13235368Sgnn * 14235368Sgnn * CDDL HEADER START 15235368Sgnn * 16235368Sgnn * The contents of this file are subject to the terms of the 17235368Sgnn * Common Development and Distribution License, Version 1.0 only 18235368Sgnn * (the "License"). You may not use this file except in compliance 19235368Sgnn * with the License. 20235368Sgnn * 21235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 22235368Sgnn * or http://www.opensolaris.org/os/licensing. 23235368Sgnn * See the License for the specific language governing permissions 24235368Sgnn * and limitations under the License. 25235368Sgnn * 26235368Sgnn * CDDL HEADER END 27235368Sgnn * 28235368Sgnn * 14-Aug-2006 Brendan Gregg Created this. 29235368Sgnn * 14-Aug-2006 " " Last update. 30235368Sgnn */ 31235368Sgnn 32235368Sgnn#pragma D option quiet 33235368Sgnn#pragma D option destructive 34235368Sgnn#pragma D option switchrate=10hz 35235368Sgnn 36235368Sgnninline int SCREEN_OUTPUT = 0; /* Set to 1 for screen output */ 37235368Sgnn 38235368Sgnn/* barks prevents woof.d from barking too much (up to 20 barks/second) */ 39235368Sgnnint barks; 40235368Sgnn 41235368Sgnndtrace:::BEGIN 42235368Sgnn{ 43235368Sgnn SCREEN_OUTPUT ? trace("Beware of the dog!\n") : 1; 44235368Sgnn} 45235368Sgnn 46235368Sgnn/* 47235368Sgnn * Call the shell to run a background audioplay command (cat > /dev/audio 48235368Sgnn * doesn't always work). One problem this creates is a feedback loop, 49235368Sgnn * where we bark at our own barks, or at other dogs barks; entertaining 50235368Sgnn * as this is, it can really slog the system and has been avoided by 51235368Sgnn * checking our ancestory. 52235368Sgnn */ 53235368Sgnnproc:::exec-success 54235368Sgnn/!progenyof($pid) && barks++ < 2/ 55235368Sgnn{ 56235368Sgnn SCREEN_OUTPUT ? trace("Woof! ") : 1; 57235368Sgnn system("audioplay /usr/share/audio/samples/au/bark.au &"); 58235368Sgnn} 59235368Sgnn 60235368Sgnnprofile:::tick-10hz 61235368Sgnn{ 62235368Sgnn barks = 0; 63235368Sgnn} 64