aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv
diff options
context:
space:
mode:
authorOlaf Hering <olaf@aepfle.de>2013-04-24 10:48:51 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-24 12:02:35 -0400
commitd3d1ee3ab28711360937839423158cc185f710f2 (patch)
treea19d46779757647a490f11aff5527630650fde0e /tools/hv
parent038336a5b40ceeea394a6eb3e8c6fc75701eec47 (diff)
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: Olaf Hering <olaf@aepfle.de> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/hv')
-rw-r--r--tools/hv/hv_vss_daemon.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index 921c1bec0305..a5da91df4f76 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -23,6 +23,7 @@
23#include <sys/poll.h> 23#include <sys/poll.h>
24#include <linux/types.h> 24#include <linux/types.h>
25#include <stdio.h> 25#include <stdio.h>
26#include <mntent.h>
26#include <stdlib.h> 27#include <stdlib.h>
27#include <unistd.h> 28#include <unistd.h>
28#include <string.h> 29#include <string.h>
@@ -47,11 +48,10 @@ static int vss_operate(int operation)
47{ 48{
48 char *fs_op; 49 char *fs_op;
49 char cmd[512]; 50 char cmd[512];
50 char buf[512]; 51 char match[] = "/dev/";
51 FILE *file; 52 FILE *mounts;
52 char *p; 53 struct mntent *ent;
53 char *x; 54 int error = 0, root_seen = 0;
54 int error = 0;
55 55
56 switch (operation) { 56 switch (operation) {
57 case VSS_OP_FREEZE: 57 case VSS_OP_FREEZE:
@@ -64,25 +64,28 @@ static int vss_operate(int operation)
64 return -1; 64 return -1;
65 } 65 }
66 66
67 file = popen("mount | awk '/^\\/dev\\// { print $3}'", "r"); 67 mounts = setmntent("/proc/mounts", "r");
68 if (file == NULL) 68 if (mounts == NULL)
69 return -1; 69 return -1;
70 70
71 while ((p = fgets(buf, sizeof(buf), file)) != NULL) { 71 while((ent = getmntent(mounts))) {
72 x = strchr(p, '\n'); 72 if (strncmp(ent->mnt_fsname, match, strlen(match)))
73 *x = '\0';
74 if (!strncmp(p, "/", sizeof("/")))
75 continue; 73 continue;
76 74 if (strcmp(ent->mnt_dir, "/") == 0) {
77 sprintf(cmd, "%s %s %s", "fsfreeze ", fs_op, p); 75 root_seen = 1;
76 continue;
77 }
78 snprintf(cmd, sizeof(cmd), "fsfreeze %s '%s'", fs_op, ent->mnt_dir);
78 syslog(LOG_INFO, "VSS cmd is %s\n", cmd); 79 syslog(LOG_INFO, "VSS cmd is %s\n", cmd);
79 error = system(cmd); 80 error |= system(cmd);
80 } 81 }
81 pclose(file); 82 endmntent(mounts);
82 83
83 sprintf(cmd, "%s %s %s", "fsfreeze ", fs_op, "/"); 84 if (root_seen) {
84 syslog(LOG_INFO, "VSS cmd is %s\n", cmd); 85 sprintf(cmd, "fsfreeze %s /", fs_op);
85 error = system(cmd); 86 syslog(LOG_INFO, "VSS cmd is %s\n", cmd);
87 error |= system(cmd);
88 }
86 89
87 return error; 90 return error;
88} 91}