[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-mcron] [PATCH 16/33] main: Add cron-file-descriptors.
From: |
Mathieu Lirzin |
Subject: |
[Bug-mcron] [PATCH 16/33] main: Add cron-file-descriptors. |
Date: |
Sun, 27 Sep 2015 23:00:27 +0200 |
* scm/mcron/main.scm (fd-list): Delete variable.
(cron-file-descriptors): New procedure that returns a list instead of
mutating 'fd-list'.
(process-update-request): Add 'fdes-list' parameter. Adapt caller by
using 'cron-file-descriptors' as an effective parameter. Use 'sock'
identifier
instead of 'socket' to avoid confusion with 'socket' procedure.
---
scm/mcron/main.scm | 59 ++++++++++++++++++++++++++----------------------------
1 file changed, 28 insertions(+), 31 deletions(-)
diff --git a/scm/mcron/main.scm b/scm/mcron/main.scm
index e99578e..3583e14 100644
--- a/scm/mcron/main.scm
+++ b/scm/mcron/main.scm
@@ -382,37 +382,33 @@ option.\n")
(with-output-to-file config-pid-file
(lambda () (display (getpid)) (newline)))))
-
-
-;; If we are running as cron or crond, we establish a socket to listen for
-;; updates from a crontab program. This is put into fd-list so that we can
-;; inform the main wait-run-wait execution loop to listen for incoming messages
-;; on this socket.
-
-(define fd-list '())
-
-(when (eq? command-type 'cron)
- (catch #t
- (lambda ()
- (let ((socket (socket AF_UNIX SOCK_STREAM 0)))
- (bind socket AF_UNIX config-socket-file)
- (listen socket 5)
- (set! fd-list (list socket))))
- (lambda (key . args)
- (delete-file config-pid-file)
- (mcron-error 1
- "Cannot bind to UNIX socket "
- config-socket-file))))
-
-(define (process-update-request)
+(define (cron-file-descriptors)
+ "Establish a socket to listen for updates from a crontab program, and return
+a list containing the file descriptors correponding to the files read by
+crontab. This requires that command-type is 'cron."
+ (if (eq? command-type 'cron)
+ (catch #t
+ (lambda ()
+ (let ((sock (socket AF_UNIX SOCK_STREAM 0)))
+ (bind sock AF_UNIX config-socket-file)
+ (listen sock 5)
+ (list sock)))
+ (lambda (key . args)
+ (delete-file config-pid-file)
+ (mcron-error 1
+ "Cannot bind to UNIX socket "
+ config-socket-file)))
+ '()))
+
+(define (process-update-request fdes-list)
"Read a user name from the socket, dealing with the /etc/crontab special
case, remove all the user's jobs from the job list, and then re-read the
user's updated file. In the special case drop all the system jobs and re-read
the /etc/crontab file. This function should be called whenever a message
comes in on the above socket."
- (let* ((socket (car (accept (car fd-list))))
- (user-name (read-line socket)))
- (close socket)
+ (let* ((sock (car (accept (car fdes-list))))
+ (user-name (read-line sock)))
+ (close sock)
(set-configuration-time (current-time))
(catch-mcron-error
(if (string=? user-name "/etc/crontab")
@@ -443,10 +439,11 @@ comes in on the above socket."
;; core, and when it drops out (can only be because a message has come in on
the
;; socket) we process the socket request before restarting the loop again.
;; Sergey Poznyakoff: we can also drop out of run-job-loop because of a
SIGCHLD,
-;; so must test fd-list.
+;; so must test FDES-LIST.
(catch-mcron-error
- (while #t
- (run-job-loop fd-list)
- (unless (null? fd-list)
- (process-update-request))))
+ (let ((fdes-list (cron-file-descriptors)))
+ (while #t
+ (run-job-loop fdes-list)
+ (unless (null? fdes-list)
+ (process-update-request fdes-list)))))
- [Bug-mcron] [PATCH 05/33] main: Add show-package-information., (continued)
- [Bug-mcron] [PATCH 05/33] main: Add show-package-information., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 04/33] main: Add show-version., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 08/33] build: Improve maintainer-clean rule., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 07/33] Augment TODO., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 09/33] build: Generate 'ChangeLog' upon 'make dist'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 10/33] build: Fix prerequisite of the man page target., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 11/33] main: Import the modules used in one time., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 12/33] main: Use 'when' and 'unless' special forms., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 14/33] main: Make 'catch-mcron-error' macro hygienic., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 16/33] main: Add cron-file-descriptors.,
Mathieu Lirzin <=
- [Bug-mcron] [PATCH 27/33] main: Improve 'process-user-file' definition., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 15/33] main: Add docstrings., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 26/33] mcron: Make functions 'static'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 29/33] environment: Redefine 'modify-environment'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 17/33] main: Add main., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 21/33] main: Remove obsolete debug option., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 22/33] redirect: Use module (ice-9 regex)., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 23/33] mcron: Add forward declarations., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 28/33] main: Remove unused 'regular-file?' procedure., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 24/33] mcron: Use symbolic constants., Mathieu Lirzin, 2015/09/27