From b2b014fc723aaba877e263d10269de3985fad3aa Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Thu, 17 Sep 2020 17:07:25 -0700 Subject: [PATCH] When chat() fails (e.g. to open a file), display an error dialog rather than just falling over and twitching like an injured slug --- src/sbbs3/umonitor/chat.c | 21 +++++++++++---------- src/sbbs3/umonitor/umonitor.c | 14 ++++++++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/sbbs3/umonitor/chat.c b/src/sbbs3/umonitor/chat.c index 389d9319c5..3cab69648a 100644 --- a/src/sbbs3/umonitor/chat.c +++ b/src/sbbs3/umonitor/chat.c @@ -129,7 +129,7 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac int in,out; char inpath[MAX_PATH]; char outpath[MAX_PATH]; - char usrname[128]; + char usrname[128] = "Unknown user"; char *p; char ch; time_t now; @@ -139,34 +139,35 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac gettextinfo(&ti); if((buf=(char *)alloca(ti.screenwidth*ti.screenheight*2))==NULL) { - return(-1); + return __LINE__; } if(getnodedat(cfg,nodenum,node,FALSE,NULL)) - return(-1); + return __LINE__; username(cfg,node->useron,usrname); - gettext(1,1,ti.screenwidth,ti.screenheight,buf); - drawchatwin(boxch,usrname,cfg->sys_op); - sprintf(outpath,"%slchat.dab",cfg->node_path[nodenum-1]); if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE ,DEFFILEMODE))==-1) - return(-1); + return __LINE__; sprintf(inpath,"%schat.dab",cfg->node_path[nodenum-1]); if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE ,DEFFILEMODE))==-1) { close(out); - return(-1); + return __LINE__; } if((p=(char *)alloca(PCHAT_LEN))==NULL) { close(in); close(out); - return(-1); + return __LINE__; } + + gettext(1,1,ti.screenwidth,ti.screenheight,buf); + drawchatwin(boxch,usrname,cfg->sys_op); + memset(p,0,PCHAT_LEN); write(in,p,PCHAT_LEN); write(out,p,PCHAT_LEN); @@ -176,7 +177,7 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac togglechat(cfg,nodenum,node,TRUE); while(in != -1) { - + now=time(NULL); if(now!=last_nodechk) { diff --git a/src/sbbs3/umonitor/umonitor.c b/src/sbbs3/umonitor/umonitor.c index 8c5e9ef994..6613c40205 100644 --- a/src/sbbs3/umonitor/umonitor.c +++ b/src/sbbs3/umonitor/umonitor.c @@ -1192,8 +1192,11 @@ USAGE: uifc.msg("Error reading node data!"); continue; } - if((node.status==NODE_INUSE) && node.useron) - chat(&cfg,main_dflt,&node,&boxch,NULL); + if((node.status==NODE_INUSE) && node.useron) { + int result = chat(&cfg,main_dflt,&node,&boxch,NULL); + if(result != 0) + uifc.msgf("Chat error: %d (%s)", result, strerror(errno)); + } continue; } @@ -1305,9 +1308,12 @@ USAGE: break; case 3: /* Chat with User */ - chat(&cfg,main_dflt,&node,&boxch,NULL); + { + int result = chat(&cfg,main_dflt,&node,&boxch,NULL); + if(result != 0) + uifc.msgf("Chat error %d (%s)", result, strerror(errno)); break; - + } case 4: /* Node Toggles */ node_toggles(&cfg, j); break; -- GitLab