Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. //
  2. // Created by Fiordarancio, Matteo on 2019-07-04.
  3. //
  4.  
  5. #include<stdio.h>
  6. #include<string.h>
  7. #include<stdlib.h>
  8. #include<sys/types.h>
  9. #include<sys/socket.h>
  10. #include<sys/time.h>
  11. #include<netinet/in.h>
  12. #include<signal.h>
  13. #include<errno.h>
  14.  
  15. //Constants and global variable declaration goes here
  16. #define MAX_LEN 128
  17.  
  18. //Service structure definition goes here
  19. typedef struct {
  20. char transport_protocol[3];
  21. char service_mode[6];
  22. char service_port[10];
  23. char service_full_path_name[200];
  24. char service_name[50];
  25. int socket_file_descriptor;
  26. int PID;
  27. } service;
  28.  
  29. //Function prototype devoted to handle the death of the son process
  30. void handle_signal (int sig);
  31. service * read_file();
  32.  
  33. int main(int argc,char **argv,char **env){ // NOTE: env is the variable to be passed, as last argument, to execle system-call
  34. // Other variables declaration goes here
  35. read_file();
  36.  
  37. // Server behavior implementation goes here
  38.  
  39.  
  40. signal (SIGCHLD,handle_signal); /* Handle signals sent by son processes - call this function when it's ought to be */
  41.  
  42. return 0;
  43. }
  44.  
  45. service * read_file(){
  46. FILE *conf_file = fopen("inetd.conf", "r");
  47. char line[MAX_LEN];
  48.  
  49. if (conf_file == NULL)
  50. {
  51. perror("Error while opening the file.\n");
  52. exit(EXIT_FAILURE);
  53. }
  54.  
  55. fscanf(conf_file,"%[^\n]", line);
  56. printf("%s", line);
  57.  
  58. fclose(conf_file);
  59. return NULL;
  60. }
  61.  
  62.  
  63. // handle_signal implementation
  64. void handle_signal (int sig){
  65. // Call to wait system-call goes here
  66.  
  67.  
  68. switch (sig) {
  69. case SIGCHLD :
  70. // Implementation of SIGCHLD handling goes here
  71.  
  72.  
  73. break;
  74. default : printf ("Signal not known!\n");
  75. break;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement