1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * woof.d - Bark whenever new processes appear. Needs /dev/audio.
1N/A * Written in DTrace (Solaris 10 3/05).
1N/A *
1N/A * $Id: woof.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: woof.d &
1N/A *
1N/A * SEE ALSO: /usr/dt/bin/sdtaudiocontrol # to set volume
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2006 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 14-Aug-2006 Brendan Gregg Created this.
1N/A * 14-Aug-2006 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option destructive
1N/A#pragma D option switchrate=10hz
1N/A
1N/Ainline int SCREEN_OUTPUT = 0; /* Set to 1 for screen output */
1N/A
1N/A/* barks prevents woof.d from barking too much (up to 20 barks/second) */
1N/Aint barks;
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A SCREEN_OUTPUT ? trace("Beware of the dog!\n") : 1;
1N/A}
1N/A
1N/A/*
1N/A * Call the shell to run a background audioplay command (cat > /dev/audio
1N/A * doesn't always work). One problem this creates is a feedback loop,
1N/A * where we bark at our own barks, or at other dogs barks; entertaining
1N/A * as this is, it can really slog the system and has been avoided by
1N/A * checking our ancestory.
1N/A */
1N/Aproc:::exec-success
1N/A/!progenyof($pid) && barks++ < 2/
1N/A{
1N/A SCREEN_OUTPUT ? trace("Woof! ") : 1;
1N/A system("audioplay /usr/share/audio/samples/au/bark.au &");
1N/A}
1N/A
1N/Aprofile:::tick-10hz
1N/A{
1N/A barks = 0;
1N/A}