message queues - please some checkup from the pros
hi folks i hope, if some of you master-of-the-posix guys could look throught the program and say whats the problem.
the following happened: i had to do a message queue: prog1: send lines from input via msq. to the next program prog2: change all input to big letters and send to prog 3 prog3: output the lines in addition: with quit all proggs. quit and implement a signal handler (sigint) if someone could help with the following i would be very grateful: 1) i did this small prog. on debian a friend of mine tried to run it on solaris and had some problems when trying to quit the proggs (it resultet in a loop) 2) i know of course this prog. can be done better faster intelligenter stronger .... :D im not a pro (yet) ... but if there are some mistakes that just happened by luck to not result in an error ... please tell me ok here is the code msq.h Code:
#include <sys/types.h> Code:
#include "./msq.h" Code:
#include "./msq.h" Code:
#include "./msq.h" [edit] oh btw. i am from austria ... so the error messages are written in german but i hope thats not a problem [/edit] |
hiho kermit
german: griaß di *g* also ich hab mal deinen code ausprobiert hier was mir aufgefallen ist (ich weiß nicht ob es bei dir das gleiche problem ist!) mir sind 2 dinge aufgefallen 1. bei input.c krieg ich einen compile warning da du gets(); stat fgets(); verwendest erklärung: gets(); schaut nicht auf die puffer größe (bei dir variable text) und somit könnts zu einem puffer überlauf kommen deshalb ist diese funktion unsicher! lösung: ganz oben füge hinzu #include <stdio.h> gets(text); ersetzen durch fgets(text,size,stdin); 2. bei mir hat gar nix funktioniert, weil die berichtigung für die message queue falsch war PS: fall du irgendwo einen fehler hast (also die funktion liefert einen fehlercode) dann verwende perror("ERROR"); die funktion perror gibt dir den fehlertext aus, des letzten fehlers dadurch hab ich gekriegt: ERROR: Permission denied lösung: in jedem code file außer msq.h ändere die msgget funktion! bei der msgget musst du noch die berechtigung angeben mit der die message queue geöffnet werden soll: z.B. bei input.c --> input_id=msgget(key_in,IPC_CREAT|0666); // 0666 ist quasi standard berechtigung (-rw-rw-rw-) output.c --> output_id=msgget(key_out,0|0666); compute.c --> toinput_id=msgget(key_in, 0|0666); das waren bei mir die probleme hoffe du schaffst die prüfung good luck ;-) english: the problems i've found: 1. gets(); is used in input.c gets is unsafe because it can cause a buffer overflow because it from the man page: Never use gets(). Because it is impossible to tell withÂ_ out knowing the data in advance how many characters gets() will read, and because gets() will continue to store charÂ_ acters past the end of the buffer, it is extremely dangerÂ_ ous to use. It has been used to break computer security. Use fgets() instead. so i changed input.c 1: #include <stdio.h> 2: fgets(text,size,stdin); 2. the priviledge for the message queue isn't set using perror("ERROR"); i got ERROR: Permission denied so i changed every msgget(); to msgget(key,flag|0666); where key is the key variable used in the code and flag the flags set (0 or IPC_CREAT) now it works great good luck for your exam |
thx a lot thinking for the answer (for the german as well as for the english version) :D
first i used scanf but i couldnt solve the format problem. i guess it would have been a small syntax change but well ... works fine now. thx even more to show me the permission error ... thats something my theacher likes to look at :D ok im back to work :study: working on threads and semaphores now and im sure im coming back for some questions :D |
you're welcome
|
huhu i am back:D
i need some more help or verification for the following code please ok this task was about threads and semaphores ... a better topic to do some mistakes i guess the task just was to have 1file: to read from stdin and write it in a message queue. then open a thread and let it read from the message queue and write the content in a file. in addition i had to do a semaphore for the second prog. 2file: to read from the file (if the semaphore isnt set) and delete the file afterwards. write_file (nice name or? :D) Code:
#include <sys/types.h> Code:
#include <sys/types.h> i hope someone (thinking perhaps :D ) could take a quick look at it to point to me to some mistakes. thanks |
All times are GMT -5. The time now is 12:33 AM. |