Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Plugged security hole, program no longer terminates unless signal is sent before signal() functions executed.

...

Code Block
bgColor#ccccff
#include <signal.h>
#include <stdlib.h>
#include <string.h>

volatile sig_atomic_t sig1 = 0;
volatile sig_atomic_t sig2 = 0;

void sig1_handler(int signum) {
  sig1 = 1;
}

void sig2_handler(int signum) {
  sig2 = 1;
}

int main(void) {
  signal(SIGUSR1, sig1_handler);
  signal(SIGUSR2, sig2_handler);

  while (1) {
    if (sig1) break;
    sleep(SLEEP_TIME);
  }

   signal(SIGUSR2, sig2_handler);/* ... */

  while (1) {
    if (sig2) break;
    sleep(SLEEP_TIME);
  }

  /* ... */

  return 0;
}

...