home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ccicpg!felix!fritz!scotth
- From: scotth@felix.filenet.com (Scott Hopson)
- Newsgroups: comp.unix.questions
- Subject: Re: Finger and .plan, .project
- Message-ID: <19076@fritz.filenet.com>
- Date: 25 Jul 92 08:18:11 GMT
- Reply-To: scotth@fritz.filenet.com (Scott Hopson)
- Organization: FileNet Corp., Costa Mesa, CA
- Lines: 89
-
- Since the finger and .plan, .project question has reared it's ugly head
- again, I thought I'd put in my $.02
-
- Here's a program that responds to readers of your .plan or .project files.
- You need to make them named pipes. Use "/etc/mknod .plan p" and
- "/etc/mknod .project p". You must be sure that this daemon gets started
- after your system is rebooted or readers like "finger" will hang. I use
- cron to start the daemon since our systems goes down every weekend for
- backups.
-
- --------------------------------CUT HERE----------------------------------
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <sys/file.h>
- #include <sys/ioctl.h>
-
- static char *project = "Something very very secret...\n";
- static char *plan = "To catch the person who is fingering me...\n";
- static char *msg = "\nYou Fingered me on ";
- static char *msg1 = "\n Caught you... Ha Ha\n\n";
-
- char *getenv();
-
- main()
- {
- int fd1,fd2;
- int len1,len2,len3,len4;
- char *buffer;
- char projectPath[80];
- char planPath[80];
- long t;
-
- if((buffer = getenv("HOME")) == NULL)
- {
- perror("getenv");
- exit(0);
- }
-
- strcpy(projectPath,buffer); /* get the paths for .plan, .project */
- strcpy(planPath,buffer);
- strcat(projectPath,"/.project");
- strcat(planPath,"/.plan");
-
- len1 = strlen(project);
- len2 = strlen(plan);
- len3 = strlen(msg);
- len4 = strlen(msg1);
-
- /*** start daemon code *************************************************/
-
- if(fork() != 0) exit(0);
-
- close(0);
- close(1);
- close(2);
-
- fd1 = open("/dev/tty",O_RDWR);
- ioctl(fd1,TIOCNOTTY,0); /** detach from controlling TTY **/
- close(fd1);
-
- /*** end daemon code ***************************************************/
-
- while(1<2) /* loop forever */
- { /* finger reads .project first */
- fd1 = open(projectPath,O_WRONLY); /* blocks until read */
- write(fd1,project,len1); /* write your message for .project */
- close(fd1);
- fd2 = open(planPath,O_WRONLY); /* blocks until read */
- write(fd2,plan,len2); /* write your .plan messages */
- write(fd2,msg,len3);
- time(&t); /* I tell the user the current time */
- buffer = ctime(&t);
- write(fd2,buffer,27);
- write(fd2,msg1,len4);
- close(fd2);
- }
-
- }
-
- --------------------------------CUT HERE----------------------------------
-
- Note: this is not a perfect example, but you should be able to modify it
- to suit your own needs.
-
- Have Fun....
-
- --
- Scott Hopson (scotth@filenet.com)
-