From: Oleg Nesterov <oleg@redhat.com>
To: Xiaotian Feng <dfeng@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Neil Horman <nhorman@tuxdriver.com>,
Roland McGrath <roland@redhat.com>
Subject: Re: [RFC PATCH V2] core_pattern: fix long parameters was truncated by core_pattern handler
Date: Mon, 2 Aug 2010 15:50:13 +0200 [thread overview]
Message-ID: <20100802135013.GA5877@redhat.com> (raw)
In-Reply-To: <1280751836-1826-1-git-send-email-dfeng@redhat.com>
On 08/02, Xiaotian Feng wrote:
>
> @@ -1466,78 +1496,126 @@ static int format_corename(char *corename, long signr)
> goto out;
> /* Double percent, output one percent */
> case '%':
> - if (out_ptr == out_end)
> - goto out;
> *out_ptr++ = '%';
Hmm. Not sure I understand why we do not need to check the space here.
> - rc = snprintf(out_ptr, out_end - out_ptr,
> - "%d", task_tgid_vnr(current));
> - if (rc > out_end - out_ptr)
> - goto out;
> + rc = snprintf(NULL, 0, "%d",
> + task_tgid_vnr(current));
> + if (rc > out_end - out_ptr) {
> + ret = expand_corename(corename,
> + &out_end,
> + &out_ptr, &size);
> + if (ret)
> + return ret;
> + }
> + rc = snprintf(out_ptr, rc + 1, "%d",
> + task_tgid_vnr(current));
Probably it makes sense to factor out this code?
Roughly, something like:
struct core_name {
char *corename;
int len, free;
};
static bool cn_printf(struct core_name *cn, const char *fmt, ...)
{
char *cur;
int need;
va_list ap;
retry:
cur = cn->corename + (cn->len - cn->free);
need = vsnprintf(cur, cn->free, fmt, ap);
if (likely(need < free)) {
free -= need;
return true;
}
increase ->len, realloc ->corename or return false;
goto retry;
}
Then format_corename() can just do
if (!cn_printf(&cn, ...))
return -ENOMEM;
consistently.
Also. Not sure this really makes sense, but if we ever need to expand the
string, perhaps it makes sense to remeber this fact so that the next time
we start with len > CORENAME_MAX_SIZE. In any case, I think this needs a
separate patch.
Oleg.
next prev parent reply other threads:[~2010-08-02 13:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-29 12:42 [RFC PATCH] core_pattern: fix long parameters was truncated by core_pattern handler Xiaotian Feng
2010-07-29 13:31 ` Neil Horman
2010-08-02 12:23 ` [RFC PATCH V2] " Xiaotian Feng
2010-08-02 13:50 ` Oleg Nesterov [this message]
2010-08-03 10:59 ` Neil Horman
2010-08-20 9:22 ` [RFC PATCH v3] " Xiaotian Feng
2010-08-20 9:35 ` Xiaotian Feng
2010-08-20 9:35 ` Xiaotian Feng
2010-08-23 11:07 ` Neil Horman
2010-08-23 23:02 ` KOSAKI Motohiro
2010-08-23 21:18 ` Andrew Morton
2010-08-24 6:18 ` Xiaotian Feng
2010-08-24 6:28 ` Andrew Morton
2010-08-24 9:42 ` [PATCH v4] " Xiaotian Feng
2010-08-24 22:47 ` Andrew Morton
2010-08-25 1:58 ` Xiaotian Feng
2010-08-25 2:17 ` [PATCH v5] " Xiaotian Feng
2010-08-02 14:30 ` [RFC PATCH V2] " Denys Vlasenko
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=20100802135013.GA5877@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dfeng@redhat.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=roland@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).