I have question about this piece of code fragment. When I run a c-programb on its own, it works fine.
But when I fork this program from another program, I get this program to do segfault at fgets.
Any suggestions from what's wrong with fgets? I just want read content fo the file upto what the buffer can hold. These three lines never get executed:
syslog(LOG_INFO,"Reading 100 Bytes of config file\n");
fclose(configfile);
syslog(LOG_INFO,"Closing of config file\n");
server.conf:
progb.c:
Code:
FILE *configfile;
char conf[100];
syslog(LOG_INFO,"Reading config file\n");
configfile= fopen("./server.conf", "r");
syslog(LOG_INFO,"After Opening config file\n");
fgets(conf,100, configfile);
syslog(LOG_INFO,"Reading 100 Bytes of config file\n");
fclose(configfile);
syslog(LOG_INFO,"Closing of config file\n");
syslog:
Dec 28 15:48:53 localhost [19674]: Version 1.0
Dec 28 15:48:53 localhost [19674]: Reading config file
Dec 28 15:48:53 localhost [19674]: After Opening config file
According to gdb:
(gdb) out conf
"num_of_files=3;\n", '\0' <repeats 80 times>(gdb)