URL: https://github.com/SSSD/sssd/pull/107
Title: #107: WATCHDOG: Avoid non async-signal-safe from the signal_handler

lslebodn commented:
"""
On (03/01/17 06:41), fidencio wrote:
>Argh, and also:
>```
>diff --git a/src/util/util_watchdog.c b/src/util/util_watchdog.c
>index 17954d1..77ba705 100644
>--- a/src/util/util_watchdog.c
>+++ b/src/util/util_watchdog.c
>@@ -50,7 +50,7 @@ static bool watchdog_detect_timeshift(void)
>     if (cur_time < prev_time) {
>         /* Time shift detected. We need to restart watchdog. */
>         if (write(watchdog_ctx.pipefd[1], "1", 1) != 1) {
>-            _exit(1);
>+            kill(-getpgrp(), SIGTERM);
That would work if we call setpgrp() in server_setup
or just in sssd_be; because other processes does/should not use fork/exec

You can try following example:
```
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>

int test_func(int main_sec_sleep)
{
    int ret;
    pid_t main_pid = getpid();
    setpgrp();

    printf(" getpid() %d:\n", getpid());
    printf(" getpgrp() %d:\n", getpgrp());

    for (int i=0; i<3; i++) {
        ret = fork();
        if ( ret == 0 ) {
            printf("  getpid() %d:\n", getpid());
            printf("  getpgrp() %d:\n", getpgrp());
            sleep(1000);
            break;
        }
    }

    if ( main_pid == getpid()) {
        sleep(main_sec_sleep);
        kill(-main_pid, 9);
    }
}

int main(void)
{
    int ret;
    pid_t main_pid = getpid();

    printf("getpid() %d:\n", getpid());
    printf("getpgrp() %d:\n", getpgrp());

    for (int i=0; i<3; i++) {
        ret = fork();
        if ( ret == 0 ) {
            test_func(5 + i);
            break;
        }
    }

    if ( main_pid == getpid()) {
        sleep(15);
        kill(-main_pid, 9);
    }
}

```

As you can see I could use -main_pid() in kill
becsaue getpid and getpgrp returned the same value

LS


"""

See the full comment at 
https://github.com/SSSD/sssd/pull/107#issuecomment-270635169
_______________________________________________
sssd-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to