Changeset View
Changeset View
Standalone View
Standalone View
ksysguardd/Linux/softraid.c
Show First 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | 205 | void getMdadmDetail( ArrayInfo* MyArray ) { | |||
---|---|---|---|---|---|
210 | char sensorName[128]; | 210 | char sensorName[128]; | ||
211 | char arrayDevice[ARRAYNAMELEN + 5 + 1]; | 211 | char arrayDevice[ARRAYNAMELEN + 5 + 1]; | ||
212 | char format[ 32 ]; | 212 | char format[ 32 ]; | ||
213 | char lineBuf[ 1024 ]; | 213 | char lineBuf[ 1024 ]; | ||
214 | char mdadmStatBuf[ MDADMSTATBUFSIZE ]; /* Buffer for mdadm --detail */ | 214 | char mdadmStatBuf[ MDADMSTATBUFSIZE ]; /* Buffer for mdadm --detail */ | ||
215 | char* mdadmStatBufP; | 215 | char* mdadmStatBufP; | ||
216 | 216 | | |||
217 | /* Create a pipe */ | 217 | /* Create a pipe */ | ||
218 | if(pipe(fd) == -1) | 218 | if(pipe2(fd, O_CLOEXEC) == -1) | ||
219 | { | 219 | { | ||
220 | perror("Could not create a pipe to launch mdadm."); | 220 | perror("Could not create a pipe to launch mdadm."); | ||
221 | exit(1); | 221 | exit(1); | ||
222 | } | 222 | } | ||
223 | 223 | | |||
224 | /* Fork */ | 224 | /* Fork */ | ||
225 | if((ChildPID = fork()) == -1) | 225 | if((ChildPID = fork()) == -1) | ||
226 | { | 226 | { | ||
Show All 16 Lines | 234 | /* Child process */ | |||
243 | snprintf( arrayDevice, sizeof( arrayDevice ), "/dev/%s", MyArray->ArrayName ); | 243 | snprintf( arrayDevice, sizeof( arrayDevice ), "/dev/%s", MyArray->ArrayName ); | ||
244 | execl ("/sbin/mdadm", "mdadm", "--detail", arrayDevice, (char *)0); | 244 | execl ("/sbin/mdadm", "mdadm", "--detail", arrayDevice, (char *)0); | ||
245 | exit(0); /* In case /sbin/mdadm isn't found */ | 245 | exit(0); /* In case /sbin/mdadm isn't found */ | ||
246 | /* Child is now dead, as per our request */ | 246 | /* Child is now dead, as per our request */ | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | /* Parent process */ | 249 | /* Parent process */ | ||
250 | 250 | | |||
251 | /* Close input side of pipe */ | | |||
252 | close(fd[1]); | | |||
253 | | ||||
254 | waitpid( ChildPID, 0, 0); | 251 | waitpid( ChildPID, 0, 0); | ||
255 | 252 | | |||
256 | /* Fill mdadmStatBuf with pipe's output */ | 253 | /* Fill mdadmStatBuf with pipe's output */ | ||
257 | nbytes = read( fd[0], mdadmStatBuf, MDADMSTATBUFSIZE-1 ); | 254 | nbytes = read( fd[0], mdadmStatBuf, MDADMSTATBUFSIZE-1 ); | ||
258 | if (nbytes >= 0) | 255 | if (nbytes >= 0) | ||
259 | mdadmStatBuf[nbytes] = '\0'; | 256 | mdadmStatBuf[nbytes] = '\0'; | ||
260 | 257 | | |||
261 | /* Now, go through mdadmStatBuf line by line. Register monitors along the way */ | 258 | /* Now, go through mdadmStatBuf line by line. Register monitors along the way */ | ||
Show All 30 Lines | 287 | else if ( sscanf(lineBuf, "Preferred Minor : %d", &MyArray->PreferredMinor) == 1 ) { | |||
292 | if ( !MyArray->PreferredMinorIsRegistered ) { | 289 | if ( !MyArray->PreferredMinorIsRegistered ) { | ||
293 | sprintf(sensorName, "SoftRaid/%s/PreferredMinor", MyArray->ArrayName); | 290 | sprintf(sensorName, "SoftRaid/%s/PreferredMinor", MyArray->ArrayName); | ||
294 | registerMonitor(sensorName, "integer", printArrayAttribute, printArrayAttributeInfo, StatSM ); | 291 | registerMonitor(sensorName, "integer", printArrayAttribute, printArrayAttributeInfo, StatSM ); | ||
295 | MyArray->PreferredMinorIsRegistered = true; | 292 | MyArray->PreferredMinorIsRegistered = true; | ||
296 | } | 293 | } | ||
297 | } | 294 | } | ||
298 | } | 295 | } | ||
299 | 296 | | |||
297 | /* Close pipe */ | ||||
298 | close(fd[0]); | ||||
299 | close(fd[1]); | ||||
300 | | ||||
300 | /* Note: Don't test NumBlocksIsAlive, because it hasn't been set yet */ | 301 | /* Note: Don't test NumBlocksIsAlive, because it hasn't been set yet */ | ||
301 | if ( (!MyArray->ArraySizeIsAlive && MyArray->ArraySizeIsRegistered ) || | 302 | if ( (!MyArray->ArraySizeIsAlive && MyArray->ArraySizeIsRegistered ) || | ||
302 | (!MyArray->UsedDeviceSizeIsAlive && MyArray->UsedDeviceSizeIsRegistered ) || | 303 | (!MyArray->UsedDeviceSizeIsAlive && MyArray->UsedDeviceSizeIsRegistered ) || | ||
303 | (!MyArray->PreferredMinorIsAlive && MyArray->PreferredMinorIsRegistered ) | 304 | (!MyArray->PreferredMinorIsAlive && MyArray->PreferredMinorIsRegistered ) | ||
304 | ) { | 305 | ) { | ||
305 | print_error( "RECONFIGURE" ); | 306 | print_error( "RECONFIGURE" ); | ||
306 | log_error( "Soft raid device disappeared" ); | 307 | log_error( "Soft raid device disappeared" ); | ||
307 | return; | 308 | return; | ||
▲ Show 20 Lines • Show All 308 Lines • Show Last 20 Lines |