From owner-freebsd-bugs@FreeBSD.ORG Thu Mar 13 23:50:01 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9CE25371 for ; Thu, 13 Mar 2014 23:50:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8815CF7B for ; Thu, 13 Mar 2014 23:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s2DNo1mq010864 for ; Thu, 13 Mar 2014 23:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s2DNo108010863; Thu, 13 Mar 2014 23:50:01 GMT (envelope-from gnats) Date: Thu, 13 Mar 2014 23:50:01 GMT Message-Id: <201403132350.s2DNo108010863@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: oliver Subject: Re: bin/166181: [patch] calendar(1): calendar -a does not work X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: oliver List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Mar 2014 23:50:01 -0000 The following reply was made to PR bin/166181; it has been noted by GNATS. From: oliver To: bug-followup@FreeBSD.org, mla_strick@att.net Cc: Subject: Re: bin/166181: [patch] calendar(1): calendar -a does not work Date: Fri, 14 Mar 2014 00:37:13 +0100 --MP_/2_vQjW5KtHVoyOm9Zq0qQ6L Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline I found this problem is still there in stable/10.0 and CURRRENT. I could reproduce the problem: If you have multiple calendar files for multiple users, only the first calendar file will be mailed. That's because the function walkthrough_dates was only intended to run once. So it does not reset its state and stays on the last day. This can be fixed, as the PR sender did, but that causes the program to start from the beginning, adding the new events from the next users calendar to the existing struct. so for every run, the old entries are kept and the new ones are added. So events from a users (private) calendar are send to other users, which is not acceptable. So here is a patch that cleans up the events after each call of cal() in "-a" mode and resets the struct for a new run. I've tested the patch against some test calendars, and could not find any further issues. Every user only gets the events from his own calendar. Greetings, Oliver --MP_/2_vQjW5KtHVoyOm9Zq0qQ6L Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=patch.txt diff -u /usr/src/usr.bin/calendar/calendar.c ./calendar.c --- /usr/src/usr.bin/calendar/calendar.c 2014-03-03 19:22:25.000000000 +0100 +++ ./calendar.c 2014-03-12 23:36:31.000000000 +0100 @@ -209,8 +209,10 @@ (void)setegid(pw->pw_gid); (void)initgroups(pw->pw_name, pw->pw_gid); (void)seteuid(pw->pw_uid); - if (!chdir(pw->pw_dir)) + if (!chdir(pw->pw_dir)) { cal(); + remove_all_events(); + } (void)seteuid(0); } else diff -u /usr/src/usr.bin/calendar/calendar.h ./calendar.h --- /usr/src/usr.bin/calendar/calendar.h 2014-03-03 19:22:25.000000000 +0100 +++ ./calendar.h 2014-03-12 23:53:24.000000000 +0100 @@ -120,6 +120,7 @@ struct event *event_add(int, int, int, char *, int, char *, char *); void event_continue(struct event *events, char *txt); void event_print_all(FILE *fp); + struct event { int year; int month; @@ -183,6 +184,8 @@ extern int debug_remember; void generatedates(struct tm *tp1, struct tm *tp2); void dumpdates(void); +void remove_all_events(void); +void remove_eventlist(struct event **list); int remember_ymd(int y, int m, int d); int remember_yd(int y, int d, int *rm, int *rd); int first_dayofweek_of_year(int y); @@ -190,6 +193,7 @@ int walkthrough_dates(struct event **e); void addtodate(struct event *e, int year, int month, int day); + /* pom.c */ #define MAXMOONS 18 void pom(int year, double UTCoffset, int *fms, int *nms); Common subdirectories: /usr/src/usr.bin/calendar/calendars and ./calendars diff -u /usr/src/usr.bin/calendar/dates.c ./dates.c --- /usr/src/usr.bin/calendar/dates.c 2014-02-19 00:43:47.000000000 +0100 +++ ./dates.c 2014-03-13 00:44:43.000000000 +0100 @@ -256,6 +256,45 @@ } } + +void +remove_eventlist(struct event **head) +{ + struct event *del; + del = *head; + while(del != NULL) { + *head = (*head)->next; + free(del); + del = *head; + } + free(*head); +} + + +void +remove_all_events(void) +{ + struct cal_year *y; + struct cal_month *m; + struct cal_day *d; + + y = hyear; + while (y != NULL) { + m = y->months; + while (m != NULL) { + d = m->days; + while (d != NULL) { + remove_eventlist(&d->events); + d->events = NULL; + d = d->nextday; + } + m = m->nextmonth; + } + y = y->nextyear; + } +} + + int remember_ymd(int yy, int mm, int dd) { @@ -368,6 +407,7 @@ return (-1); } + int walkthrough_dates(struct event **e) { @@ -401,6 +441,7 @@ return (1); } + y = NULL; return (0); } --MP_/2_vQjW5KtHVoyOm9Zq0qQ6L--