[lxc-devel] [PATCH] don't truncate environment sometimes in setproctitle
Tycho Andersen
tycho.andersen at canonical.com
Mon Nov 16 21:49:56 UTC 2015
Instead, let's just allocate new space for the proctitle to live and point
the kernel at that.
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
src/lxc/lxccontainer.c | 2 +-
src/lxc/utils.c | 29 +++++++++--------------------
2 files changed, 10 insertions(+), 21 deletions(-)
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 5207255..c46d4f0 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -762,7 +762,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
* characters; all that it means is that the proctitle will be
* ugly. Similarly, we also don't care if setproctitle()
* fails. */
- snprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name);
+ snprintf(title, sizeof(title), "[lxc monitor this is a really long proctitle 01234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890] %s %s", c->config_path, c->name);
INFO("Attempting to set proc title to %s", title);
setproctitle(title);
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index dac6418..a5ec2ec 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1349,6 +1349,7 @@ char *get_template_path(const char *t)
*/
int setproctitle(char *title)
{
+ static char *proctitle = NULL;
char buf[2048], *tmp;
FILE *f;
int i, len, ret = 0;
@@ -1413,28 +1414,16 @@ int setproctitle(char *title)
* want to have room for it. */
len = strlen(title) + 1;
- /* We're truncating the environment, so we should use at most the
- * length of the argument + environment for the title. */
- if (len > env_end - arg_start) {
- arg_end = env_end;
- len = env_end - arg_start;
- title[len-1] = '\0';
- } else {
- /* Only truncate the environment if we're actually going to
- * overwrite part of it. */
- if (len >= arg_end - arg_start) {
- env_start = env_end;
- }
-
- arg_end = arg_start + len;
-
- /* check overflow */
- if (arg_end < len || arg_end < arg_start) {
- return -1;
- }
-
+ /* If we don't have enough room by just overwriting the old proctitle,
+ * let's allocate a new one.
+ */
+ if (len > arg_end - arg_start) {
+ proctitle = realloc(proctitle, len);
+ arg_start = (unsigned long) proctitle;
}
+ arg_end = arg_start + len;
+
brk_val = syscall(__NR_brk, 0);
prctl_map = (struct prctl_mm_map) {
--
2.5.0
More information about the lxc-devel
mailing list