Il mio prototipo per ora è il seguente:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
int fd, d;
size_t lsize;
FILE* conf_file;
char * line = NULL;
if (argc == 1) {
printf("\nCommand syntax:\n");
printf("\n\tprogramd [ start | stop ]\n");
printf("\t\tstart: start daemon\n");
printf("\t\tstop: stop daemon\n");
}
else if (strcmp(argv[1], "start") == 0) {
conf_file = fopen("/etc/program/program.conf", "r");
if (conf_file == NULL) perror("File not open");
while (!feof(conf_file)) {
d = getline(line, lsize, "/etc/program/program.conf");
printf("%d\n", d);
printf("%s\n", line);
}
}
return(0);
}
Compilazione ed esecuzione vanno nel modo seguente:
bash-3.1# gcc programd.c -o programd
bash-3.1# ./programd
Command syntax:
programd [ start | stop ]
start: start daemon
stop: stop daemon
bash-3.1# ./programd start
-1
Segmentation fault
bash-3.1#
mentre il file di configurazione è il seguente:
# Begin configuration file
OPT=/etc/myprogram/myprogram.log
OPT=/etc/myprogram/myprogram.lock
# End configuration file