mirror of
https://github.com/0intro/wmii
synced 2024-12-17 00:52:37 +03:00
improved error handling in bar2
This commit is contained in:
parent
66102dbbcb
commit
76f6c8b6b3
102
cmd/wmiibar2.c
102
cmd/wmiibar2.c
@ -39,6 +39,7 @@
|
|||||||
enum {
|
enum {
|
||||||
Droot,
|
Droot,
|
||||||
Ditem,
|
Ditem,
|
||||||
|
Fctl,
|
||||||
Fdisplay,
|
Fdisplay,
|
||||||
Ffont,
|
Ffont,
|
||||||
Fevent,
|
Fevent,
|
||||||
@ -54,6 +55,13 @@ typedef struct {
|
|||||||
unsigned long border;
|
unsigned long border;
|
||||||
} Item;
|
} Item;
|
||||||
|
|
||||||
|
static char E9pversion[] = "9P versions differ";
|
||||||
|
static char Enoperm[] = "permission denied";
|
||||||
|
static char Enofid[] = "invalid fid";
|
||||||
|
static char Enofile[] = "file not found";
|
||||||
|
static char Enomode[] = "mode not supported";
|
||||||
|
static char Enofunc[] = "function not supported";
|
||||||
|
|
||||||
static unsigned char *msg[IXP_MAX_MSG];
|
static unsigned char *msg[IXP_MAX_MSG];
|
||||||
char *errstr = 0;
|
char *errstr = 0;
|
||||||
static size_t nitem = 0;
|
static size_t nitem = 0;
|
||||||
@ -173,6 +181,7 @@ qid_to_name(Qid *qid)
|
|||||||
snprintf(buf, sizeof(buf), "%u", i);
|
snprintf(buf, sizeof(buf), "%u", i);
|
||||||
return buf;
|
return buf;
|
||||||
break;
|
break;
|
||||||
|
case Fctl: return "ctl"; break;
|
||||||
case Fdisplay: return "display"; break;
|
case Fdisplay: return "display"; break;
|
||||||
case Ffont: return "font"; break;
|
case Ffont: return "font"; break;
|
||||||
case Fdata: return "data"; break;
|
case Fdata: return "data"; break;
|
||||||
@ -191,6 +200,8 @@ name_to_type(char *name)
|
|||||||
return Droot;
|
return Droot;
|
||||||
if(!strncmp(name, "default", 8) || !strncmp(name, "new", 4))
|
if(!strncmp(name, "default", 8) || !strncmp(name, "new", 4))
|
||||||
return Ditem;
|
return Ditem;
|
||||||
|
if(!strncmp(name, "ctl", 4))
|
||||||
|
return Fctl;
|
||||||
if(!strncmp(name, "display", 8))
|
if(!strncmp(name, "display", 8))
|
||||||
return Fdisplay;
|
return Fdisplay;
|
||||||
if(!strncmp(name, "font", 5))
|
if(!strncmp(name, "font", 5))
|
||||||
@ -254,7 +265,7 @@ static int
|
|||||||
xversion(IXPReq *r)
|
xversion(IXPReq *r)
|
||||||
{
|
{
|
||||||
if(strncmp(r->fcall->version, IXP_VERSION, strlen(IXP_VERSION))) {
|
if(strncmp(r->fcall->version, IXP_VERSION, strlen(IXP_VERSION))) {
|
||||||
errstr = "9P versions differ";
|
errstr = E9pversion;
|
||||||
return -1;
|
return -1;
|
||||||
} else if(r->fcall->maxmsg > IXP_MAX_MSG)
|
} else if(r->fcall->maxmsg > IXP_MAX_MSG)
|
||||||
r->fcall->maxmsg = IXP_MAX_MSG;
|
r->fcall->maxmsg = IXP_MAX_MSG;
|
||||||
@ -282,12 +293,12 @@ xwalk(IXPReq *r)
|
|||||||
IXPMap *m;
|
IXPMap *m;
|
||||||
|
|
||||||
if(!(m = ixp_server_fid2map(r, r->fcall->fid))) {
|
if(!(m = ixp_server_fid2map(r, r->fcall->fid))) {
|
||||||
errstr = "no dir associated with fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(r->fcall->fid != r->fcall->newfid
|
if(r->fcall->fid != r->fcall->newfid
|
||||||
&& (ixp_server_fid2map(r, r->fcall->newfid))) {
|
&& (ixp_server_fid2map(r, r->fcall->newfid))) {
|
||||||
errstr = "fid alreay in use";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(r->fcall->nwname) {
|
if(r->fcall->nwname) {
|
||||||
@ -296,7 +307,7 @@ xwalk(IXPReq *r)
|
|||||||
&& !mkqid(&dir, r->fcall->wname[nwqid], &r->fcall->wqid[nwqid]); nwqid++)
|
&& !mkqid(&dir, r->fcall->wname[nwqid], &r->fcall->wqid[nwqid]); nwqid++)
|
||||||
dir = r->fcall->wqid[nwqid];
|
dir = r->fcall->wqid[nwqid];
|
||||||
if(!nwqid) {
|
if(!nwqid) {
|
||||||
errstr = "file not found";
|
errstr = Enofile;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,12 +331,11 @@ xopen(IXPReq *r)
|
|||||||
IXPMap *m = ixp_server_fid2map(r, r->fcall->fid);
|
IXPMap *m = ixp_server_fid2map(r, r->fcall->fid);
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
errstr = "invalid fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(!(r->fcall->mode | IXP_OREAD) && !(r->fcall->mode | IXP_OWRITE)) {
|
if(!(r->fcall->mode | IXP_OREAD) && !(r->fcall->mode | IXP_OWRITE)) {
|
||||||
fprintf(stderr, "got mode 0x%x\n", r->fcall->mode);
|
errstr = Enomode;
|
||||||
errstr = "mode not supported";
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
r->fcall->id = ROPEN;
|
r->fcall->id = ROPEN;
|
||||||
@ -357,7 +367,7 @@ xremove(IXPReq *r)
|
|||||||
unsigned short i;
|
unsigned short i;
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
errstr = "invalid fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
i = qpath_item(m->qid.path);
|
i = qpath_item(m->qid.path);
|
||||||
@ -368,7 +378,7 @@ xremove(IXPReq *r)
|
|||||||
r->fcall->id = RREMOVE;
|
r->fcall->id = RREMOVE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
errstr = "permission denied";
|
errstr = Enoperm;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +392,7 @@ xread(IXPReq *r)
|
|||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
errstr = "invalid fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
i = qpath_item(m->qid.path);
|
i = qpath_item(m->qid.path);
|
||||||
@ -390,10 +400,12 @@ xread(IXPReq *r)
|
|||||||
if(!r->fcall->offset) {
|
if(!r->fcall->offset) {
|
||||||
switch (qpath_type(m->qid.path)) {
|
switch (qpath_type(m->qid.path)) {
|
||||||
case Droot:
|
case Droot:
|
||||||
|
r->fcall->count = mkstat(&stat, &root_qid, "ctl", 0, DMWRITE);
|
||||||
|
p = ixp_enc_stat(p, &stat);
|
||||||
if(align == SOUTH || align == NORTH)
|
if(align == SOUTH || align == NORTH)
|
||||||
r->fcall->count = mkstat(&stat, &root_qid, "display", 6, DMREAD | DMWRITE);
|
r->fcall->count += mkstat(&stat, &root_qid, "display", 6, DMREAD | DMWRITE);
|
||||||
else
|
else
|
||||||
r->fcall->count = mkstat(&stat, &root_qid, "display", 5, DMREAD | DMWRITE); /* none */
|
r->fcall->count += mkstat(&stat, &root_qid, "display", 5, DMREAD | DMWRITE); /* none */
|
||||||
p = ixp_enc_stat(p, &stat);
|
p = ixp_enc_stat(p, &stat);
|
||||||
r->fcall->count += mkstat(&stat, &root_qid, "font", strlen(font), DMREAD | DMWRITE);
|
r->fcall->count += mkstat(&stat, &root_qid, "font", strlen(font), DMREAD | DMWRITE);
|
||||||
p = ixp_enc_stat(p, &stat);
|
p = ixp_enc_stat(p, &stat);
|
||||||
@ -427,6 +439,9 @@ xread(IXPReq *r)
|
|||||||
p = ixp_enc_stat(p, &stat);
|
p = ixp_enc_stat(p, &stat);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Fctl:
|
||||||
|
errstr = Enoperm;
|
||||||
|
break;
|
||||||
case Fdisplay:
|
case Fdisplay:
|
||||||
switch(align) {
|
switch(align) {
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
@ -469,7 +484,8 @@ xread(IXPReq *r)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error_xread:
|
error_xread:
|
||||||
errstr = "invalid read request";
|
if(!errstr)
|
||||||
|
errstr = "invalid read";
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -486,7 +502,7 @@ xstat(IXPReq *r)
|
|||||||
Qid dir;
|
Qid dir;
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
errstr = "invalid fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
i = qpath_item(m->qid.path);
|
i = qpath_item(m->qid.path);
|
||||||
@ -522,7 +538,8 @@ xstat(IXPReq *r)
|
|||||||
mkstat(&r->fcall->stat, &dir, qid_to_name(&m->qid), strlen(item[i]->color), DMREAD | DMWRITE);
|
mkstat(&r->fcall->stat, &dir, qid_to_name(&m->qid), strlen(item[i]->color), DMREAD | DMWRITE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errstr = "invalid stat request";
|
if(!errstr)
|
||||||
|
errstr = "invalid stat";
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -538,7 +555,7 @@ xwrite(IXPReq *r)
|
|||||||
unsigned short i;
|
unsigned short i;
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
errstr = "invalid fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,17 +594,20 @@ xwrite(IXPReq *r)
|
|||||||
case Fcolor:
|
case Fcolor:
|
||||||
if(i == nitem)
|
if(i == nitem)
|
||||||
new_item();
|
new_item();
|
||||||
if((i >= nitem) || (r->fcall->count != 24))
|
if((i >= nitem) || (r->fcall->count != 24)
|
||||||
goto error_xwrite;
|
|| (r->fcall->data[0] != '#') || (r->fcall->data[8] != '#')
|
||||||
if(r->fcall->data[0] != '#' || r->fcall->data[8] != '#' || r->fcall->data[16] != '#')
|
|| (r->fcall->data[16] != '#')) {
|
||||||
|
errstr = "wrong color format";
|
||||||
goto error_xwrite;
|
goto error_xwrite;
|
||||||
|
}
|
||||||
memcpy(item[i]->color, r->fcall->data, r->fcall->count);
|
memcpy(item[i]->color, r->fcall->data, r->fcall->count);
|
||||||
item[i]->color[r->fcall->count] = 0;
|
item[i]->color[r->fcall->count] = 0;
|
||||||
/* TODO: update color */
|
/* TODO: update color */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error_xwrite:
|
error_xwrite:
|
||||||
errstr = "invalid write request";
|
if(!errstr)
|
||||||
|
errstr = "invalid write";
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -601,7 +621,7 @@ xclunk(IXPReq *r)
|
|||||||
IXPMap *m = ixp_server_fid2map(r, r->fcall->fid);
|
IXPMap *m = ixp_server_fid2map(r, r->fcall->fid);
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
errstr = "invalid fid";
|
errstr = Enofid;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ixp_server_detach_map(m, r->map);
|
ixp_server_detach_map(m, r->map);
|
||||||
@ -610,25 +630,6 @@ xclunk(IXPReq *r)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
doixp(IXPReq *r)
|
|
||||||
{
|
|
||||||
switch(r->fcall->id) {
|
|
||||||
case TVERSION: return xversion(r); break;
|
|
||||||
case TATTACH: return xattach(r); break;
|
|
||||||
case TWALK: return xwalk(r); break;
|
|
||||||
case TREMOVE: return xremove(r); break;
|
|
||||||
case TOPEN: return xopen(r); break;
|
|
||||||
case TREAD: return xread(r); break;
|
|
||||||
case TWRITE: return xwrite(r); break;
|
|
||||||
case TCLUNK: return xclunk(r); break;
|
|
||||||
case TSTAT: return xstat(r); break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_ixp_req(IXPServer *s, IXPConn *c)
|
handle_ixp_req(IXPServer *s, IXPConn *c)
|
||||||
{
|
{
|
||||||
@ -642,11 +643,24 @@ handle_ixp_req(IXPServer *s, IXPConn *c)
|
|||||||
}
|
}
|
||||||
if(!r->fcall)
|
if(!r->fcall)
|
||||||
r->fcall = cext_emallocz(sizeof(Fcall));
|
r->fcall = cext_emallocz(sizeof(Fcall));
|
||||||
if((msize = ixp_msg_to_fcall(msg, IXP_MAX_MSG, r->fcall)))
|
if((msize = ixp_msg_to_fcall(msg, IXP_MAX_MSG, r->fcall))) {
|
||||||
ret = doixp(r);
|
switch(r->fcall->id) {
|
||||||
|
case TVERSION: ret = xversion(r); break;
|
||||||
|
case TATTACH: ret = xattach(r); break;
|
||||||
|
case TWALK: ret = xwalk(r); break;
|
||||||
|
case TREMOVE: ret = xremove(r); break;
|
||||||
|
case TOPEN: ret = xopen(r); break;
|
||||||
|
case TREAD: ret = xread(r); break;
|
||||||
|
case TWRITE: ret = xwrite(r); break;
|
||||||
|
case TCLUNK: ret = xclunk(r); break;
|
||||||
|
case TSTAT: ret = xstat(r); break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(ret == -1) {
|
if(ret == -1) {
|
||||||
if(!errstr)
|
if(!errstr)
|
||||||
errstr = "function not supported";
|
errstr = Enofunc;
|
||||||
r->fcall->id = RERROR;
|
r->fcall->id = RERROR;
|
||||||
cext_strlcpy(r->fcall->errstr, errstr, sizeof(r->fcall->errstr));
|
cext_strlcpy(r->fcall->errstr, errstr, sizeof(r->fcall->errstr));
|
||||||
}
|
}
|
||||||
@ -729,7 +743,7 @@ main(int argc, char *argv[])
|
|||||||
new_item();
|
new_item();
|
||||||
cext_strlcpy(item[0]->color, BLITZ_SEL_COLOR, sizeof(item[0]->color));
|
cext_strlcpy(item[0]->color, BLITZ_SEL_COLOR, sizeof(item[0]->color));
|
||||||
|
|
||||||
font = strdup("fixed");
|
font = strdup(BLITZ_FONT);
|
||||||
|
|
||||||
if((errstr = ixp_server_loop(&srv))) {
|
if((errstr = ixp_server_loop(&srv))) {
|
||||||
fprintf(stderr, "wmiibar: fatal: %s\n", errstr);
|
fprintf(stderr, "wmiibar: fatal: %s\n", errstr);
|
||||||
|
Loading…
Reference in New Issue
Block a user