bin/166181: [patch] calendar(1): calendar -a does not work
oliver
oliver at beefrankly.org
Thu Mar 13 23:50:01 UTC 2014
The following reply was made to PR bin/166181; it has been noted by GNATS.
From: oliver <oliver at beefrankly.org>
To: bug-followup at FreeBSD.org, mla_strick at 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--
More information about the freebsd-bugs
mailing list