lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 26 Mar 2013 18:45:33 +0000
From:	KY Srinivasan <kys@...rosoft.com>
To:	Olaf Hering <olaf@...fle.de>,
	"gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>
CC:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH 3/3] tools: hv: use getmntent in hv_vss_daemon



> -----Original Message-----
> From: Olaf Hering [mailto:olaf@...fle.de]
> Sent: Tuesday, March 26, 2013 11:28 AM
> To: KY Srinivasan; gregkh@...uxfoundation.org
> Cc: linux-kernel@...r.kernel.org; Olaf Hering
> Subject: [PATCH 3/3] 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@...fle.de>

Thanks for addressing this.

Acked by: K. Y. Srinivasan <kys@...rosoft.com>
> ---
>  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;
>  }
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ