6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2013 Joshua M. Clulow <josh@sysmgr.org>
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /* Copyright (c) 1987, 1988 Microsoft Corporation */
32 /* All Rights Reserved */
33
34 #ifdef lint
35 /* make lint happy */
36 #define __EXTENSIONS__
37 #endif
38
39 #include <sys/contract/process.h>
40 #include <sys/ctfs.h>
41 #include <sys/param.h>
42 #include <sys/resource.h>
43 #include <sys/stat.h>
44 #include <sys/task.h>
45 #include <sys/time.h>
532 t = time(NULL);
533 last_time = t;
534 /*
535 * reset_needed might have been set in the functions
536 * call path from initialize()
537 */
538 if (reset_needed) {
539 continue;
540 }
541 }
542 t_old = t;
543
544 if (next_event == NULL && !el_empty()) {
545 next_event = (struct event *)el_first();
546 }
547 if (next_event == NULL) {
548 ne_time = INFINITY;
549 } else {
550 ne_time = next_event->time - t;
551 #ifdef DEBUG
552 cftime(timebuf, "%C", &next_event->time);
553 (void) fprintf(stderr, "next_time=%ld %s\n",
554 next_event->time, timebuf);
555 #endif
556 }
557 if (ne_time > 0) {
558 /*
559 * reset_needed may be set in the functions call path
560 * from idle()
561 */
562 if (idle(ne_time) || reset_needed) {
563 reset_needed = 1;
564 continue;
565 }
566 }
567
568 if (stat(QUEDEFS, &buf)) {
569 msg("cannot stat QUEDEFS file");
570 } else if (lastmtime != buf.st_mtime) {
571 quedefs(LOAD);
572 lastmtime = buf.st_mtime;
606 * bump up to next 30 second
607 * increment
608 * 1 <= newtime <= 30
609 */
610 newtime = 30 - (last_time % 30);
611 newtime += last_time;
612
613 /*
614 * get the next scheduled event,
615 * not the one that we just
616 * kicked off!
617 */
618 next_event->time =
619 next_time(next_event, newtime);
620 t_old = time(NULL);
621 } else {
622 next_event->time =
623 next_time(next_event, (time_t)0);
624 }
625 #ifdef DEBUG
626 cftime(timebuf, "%C", &next_event->time);
627 (void) fprintf(stderr,
628 "pushing back cron event %s at %ld (%s)\n",
629 next_event->cmd, next_event->time, timebuf);
630 #endif
631
632 switch (el_add(next_event, next_event->time,
633 (next_event->u)->ctid)) {
634 case -1:
635 ignore_msg("main", "cron", next_event);
636 break;
637 case -2: /* event time lower than init time */
638 reset_needed = 1;
639 break;
640 }
641 break;
642 default:
643 /* remove at or batch job from system */
644 if (delayed) {
645 delayed = 0;
646 break;
1254 /* set the home of this entry */
1255 e->of.ct.home = dup_shared(home);
1256 /* have the event point to it's owner */
1257 e->u = u;
1258 /* insert this event at the front of this user's event list */
1259 e->link = u->ctevents;
1260 u->ctevents = e;
1261 /* set the time for the first occurance of this event */
1262 e->time = next_time(e, reftime);
1263 /* finally, add this event to the main event list */
1264 switch (el_add(e, e->time, u->ctid)) {
1265 case -1:
1266 ignore_msg("readcron", "cron", e);
1267 break;
1268 case -2: /* event time lower than init time */
1269 reset_needed = 1;
1270 break;
1271 }
1272 cte_valid();
1273 #ifdef DEBUG
1274 cftime(timebuf, "%C", &e->time);
1275 (void) fprintf(stderr, "inserting cron event %s at %ld (%s)\n",
1276 e->cmd, e->time, timebuf);
1277 #endif
1278 }
1279 cte_sendmail(u->name); /* mail errors if any to user */
1280 (void) fclose(cf);
1281 rel_shared(tz);
1282 rel_shared(shell);
1283 rel_shared(home);
1284 }
1285
1286 /*
1287 * Below are the functions for handling of errors in crontabs. Concept is to
1288 * collect faulty lines and send one email at the end of the crontab
1289 * evaluation. If there are erroneous lines only ((cte_nvalid == 0), evaluation
1290 * of crontab is aborted. Otherwise reading of crontab is continued to the end
1291 * of the file but no further error logging appears.
1292 */
1293 static void
1294 cte_init()
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2013 Joshua M. Clulow <josh@sysmgr.org>
26 *
27 * Copyright (c) 2014 Gary Mills
28 */
29
30 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
31 /* All Rights Reserved */
32
33 /* Copyright (c) 1987, 1988 Microsoft Corporation */
34 /* All Rights Reserved */
35
36 #ifdef lint
37 /* make lint happy */
38 #define __EXTENSIONS__
39 #endif
40
41 #include <sys/contract/process.h>
42 #include <sys/ctfs.h>
43 #include <sys/param.h>
44 #include <sys/resource.h>
45 #include <sys/stat.h>
46 #include <sys/task.h>
47 #include <sys/time.h>
534 t = time(NULL);
535 last_time = t;
536 /*
537 * reset_needed might have been set in the functions
538 * call path from initialize()
539 */
540 if (reset_needed) {
541 continue;
542 }
543 }
544 t_old = t;
545
546 if (next_event == NULL && !el_empty()) {
547 next_event = (struct event *)el_first();
548 }
549 if (next_event == NULL) {
550 ne_time = INFINITY;
551 } else {
552 ne_time = next_event->time - t;
553 #ifdef DEBUG
554 cftime(timebuf, "%+", &next_event->time);
555 (void) fprintf(stderr, "next_time=%ld %s\n",
556 next_event->time, timebuf);
557 #endif
558 }
559 if (ne_time > 0) {
560 /*
561 * reset_needed may be set in the functions call path
562 * from idle()
563 */
564 if (idle(ne_time) || reset_needed) {
565 reset_needed = 1;
566 continue;
567 }
568 }
569
570 if (stat(QUEDEFS, &buf)) {
571 msg("cannot stat QUEDEFS file");
572 } else if (lastmtime != buf.st_mtime) {
573 quedefs(LOAD);
574 lastmtime = buf.st_mtime;
608 * bump up to next 30 second
609 * increment
610 * 1 <= newtime <= 30
611 */
612 newtime = 30 - (last_time % 30);
613 newtime += last_time;
614
615 /*
616 * get the next scheduled event,
617 * not the one that we just
618 * kicked off!
619 */
620 next_event->time =
621 next_time(next_event, newtime);
622 t_old = time(NULL);
623 } else {
624 next_event->time =
625 next_time(next_event, (time_t)0);
626 }
627 #ifdef DEBUG
628 cftime(timebuf, "%+", &next_event->time);
629 (void) fprintf(stderr,
630 "pushing back cron event %s at %ld (%s)\n",
631 next_event->cmd, next_event->time, timebuf);
632 #endif
633
634 switch (el_add(next_event, next_event->time,
635 (next_event->u)->ctid)) {
636 case -1:
637 ignore_msg("main", "cron", next_event);
638 break;
639 case -2: /* event time lower than init time */
640 reset_needed = 1;
641 break;
642 }
643 break;
644 default:
645 /* remove at or batch job from system */
646 if (delayed) {
647 delayed = 0;
648 break;
1256 /* set the home of this entry */
1257 e->of.ct.home = dup_shared(home);
1258 /* have the event point to it's owner */
1259 e->u = u;
1260 /* insert this event at the front of this user's event list */
1261 e->link = u->ctevents;
1262 u->ctevents = e;
1263 /* set the time for the first occurance of this event */
1264 e->time = next_time(e, reftime);
1265 /* finally, add this event to the main event list */
1266 switch (el_add(e, e->time, u->ctid)) {
1267 case -1:
1268 ignore_msg("readcron", "cron", e);
1269 break;
1270 case -2: /* event time lower than init time */
1271 reset_needed = 1;
1272 break;
1273 }
1274 cte_valid();
1275 #ifdef DEBUG
1276 cftime(timebuf, "%+", &e->time);
1277 (void) fprintf(stderr, "inserting cron event %s at %ld (%s)\n",
1278 e->cmd, e->time, timebuf);
1279 #endif
1280 }
1281 cte_sendmail(u->name); /* mail errors if any to user */
1282 (void) fclose(cf);
1283 rel_shared(tz);
1284 rel_shared(shell);
1285 rel_shared(home);
1286 }
1287
1288 /*
1289 * Below are the functions for handling of errors in crontabs. Concept is to
1290 * collect faulty lines and send one email at the end of the crontab
1291 * evaluation. If there are erroneous lines only ((cte_nvalid == 0), evaluation
1292 * of crontab is aborted. Otherwise reading of crontab is continued to the end
1293 * of the file but no further error logging appears.
1294 */
1295 static void
1296 cte_init()
|