From: Olaf Hering <olaf@aepfle.de>
To: kys@microsoft.com, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, Olaf Hering <olaf@aepfle.de>
Subject: [PATCH 3/3] tools: hv: use getmntent in hv_vss_daemon
Date: Tue, 26 Mar 2013 16:28:29 +0100 [thread overview]
Message-ID: <1364311709-18228-3-git-send-email-olaf@aepfle.de> (raw)
In-Reply-To: <1364311709-18228-1-git-send-email-olaf@aepfle.de>
As suggested by Paolo Bonzini, use getmntent instead of parsing output
of mount(1).
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
tools/hv/hv_vss_daemon.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index dc3eb1e..e37d86c 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -23,6 +23,7 @@
#include <sys/poll.h>
#include <linux/types.h>
#include <stdio.h>
+#include <mntent.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -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;
}
next prev parent reply other threads:[~2013-03-26 15:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-26 15:28 [PATCH 1/3] Tools: hv: fix warnings " Olaf Hering
2013-03-26 15:28 ` [PATCH 2/3] tools: hv: fix checks for origin of netlink message " Olaf Hering
2013-03-26 18:45 ` KY Srinivasan
2013-03-26 15:28 ` Olaf Hering [this message]
2013-03-26 18:45 ` [PATCH 3/3] tools: hv: use getmntent " KY Srinivasan
2013-03-26 18:44 ` [PATCH 1/3] Tools: hv: fix warnings " KY Srinivasan
2013-04-19 23:24 ` Greg KH
2013-04-21 22:32 ` KY Srinivasan
2013-04-22 1:13 ` Greg KH
2013-04-23 12:43 ` KY Srinivasan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364311709-18228-3-git-send-email-olaf@aepfle.de \
--to=olaf@aepfle.de \
--cc=gregkh@linuxfoundation.org \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®