Return to BSD News archive
Newsgroups: comp.os.386bsd.bugs Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!usc!howland.reston.ans.net!spool.mu.edu!cass.ma02.bull.com!syd.bull.oz.au!melb.bull.oz.au!zen!sjg From: sjg@zen.void.oz.au (Simon J. Gerraty) Subject: [fix] /usr/ucb/msgs does not update .msgsrc correctly Organization: Zen programming... Message-ID: <1993Oct21.222225.4387@zen.void.oz.au> Date: Thu, 21 Oct 1993 22:22:25 GMT Lines: 169 I'm posting this in case it is relevant to other *BSD groups It has been sent via sendbug to 386bsd_bugs@bsd.coe.montana.edu Index: usr.bin/msgs/msgs.c 386BSD-0.1.2.3 Description: /usr/ucb/msgs does not update .msgsrc correctly msgs.c opens .msgsrc with append mode ("a"), and despite its attempt to fseek() to the start of the file when it wants to update it, the new value gets appended. Repeat-By: Run msgs several times (assuming there are msgs in /var/msgs) Then cat ~/.msgsrc Fix: This patch modifies msgs.c to fopen() for write, and close .msgsrc each time it is to be updated. It could be neater but I've minimized the changes. *** usr.bin/msgs/msgs.c~ Fri Apr 19 09:17:12 1991 --- usr.bin/msgs/msgs.c Thu Oct 21 22:52:05 1993 *************** *** 104,109 **** --- 104,110 ---- char *sep = "-"; char inbuf[BUFSIZ]; char fname[128]; + char mfname[128]; char cmdbuf[128]; char subj[128]; char from[128]; *************** *** 381,388 **** totty = (isatty(fileno(stdout)) != 0); use_pager = use_pager && totty; ! sprintf(fname, "%s/%s", getenv("HOME"), MSGSRC); ! msgsrc = fopen(fname, "r"); if (msgsrc) { newrc = NO; fscanf(msgsrc, "%d\n", &nextmsg); --- 382,389 ---- totty = (isatty(fileno(stdout)) != 0); use_pager = use_pager && totty; ! sprintf(mfname, "%s/%s", getenv("HOME"), MSGSRC); ! msgsrc = fopen(mfname, "r"); if (msgsrc) { newrc = NO; fscanf(msgsrc, "%d\n", &nextmsg); *************** *** 390,396 **** if (nextmsg > lastmsg+1) { printf("Warning: bounds have been reset (%d, %d)\n", firstmsg, lastmsg); ! truncate(fname, (off_t)0); newrc = YES; } else if (!rcfirst) --- 391,397 ---- if (nextmsg > lastmsg+1) { printf("Warning: bounds have been reset (%d, %d)\n", firstmsg, lastmsg); ! truncate(mfname, (off_t)0); newrc = YES; } else if (!rcfirst) *************** *** 398,408 **** } else newrc = YES; ! msgsrc = fopen(fname, "a"); if (msgsrc == NULL) { perror(fname); exit(errno); } if (rcfirst) { if (rcfirst > lastmsg+1) { printf("Warning: the last message is number %d.\n", --- 399,410 ---- } else newrc = YES; ! msgsrc = fopen(mfname, "a"); if (msgsrc == NULL) { perror(fname); exit(errno); } + fclose(msgsrc); if (rcfirst) { if (rcfirst > lastmsg+1) { printf("Warning: the last message is number %d.\n", *************** *** 414,423 **** } if (newrc) { nextmsg = firstmsg; ! fseek(msgsrc, 0L, 0); fprintf(msgsrc, "%d\n", nextmsg); ! fflush(msgsrc); } #ifdef V7 if (totty) { --- 416,426 ---- } if (newrc) { nextmsg = firstmsg; ! if (msgsrc = fopen(mfname, "w")) { fprintf(msgsrc, "%d\n", nextmsg); ! fclose(msgsrc); } + } #ifdef V7 if (totty) { *************** *** 558,567 **** sep = "-"; if (msg >= nextmsg) { nextmsg = msg + 1; ! fseek(msgsrc, 0L, 0); fprintf(msgsrc, "%d\n", nextmsg); ! fflush(msgsrc); } if (newmsg) fclose(newmsg); if (quitit) --- 561,571 ---- sep = "-"; if (msg >= nextmsg) { nextmsg = msg + 1; ! if (msgsrc = fopen(mfname, "w")) { fprintf(msgsrc, "%d\n", nextmsg); ! fclose(msgsrc); } + } if (newmsg) fclose(newmsg); if (quitit) *************** *** 573,581 **** */ if (--msg >= nextmsg) { nextmsg = msg + 1; ! fseek(msgsrc, 0L, 0); fprintf(msgsrc, "%d\n", nextmsg); ! fflush(msgsrc); } if (already && !quitit && lastcmd && totty) { /* --- 577,586 ---- */ if (--msg >= nextmsg) { nextmsg = msg + 1; ! if (msgsrc = fopen(mfname, "w")) { fprintf(msgsrc, "%d\n", nextmsg); ! fclose(msgsrc); ! } } if (already && !quitit && lastcmd && totty) { /* -- Simon J. Gerraty <sjg@zen.void.oz.au> #include <disclaimer> /* imagine something _very_ witty here */