mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
bye to close(), welcome to VIR_(FORCE_)CLOSE()
Using automated replacement with sed and editing I have now replaced all occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of course. Some replacements were straight forward, others I needed to pay attention. I hope I payed attention in all the right places... Please have a look. This should have at least solved one more double-close error.
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
|
||||
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
|
||||
|
||||
#include "files.h"
|
||||
|
||||
static unsigned int testDebug = -1;
|
||||
static unsigned int testVerbose = -1;
|
||||
|
||||
@@ -222,8 +224,10 @@ void virtTestCaptureProgramExecChild(const char *const argv[],
|
||||
open_max = sysconf (_SC_OPEN_MAX);
|
||||
for (i = 0; i < open_max; i++) {
|
||||
if (i != stdinfd &&
|
||||
i != pipefd)
|
||||
close(i);
|
||||
i != pipefd) {
|
||||
int tmpfd = i;
|
||||
VIR_FORCE_CLOSE(tmpfd);
|
||||
}
|
||||
}
|
||||
|
||||
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
|
||||
@@ -237,8 +241,7 @@ void virtTestCaptureProgramExecChild(const char *const argv[],
|
||||
execve(argv[0], (char *const*)argv, (char *const*)env);
|
||||
|
||||
cleanup:
|
||||
if (stdinfd != -1)
|
||||
close(stdinfd);
|
||||
VIR_FORCE_CLOSE(stdinfd);
|
||||
}
|
||||
|
||||
int virtTestCaptureProgramOutput(const char *const argv[],
|
||||
@@ -252,10 +255,10 @@ int virtTestCaptureProgramOutput(const char *const argv[],
|
||||
int pid = fork();
|
||||
switch (pid) {
|
||||
case 0:
|
||||
close(pipefd[0]);
|
||||
VIR_FORCE_CLOSE(pipefd[0]);
|
||||
virtTestCaptureProgramExecChild(argv, pipefd[1]);
|
||||
|
||||
close(pipefd[1]);
|
||||
VIR_FORCE_CLOSE(pipefd[1]);
|
||||
_exit(1);
|
||||
|
||||
case -1:
|
||||
@@ -267,7 +270,7 @@ int virtTestCaptureProgramOutput(const char *const argv[],
|
||||
int ret = -1;
|
||||
int want = buflen-1;
|
||||
|
||||
close(pipefd[1]);
|
||||
VIR_FORCE_CLOSE(pipefd[1]);
|
||||
|
||||
while (want) {
|
||||
if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
|
||||
@@ -275,7 +278,7 @@ int virtTestCaptureProgramOutput(const char *const argv[],
|
||||
got += ret;
|
||||
want -= ret;
|
||||
}
|
||||
close(pipefd[0]);
|
||||
VIR_FORCE_CLOSE(pipefd[0]);
|
||||
|
||||
if (!ret)
|
||||
(*buf)[got] = '\0';
|
||||
|
||||
Reference in New Issue
Block a user