Old stuff/ecole_etude_fac_de_pau/licence_3/projet_commun_se/html/barman.c
(Deskargatu)
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/shm.h>
#include "include/global.h"
#include "include/demandes.h"
#include "include/shm.h"
#include "include/bar_gerer_com.h"
#include "include/bar_security.h"
#include "include/bar_ordo.h"
#include "include/blonde.h"
#include "include/brune.h"
/*
Barman
Programme serveur, gerant des entrees sorties tcp/ip
Envoie des signaux aux tireuses pour les preparations
Renvoie les bieres servies via tcp/ip
*/
int main(int argc, char** argv)
{
pid_t pid;
if (setpgid(0,getpid()) == -1)
{
perror("barman.c setpgid");
exit(-1);
}
// Creation du tube, pour envoyer les bieres
struct stat sb;
if (lstat("tube", &sb) == -1 && errno == ENOENT)
{
printf("barman.c: \tCreating pipe\n");
if (mkfifo("tube", S_IRUSR|S_IWUSR|0777) == -1)
{
perror("mk fifo");
exit(-1);
}
}
if (lstat("tube", &sb) == -1)
{
perror("erreur sur les stats sur le tube");
exit(-1);
}
if ((sb.st_mode & S_IFIFO) != S_IFIFO )
{
perror("fichier tube non fifo");
exit(-1);
}
// Generation de la shm pour tout le monde
if ((id_shm = gen_shm("./cle_bar",sizeof(flags)+8*sizeof(int)+sizeof(demande),(void*)&flg,1)) == -1)
{
perror("barman.c: \tgeneration de la shm");
exit(-1);
}
// toute la shm a 0
bzero(flg,sizeof(flg)+9*sizeof(int)+sizeof(demande));
buffer = (demande*)(flg);
// Forks successifs pour les differents modules
printf("barman.c: \t\tLoading Com ...\n");
pid = fork();
if (pid == -1) { perror("main: Fork loop error"); exit(-1); }
if(pid == 0)
{
bar_gerer_com();
return (0);
}
printf("barman.c: \t\tOK\n");
printf("barman.c: \t\tLoading Ordonnanceur ...\n");
pid = fork();
if (pid == -1)
{
perror("main: Fork loop error");
exit(-1);
}
else if(pid == 0)
{
bar_ordo();
return (0);
}
printf("barman.c: \t\tOK\n");
printf("barman.c: \t\tLoading Security ...\n");
pid = fork();
if (pid == -1)
{
perror("main: Fork loop error");
exit(-1);
}
else if(pid == 0)
{
bar_security();
return (0);
}
printf("barman.c: \t\tOK\n");
while(1) { pause(); }
return 0;
}