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 26 Lines | |||||
253 | 253 | | |||
254 | waitpid( ChildPID, 0, 0); | 254 | waitpid( ChildPID, 0, 0); | ||
255 | 255 | | |||
256 | /* Fill mdadmStatBuf with pipe's output */ | 256 | /* Fill mdadmStatBuf with pipe's output */ | ||
257 | nbytes = read( fd[0], mdadmStatBuf, MDADMSTATBUFSIZE-1 ); | 257 | nbytes = read( fd[0], mdadmStatBuf, MDADMSTATBUFSIZE-1 ); | ||
258 | if (nbytes >= 0) | 258 | if (nbytes >= 0) | ||
259 | mdadmStatBuf[nbytes] = '\0'; | 259 | mdadmStatBuf[nbytes] = '\0'; | ||
260 | 260 | | |||
261 | /* Close output side of pipe */ | ||||
262 | close(fd[0]); | ||||
263 | | ||||
261 | /* Now, go through mdadmStatBuf line by line. Register monitors along the way */ | 264 | /* Now, go through mdadmStatBuf line by line. Register monitors along the way */ | ||
262 | sprintf( format, "%%%d[^\n]\n", (int)sizeof( lineBuf ) - 1 ); | 265 | sprintf( format, "%%%d[^\n]\n", (int)sizeof( lineBuf ) - 1 ); | ||
263 | mdadmStatBufP = mdadmStatBuf; | 266 | mdadmStatBufP = mdadmStatBuf; | ||
264 | while (sscanf(mdadmStatBufP, format, lineBuf) != EOF) { | 267 | while (sscanf(mdadmStatBufP, format, lineBuf) != EOF) { | ||
265 | lineBuf[sizeof(lineBuf) - 1] = '\0'; | 268 | lineBuf[sizeof(lineBuf) - 1] = '\0'; | ||
266 | mdadmStatBufP += strlen(lineBuf) + 1; /* move mdadmStatBufP to next line */ | 269 | mdadmStatBufP += strlen(lineBuf) + 1; /* move mdadmStatBufP to next line */ | ||
267 | 270 | | |||
268 | if ( sscanf(lineBuf, " Array Size : %d", &MyArray->ArraySizeKB) == 1 ) { | 271 | if ( sscanf(lineBuf, " Array Size : %d", &MyArray->ArraySizeKB) == 1 ) { | ||
▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines |