aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-05-06 12:55:01 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-05-06 12:55:01 +0300
commit01700538971e3a798abe1f503c1f3c6d646a1981 (patch)
tree20bd9011d9268e3477fdbf4131e3daf8a9fc8ebd
parentb401a6145f3d86c808e2315b09e69b2a734b9e0e (diff)
downloadmicron-01700538971e3a798abe1f503c1f3c6d646a1981.tar.gz
micron-01700538971e3a798abe1f503c1f3c6d646a1981.tar.bz2
Implement the -P option (pidfile)
-rw-r--r--NEWS10
-rw-r--r--configure.ac2
-rw-r--r--doc/micrond.87
-rw-r--r--src/micrond.c25
4 files changed, 39 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 76215af..04e3a3e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,16 @@
-micron -- history of user-visible changes. 2021-04-15
+micron -- history of user-visible changes. 2021-05-06
See the end of file for copying conditions.
Please send micron bug reports to <gray@gnu.org>
+Version 1.2.90 (git)
+
+* New option -P FILE
+
+Writes PID of the running process to FILE. The file will be removed
+when the program terminates.
+
+
Version 1.2, 2021-04-15
* Fix cronjob access serialization
diff --git a/configure.ac b/configure.ac
index d8ddcab..066f3c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,7 +15,7 @@
# with micron. If not, see <http://www.gnu.org/licenses/>. */
AC_PREREQ(2.63)
-AC_INIT([micron],[1.2],[gray@gnu.org.ua])
+AC_INIT([micron],[1.2.90],[gray@gnu.org.ua])
AC_CONFIG_SRCDIR([src/micron.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADER([config.h])
diff --git a/doc/micrond.8 b/doc/micrond.8
index 591a964..5ac2752 100644
--- a/doc/micrond.8
+++ b/doc/micrond.8
@@ -13,7 +13,7 @@
.\"
.\" You should have received a copy of the GNU General Public License along
.\" with micron. If not, see <http://www.gnu.org/licenses/>. */
-.TH MICROND 8 "January 24, 2021" "MICROND" "System Manager's Manual"
+.TH MICROND 8 "May 6, 2021" "MICROND" "System Manager's Manual"
.SH NAME
micrond \- a minimal cron implementation
.SH SYNOPSIS
@@ -23,6 +23,7 @@ micrond \- a minimal cron implementation
[\fB\-l \fIPRI\fR]\
[\fB\-m \fIMAILER\fR]\
[\fB\-o \fIOPTIONS\fR]\
+ [\fB\-P \fIFILE\fR]\
[\fB\-p \fIDEV\fR]\
[\fB\-t \fISECONDS\fR]
.SH DESCRIPTION
@@ -197,6 +198,10 @@ for a discussion of day field semantics.
See also the \fB_MICRON_DAY_SEMANTICS\fR built-in variable.
.RE
.TP
+\fB\-P \fIFILE\fR
+Write the PID of the cron daemon to \fIFILE\fR. The file will be
+removed when the program terminates.
+.TP
\fB\-p \fISOCKET\fR
Send messages to syslog via this socket. \fISOCKET\fR is either an
absolute file name of a UNIX socket, or a host name or IPv4 address
diff --git a/src/micrond.c b/src/micrond.c
index 0d0e1e2..bc82493 100644
--- a/src/micrond.c
+++ b/src/micrond.c
@@ -128,7 +128,8 @@ int log_level = LOG_INFO;
mode_t saved_umask;
/* Time to wait for all cronjobs to terminate before stopping micrond. */
unsigned micron_termination_timeout = 60;
-
+/* Name of the file where to store the PID */
+char *pidfile;
/* Boolean flag used to filter out @reboot jobs when rescanning. */
static int running;
static struct cronjob_options micron_options = {
@@ -265,6 +266,7 @@ usage(void)
printf(" -m MAILER set mailer command\n");
printf(" -N disable safety checking (for debugging only!)\n");
printf(" -o OPTS set crontab options\n");
+ printf(" -P FILE write the PID of the cron daemon to FILE\n");
printf(" -p SOCKET send messages to syslog via this SOCKET\n");
printf(" -S log to syslog even if running in foreground\n");
printf(" -s log output from cronjobs to syslog\n");
@@ -345,7 +347,7 @@ main(int argc, char **argv)
set_progname(argv[0]);
- while ((c = getopt(argc, argv, "hg:fNl:m:o:p:Sst:v")) != EOF) {
+ while ((c = getopt(argc, argv, "hg:fNl:m:o:P:p:Sst:v")) != EOF) {
switch (c) {
case 'h':
usage();
@@ -379,6 +381,10 @@ main(int argc, char **argv)
set_crontab_options(optarg);
break;
+ case 'P':
+ pidfile = optarg;
+ break;
+
case 'p':
micron_log_dev = optarg;
break;
@@ -460,6 +466,18 @@ main(int argc, char **argv)
} else if (micron_options.syslog_facility)
micron_log_open(progname, LOG_CRON);
+ if (pidfile) {
+ FILE *fp = fopen(pidfile, "w");
+ if (fp) {
+ fprintf(fp, "%lu\n", (unsigned long) getpid());
+ fclose(fp);
+ } else {
+ micron_log(LOG_ERR, "can't open pidfile %s for writing: %s",
+ pidfile, strerror(errno));
+ pidfile = NULL;
+ }
+ }
+
saved_umask = umask(077);
crongroups_parse_all(PARSE_ALWAYS);
@@ -507,6 +525,9 @@ main(int argc, char **argv)
thread_info[i].stop(thread_info[i].tid);
}
+ if (pidfile)
+ unlink(pidfile);
+
micron_log_close();
return EXIT_OK;

Return to:

Send suggestions and report system problems to the System administrator.