[lttng-dev] [LTTNG-TOOLS 2.4 RFC PATCH] Kernel consumer generate indexes
Mathieu Desnoyers
mathieu.desnoyers at efficios.com
Fri Aug 9 11:55:05 EDT 2013
* Mathieu Desnoyers (mathieu.desnoyers at efficios.com) wrote:
> * Julien Desfossez (jdesfossez at efficios.com) wrote:
[...]
> > +static int create_index_file(struct lttng_consumer_stream *stream)
> > +{
> > + char *index_name;
> > + struct lttng_packet_index_file_hdr hdr;
> > + int ret;
> > +
> > + ret = asprintf(&index_name, "%s.idx", stream->name);
> > + if (ret < 0) {
> > + PERROR("Allocating index name");
> > + goto error;
> > + }
> > + ret = utils_create_stream_file(stream->chan->pathname,
> > + index_name, 0, 0, stream->uid,
> > + stream->gid);
> > + free(index_name);
> > + if (ret < 0) {
> > + goto error;
> > + }
> > +
> > + stream->index_fd = ret;
> > + strncpy(hdr.magic, INDEX_MAGIC, sizeof(hdr.magic));
>
> If you use strncpy, it's because you don't trust that INDEX_MAGIC will
> always fit within hdr.magic. If it is the case, then you should always
> do:
>
> hdr.magic[sizeof(hdr.magic) - 1] = '\0';
>
> after the strncpy.
In this case, you'll want to use a memcpy, since you clearly copy from a
fixed-sized to a fixed-sized area, which need to have both the same
size.
memcpy(hdr.magic, INDEX_MAGIC, sizeof(hdr.magic));
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list