+
+ trace_path = USTD_DEFAULT_TRACE_PATH;
+ }
+
+ asprintf(&tmp, "%s/%u_%lld", trace_path, buf->pid, buf->pidunique);
+ result = create_dir_if_needed(tmp);
+ if(result == -1) {
+ ERR("could not create directory %s", tmp);
+ free(tmp);
+ return 1;
+ }
+ free(tmp);
+
+ asprintf(&tmp, "%s/%u_%lld/%s", trace_path, buf->pid, buf->pidunique, buf->name);
+ result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 00600);
+ if(result == -1) {
+ PERROR("open");
+ ERR("failed opening trace file %s", tmp);
+ return 1;
+ }
+ buf_local->file_fd = fd;
+ free(tmp);
+
+ return 0;
+}
+
+int on_close_buffer(struct libustd_callbacks *data, struct buffer_info *buf)
+{
+ struct buffer_info_local *buf_local = buf->user_data;
+ int result = close(buf_local->file_fd);
+ free(buf_local);
+ if(result == -1) {
+ PERROR("close");