SHARE
TWEET

Untitled

a guest Dec 2nd, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void sendMessageQueue(int uzenetsor, char * message)
  2. {
  3.     const struct uzenet uz = {5, message};
  4.     int status;
  5.  
  6.     status = msgsnd(uzenetsor, &uz, strlen(uz.mtext) + 1, 0);
  7.     // a 3. param ilyen is lehet: sizeof(uz.mtext)
  8.     // a 4. parameter gyakran IPC_NOWAIT, ez a 0-val azonos
  9.     if (status < 0)
  10.         perror("msgsnd");
  11. }
  12.  
  13. // receiving a message.
  14. void recieveMessageQueue(int uzenetsor)
  15. {
  16.     struct uzenet uz;
  17.     int status;
  18.     // az utolso parameter(0) az uzenet azonositoszama
  19.     // ha az 0, akkor a sor elso uzenetet vesszuk ki
  20.     // ha >0 (5), akkor az 5-os uzenetekbol a kovetkezot
  21.     // vesszuk ki a sorbol
  22.     status = msgrcv(uzenetsor, &uz, 1024, 5, 0);
  23.  
  24.     if (status < 0)
  25.         perror("msgsnd");
  26.     else
  27.         printf("A csódbiztos ezt az összegzést kapta: %s\n",uz.mtext);
  28. }
  29. //END OF DEFINITLY MY CODE
  30.  
  31. void sendSavingAction(Data **myDataarr, int dataCount, char *place, const char *argv[])
  32. {
  33.    
  34.  
  35.     int uzenetsor, status;
  36.     key_t kulcs;
  37.     kulcs = ftok(argv[0], 1);
  38.     uzenetsor = msgget(kulcs, 0600 | IPC_CREAT);
  39.  
  40.     char pipename[20];
  41.     int fd;
  42.     sprintf(pipename, "/tmp/%dmyuniquechars", getpid());
  43.     int fid = mkfifo(pipename, S_IRUSR | S_IWUSR);
  44.     if (fid == -1)
  45.     {
  46.        
  47.         remove(pipename);
  48.         int fid = mkfifo(pipename, S_IRUSR|S_IWUSR);
  49.         printf("Error number: %i \n",errno);
  50.         //perror("Gaz van:");
  51.         //exit(EXIT_FAILURE);
  52.     }
  53.  
  54.     pid_t child = fork();
  55.  
  56.     if (child > 0) //parent
  57.     {
  58.         //printf("Parent");
  59.         char s[1024] = "Semmi";
  60.         fd = open(pipename,O_RDONLY);
  61.         read(fd, s, sizeof(s));
  62.         //Arrived message from rescue team
  63.         close(fd);
  64.         printf("Csődbiztos ezt a kérést kapta: %s\n", s);
  65.  
  66.         fd = open(pipename, O_WRONLY);
  67.         char listOfPeople[1024] = "";
  68.         for (size_t i = 0; i < dataCount; i++)
  69.         {
  70.             if (strcmp(place, myDataarr[i]->place) == 0)
  71.             {
  72.                 strcat(listOfPeople, myDataarr[i]->name);
  73.                 strcat(listOfPeople, "_");
  74.             }
  75.         }
  76.         write(fd, listOfPeople, strlen(listOfPeople));
  77.         close(fd);
  78.  
  79.         recieveMessageQueue(uzenetsor);
  80.  
  81.         printf("-------------------------\n");
  82.  
  83.         sleep(2);
  84.         kill(child, SIGKILL);
  85.     }
  86.     else
  87.     {
  88.         //printf("Rescue team alias child.\n");//mentoexpedicio folyamat
  89.  
  90.         fd = open(pipename, O_WRONLY);
  91.         write(fd, "Kell a mentésre várók listája\n", 35);
  92.         close(fd);
  93.  
  94.         sleep(1);
  95.         char s[1024] = "Semmi";
  96.         fd = open(pipename, O_RDONLY);
  97.         read(fd, s, sizeof(s));
  98.         close(fd);
  99.  
  100.         printf("A mentő csapatok ezt a névsort kapták: %s\n", s);
  101.         int sum = 0;
  102.         for (size_t i = 0; i < strlen(s); i++)
  103.         {
  104.             printf("----\n");
  105.             if (s[i] == '_')
  106.             {
  107.                 sum = sum + 1;
  108.             }
  109.         }
  110.         char  messageToSend [1024] = "";
  111.         char snum[5];
  112.         sprintf(snum, "%d", sum);
  113.        
  114.         strcpy(messageToSend,place);
  115.         strcat(messageToSend," ből hozott a mentőexpedíció haza ennyi embert: ");
  116.         strcat(messageToSend,snum);
  117.  
  118.         printf("TESTPRINT DSDSSDDS   %s\n",messageToSend);
  119.  
  120.        
  121.         sendMessageQueue(uzenetsor,messageToSend); // Parent sends a message.
  122.  
  123.         //sleep until killed by parent prevents menu showing twice
  124.         sleep(20);
  125.     }
  126. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top