cronie-crond / cronie

Cronie cron daemon project
Other
453 stars 77 forks source link

The cond service occasionally shows status "Active: deactivating" #139

Closed YoruStar closed 1 year ago

YoruStar commented 1 year ago

Hello, I found something wrong with my crond service

Execute the commands systemctl restart crond and systemctl reload crond at the same time , The cond service occasionally shows status Active: deactivating .

When the command systemctl reload crond is executed, systemd will send the HUP to the crond process. Under normal circumstances, the crond process will modify the behavior of the HUP signal (without interrupting the process, and only record the received signal in the global variable). However, after executing the command systemctl restart crond, the crond process received the HUP signal sent by the command systemctl reload crond before it could modify the HUP signal behavior just after the crond process was started, which caused the crond process to be interrupted, so the crond service status appears as Active: deactivating .

I try to add a dead loop at the beginning of the main function of the crond service to reproduce this situation

int main(int argc, char *argv[]) {
    while (1)
    {
        /* code */
    }

    struct sigaction sact;
    cron_db database;
    int fd;
    char *cs;
    pid_t pid = getpid();
    long oldGMToff;
    struct timeval tv;
    struct timezone tz;
    char buf[256];

    ... ...

Replace process to /usr/sbin/crond, Execute the commands systemctl restart crond and systemctl reload crond successively, the result as follows

[root@localhost SOURCES]# systemctl restart crond &
[1] 945128
[root@localhost SOURCES]# systemctl reload crond &
[2] 945171
[root@localhost SOURCES]# systemctl status crond
● crond.service - Command Scheduler
     Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
     Active: deactivating (start) since Wed 2023-02-01 10:13:00 CST; 9s ago
Cntrl PID: 945139 (crond)
      Tasks: 1 (limit: 8645)
     Memory: 204.0K
     CGroup: /system.slice/crond.service
             └─ 945139 /usr/sbin/crond -n

Feb 01 10:13:00 localhost.localdomain systemd[1]: Starting Command Scheduler...

I also tried to change the Type of cron.service to forking, and set the PIDFile to /var/run/cron.pid , but this seems to be getting worse

t8m commented 1 year ago

If there was any other signal that is by default ignored we could use that to signal the reload. The only such signal is SIGURG which is in POSIX1.2001 only. I assume we could use it as we do not use sockets so it should not be received spuriously.

On the other hand, why do you call restart and reload simultaneously?