From 818bae2780a6a3d12a4b434f1637ef807d84f294 Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Wed, 24 Apr 2013 07:48:51 -0700 Subject: [PATCH] --- yaml --- r: 363231 b: refs/heads/master c: d3d1ee3ab28711360937839423158cc185f710f2 h: refs/heads/master i: 363229: 960276b88719b2b3b9af1887f45427cd80656fd9 363227: 7f5c107399fc2602afd386124c76386230d6b6df 363223: 66f22688f981815a377ba40745b9517a8d6238c0 363215: 20407978985a3884040f6b31309a538e509013ba 363199: 23963c9fc0683e1443c814173f0deeca6e5f8aa4 v: v3 --- [refs] | 2 +- trunk/tools/hv/hv_vss_daemon.c | 39 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/[refs] b/[refs] index 492c75cf2e98..06d561a4b14e 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 038336a5b40ceeea394a6eb3e8c6fc75701eec47 +refs/heads/master: d3d1ee3ab28711360937839423158cc185f710f2 diff --git a/trunk/tools/hv/hv_vss_daemon.c b/trunk/tools/hv/hv_vss_daemon.c index 921c1bec0305..a5da91df4f76 100644 --- a/trunk/tools/hv/hv_vss_daemon.c +++ b/trunk/tools/hv/hv_vss_daemon.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -47,11 +48,10 @@ static int vss_operate(int operation) { char *fs_op; char cmd[512]; - char buf[512]; - FILE *file; - char *p; - char *x; - int error = 0; + char match[] = "/dev/"; + FILE *mounts; + struct mntent *ent; + int error = 0, root_seen = 0; switch (operation) { case VSS_OP_FREEZE: @@ -64,25 +64,28 @@ static int vss_operate(int operation) return -1; } - file = popen("mount | awk '/^\\/dev\\// { print $3}'", "r"); - if (file == NULL) + mounts = setmntent("/proc/mounts", "r"); + if (mounts == NULL) return -1; - while ((p = fgets(buf, sizeof(buf), file)) != NULL) { - x = strchr(p, '\n'); - *x = '\0'; - if (!strncmp(p, "/", sizeof("/"))) + while((ent = getmntent(mounts))) { + if (strncmp(ent->mnt_fsname, match, strlen(match))) continue; - - sprintf(cmd, "%s %s %s", "fsfreeze ", fs_op, p); + if (strcmp(ent->mnt_dir, "/") == 0) { + 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); - error = system(cmd); + error |= system(cmd); } - pclose(file); + endmntent(mounts); - sprintf(cmd, "%s %s %s", "fsfreeze ", fs_op, "/"); - syslog(LOG_INFO, "VSS cmd is %s\n", cmd); - error = system(cmd); + if (root_seen) { + sprintf(cmd, "fsfreeze %s /", fs_op); + syslog(LOG_INFO, "VSS cmd is %s\n", cmd); + error |= system(cmd); + } return error; }