Skip to content

Commit

Permalink
cmd: fix using mutex before initialization
Browse files Browse the repository at this point in the history
possible fix for crash at startup on macos
  • Loading branch information
qwx9 committed Jan 24, 2025
1 parent ee1003c commit 5339501
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cmd/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ static QLock cmdlock;
void
killcmd(void)
{
if(cmdfs == nil)
return;
qlock(&cmdlock);
freefs(cmdfs);
cmdfs = nil;
qunlock(&cmdlock);
close(outfd[1]);
outfd[1] = -1;
close(infd[1]);
infd[1] = -1;
qunlock(&cmdlock);
}

void
flushcmd(void)
{
qlock(&cmdlock);
if(cmdfs == nil){
qunlock(&cmdlock);
if(cmdfs == nil)
return;
}
qlock(&cmdlock);
flushfs(cmdfs);
qunlock(&cmdlock);
}
Expand All @@ -40,13 +40,11 @@ sendcmd(char *cmd)
{
int n;

if(cmdfs == nil)
return;
qlock(&cmdlock);
n = strlen(cmd);
DPRINT(Debugcmd, "> [%d][%s]", n, cmd);
qlock(&cmdlock);
if(cmdfs == nil){
qunlock(&cmdlock);
return;
}
writefs(cmdfs, cmd, n);
qunlock(&cmdlock);
}
Expand Down

0 comments on commit 5339501

Please sign in to comment.