home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / hackers / 1981 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  24.9 KB

  1. Path: sparky!uunet!stanford.edu!agate!neon.cchem.berkeley.edu!gezelter
  2. From: gezelter@neon.cchem.berkeley.edu (Dan Gezelter)
  3. Newsgroups: alt.hackers
  4. Subject: .plan pipe to backfinger.
  5. Date: 25 Jan 1993 22:12:36 GMT
  6. Organization: UC Berkeley
  7. Lines: 763
  8. Approved: myself
  9. Distribution: world
  10. Message-ID: <1k1okk$beu@agate.berkeley.edu>
  11. NNTP-Posting-Host: neon.cchem.berkeley.edu
  12.  
  13. Here's the latest version of the .plan pipe program that I've
  14. inherited from numerous other people.  It was posted to alt.sources a
  15. while back, so somewhere there exists an archive, but I know not
  16. where.  If you modify the code, I'd appreciate some e-mail telling me
  17. what you've done...  I NO LONGER SUPPORT OR RUN THIS CODE.  It was too
  18. slow and annoying to my friends, so I gave up.  Also, Ultrix machines
  19. refuse to print .plans that aren't plain text files.  Don't even try
  20. to run this on an ultrix machine.
  21.  
  22. YOU MUST MODIFY SOME OF THE SHELL SCRIPTS CONTAINED HEREIN.  They
  23. contain site specific information and will not work without
  24. modification.
  25.  
  26.  
  27. -------------CUT HERE----------------
  28. #! /bin/sh
  29. # This is a shell archive.  Remove anything before this line, then unpack
  30. # it by saving it into a file and typing "sh file".  To overwrite existing
  31. # files, type "sh file -c".  You can also feed this as standard input via
  32. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  33. # will see the following message at the end:
  34. #        "End of shell archive."
  35. # Contents:  MANIFEST Makefile README backfinger check-plan logfinger
  36. #   plan.c plan.nr start-plan stop-plan
  37. # Wrapped by gezelter@neon.cchem.berkeley.edu on Tue Nov 10 15:03:36 1992
  38. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  39. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  41. else
  42. echo shar: Extracting \"'MANIFEST'\" \(690 characters\)
  43. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  44. XMANIFEST - This file
  45. XMakefile - The makefile
  46. XREADME   - Original notes, notes for first set of changes, and notes
  47. X       for my changes
  48. Xplan.c   - The program
  49. Xplan.nr  - A man page
  50. Xlogfinger - a sh script that I wrote to figure out remote fingering
  51. X            addresses.  WARNING:  You may need to make some mods
  52. X            to logfinger before it will work for you.
  53. Xbackfinger - a script that logfinger calls to determine who is logged
  54. X             in at the remote address.
  55. Xstart-finger - starts a bunch of plan processes on a cluster of
  56. X               diskless workstations.
  57. Xstop-finger - looks through the .planpid directory and kills all
  58. X              plan processes on remote machines.
  59. END_OF_FILE
  60. if test 690 -ne `wc -c <'MANIFEST'`; then
  61.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  62. fi
  63. # end of 'MANIFEST'
  64. fi
  65. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  66.   echo shar: Will not clobber existing file \"'Makefile'\"
  67. else
  68. echo shar: Extracting \"'Makefile'\" \(2053 characters\)
  69. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  70. XDEST          = $(HOME)/bin
  71. X
  72. XEXTHDRS          = /usr/include/fcntl.h \
  73. X        /usr/include/signal.h \
  74. X        /usr/include/stdio.h \
  75. X                /usr/include/dirent.h \
  76. X        /usr/include/sys/fcntl.h \
  77. X        /usr/include/sys/file.h \
  78. X        /usr/include/sys/stat.h \
  79. X        /usr/include/sys/sysmacros.h \
  80. X        /usr/include/sys/sysmacros.h \
  81. X        /usr/include/sys/types.h \
  82. X        /usr/include/sys/types.h
  83. X
  84. XHDRS          =
  85. X
  86. XLDFLAGS          =
  87. X
  88. XLIBS          =
  89. X
  90. XCC            = cc
  91. X
  92. XLINKER          = cc
  93. X
  94. XMAKEFILE      = Makefile
  95. X
  96. XOBJS          = plan.o
  97. X
  98. XPRINT          = pr
  99. X
  100. XPROGRAM          = plan
  101. X
  102. XSRCS          = plan.c
  103. X
  104. XLOGGER        = logfinger
  105. X
  106. XBACKER        = backfinger
  107. X
  108. XPLANPID       = $(HOME)/.planpid
  109. X
  110. Xall:        $(PROGRAM) planpid man
  111. X
  112. X$(PROGRAM):     $(OBJS) $(LIBS)
  113. X        @echo -n "Loading $(PROGRAM) ... "
  114. X        @$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM)
  115. X        @echo "done"
  116. X
  117. Xplanpid:;    @if [ -d $(HOME)/.planpid ] ; \
  118. X        then echo "Make sure you copy .plan to .realplan" ; \
  119. X        else \
  120. X            echo "Making .planpid directory" ;\
  121. X            mkdir "$(HOME)/.planpid"  ; \
  122. X            echo  "Make sure you copy .plan to .realplan" ;\
  123. X        fi
  124. X
  125. Xman:;        @nroff -man plan.nr > plan.man
  126. Xclean:;        @rm -f $(OBJS)
  127. X
  128. Xdepend:;    @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
  129. X
  130. Xindex:;        @ctags -wx $(HDRS) $(SRCS)
  131. X
  132. Xinstall:    $(PROGRAM) planpid man
  133. X        @echo Installing $(PROGRAM) in $(DEST)
  134. X        @cp $(PROGRAM) $(DEST)/$(PROGRAM)
  135. X        @strip $(DEST)/$(PROGRAM)
  136. X        @echo Installing $(LOGGER) in $(DEST)
  137. X        @cp $(LOGGER) $(DEST)/$(LOGGER)
  138. X        @echo Installing $(BACKER) in $(DEST)
  139. X        @cp $(BACKER) $(DEST)/$(BACKER)
  140. X
  141. Xprint:;        @$(PRINT) $(HDRS) $(SRCS)
  142. X
  143. Xprogram:        $(PROGRAM)
  144. X
  145. Xtags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
  146. X
  147. Xupdate:        $(DEST)/$(PROGRAM) $(DEST)/$(LOGGER) $(DEST)/$(BACKER)
  148. X
  149. X$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
  150. X        @make -f $(MAKEFILE) DEST=$(DEST) install
  151. X###
  152. Xplan.o: /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
  153. X    /usr/include/sys/sysmacros.h /usr/include/sys/file.h \
  154. X    /usr/include/sys/types.h \
  155. X    /usr/include/fcntl.h /usr/include/stdio.h /usr/include/sys/stat.h \
  156. X    /usr/include/signal.h /usr/include/dirent.h
  157. END_OF_FILE
  158. if test 2053 -ne `wc -c <'Makefile'`; then
  159.     echo shar: \"'Makefile'\" unpacked with wrong size!
  160. fi
  161. # end of 'Makefile'
  162. fi
  163. if test -f 'README' -a "${1}" != "-c" ; then 
  164.   echo shar: Will not clobber existing file \"'README'\"
  165. else
  166. echo shar: Extracting \"'README'\" \(6800 characters\)
  167. sed "s/^X//" >'README' <<'END_OF_FILE'
  168. XAll I did was modify Karen's code so that it puts the pid
  169. Xfiles in the ~/.planpid directory.  The actual pid files
  170. Xtake the hostname of the machine that plan is running on 
  171. Xand reside in that directory.  This was necessary to have
  172. Xplan working on a cluster of diskless workstations (which
  173. Xneed a new named pipe for each machine).  To get that to
  174. Xwork, you need to soft link ~/.plan to /tmp/.plan and then
  175. Xrun plan -f /tmp/.plan yourprogram.  This creates a named
  176. Xpipe on each machine in a subdirectory that that machine
  177. Xcan use named pipes on.  The soft link points to the
  178. Xright place no matter which machine it is, but you need
  179. Xa new planpid file for each host.  
  180. X
  181. XI also replaced logfinger with a faster and pretty nifty
  182. Xsh script that figures out the IP address and hostname of
  183. Xsomeone that is remotely fingering you.  You're may
  184. Xhave to make some major mods to this before it will work
  185. Xfor you.  What would be really cool is if someone can get
  186. Xlogfinger to figure out all the relevant details *no matter
  187. Xwhere* you are being fingered from. (local or remote) Anyone
  188. Xhave any ideas?
  189. X
  190. XDan   (gezelter@lithium.cchem.berkeley.edu)
  191. X
  192. X
  193. XAll I did was to put in a function that keeps track of the PID for
  194. Xplan by writing it to a file called ".planpid" in your home directory.
  195. XNow you run plan in your .login, and, to kill the process when you log
  196. Xout, put something like this in your .logout:
  197. X
  198. X    kill `cat /home/mine/.planpid`
  199. X    rm -f /home/mine/.planpid
  200. X
  201. XYou have to remove the .planpid (or modify the code), because the 
  202. Xprogram will not run if a plan is already running, which it assumes
  203. Xwhen it finds a .planpid file already there.
  204. X
  205. XIf someone wanted to run multiple plans, maybe one for a .signature
  206. Xand another for a .plan, the save name for the PID could be changed,
  207. Xand the program compiled twice (the binary is not that big, ~40K on
  208. Xthe HP 425's I used), or, if someone is really motivated, they could
  209. Xadd a command line argument for the save name.
  210. X
  211. XSure, my modification isn't very complex, but it does what I needed
  212. Xit to do, and maybe someone else can use it.
  213. X
  214. XKaren    (napalm@ugcs.caltech.edu)
  215. X
  216. X****  Additions by Geoff Loker ****
  217. X
  218. XI have modified Tony Rems' code for plan a bit to get rid of the
  219. Xnecessity for hard-coding in the file name to be set up as a FIFO.
  220. XThe program will now accept an optional argument that specifies the
  221. Xname of the FIFO to be used.  If that argument is not set, the default
  222. XFIFO is $HOME/.plan.
  223. X
  224. XIn order to use this program, your O/S needs to support named pipes.
  225. XYou also need to link in getopt for the changes to work.
  226. X
  227. XAny executable program can be set up to run when the specified FIFO is
  228. Xopened, but don't forget that the program you specify to run is being
  229. Xrun under your userid.
  230. X
  231. X****  Original README ****
  232. X
  233. XDate: Thu, 11 Apr 91 14:09:10 MST
  234. XFrom: Jim Armstrong <armstron@cs.arizona.edu>
  235. XSubject: RE: fingeree ...
  236. X
  237. X> >About a month ago there was a sample program posted to this newsgroup that
  238. X> >set up a FIFO named pipe as your .plan file.  I modified the code to set up
  239. X> >a simple (perhaps naive) finger monitor for users on my machine.  The process
  240. X> do you still have the source for it? would you send it to me?
  241. X
  242. XHere is the article which appeared in comp.unix.questions a while back.  It
  243. Xcontains generic code that will run any program you want whenever a certain
  244. Xfile is accessed (i.e. the .plan file in this case).  All you have to do is
  245. Xcompile it (it creates an executable called 'plan') and then to get it
  246. Xrunning say 'plan a.out &' where a.out is some program you have written.
  247. XI don't have my program any more, but basically what I did was a ps au
  248. Xwithin that program.  It used egrep to search for someone currently fingering
  249. Xme and appended the output to a file.  To get really fancy you could then
  250. Xread from that file to find out exactly who it is (all in the same program)
  251. Xand print out a nice personal message to whoever is fingering you as part
  252. Xof what looks to be your .plan file.  A couple of things to watch out for:
  253. XIf the finger is remote, the ps au won't find anything.  Also, if two people
  254. Xfinger you at the same time you may run into trouble, but I didn't try
  255. Xexperimenting with this too much.  I also found it helpful to timestamp a
  256. Xdate to the file, too (I used localtime() for efficiency).  This makes it
  257. Xeasier to look back later at the file and see who's been fingering you and
  258. Xwhen while you were not logged on.  It also helpful in debugging your program.
  259. X
  260. XSo set up this code and experiment with different programs.  Just be creative
  261. Xand see what else you can do with it.  One idea I used for a while is making
  262. Xit print a different quote each time.  The possibilites are endless.  Enjoy.
  263. X
  264. XJim
  265. X
  266. X
  267. XArticle 31270 of comp.unix.questions:
  268. XFrom: rembo@unisoft.UUCP (Tony Rems)
  269. XNewsgroups: comp.unix.questions
  270. XSubject: Re: Finger
  271. XDate: 22 Feb 91 02:44:17 GMT
  272. XReply-To: rembo@unisoft.UUCP (Tony Rems)
  273. XOrganization: UniSoft Corporation -- UNIX R Us.
  274. X
  275. XIn article <37675@netnews.upenn.edu> minzhi@eniac.seas.upenn.edu (Min-Zhi Shao) writes:
  276. X>
  277. X>    When I fingered our system administrator, I got the following result:
  278. X>
  279. X>_________________________________________________________________________
  280. X>Login name: gardella              In real life: Ed Gardella [CETS]
  281. X>Directory: /home/cets/gardella          Shell: /usr/local/bin/bash
  282. X>On since Feb 15 19:49:04 on ttyp1 from TSTEST.SEAS.UPEN
  283. X>14 minutes Idle Time
  284. X>No unread mail
  285. X>Project: System Administrator eniac.seas.upenn.edu
  286. X>Plan:
  287. X>         Meander about until something interesting comes along.
  288. X>
  289. X>Office: 154 Moore Building           Work Phone: 898-2491
  290. X>                                     Home Phone: 387-4104
  291. X>
  292. X>I have been fingered 3 times today
  293. X>_________________________________________________________________________
  294. X>
  295. X>the .plan file in his home directory looks like:
  296. X>
  297. X>prw-r--r--  1 gardella        0 Feb 15 23:48 /home/cets/gardella/.plan
  298. X>^
  299. X
  300. XAs you have found out by now, I'm sure, the p means that this is 
  301. Xa named pipe aka a FIFO.  If you'd like to do this yourself, here
  302. Xis a little program I wrote to do it (see the comments at the
  303. Xthe beginning of the plan.c file for usage info):  
  304. X
  305. XHere's the shar of my plan program, just cut up until it says
  306. X"cut here", and then type 'sh filename' using whatever filename
  307. Xyou save it as.  If you use 'plan' it will get overwritten.
  308. X
  309. XThe code here should compile w/o any problems on any BSD machine,
  310. XI have tried it on a Sun, Vax 750, and Pyramid 90x.  It should
  311. Xalso work properly on any SVR4.0 machine.  
  312. X
  313. XThe code is pretty heavily commented so it should be self
  314. Xexplanatory.  
  315. X
  316. XNote that you should put a -DFILENAME="your_home_dir/.plan"
  317. Xto get it to put your path in, or you can just edit the 
  318. Xsource and change the value of FILENAME permanently.  
  319. X
  320. XIf you have any problems getting it compiled, just send me mail.
  321. X
  322. XEnjoy.  
  323. X
  324. X-Tony
  325. X
  326. END_OF_FILE
  327. if test 6800 -ne `wc -c <'README'`; then
  328.     echo shar: \"'README'\" unpacked with wrong size!
  329. fi
  330. # end of 'README'
  331. fi
  332. if test -f 'backfinger' -a "${1}" != "-c" ; then 
  333.   echo shar: Will not clobber existing file \"'backfinger'\"
  334. else
  335. echo shar: Extracting \"'backfinger'\" \(316 characters\)
  336. sed "s/^X//" >'backfinger' <<'END_OF_FILE'
  337. X#!/bin/sh
  338. X
  339. X# Store the fingering info in .fingerees and finger the remote
  340. X# host to find out who fingered us.  This is done in a separate
  341. X# shell in order to avoid printing those damned [pid] messages
  342. X# to the other machine.
  343. X
  344. Xecho "Remote Host $1 ($2) at `date`" >> $HOME/.fingerees
  345. Xfinger @$2 >> $HOME/.fingerees &
  346. END_OF_FILE
  347. if test 316 -ne `wc -c <'backfinger'`; then
  348.     echo shar: \"'backfinger'\" unpacked with wrong size!
  349. fi
  350. chmod +x 'backfinger'
  351. # end of 'backfinger'
  352. fi
  353. if test -f 'check-plan' -a "${1}" != "-c" ; then 
  354.   echo shar: Will not clobber existing file \"'check-plan'\"
  355. else
  356. echo shar: Extracting \"'check-plan'\" \(207 characters\)
  357. sed "s/^X//" >'check-plan' <<'END_OF_FILE'
  358. X#!/bin/sh
  359. XClients=`ls /home/miller/gezelter/.planpid`
  360. Xecho $Clients
  361. Xfor i in $Clients; do
  362. X   thisHost=$i
  363. X   thisPid=`cat $HOME/.planpid/$i`
  364. X   echo $thisHost $thisPid
  365. X   rsh $i "ps aux | grep $thisPid"
  366. Xdone
  367. END_OF_FILE
  368. if test 207 -ne `wc -c <'check-plan'`; then
  369.     echo shar: \"'check-plan'\" unpacked with wrong size!
  370. fi
  371. chmod +x 'check-plan'
  372. # end of 'check-plan'
  373. fi
  374. if test -f 'logfinger' -a "${1}" != "-c" ; then 
  375.   echo shar: Will not clobber existing file \"'logfinger'\"
  376. else
  377. echo shar: Extracting \"'logfinger'\" \(1184 characters\)
  378. sed "s/^X//" >'logfinger' <<'END_OF_FILE'
  379. X#!/bin/sh
  380. X
  381. X# These commands get the hostname and IP address of the machine 
  382. X# that is talking to us over port 79 (the finger port).
  383. X
  384. XHost=`netstat | sed -n -e "s/\.[0-9][0-9]* [ ]*EST.*//" -e "s/.*fing[e]*[r]* [ ]*//p"`
  385. XIP=`netstat -n | sed -n -e "s/\.[0-9][0-9]* [ ]*EST.*//" -e "s/.*\.79 [ ]*//p"`
  386. X
  387. X# These lines check to see if I am logged in from home in order to
  388. X# inform less experienced people which port to use for talk.
  389. X
  390. Xif [ -r $HOME/.rem.tty ]
  391. Xthen
  392. X   mytty=`cat $HOME/.rem.tty`
  393. Xelse 
  394. X   mytty=""
  395. Xfi
  396. X
  397. X# These lines are self-explanatory.
  398. X
  399. XthisHost=`hostname`
  400. XtheDate=`date`
  401. X
  402. X# and this one should be changed to whatever your workstation is...
  403. X
  404. XmyWS="magnesium.cchem.berkeley.edu"
  405. X
  406. X$HOME/bin/backfinger $Host $IP
  407. X
  408. X# Print out the expected finger information and give some interesting info.
  409. X
  410. Xcat $HOME/.realplan
  411. Xecho _________________________________________________________________________
  412. Xecho "You are fingering me from $Host ($IP)  Who are you?" 
  413. Xecho To talk to me, use \"talk $USER\@$myWS $mytty\"
  414. Xecho _________________________________________________________________________
  415. Xecho "$thisHost :  Fingering from $Host ($IP) on $theDate" | \
  416. X      /usr/lib/sendmail $USER
  417. END_OF_FILE
  418. if test 1184 -ne `wc -c <'logfinger'`; then
  419.     echo shar: \"'logfinger'\" unpacked with wrong size!
  420. fi
  421. chmod +x 'logfinger'
  422. # end of 'logfinger'
  423. fi
  424. if test -f 'plan.c' -a "${1}" != "-c" ; then 
  425.   echo shar: Will not clobber existing file \"'plan.c'\"
  426. else
  427. echo shar: Extracting \"'plan.c'\" \(5725 characters\)
  428. sed "s/^X//" >'plan.c' <<'END_OF_FILE'
  429. X/*    THIS IS THE UNPUBLISHED SOURCE CODE OF REMBO        */
  430. X/*    The copyright notice above does not evidence any       */
  431. X/*    actual or intended publication of such source code.    */
  432. X/*    So, use it if you like, but give me credit.        */
  433. X
  434. X
  435. X/*     Usage: plan [-f file_name] program_name            */
  436. X
  437. X
  438. X/*    Description:                    */
  439. X
  440. X/*     This program takes the full pathname of an    */
  441. X/*     executable and runs it on a fifo in the     */
  442. X/*    user's home directory named .plan.  This    */
  443. X/*     way, when finger is executed, the output    */
  444. X/*     of the program goes to the fifo.        */
  445. X    
  446. X/*    Written by:  Tony Rems                 */
  447. X
  448. X/*     Send bugs and flames to /dev/null or         */
  449. X/*     rembo@unisoft.com                 */
  450. X
  451. X/*    Modifications:                    */
  452. X
  453. X/*    September 1991                    */
  454. X/*           (by Geoff Loker geoff@mdms.moore.com)    */
  455. X/*    Modified the program so that the path to the    */
  456. X/*    .plan file is not hardcoded in.  Now any number    */
  457. X/*    of users can use the program at the same time.    */
  458. X/*    I also modified the program to use an optional    */
  459. X/*    argument to specify which file to use.  The    */
  460. X/*    default file used is still the user's .plan,    */
  461. X/*    but this can now also be used to set up        */
  462. X/*    .signatures or any other file the user wants.    */
  463. X
  464. X/*    Even more modifications                */
  465. X
  466. X/*    January 1992                    */
  467. X/*          (by Karen Bruner napalm@ugcs.caltech.edu) */
  468. X/*    Added pid_deal function, so people can stick    */
  469. X/*     the program in their .login, and then have it    */
  470. X/*    killed by their .logout.  Program will not    */
  471. X/*    run if a .planpid file, the file with the PID    */
  472. X/*    for plan, already exists in the user's home    */
  473. X/*    directory.                    */
  474. X
  475. X/*      Yet still more modifications                    */
  476. X
  477. X/*      January 1992                                    */
  478. X/*      (by Dan Gezelter gezelter@lithium.cchem.berkeley.edu) */
  479. X/*      Modified pid_deal function to put the pid       */
  480. X/*      files in a subdirectory called .planpid/        */
  481. X/*      The pid files then take on the name of the      */
  482. X/*      host that plan is running on.   This was        */
  483. X/*      necessary to have plan working on a cluster     */
  484. X/*      of diskless workstations.                       */
  485. X
  486. X#include <sys/types.h>
  487. X#include <sys/file.h>
  488. X#include <stdio.h>
  489. X#include <fcntl.h>
  490. X#include <sys/stat.h>
  491. X#include <signal.h>
  492. X#include <string.h>
  493. X#include <dirent.h>
  494. X
  495. X/* Defines */
  496. X#define PERMS 0666
  497. X#define USAGE "%s [-f file_name] program_name\n"
  498. X
  499. X/* Function prototypes */
  500. Xvoid sig_handler();
  501. Xint pid_deal();    
  502. X
  503. Xmain (argc, argv)
  504. Xint argc;
  505. Xchar *argv[];
  506. X{
  507. X        int c, fflg;
  508. X    char *file;
  509. X        extern char *optarg;
  510. X    extern int optind;
  511. X    int fd;
  512. X    int pid;
  513. X    int status;
  514. X    char *getenv(), *home, plan[256], *strcat(), *strcpy();
  515. X    int pid_check;
  516. X    
  517. X    fflg = c = 0;
  518. X    while ((c = getopt(argc, argv, "f:")) != EOF) {
  519. X      file = optarg;
  520. X      fflg++;
  521. X    }
  522. X
  523. X/* Comment out the next line if you don't want to have PID recorded
  524. X   to file .planpid */
  525. X
  526. X    pid_check = pid_deal(); /* check for .planpid, if none, write
  527. X                   .planpid */
  528. X
  529. X/* Uncomment next line if you commented out previous line */
  530. X
  531. X/*  pid_check = 1; */
  532. X
  533. X  if (pid_check == 1)  /* execute remaining part of program if .planpid
  534. X              does not exist, i.e., no other plan process is
  535. X              running */
  536. X    {
  537. X    if (fflg)
  538. X      strcpy(plan, file);
  539. X    else {
  540. X      home = getenv("HOME");
  541. X      strcpy(plan, home);
  542. X      strcat(plan, "/.plan");
  543. X    }
  544. X/*    setenv("PLAN", plan, 1); */
  545. X
  546. X    if ( argc != optind + 1 ) {
  547. X        fprintf (stderr, USAGE, argv[0]);
  548. X        exit(1);
  549. X    }  /* if */
  550. X
  551. X/* Catch interrupts for cleanup */
  552. X    signal(SIGTERM, sig_handler);
  553. X    signal(SIGINT, sig_handler);
  554. X    signal(SIGHUP, sig_handler);
  555. X
  556. X    unlink (plan);
  557. X
  558. X/* Make the fifo */
  559. X    if ((mknod(plan, S_IFIFO | PERMS, 0)) < 0 ) {
  560. X        perror("mknod");
  561. X        exit(2);
  562. X    }  /* if */
  563. X
  564. X    while (1) {
  565. X        if ((fd = open(plan, O_WRONLY)) < 0 ) {
  566. X            perror("open");
  567. X            exit(3);
  568. X        } /* if */
  569. X
  570. X/* Once our open completes we know that someone else has
  571. X * opened the FIFO for reading, so we can know run our 
  572. X * program on it.  So, we fork, exec our program and
  573. X * wait for the child to complete.
  574. X */
  575. X        switch (pid = fork()) {
  576. X            case -1:
  577. X                perror("fork");
  578. X                exit(4);
  579. X                break;
  580. X            case 0:
  581. X/* If we're in the child, we copy our fifo to stdout */
  582. X/* and exec the program given */
  583. X                dup2(fd, 1);
  584. X                execlp(argv[optind],argv[optind],(void *)NULL);
  585. X                perror("child returned");
  586. X                exit(5);
  587. X                break;
  588. X            default:
  589. X/* If we're in the parent, we close the pipe and wait */
  590. X                close(fd);
  591. X                while (wait(&status) != pid)
  592. X                    ;
  593. X                break;
  594. X        } /* switch */
  595. X        sleep(2);
  596. X        close(fd);
  597. X    } /* while */
  598. X    }  /* end of my if (pid_check... */
  599. X
  600. X  else
  601. X    printf("plan already running\n");
  602. X
  603. X} /* main */
  604. X
  605. Xvoid sig_handler()  /* cleanup */
  606. X{
  607. X    char *plan, *getenv();
  608. X    
  609. X    plan = getenv("PLAN");
  610. X
  611. X    unlink(plan);
  612. X    exit(0);
  613. X}
  614. X
  615. Xint pid_deal()    /* function for recording pid and making sure process
  616. X           isn't already running */
  617. X{
  618. X  char savepid[100];    /* string for file name */
  619. X  FILE *sp;
  620. X  int checker;        /* return value:  0 if .planpid exists, and
  621. X               program shouldn't be run, 1 if not */
  622. X  char *home;
  623. X  char *host[64];
  624. X  int namelen;
  625. X  namelen = 64;
  626. X
  627. X  home = getenv("HOME");        /* put save name for file */
  628. X  gethostname(host,namelen);            /* and host id */
  629. X  strcpy(savepid, home);        /* in savepid */
  630. X  strcat(savepid, "/.planpid/");
  631. X  strcat(savepid, host);
  632. X
  633. X  if ((sp = fopen(savepid, "r")) != NULL) /* test for existence of 
  634. X                         .planpid by trying to open
  635. X                         the file for reading */
  636. X    checker = 0;     /* return a zero if read was successful, i.e.,
  637. X               file already exists */
  638. X    
  639. X  else
  640. X    checker = 1;    /* file doesn't exist, return a 1 to execute
  641. X               the rest of the program */
  642. X  fclose(sp);
  643. X
  644. X  if (checker == 1)
  645. X    {
  646. X      sp = fopen(savepid, "w");
  647. X      fprintf(sp, "%d", getpid());     /* puts PID for plan into file */
  648. X      fclose(sp);
  649. X    }
  650. X
  651. X  return checker;
  652. X} 
  653. END_OF_FILE
  654. if test 5725 -ne `wc -c <'plan.c'`; then
  655.     echo shar: \"'plan.c'\" unpacked with wrong size!
  656. fi
  657. # end of 'plan.c'
  658. fi
  659. if test -f 'plan.nr' -a "${1}" != "-c" ; then 
  660.   echo shar: Will not clobber existing file \"'plan.nr'\"
  661. else
  662. echo shar: Extracting \"'plan.nr'\" \(1581 characters\)
  663. sed "s/^X//" >'plan.nr' <<'END_OF_FILE'
  664. X.TH PLAN L "\*(V)" "4BSD"
  665. X.SH NAME
  666. Xplan - run an executable when a specified FIFO is opened
  667. X.SH SYNOPSIS
  668. X.B plan
  669. X[
  670. X.BR -f file
  671. X]
  672. X.B executable
  673. X.SH DESCRIPTION
  674. X.I plan
  675. Xtakes the name of an executable program and runs it on a FIFO that
  676. Xis specified on the command line or on a FIFO in the user's home directory
  677. Xnamed .plan.  Whenever the FIFO is accessed, the output of the executable
  678. Xprogram goes to the FIFO.  It also writes the PID of plan to a file, so
  679. Xthe process can be killed during logout, and it checks for the existence
  680. Xof this file to make sure plan isn't already running.
  681. X.SH OPTIONS
  682. X.TP
  683. X.B \-f file_name
  684. XThe \fB\-f flag causes \fIplan\fR to set up the specified \fBfile_name\fR
  685. Xas a FIFO rather than the default \fB$HOME/.plan\fR.
  686. X.PP
  687. XSome sample uses of \fIplan\fR would be:
  688. X.TP
  689. X.B plan /usr/games/fortune &
  690. XThis will display a randomly selected fortune as the contents of
  691. Xyour .plan file whenever you are fingered.
  692. X.TP
  693. X.B plan -f ~/.signature ~/bin/gensig &
  694. XThis will run the program gensig whenever your .signature file is accessed,
  695. Xallowing you to change your .signature whenever you post.
  696. X.TP
  697. X.B plan ~/bin/logfinger &
  698. XThis will run the program logfinger whenever your .plan file is accessed,
  699. Xand you can log all instances of people fingering you.
  700. X.SH AUTHOR
  701. XTony Rems (rembo@unisoft.com)
  702. X.PP
  703. XModifications by Geoff Loker (geoff@mdms.moore.com)
  704. X.PP
  705. XMore modifications by Karen Bruner (napalm@ugcs.caltech.edu)
  706. X.PP
  707. XEven more modifications by Dan Gezelter (gezelter@lithium.cchem.berkeley.edu)
  708. X.SH BUGS
  709. XYour system must support named pipes in order for this to work.
  710. END_OF_FILE
  711. if test 1581 -ne `wc -c <'plan.nr'`; then
  712.     echo shar: \"'plan.nr'\" unpacked with wrong size!
  713. fi
  714. # end of 'plan.nr'
  715. fi
  716. if test -f 'start-plan' -a "${1}" != "-c" ; then 
  717.   echo shar: Will not clobber existing file \"'start-plan'\"
  718. else
  719. echo shar: Extracting \"'start-plan'\" \(521 characters\)
  720. sed "s/^X//" >'start-plan' <<'END_OF_FILE'
  721. X#!/bin/csh
  722. Xset Clients = `ypcat ethers | awk '{print $2}'`
  723. Xset AllHosts = "$Clients lithium"
  724. Xecho $AllHosts
  725. X/bin/mv $HOME/.login $HOME/.login.sv
  726. X/bin/mv $HOME/.logout $HOME/.logout.sv
  727. X/bin/mv $HOME/.cshrc $HOME/.cshrc.sv
  728. Xecho "~/bin/plan -f /tmp/.plan ~/bin/logfinger &" > $HOME/.login
  729. Xecho logout >> $HOME/.login
  730. Xchmod 744 $HOME/.login
  731. Xforeach i ($AllHosts)
  732. X   echo $i
  733. X   rlogin $i
  734. Xend
  735. X/bin/rm $HOME/.login
  736. X/bin/mv $HOME/.login.sv $HOME/.login
  737. X/bin/mv $HOME/.logout.sv $HOME/.logout
  738. X/bin/mv $HOME/.cshrc.sv $HOME/.cshrc
  739. END_OF_FILE
  740. if test 521 -ne `wc -c <'start-plan'`; then
  741.     echo shar: \"'start-plan'\" unpacked with wrong size!
  742. fi
  743. chmod +x 'start-plan'
  744. # end of 'start-plan'
  745. fi
  746. if test -f 'stop-plan' -a "${1}" != "-c" ; then 
  747.   echo shar: Will not clobber existing file \"'stop-plan'\"
  748. else
  749. echo shar: Extracting \"'stop-plan'\" \(221 characters\)
  750. sed "s/^X//" >'stop-plan' <<'END_OF_FILE'
  751. X#!/bin/sh
  752. XClients=`ls /home/miller/gezelter/.planpid`
  753. Xecho $Clients
  754. Xfor i in $Clients; do
  755. X   thisHost=$i
  756. X   thisPid=`cat $HOME/.planpid/$i`
  757. X   echo $thisHost $thisPid
  758. X   rsh $i kill $thisPid
  759. Xdone
  760. X/bin/rm $HOME/.planpid/*
  761. END_OF_FILE
  762. if test 221 -ne `wc -c <'stop-plan'`; then
  763.     echo shar: \"'stop-plan'\" unpacked with wrong size!
  764. fi
  765. chmod +x 'stop-plan'
  766. # end of 'stop-plan'
  767. fi
  768. echo shar: End of shell archive.
  769. exit 0
  770. -------------CUT HERE--------------
  771. -- 
  772. _________________________________________________________________________
  773. Don't step on my blue suede .sig      gezelter@lithium.cchem.berkeley.edu
  774. -------------------------------------------------------------------------
  775.