@@ -4316,49 +4316,57 @@ static void clear_func_filters(void)
}
}
-static void make_instances(void)
+static void make_instance(struct buffer_instance *instance)
{
- struct buffer_instance *instance;
struct stat st;
char *path;
int ret;
+ path = get_instance_dir(instance);
+ ret = stat(path, &st);
+ if (ret < 0) {
+ ret = mkdir(path, 0777);
+ if (ret < 0)
+ die("mkdir %s", path);
+ } else
+ /* Don't delete instances that already exist */
+ instance->flags |= BUFFER_FL_KEEP;
+ tracecmd_put_tracing_file(path);
+
+}
+
+static void make_instances(void)
+{
+ struct buffer_instance *instance;
+
for_each_instance(instance) {
if (is_guest(instance))
continue;
+ make_instance(instance);
+ }
+}
- path = get_instance_dir(instance);
- ret = stat(path, &st);
- if (ret < 0) {
- ret = mkdir(path, 0777);
- if (ret < 0)
- die("mkdir %s", path);
- } else
- /* Don't delete instances that already exist */
- instance->flags |= BUFFER_FL_KEEP;
- tracecmd_put_tracing_file(path);
+static void tracecmd_remove_instance(struct buffer_instance *instance)
+{
+ char *path;
+
+ if (instance->tracing_on_fd > 0) {
+ close(instance->tracing_on_fd);
+ instance->tracing_on_fd = 0;
}
+ path = get_instance_dir(instance);
+ tracecmd_put_tracing_file(path);
}
void tracecmd_remove_instances(void)
{
struct buffer_instance *instance;
- char *path;
- int ret;
for_each_instance(instance) {
/* Only delete what we created */
if (is_guest(instance) || (instance->flags & BUFFER_FL_KEEP))
continue;
- if (instance->tracing_on_fd > 0) {
- close(instance->tracing_on_fd);
- instance->tracing_on_fd = 0;
- }
- path = get_instance_dir(instance);
- ret = rmdir(path);
- if (ret < 0)
- die("rmdir %s", path);
- tracecmd_put_tracing_file(path);
+ tracecmd_remove_instance(instance);
}
}
In order to reuse the code which creates / deletes tracing instances, these two functions are refactotred. A new ones are implemented: make_instance() and tracecmd_remove_instance(). Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com> --- tracecmd/trace-record.c | 54 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-)