summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c109
1 files changed, 50 insertions, 59 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index dad1814..18165e0 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -54,12 +54,11 @@ void lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx) {
ctx->flush_acknowledged = true;
}
-#define req_debugf(fmt, ...) \
- log_debugf("cid=%zu: %s(tag=%"PRIu16"): " fmt, \
- cr_getcid(), \
- lib9p_msgtype_str(ctx->basectx.version, ctx->net_bytes[4]), \
- ctx->tag \
- __VA_OPT__(,) __VA_ARGS__)
+#define req_debug(...) \
+ log_debugln( \
+ "cid=", cr_getcid(), ": ", \
+ lib9p_msgtype_str(ctx->basectx.version, ctx->net_bytes[4]), "(tag=", ctx->tag, "): ", \
+ __VA_ARGS__)
/* structs ********************************************************************/
@@ -356,13 +355,7 @@ static void srv_msglog(struct srv_req *req, enum lib9p_msg_type typ, void *hostm
srv->msglog(req, 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"
- log_infof("%c %v", typ % 2 ? '<' : '>', lo_box_lib9p_msg_as_fmt_formatter(&req->basectx, typ, hostmsg));
-#pragma GCC diagnostic pop
+ log_infoln(typ % 2 ? "< " : "> ", (lib9p_msg, &req->basectx, typ, hostmsg));
}
static ssize_t srv_write_Rmsg(struct srv_req *req, struct lib9p_Rmsg_send_buf *resp) {
@@ -373,7 +366,7 @@ static ssize_t srv_write_Rmsg(struct srv_req *req, struct lib9p_Rmsg_send_buf *r
return r;
}
-#define srv_nonrespond_errorf log_errorf
+#define srv_nonrespond_error log_errorln
static void srv_respond_error(struct srv_req *req) {
#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L
@@ -409,7 +402,7 @@ static void srv_respond_error(struct srv_req *req) {
srv_msglog(req, LIB9P_TYP_Rerror, &host);
r = srv_write_Rmsg(req, &net);
if (r < 0)
- srv_nonrespond_errorf("write: %s", net_strerror(-r));
+ srv_nonrespond_error("write: ", net_strerror(-r));
}
/* read coroutine *************************************************************/
@@ -421,11 +414,11 @@ static inline bool srv_read_exactly(lo_interface net_stream_conn fd, uint8_t *bu
while (*done < goal) {
ssize_t r = io_read(fd, &buf[*done], goal - *done);
if (r < 0) {
- srv_nonrespond_errorf("read: %s", net_strerror(-r));
+ srv_nonrespond_error("read: ", net_strerror(-r));
return true;
} else if (r == 0) {
if (*done != 0)
- srv_nonrespond_errorf("read: unexpected EOF");
+ srv_nonrespond_error("read: unexpected EOF");
return true;
}
*done += r;
@@ -443,7 +436,7 @@ void lib9p_srv_accept_and_read_loop(struct lib9p_srv *srv, lo_interface net_stre
for (;;) {
lo_interface net_stream_conn conn = LO_CALL(listener, accept);
if (LO_IS_NULL(conn)) {
- srv_nonrespond_errorf("accept: error");
+ srv_nonrespond_error("accept: error");
srv->readers--;
if (srv->readers == 0)
while (srv->writers > 0)
@@ -478,7 +471,7 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
break;
size_t goal = uint32le_decode(buf);
if (goal < 7) {
- srv_nonrespond_errorf("T-message is impossibly small");
+ srv_nonrespond_error("T-message is impossibly small");
break;
}
if (srv_read_exactly(conn.fd, buf, 7, &done))
@@ -494,11 +487,9 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
.net_bytes = buf,
};
if (goal > sess.max_msg_size) {
- lib9p_errorf(&req.basectx,
- LIB9P_ERRNO_L_EMSGSIZE, "T-message larger than %s limit (%zu > %"PRIu32")",
- sess.initialized ? "negotiated" : "server",
- goal,
- sess.max_msg_size);
+ lib9p_error(&req.basectx, LIB9P_ERRNO_L_EMSGSIZE,
+ "T-message larger than ", sess.initialized ? "negotiated" : "server", " limit",
+ " (", goal, " > ", sess.max_msg_size, ")");
srv_respond_error(&req);
continue;
}
@@ -541,7 +532,7 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
MAP_FOREACH(&sess.fids, fid, fidinfo) {
srv_fid_del(&pseudoreq, fid, fidinfo, false);
if (lib9p_ctx_has_error(&pseudoreq.basectx)) {
- srv_nonrespond_errorf("clunk: %.*s", CONFIG_9P_MAX_ERR_SIZE, pseudoreq.basectx.err_msg);
+ srv_nonrespond_error("clunk: ", (strn, pseudoreq.basectx.err_msg, CONFIG_9P_MAX_ERR_SIZE));
lib9p_ctx_clear_error(&pseudoreq.basectx);
}
}
@@ -746,9 +737,9 @@ static void handle_Tversion(struct srv_req *ctx,
uint32_t min_msg_size = _LIB9P_MAX(lib9p_version_min_Rerror_size(ctx->basectx.version),
lib9p_version_min_Rread_size(ctx->basectx.version)+1);
if (req->max_msg_size < min_msg_size) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EDOM, "requested max_msg_size is less than minimum for %s (%"PRIu32" < %"PRIu32")",
- lib9p_version_str(version), req->max_msg_size, min_msg_size);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EDOM, "requested max_msg_size is less than minimum for ", lib9p_version_str(version),
+ " (", req->max_msg_size, " < ", min_msg_size,")");
goto tversion_return;
}
@@ -780,7 +771,7 @@ static void handle_Tversion(struct srv_req *ctx,
MAP_FOREACH(&ctx->parent_sess->fids, fid, fidinfo) {
srv_fid_del(ctx, fid, fidinfo, false);
if (lib9p_ctx_has_error(&ctx->basectx)) {
- srv_nonrespond_errorf("clunk: %.*s", CONFIG_9P_MAX_ERR_SIZE, ctx->basectx.err_msg);
+ srv_nonrespond_error("clunk: ", (strn, ctx->basectx.err_msg, CONFIG_9P_MAX_ERR_SIZE));
lib9p_ctx_clear_error(&ctx->basectx);
}
}
@@ -839,21 +830,22 @@ static void handle_Tattach(struct srv_req *ctx,
lib9p_error(&ctx->basectx,
LIB9P_ERRNO_L_EACCES, "FID provided as auth-file is not an auth-file");
else if (!lib9p_str_eq(afid->user->name, req->uname))
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file is for user=\"%.*s\" and cannot be used for user=\"%.*s\"",
- afid->user->name.len, afid->user->name.utf8,
- req->uname.len, req->uname.utf8);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EACCES,
+ "FID provided as auth-file is for user=", (qmem, afid->user->name.utf8, afid->user->name.len),
+ " and cannot be used for user=", (qmem, req->uname.utf8, req->uname.len));
#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L
else if (afid->user->num != req->unum)
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file is for user=%"PRIu32" and cannot be used for user=%"PRIu32,
- afid->user->num, req->unum);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EACCES,
+ "FID provided as auth-file is for user=", afid->user->num,
+ " and cannot be used for user=", req->unum);
#endif
else if (!lib9p_str_eq(afid->auth.aname, req->aname))
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file is for tree=\"%.*s\" and cannot be used for tree=\"%.*s\"",
- afid->auth.aname.len, afid->auth.aname.utf8,
- req->aname.len, req->aname.utf8);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EACCES,
+ "FID provided as auth-file is for tree=", (qmem, afid->auth.aname.utf8, afid->auth.aname.len),
+ " and cannot be used for tree=", (qmem, req->aname.utf8, req->aname.len));
else if (!afid->auth.completed)
lib9p_error(&ctx->basectx,
LIB9P_ERRNO_L_EACCES, "FID provided as auth-file has not completed authentication");
@@ -905,11 +897,11 @@ static void handle_Tflush(struct srv_req *ctx,
switch (cr_select_l(CR_SELECT_RECV(&oldreq->flush_ch, &res),
CR_SELECT_SEND(&ctx->flush_ch, &res))) {
case 0: /* original request returned */
- req_debugf("original request (tag=%"PRIu16") returned", req->oldtag);
+ req_debug("original request (tag=", req->oldtag, ") returned");
ctx->flush_acknowledged = (res == _LIB9P_SRV_FLUSH_SILENT);
break;
case 1: /* flush itself got flushed */
- req_debugf("flush itself flushed");
+ req_debug("flush itself flushed");
ctx->flush_acknowledged = true;
break;
}
@@ -929,8 +921,8 @@ static void handle_Twalk(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto twalk_return;
}
if (fidinfo->flags & FIDFLAG_OPEN) {
@@ -1007,8 +999,8 @@ static void handle_Topen(struct srv_req *ctx,
/* Check that the FID is valid for this. */
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto topen_return;
}
if (fidinfo->flags & FIDFLAG_OPEN) {
@@ -1177,8 +1169,8 @@ static void handle_Tread(struct srv_req *ctx,
/* Check that the FID is valid for this. */
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto tread_return;
}
if (!(fidinfo->flags & FIDFLAG_OPEN_R)) {
@@ -1198,9 +1190,8 @@ static void handle_Tread(struct srv_req *ctx,
fidinfo->dir.off = 0;
fidinfo->dir.buffered_dirent = (struct lib9p_srv_dirent){};
} else if (req->offset != fidinfo->dir.off) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EINVAL, "invalid offset (must be 0 or %"PRIu64"): %"PRIu64,
- fidinfo->dir.off, req->offset);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EINVAL, "invalid offset (must be 0 or ", fidinfo->dir.off, "): ", req->offset);
goto tread_return;
}
/* Read. */
@@ -1299,8 +1290,8 @@ static void handle_Twrite(struct srv_req *ctx,
/* Check that the FID is valid for this. */
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto twrite_return;
}
if (!(fidinfo->flags & FIDFLAG_OPEN_W)) {
@@ -1326,8 +1317,8 @@ static void handle_Tclunk(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto tclunk_return;
}
@@ -1343,8 +1334,8 @@ static void handle_Tremove(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto tremove_return;
}
@@ -1379,8 +1370,8 @@ static void handle_Tstat(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
- lib9p_errorf(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number %"PRIu32, req->fid);
+ lib9p_error(&ctx->basectx,
+ LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
goto tstat_return;
}
struct srv_pathinfo *pathinfo = map_load(&ctx->parent_sess->paths, fidinfo->path);