Skip to content

Commit 05e2610

Browse files
committed
uftrace: Improve logfile creation location
Ensure that when using "--logfile=<name>", the logfile is created inside the uftrace.data directory. Additionally, when using both "--host" and "--logfile" options simultaneously on the client, the logfile in the uftrace.data directory is sent to the host. Fixed: namhyung#831 Signed-off-by: Rihyeon Kim <[email protected]>
1 parent f3b92bb commit 05e2610

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

cmds/record.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -1423,12 +1423,15 @@ static void send_event_file(int sock, const char *dirname)
14231423
send_trace_metadata(sock, dirname, "events.txt");
14241424
}
14251425

1426-
static void send_log_file(int sock, const char *logfile)
1426+
static void send_log_file(int sock, const char *dirname, const char *logfile)
14271427
{
1428-
if (access(logfile, F_OK) != 0)
1428+
char *logfile_path = NULL;
1429+
xasprintf(&logfile_path, "%s/%s", dirname, logfile);
1430+
1431+
if (access(logfile_path, F_OK) != 0)
14291432
return;
14301433

1431-
send_trace_metadata(sock, NULL, (char *)logfile);
1434+
send_trace_metadata(sock, dirname, (char *)logfile);
14321435
}
14331436

14341437
static void update_session_maps(struct uftrace_opts *opts)
@@ -2070,7 +2073,7 @@ static void write_symbol_files(struct writer_data *wd, struct uftrace_opts *opts
20702073
if (opts->event)
20712074
send_event_file(sock, opts->dirname);
20722075
if (opts->logfile)
2073-
send_log_file(sock, opts->logfile);
2076+
send_log_file(sock, opts->dirname, opts->logfile);
20742077

20752078
send_trace_end(sock);
20762079
close(sock);
@@ -2275,7 +2278,7 @@ int command_record(int argc, char *argv[], struct uftrace_opts *opts)
22752278
check_perf_event(opts);
22762279

22772280
if (!opts->nop) {
2278-
if (create_directory(opts->dirname) < 0)
2281+
if (!opts->logfile && (create_directory(opts->dirname) < 0))
22792282
return -1;
22802283

22812284
xasprintf(&channel, "%s/%s", opts->dirname, ".channel");

uftrace.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,16 @@ int main(int argc, char *argv[])
14741474
debug = 1;
14751475

14761476
if (opts.logfile) {
1477-
logfp = fopen(opts.logfile, "a");
1477+
char *logfile_path = NULL;
1478+
if (create_directory(opts.dirname) < 0) {
1479+
ret = -1;
1480+
goto cleanup;
1481+
}
1482+
1483+
xasprintf(&logfile_path, "%s/%s", opts.dirname, opts.logfile);
1484+
logfp = fopen(logfile_path, "a");
1485+
free(logfile_path);
1486+
14781487
if (logfp == NULL) {
14791488
logfp = stderr;
14801489
pr_err("cannot open log file");

0 commit comments

Comments
 (0)