nusb/cam: ctl message fixes

This commit is contained in:
aiju 2018-03-07 20:44:55 +00:00
parent 2da5e135dc
commit 657f0ed99a
2 changed files with 10 additions and 3 deletions

View file

@ -202,6 +202,11 @@ strread(Req *req, char *str, int len)
{ {
ReadState *rs; ReadState *rs;
if(req->fid->aux != nil){
free(((ReadState*)req->fid->aux)->buf);
free(req->fid->aux);
req->fid->aux = nil;
}
if(str == nil) if(str == nil)
return; return;
rs = emallocz(sizeof(ReadState), 1); rs = emallocz(sizeof(ReadState), 1);
@ -223,7 +228,7 @@ fsread(Req *req)
} }
f = req->fid->file; f = req->fid->file;
c = f->aux; c = f->aux;
if(req->fid->aux == nil) if(req->fid->aux == nil || req->ifcall.offset == 0)
if(f == c->formatsfile) if(f == c->formatsfile)
strread(req, formatread(c), -1); strread(req, formatread(c), -1);
else if(f == c->ctlfile) else if(f == c->ctlfile)
@ -267,8 +272,10 @@ err: respond(req, "the front fell off");
werrstr("invalid argument"); werrstr("invalid argument");
if(ctlwrite(c, s) < 0) if(ctlwrite(c, s) < 0)
responderror(req); responderror(req);
else else{
req->ofcall.count = req->ifcall.count;
respond(req, nil); respond(req, nil);
}
free(s); free(s);
} }

View file

@ -507,7 +507,7 @@ ctlwrite(Cam *c, char *msg)
p = findparam(f[1]); p = findparam(f[1]);
if(p == nil) if(p == nil)
return -1; return -1;
if((uint)uid >= nunit || unit[uid] == nil){ if(p->type != PARAMSPEC && ((uint)uid >= nunit || unit[uid] == nil)){
werrstr("no such unit"); werrstr("no such unit");
return -1; return -1;
} }