[CRIU] [PATCH 4/5] proc_parse: Rework status parser to use bfd

Pavel Emelyanov xemul at parallels.com
Fri Sep 19 06:31:38 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 proc_parse.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/proc_parse.c b/proc_parse.c
index 59b77a0..1a81f03 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -700,7 +700,7 @@ static int ids_parse(char *str, unsigned int *arr)
 	arr[1] = strtol(end + 1, &end, 10);
 	arr[2] = strtol(end + 1, &end, 10);
 	arr[3] = strtol(end + 1, &end, 10);
-	if (*end != '\n')
+	if (*end != '\0')
 		return -1;
 	else
 		return 0;
@@ -723,16 +723,19 @@ static int cap_parse(char *str, unsigned int *res)
 int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 {
 	int done = 0;
-	FILE *f;
-	char str[64];
+	struct bfd f;
+	char *str;
 
-	f = fopen_proc(pid, "status");
-	if (f == NULL) {
+	f.fd = open_proc(pid, "status");
+	if (f.fd < 0) {
 		pr_perror("Can't open proc status");
 		return -1;
 	}
 
-	while (done < 6 && fgets(str, sizeof(str), f)) {
+	if (bfdopen(&f))
+		return -1;
+
+	while (done < 6 && (str = breadline(&f))) {
 		if (!strncmp(str, "Uid:", 4)) {
 			if (ids_parse(str + 5, cr->uids))
 				goto err_parse;
@@ -779,11 +782,11 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 	if (done != 6) {
 err_parse:
 		pr_err("Error parsing proc status file\n");
-		fclose(f);
+		bclose(&f);
 		return -1;
 	}
 
-	fclose(f);
+	bclose(&f);
 	return 0;
 }
 
-- 
1.8.4.2




More information about the CRIU mailing list