Date: Wed, 20 Jul 2005 00:58:13 -0500 (CDT) From: shmach@osprey.net To: freebsd-questions@freebsd.org Subject: problem with devfs Message-ID: <XFMail.20050720005813.shmach@osprey.net>
next in thread | raw e-mail | index | archive | help
Hello everyone, I'm a CS student, and this previous semester I took a unix class where our teacher gave us some code for an assignment, with the goal being to compile and install it. The jist of it was the program created a device in /dev called voice, which would "speak" whatever was written to it using festival. I thought this was kinda spiffy, and tried to install it on my system at home, freebsd 5.3. The program tries to write to /dev, and because 5.3 uses devfs, /dev is read only, so it obviously fails. I thought that maybe using mknod would allow me to create a device, but the man page for mknod states that it can "be used to recreate deleted device nodes under a devfs(5) mount point by invoking it using dummy arguments", but that doesn't really help me here as the device node never existed in the first place. So, I guess I want to know if there's a way to override devfs, or would I have to write a kernel module in order to get thing to install in /dev. I don't know how to write device drivers, but I'm willing to give anything a try. :) what follows is the code. if anyone's interested, the code is also available for download from my teacher's site: http://www.emporia.edu/math-cs/simpson/bsimpson.htm The version I'm using is 1.0. #define FIFO_BUFFER_SIZE 4096 #define FIFO_NAME "/dev/voice" #define FESTIVAL "/usr/local/bin/festival" #define LOCAL "localhost" #define FESTIVAL_PORT 1314 #define PHRASE_HEAD "(SayText \"" #define PHRASE_TAIL "\")" #define INSTALL_PHRASE "(SayText \"/dev/voice installed\")" #define PAUSE_INTERVAL 5 #include "config.h" #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <ctype.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> #include <signal.h> void signal_handler(int the_sig); void signal_handler(int the_sig) { if(the_sig==SIGTERM) { kill(getppid(),SIGTERM); unlink(FIFO_NAME); exit(0); }; }; int main() { static char buffer[FIFO_BUFFER_SIZE]; int buffer_count,public_fifo; int sock,phrase_len; struct sockaddr_in client,server; struct hostent *host; char *phrase; signal(SIGTERM,&signal_handler); daemon(0,0); if(fork()==0) { printf("in the child now\n"); sleep(PAUSE_INTERVAL); host=gethostbyname(LOCAL); server.sin_family=AF_INET; server.sin_port=htons(FESTIVAL_PORT); memcpy(&server.sin_addr.s_addr,host->h_addr,host->h_length); sock=socket(AF_INET,SOCK_STREAM,0); client.sin_family=AF_INET; client.sin_port=htons(0); client.sin_addr.s_addr=htonl(INADDR_ANY); if(bind(sock,(struct sockaddr *) &client,sizeof(client)) == -1){ printf("couldn't bind to port\n"); exit(2); } connect(sock,(struct sockaddr *)&server,sizeof(server)); if(mkfifo(FIFO_NAME, 06660)<0) { printf("bad things\n"); if(errno==17) { unlink(FIFO_NAME); mknod(FIFO_NAME, S_IFIFO | 0666, 0); }; printf("there's been a fucking error...\n"); }; public_fifo=open(FIFO_NAME,O_RDWR); if(public_fifo<0) { printf("couldn't open fifo\n"); exit(1); } sleep(PAUSE_INTERVAL); sendto(sock,INSTALL_PHRASE,strlen(INSTALL_PHRASE),0,(struct sockaddr *)&server,sizeof(server)); kill(getppid(),SIGTERM); while(1) { memset(buffer,0x0,FIFO_BUFFER_SIZE); buffer_count = read(public_fifo,buffer,FIFO_BUFFER_SIZE); if(buffer_count > 0) { phrase=new char[12+strlen(buffer)]; phrase_len=12+strlen(buffer); memset(phrase,0x0,phrase_len); strcat(phrase,PHRASE_HEAD); strcat(phrase,buffer); strcat(phrase,PHRASE_TAIL); sendto(sock,phrase,phrase_len,0,(struct sockaddr *)&server,sizeof(server)); delete phrase; kill(getppid(),SIGTERM); }; }; } else execl(FESTIVAL,"festival","--server",(char *)NULL); return 0; } ---------------------------------- E-Mail: shmach@osprey.net Date: 20-Jul-2005 Time: 00:25:52 This message was sent by XFMail ----------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20050720005813.shmach>