Projet

Général

Profil

Révision cc0b0949

IDcc0b0949385fe850bf0e4a37507c3cff655ded1b
Parent c81c20ab
Enfant 52905275

Ajouté par Steve Schnepp il y a plus de 7 ans

p/if1sec-c: handle absence of state file

Voir les différences:

plugins/network/if1sec-c.c
38 38

  
39 39
int config() {
40 40
	/* Get the number of if */
41
	int f;
42
	if ( !(f=open(PROC_STAT, O_RDONLY)) ) {
41
	int f = open(PROC_STAT, O_RDONLY);
42
	if ( f == -1 ) {
43 43
		return fail("cannot open " PROC_STAT);
44 44
	}
45 45

  
......
120 120
	/* fork ourselves if not asked otherwise */
121 121
	char* no_fork = getenv("no_fork");
122 122
	if (! no_fork || strcmp("1", no_fork)) {
123
		if (fork()) return;
123
		if (fork()) return 0;
124 124
		// we are the child, complete the daemonization
125 125

  
126 126
		/* Close standard IO */
......
139 139

  
140 140
	/* Reading /proc/stat */
141 141
	int f = open(PROC_STAT, O_RDONLY);
142
	if ( f == -1 ) {
143
		return fail("cannot open " PROC_STAT);
144
	}
142 145

  
143 146
	/* open the spoolfile */
144 147
	int cache_file = open(cache_filename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
148
	if ( cache_file == -1 ) {
149
		return fail("cannot open the spoolfile");
150
	}
145 151

  
146 152
	/* loop each second */
147 153
	while (1) {
......
213 219

  
214 220
int fetch() {
215 221
	FILE* cache_file = fopen(cache_filename, "r+");
222
	if ( !cache_file ) {
223
		return fail("cannot open cache file");
224
	}
216 225

  
217 226
	/* lock */
218 227
	flock(fileno(cache_file), LOCK_EX);

Formats disponibles : Unified diff