home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9430 < prev    next >
Encoding:
Text File  |  1992-07-25  |  2.7 KB  |  100 lines

  1. Path: sparky!uunet!ccicpg!felix!fritz!scotth
  2. From: scotth@felix.filenet.com (Scott Hopson)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Finger and .plan, .project
  5. Message-ID: <19076@fritz.filenet.com>
  6. Date: 25 Jul 92 08:18:11 GMT
  7. Reply-To: scotth@fritz.filenet.com (Scott Hopson)
  8. Organization: FileNet Corp., Costa Mesa, CA
  9. Lines: 89
  10.  
  11. Since the finger and .plan, .project question has reared it's ugly head
  12. again, I thought I'd put in my $.02
  13.  
  14. Here's a program that responds to readers of your .plan or .project files.
  15. You need to make them named pipes. Use "/etc/mknod .plan p" and
  16. "/etc/mknod .project p". You must be sure that this daemon gets started
  17. after your system is rebooted or readers like "finger" will hang. I use
  18. cron to start the daemon since our systems goes down every weekend for
  19. backups.
  20.  
  21. --------------------------------CUT HERE----------------------------------
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <time.h>
  25. #include <sys/file.h>
  26. #include <sys/ioctl.h>
  27.  
  28. static char *project = "Something very very secret...\n";
  29. static char *plan    = "To catch the person who is fingering me...\n";
  30. static char *msg     = "\nYou Fingered me on ";
  31. static char *msg1    = "\n Caught you... Ha Ha\n\n";
  32.  
  33. char *getenv();
  34.  
  35. main()
  36. {
  37. int fd1,fd2;
  38. int len1,len2,len3,len4;
  39. char *buffer;
  40. char projectPath[80];
  41. char planPath[80];
  42. long t;
  43.  
  44.     if((buffer = getenv("HOME")) == NULL)
  45.     {
  46.     perror("getenv");
  47.     exit(0);
  48.     }
  49.     
  50.     strcpy(projectPath,buffer);        /* get the paths for .plan, .project */
  51.     strcpy(planPath,buffer);
  52.     strcat(projectPath,"/.project");
  53.     strcat(planPath,"/.plan");
  54.  
  55.     len1 = strlen(project);
  56.     len2 = strlen(plan);
  57.     len3 = strlen(msg);
  58.     len4 = strlen(msg1);
  59.  
  60. /*** start daemon code *************************************************/
  61.  
  62.     if(fork() != 0) exit(0);        
  63.  
  64.     close(0);
  65.     close(1);
  66.     close(2);
  67.  
  68.     fd1 = open("/dev/tty",O_RDWR);
  69.     ioctl(fd1,TIOCNOTTY,0);        /** detach from controlling TTY **/
  70.     close(fd1);
  71.  
  72. /*** end daemon code ***************************************************/
  73.  
  74.     while(1<2)    /* loop forever */
  75.     {                    /* finger reads .project first */
  76.     fd1 = open(projectPath,O_WRONLY);   /* blocks until read */
  77.     write(fd1,project,len1);   /* write your message for .project */
  78.     close(fd1);
  79.     fd2 = open(planPath,O_WRONLY);        /* blocks until read */
  80.     write(fd2,plan,len2);    /* write your .plan messages */
  81.     write(fd2,msg,len3);
  82.     time(&t);        /* I tell the user the current time */
  83.     buffer = ctime(&t);
  84.     write(fd2,buffer,27);
  85.     write(fd2,msg1,len4);
  86.     close(fd2);
  87.     }
  88.  
  89. }
  90.  
  91. --------------------------------CUT HERE----------------------------------
  92.  
  93. Note: this is not a perfect example, but you should be able to modify it
  94. to suit your own needs.
  95.  
  96. Have Fun....
  97.  
  98. -- 
  99. Scott Hopson   (scotth@filenet.com)
  100.