Bug 166181 - [patch] calendar(1): calendar -a does not work
Summary: [patch] calendar(1): calendar -a does not work
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-16 17:20 UTC by Dan Strick
Modified: 2017-12-31 22:27 UTC (History)
1 user (show)

See Also:


Attachments
patch.txt (2.40 KB, text/plain)
2014-03-13 23:37 UTC, oliver
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Strick 2012-03-16 17:20:03 UTC
	When I run "caledar -a", it seems to ignore my calendar file.

Fix: 

I don't claim to understand exactly how this code was intended to
	work, but I made the problem go away by adding the line

		y = NULL;

	just before the last return statement in the walkthrough_dates()
	function in the source file dates.c.


	Here is the context diff:

		*** dates.c.ori Mon Jan  2 19:23:46 2012
		--- dates.c     Fri Mar 16 09:26:44 2012
		***************
		*** 401,406 ****
		--- 401,407 ----
               		 *e = d->events;
		                return (1);
        		}
		+       y = NULL;
  
        		return (0);
  		}
How-To-Repeat: 	Create a personal calendar file with test entries and run
	"calendar -a" as root.
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2012-03-24 04:31:43 UTC
Responsible Changed
From-To: freebsd-bugs->eadler

I'll take it - for future reference, please use unified diffs only
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2012-03-24 04:38:51 UTC
State Changed
From-To: open->feedback

I can not reproduce this problem - an you provide an example calendar 
file and ls -laot calendar?
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2012-03-25 02:02:50 UTC
State Changed
From-To: feedback->open

submitter provided requested information
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2012-05-06 20:55:46 UTC
---------- Forwarded message ----------
From: Dan Strick <dan_strick@sbcglobal.net>
Date: 24 March 2012 20:58
Subject: Re: bin/166181: [patch] calendar(1): calendar -a does not work
To: eadler@freebsd.org
Cc: mla@mist.nodomain


Re: bug report 166181

>
> =C2=A0I can not reproduce this problem - an you provide an example calend=
ar
> =C2=A0file and ls -laot calendar?
>

Example calendar file (~guest/calendar):

=C2=A0 =C2=A0 =C2=A0 =C2=A0*/24 =C2=A0 =C2=A0test 24
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/25 =C2=A0 =C2=A0test 25
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/26 =C2=A0 =C2=A0test 26
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/27 =C2=A0 =C2=A0test 27
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/28 =C2=A0 =C2=A0test 28
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/29 =C2=A0 =C2=A0test 29
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/30 =C2=A0 =C2=A0test 30
=C2=A0 =C2=A0 =C2=A0 =C2=A0*/31 =C2=A0 =C2=A0test 31

"ls -laot calendar" produces:

=C2=A0 =C2=A0 =C2=A0 =C2=A0-rw-r--r-- =C2=A01 guest =C2=A0guest =C2=A0- 104=
 Mar 24 17:10 calendar

"ls -laot /usr/bin/calendar*" produces:

=C2=A0 =C2=A0 =C2=A0 =C2=A0-rwxr-xr-x =C2=A01 root =C2=A0wheel =C2=A0- 4528=
8 Mar 16 09:37 /usr/bin/calendar
=C2=A0 =C2=A0 =C2=A0 =C2=A0-r-xr-xr-x =C2=A01 root =C2=A0wheel =C2=A0- 4528=
8 Jan =C2=A02 23:26 /usr/bin/calendar.ori

"calendar.ori" is the program installed with release 9.0 and "calendar" is
the program I built after modifying the source file "dates.c".

Doing "diff -u dates.c.ori dates.c" produces:

=C2=A0 =C2=A0 =C2=A0 =C2=A0--- dates.c.ori 2012-01-02 19:23:46.000000000 -0=
800
=C2=A0 =C2=A0 =C2=A0 =C2=A0+++ dates.c =C2=A0 =C2=A0 2012-03-16 09:26:44.00=
0000000 -0700
=C2=A0 =C2=A0 =C2=A0 =C2=A0@@ -401,6 +401,7 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0*e =3D d->events;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0return (1);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0+ =C2=A0 =C2=A0 =C2=A0 y =3D NULL;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (0);
=C2=A0 =C2=A0 =C2=A0 =C2=A0}

Doing "calendar" as user guest produces:

=C2=A0 =C2=A0 =C2=A0 =C2=A0Mar 24 =C2=A0test 24
=C2=A0 =C2=A0 =C2=A0 =C2=A0Mar 25 =C2=A0test 25

Doing "calendar.ori -a" as root sends this email to guest:

=C2=A0 =C2=A0 =C2=A0 =C2=A0From guest@sbcglobal.net Sat Mar 24 17:47:56 201=
2
=C2=A0 =C2=A0 =C2=A0 =C2=A0Date: Sun, 25 Mar 2012 00:47:56 GMT
=C2=A0 =C2=A0 =C2=A0 =C2=A0From: "Reminder Service" <guest@mist.nodomain>
=C2=A0 =C2=A0 =C2=A0 =C2=A0To: <guest@mist.nodomain>
=C2=A0 =C2=A0 =C2=A0 =C2=A0Subject: Saturday, 24 March 2012's Calendar
=C2=A0 =C2=A0 =C2=A0 =C2=A0Precedence: bulk

=C2=A0 =C2=A0 =C2=A0 =C2=A0Mar 24 =C2=A0test 24
=C2=A0 =C2=A0 =C2=A0 =C2=A0Mar 25 =C2=A0test 25

Doing "calendar -a" as root sends no email to guest.



--=20
Eitan Adler
Source & Ports committer
X11, Bugbusting teams
Comment 5 Eitan Adler freebsd_committer freebsd_triage 2012-09-02 18:05:13 UTC
Responsible Changed
From-To: eadler->freebsd-bugs

I won't be looking at this PR for a while and I need to clear some out 
of my queue
Comment 6 grandi 2013-05-02 20:41:11 UTC
Proposed patch causes information from ALL calendars on the system to be =
mailed to each user.  Not an acceptable solution.

--=20
Steve Grandi
National Optical Astronomy Observatory/AURA Inc., Tucson AZ USA
Internet: grandi@noao.edu  Voice: +1 520 318-8228  FAX: 318-8360
Comment 7 Dan Strick 2013-05-09 00:21:30 UTC
>
> Proposed patch causes information from ALL calendars on the system to be
> mailed to each user.  Not an acceptable solution.
>

I confess to not understanding how the calendar program code is
supposed to work.  I may have confused it by using the same user id
for two different password file entries.  I noticed, for example, that
lines from one user's calendar file were sometimes mailed to the other
user.

I have since given up on running "calendar -a" via the /etc/periodic
mechanism and now just run calendar for myself out of my own crontab.
So far this seems to work.

Dan Strick
mla_strick@att.net
Comment 8 oliver 2014-03-13 23:37:13 UTC
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
Comment 9 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:35 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped