Skip to content

Commit

Permalink
use __basename() to reduce directory name from error messages
Browse files Browse the repository at this point in the history
issue reported at heterodb#737
  • Loading branch information
kaigai committed Mar 12, 2024
1 parent 1c21fb2 commit 09eac00
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/cuda_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ STROM_WRITEBACK_ERROR_STATUS(kern_errorbuf *ebuf, kern_context *kcxt)
ERRCODE_STROM_SUCCESS,
kcxt->errcode) == ERRCODE_STROM_SUCCESS)
{
const char *filename = __basenam

ebuf->errcode = kcxt->errcode;
ebuf->lineno = kcxt->error_lineno;
__strncpy(ebuf->filename,
kcxt->error_filename,
__basename(kcxt->error_filename),
KERN_ERRORBUF_FILENAME_LEN);
__strncpy(ebuf->funcname,
kcxt->error_funcname,
Expand Down
30 changes: 7 additions & 23 deletions src/gpu_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,8 @@ static bool __gpuserv_debug_output_dummy;
if (gpuserv_shared_state && \
pg_atomic_read_u32(&gpuserv_shared_state->gpuserv_debug_output) != 0) \
{ \
const char *__fname = __FILE__; \
\
for (const char *__pos = __fname; *__pos != '\0'; __pos++) \
{ \
if (__pos[0] == '/' && __pos[1] != '\0') \
__fname = __pos + 1; \
} \
fprintf(stderr, "gpuserv: " fmt " (%s:%d)\n", \
##__VA_ARGS__, __fname, __LINE__); \
##__VA_ARGS__, __basename(__FILE__), __LINE__); \
} \
} while(0)

Expand All @@ -143,13 +136,9 @@ static bool __gpuserv_debug_output_dummy;
fprintf(stderr, "gpuserv: " fmt "\n", ##__VA_ARGS__); \
else \
{ \
for (const char *__pos = filename; *__pos != '\0'; __pos++) \
{ \
if (__pos[0] == '/' && __pos[1] != '\0') \
filename = __pos + 1; \
} \
fprintf(stderr, "gpuserv: " fmt " [%s] (code=%d, %s:%d)\n", \
buffer, ##__VA_ARGS__, errcode, filename, lineno); \
buffer, ##__VA_ARGS__, errcode, \
__basename(filename), lineno); \
} \
} \
} while(0)
Expand Down Expand Up @@ -1246,22 +1235,17 @@ __gpuClientELog(gpuClient *gclient,
XpuCommand resp;
va_list ap;
struct iovec iov;
const char *pos;

for (pos = filename; *pos != '\0'; pos++)
{
if (pos[0] == '/' && pos[1] != '\0')
filename = pos + 1;
}

memset(&resp, 0, sizeof(resp));
resp.magic = XpuCommandMagicNumber;
resp.tag = XpuCommandTag__Error;
resp.length = offsetof(XpuCommand, u.error) + sizeof(kern_errorbuf);
resp.u.error.errcode = errcode,
resp.u.error.lineno = lineno;
strncpy(resp.u.error.filename, filename, KERN_ERRORBUF_FILENAME_LEN);
strncpy(resp.u.error.funcname, funcname, KERN_ERRORBUF_FUNCNAME_LEN);
strncpy(resp.u.error.filename, __basename(filename),
KERN_ERRORBUF_FILENAME_LEN);
strncpy(resp.u.error.funcname, funcname,
KERN_ERRORBUF_FUNCNAME_LEN);

va_start(ap, fmt);
vsnprintf(resp.u.error.message, KERN_ERRORBUF_MESSAGE_LEN, fmt, ap);
Expand Down
15 changes: 14 additions & 1 deletion src/xpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,19 @@ typedef struct
KCXT->vlend = KCXT->vlbuf + __bufsz; \
} while(0)

INLINE_FUNCTION(const char *)
__basename(const char *filename)
{
const char *pos;

for (pos = filename; *pos != '\0'; pos++)
{
if (pos[0] == '/' && pos[1] != '\0')
filename = pos + 1;
}
return filename;
}

INLINE_FUNCTION(void)
__STROM_EREPORT(kern_context *kcxt,
uint32_t errcode,
Expand All @@ -521,7 +534,7 @@ __STROM_EREPORT(kern_context *kcxt,
errcode != ERRCODE_STROM_SUCCESS)))
{
kcxt->errcode = errcode;
kcxt->error_filename = filename;
kcxt->error_filename = __basename(filename);
kcxt->error_lineno = lineno;
kcxt->error_funcname = funcname;
kcxt->error_message = message;
Expand Down

0 comments on commit 09eac00

Please sign in to comment.