Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Fiordarancio, Matteo on 2019-07-04.
- //
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<sys/types.h>
- #include<sys/socket.h>
- #include<sys/time.h>
- #include<netinet/in.h>
- #include<signal.h>
- #include<errno.h>
- //Constants and global variable declaration goes here
- #define MAX_LEN 128
- //Service structure definition goes here
- typedef struct {
- char transport_protocol[3];
- char service_mode[6];
- char service_port[10];
- char service_full_path_name[200];
- char service_name[50];
- int socket_file_descriptor;
- int PID;
- } service;
- //Function prototype devoted to handle the death of the son process
- void handle_signal (int sig);
- service * read_file();
- int main(int argc,char **argv,char **env){ // NOTE: env is the variable to be passed, as last argument, to execle system-call
- // Other variables declaration goes here
- read_file();
- // Server behavior implementation goes here
- signal (SIGCHLD,handle_signal); /* Handle signals sent by son processes - call this function when it's ought to be */
- return 0;
- }
- service * read_file(){
- FILE *conf_file = fopen("inetd.conf", "r");
- char line[MAX_LEN];
- if (conf_file == NULL)
- {
- perror("Error while opening the file.\n");
- exit(EXIT_FAILURE);
- }
- fscanf(conf_file,"%[^\n]", line);
- printf("%s", line);
- fclose(conf_file);
- return NULL;
- }
- // handle_signal implementation
- void handle_signal (int sig){
- // Call to wait system-call goes here
- switch (sig) {
- case SIGCHLD :
- // Implementation of SIGCHLD handling goes here
- break;
- default : printf ("Signal not known!\n");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement