[lxc-devel] [lxcfs/master] bindings: better logging for write_string()
brauner on Github
lxc-bot at linuxcontainers.org
Mon Jul 30 08:54:05 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180730/bfe73f48/attachment.bin>
-------------- next part --------------
From 83e224f3ece34b5608218d20b2c10961211e3a6d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 30 Jul 2018 10:53:19 +0200
Subject: [PATCH] bindings: better logging for write_string()
Closes #249.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
bindings.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/bindings.c b/bindings.c
index 4b6f51b..8a48f0c 100644
--- a/bindings.c
+++ b/bindings.c
@@ -97,7 +97,7 @@ struct cpuacct_usage {
#define EXP_15 2037 /* 1/exp(5sec/15min) */
#define LOAD_INT(x) ((x) >> FSHIFT)
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
-/*
+/*
* This parameter is used for proc_loadavg_read().
* 1 means use loadavg, 0 means not use.
*/
@@ -584,19 +584,26 @@ static bool write_string(const char *fnam, const char *string, int fd)
FILE *f;
size_t len, ret;
- if (!(f = fdopen(fd, "w")))
+ f = fdopen(fd, "w");
+ if (!f)
return false;
+
len = strlen(string);
ret = fwrite(string, 1, len, f);
if (ret != len) {
- lxcfs_error("Error writing to file: %s\n", strerror(errno));
+ lxcfs_error("%s - Error writing \"%s\" to \"%s\"\n",
+ strerror(errno), string ? string : "(null)",
+ fnam ? fname : "(null)");
fclose(f);
return false;
}
+
if (fclose(f) < 0) {
- lxcfs_error("Error writing to file: %s\n", strerror(errno));
+ lxcfs_error("%s - Failed to close \"%s\"\n", strerror(errno),
+ fnam ? fname : "(null)");
return false;
}
+
return true;
}
@@ -4629,7 +4636,7 @@ static int refresh_load(struct load_node *p, char *path)
p->last_pid = last_pid;
free(line);
-err_out:
+err_out:
for (; i > 0; i--)
free(idbuf[i-1]);
out:
More information about the lxc-devel
mailing list