diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-12 08:43:15 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-12 08:43:15 -0600 |
commit | 52674d0483e3754b039857be1d11798859c5bcef (patch) | |
tree | 3047d310b60032a6861776eb37175551db59c0ca /lib9p/srv.c | |
parent | ddd3f3982c6cdf8d7d0068e544cc9daf24355d32 (diff) | |
parent | a780f6fe756b1a1051d5197d81366f21c42a316b (diff) |
Merge branch 'lukeshu/9p-tests'
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index b3b9c4c..ea8b932 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -160,6 +160,21 @@ struct _lib9p_srv_req { /* base utilities *************************************************************/ +static void msglog(struct _lib9p_srv_req *req, enum lib9p_msg_type typ, void *hostmsg) { + struct lib9p_srv *srv = req->parent_sess->parent_conn->parent_srv; + if (srv->msglog) { + srv->msglog(&req->ctx, typ, hostmsg); + return; + } + /* It sucks that %v trips -Wformat and -Wformat-extra-args + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47781 */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wformat-extra-args" + infof("%c %v", typ % 2 ? '<' : '>', lo_box_lib9p_msg_as_fmt_formatter(&req->ctx.basectx, typ, hostmsg)); +#pragma GCC diagnostic pop +} + #define nonrespond_errorf errorf static ssize_t write_Rmsg(struct _lib9p_srv_req *req, struct lib9p_Rmsg_send_buf *resp) { @@ -179,10 +194,10 @@ static void respond_error(struct _lib9p_srv_req *req) { ssize_t r; struct lib9p_msg_Rerror host = { .tag = req->tag, - .ename = lib9p_strn(req->ctx.basectx.err_msg, + .errstr = lib9p_strn(req->ctx.basectx.err_msg, CONFIG_9P_MAX_ERR_SIZE), #if CONFIG_9P_ENABLE_9P2000_u - .errno = req->ctx.basectx.err_num, + .errnum = req->ctx.basectx.err_num, #endif }; @@ -190,8 +205,8 @@ static void respond_error(struct _lib9p_srv_req *req) { /* Truncate the error-string if necessary to avoid needing to * return LINUX_ERANGE. */ - if (((uint32_t)host.ename.len) + sess->rerror_overhead > sess->max_msg_size) - host.ename.len = sess->max_msg_size - sess->rerror_overhead; + if (((uint32_t)host.errstr.len) + sess->rerror_overhead > sess->max_msg_size) + host.errstr.len = sess->max_msg_size - sess->rerror_overhead; struct lib9p_Rmsg_send_buf net; @@ -199,11 +214,7 @@ static void respond_error(struct _lib9p_srv_req *req) { LIB9P_TYP_Rerror, &host, &net); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat" -#pragma GCC diagnostic ignored "-Wformat-extra-args" - infof("< %v", lo_box_lib9p_msg_Rerror_as_fmt_formatter(&host)); -#pragma GCC diagnostic pop + msglog(req, LIB9P_TYP_Rerror, &host); r = write_Rmsg(req, &net); if (r < 0) nonrespond_errorf("write: %s", net_strerror(-r)); @@ -429,11 +440,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { enum lib9p_msg_type typ; lib9p_Tmsg_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, &typ, host_req); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat" -#pragma GCC diagnostic ignored "-Wformat-extra-args" - infof("> %v", lo_box_lib9p_msg_as_fmt_formatter(&ctx->ctx.basectx, typ, host_req)); -#pragma GCC diagnostic pop + msglog(ctx, typ, host_req); /* Handle it. */ tmessage_handlers[typ](ctx, (void *)host_req, (void *)host_resp); @@ -447,11 +454,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { typ+1, host_resp, &net_resp)) goto write; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat" -#pragma GCC diagnostic ignored "-Wformat-extra-args" - infof("< %v", lo_box_lib9p_msg_as_fmt_formatter(&ctx->ctx.basectx, typ+1, &host_resp)); -#pragma GCC diagnostic pop + msglog(ctx, typ+1, &host_resp); write_Rmsg(ctx, &net_resp); } if (host_req) @@ -553,10 +556,13 @@ static inline struct _srv_fidinfo *srv_util_fidsave(struct _lib9p_srv_req *ctx, if (overwrite) { struct srv_pathinfo *old_pathinfo = pathmap_load(&ctx->parent_sess->paths, fidinfo->path); assert(old_pathinfo); - if (srv_util_pathisdir(old_pathinfo)) - LO_CALL(fidinfo->dir.io, iofree); - else - LO_CALL(fidinfo->file.io, iofree); + if (srv_util_pathisdir(old_pathinfo)) { + if (!LO_IS_NULL(fidinfo->dir.io)) + LO_CALL(fidinfo->dir.io, iofree); + } else { + if (!LO_IS_NULL(fidinfo->file.io)) + LO_CALL(fidinfo->file.io, iofree); + } srv_util_pathfree(ctx, fidinfo->path); } else { lib9p_error(&ctx->ctx.basectx, @@ -816,13 +822,6 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, pathinfo = new_pathinfo; } if (resp->nwqid == req->nwname) { - if (req->newfid == req->fid) { - if (srv_util_pathisdir(pathinfo)) - LO_CALL(fidinfo->dir.io, iofree); - else - LO_CALL(fidinfo->file.io, iofree); - fidinfo->flags = 0; - } if (!srv_util_fidsave(ctx, req->newfid, pathinfo, req->newfid == req->fid)) srv_util_pathfree(ctx, LO_CALL(pathinfo->file, qid).path); } else { |