提交 d3d1ee3a 编写于 作者: O Olaf Hering 提交者: Greg Kroah-Hartman

tools: hv: use getmntent in hv_vss_daemon

As suggested by Paolo Bonzini, use getmntent instead of parsing output
of mount(1).
Signed-off-by: NOlaf Hering <olaf@aepfle.de>
Signed-off-by: NK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 038336a5
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <sys/poll.h> #include <sys/poll.h>
#include <linux/types.h> #include <linux/types.h>
#include <stdio.h> #include <stdio.h>
#include <mntent.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
...@@ -47,11 +48,10 @@ static int vss_operate(int operation) ...@@ -47,11 +48,10 @@ static int vss_operate(int operation)
{ {
char *fs_op; char *fs_op;
char cmd[512]; char cmd[512];
char buf[512]; char match[] = "/dev/";
FILE *file; FILE *mounts;
char *p; struct mntent *ent;
char *x; int error = 0, root_seen = 0;
int error = 0;
switch (operation) { switch (operation) {
case VSS_OP_FREEZE: case VSS_OP_FREEZE:
...@@ -64,25 +64,28 @@ static int vss_operate(int operation) ...@@ -64,25 +64,28 @@ static int vss_operate(int operation)
return -1; return -1;
} }
file = popen("mount | awk '/^\\/dev\\// { print $3}'", "r"); mounts = setmntent("/proc/mounts", "r");
if (file == NULL) if (mounts == NULL)
return -1; return -1;
while ((p = fgets(buf, sizeof(buf), file)) != NULL) { while((ent = getmntent(mounts))) {
x = strchr(p, '\n'); if (strncmp(ent->mnt_fsname, match, strlen(match)))
*x = '\0';
if (!strncmp(p, "/", sizeof("/")))
continue; continue;
if (strcmp(ent->mnt_dir, "/") == 0) {
sprintf(cmd, "%s %s %s", "fsfreeze ", fs_op, p); root_seen = 1;
continue;
}
snprintf(cmd, sizeof(cmd), "fsfreeze %s '%s'", fs_op, ent->mnt_dir);
syslog(LOG_INFO, "VSS cmd is %s\n", cmd); syslog(LOG_INFO, "VSS cmd is %s\n", cmd);
error = system(cmd); error |= system(cmd);
} }
pclose(file); endmntent(mounts);
sprintf(cmd, "%s %s %s", "fsfreeze ", fs_op, "/"); if (root_seen) {
syslog(LOG_INFO, "VSS cmd is %s\n", cmd); sprintf(cmd, "fsfreeze %s /", fs_op);
error = system(cmd); syslog(LOG_INFO, "VSS cmd is %s\n", cmd);
error |= system(cmd);
}
return error; return error;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册