]> granicus.if.org Git - sysstat/commitdiff
Now use sigaction() instead of signal() for signals handling.
authorseb <seb@kluane.home>
Sat, 2 Mar 2013 14:30:01 +0000 (15:30 +0100)
committerseb <seb@kluane.home>
Sat, 2 Mar 2013 14:30:01 +0000 (15:30 +0100)
signal() manual page explicitly says to avoid using it for
signal handling, because of portability problems among other.
So use now sigaction() for that.

CHANGES
cifsiostat.c
iostat.c
mpstat.c
nfsiostat.c
pidstat.c
sadc.c
sar.c

diff --git a/CHANGES b/CHANGES
index ceb6f82ab270d7a979d3c62b6d85404ef51f5e8b..502f412e659e360d19196fa463f6742bdbcf3d8e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,8 @@ xxxx/xx/xx: Version 10.1.4 - Sebastien Godard (sysstat <at> orange.fr)
        * pidstat: -U option added. This option tells pidstat to display
          the username of the task instead of its UID.
        * pidstat manual page updated.
+       * Now use sigaction() instead of signal() for signals handling
+         to avoid portability problems.
        * FAQ updated.
 
 2012/12/23: Version 10.1.3 - Sebastien Godard (sysstat <at> orange.fr)
index 34ba8753327c437b186d8b7b06e95323b8acdf86..d59670691d2ad77a89d371f50a185476cc24d2c3 100644 (file)
@@ -55,6 +55,7 @@ int flags = 0;                /* Flag for common options and system state */
 long interval = 0;
 char timestamp[64];
 
+struct sigaction alrm_act;
 
 /*
  ***************************************************************************
@@ -84,12 +85,11 @@ void usage(char *progname)
  * SIGALRM signal handler.
  *
  * IN:
- * @sig        Signal number. Set to 0 for the first time, then to SIGALRM.
+ * @sig        Signal number.
  ***************************************************************************
  */
 void alarm_handler(int sig)
 {
-       signal(SIGALRM, alarm_handler);
        alarm(interval);
 }
 
@@ -671,7 +671,10 @@ int main(int argc, char **argv)
        printf("\n");
 
        /* Set a handler for SIGALRM */
-       alarm_handler(0);
+       memset(&alrm_act, 0, sizeof(alrm_act));
+       alrm_act.sa_handler = (void *) alarm_handler;
+       sigaction(SIGALRM, &alrm_act, NULL);
+       alarm(interval);
 
        /* Main loop */
        rw_io_stat_loop(count, &rectime);
index 935f72acd2be8d7acfb78a55929d1ab38df4f7cc..171d9ae3053df43aa275c02ee65072e747b25a49 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -1,6 +1,6 @@
 /*
  * iostat: report CPU and I/O statistics
- * (C) 1998-2012 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1998-2013 by Sebastien GODARD (sysstat <at> orange.fr)
  *
  ***************************************************************************
  * This program is free software; you can redistribute it and/or modify it *
@@ -70,6 +70,7 @@ unsigned int dm_major;        /* Device-mapper major number */
 long interval = 0;
 char timestamp[64];
 
+struct sigaction alrm_act;
 
 /*
  ***************************************************************************
@@ -122,15 +123,14 @@ void set_disk_output_unit(void)
 
 /*
  ***************************************************************************
- * SIGALRM signal handler.
+ * SIGALRM signal handler. No need to reset the handler here.
  *
  * IN:
- * @sig        Signal number. Set to 0 for the first time, then to SIGALRM.
+ * @sig        Signal number.
  ***************************************************************************
  */
 void alarm_handler(int sig)
 {
-       signal(SIGALRM, alarm_handler);
        alarm(interval);
 }
 
@@ -1594,7 +1594,10 @@ int main(int argc, char **argv)
        printf("\n");
 
        /* Set a handler for SIGALRM */
-       alarm_handler(0);
+       memset(&alrm_act, 0, sizeof(alrm_act));
+       alrm_act.sa_handler = (void *) alarm_handler;
+       sigaction(SIGALRM, &alrm_act, NULL);
+       alarm(interval);
 
        /* Main loop */
        rw_io_stat_loop(count, &rectime);
index 67f9edc862520afc02d93377d1148e4dd3ad57b3..85e0dc6583f9ac399c081a59597f1fef9ec30e29 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -73,6 +73,7 @@ int irqcpu_nr = 0;
 /* Nb of soft interrupts per processor */
 int softirqcpu_nr = 0;
 
+struct sigaction alrm_act, int_act;
 int sigint_caught = 0;
 
 /*
@@ -96,7 +97,7 @@ void usage(char *progname)
 
 /*
  ***************************************************************************
- * SIGALRM signal handler
+ * SIGALRM signal handler. No need to reset the handler here.
  *
  * IN:
  * @sig        Signal number.
@@ -104,7 +105,6 @@ void usage(char *progname)
  */
 void alarm_handler(int sig)
 {
-       signal(SIGALRM, alarm_handler);
        alarm(interval);
 }
 
@@ -796,7 +796,10 @@ void rw_mpstat_loop(int dis_hdr, int rows)
        }
 
        /* Set a handler for SIGALRM */
-       alarm_handler(0);
+       memset(&alrm_act, 0, sizeof(alrm_act));
+       alrm_act.sa_handler = (void *) alarm_handler;
+       sigaction(SIGALRM, &alrm_act, NULL);
+       alarm(interval);
 
        /* Save the first stats collected. Will be used to compute the average */
        mp_tstamp[2] = mp_tstamp[0];
@@ -811,7 +814,9 @@ void rw_mpstat_loop(int dis_hdr, int rows)
        }
 
        /* Set a handler for SIGINT */
-       signal(SIGINT, int_handler);
+       memset(&int_act, 0, sizeof(int_act));
+       int_act.sa_handler = (void *) int_handler;
+       sigaction(SIGINT, &int_act, NULL);
 
        pause();
 
index 4dddf2bf73b302f4d4e70b51973e5964fa9c5d78..edb1614cd5d64e9c8f367b9990418ad7e3097e55 100644 (file)
@@ -54,6 +54,7 @@ int flags = 0;                /* Flag for common options and system state */
 long interval = 0;
 char timestamp[64];
 
+struct sigaction alrm_act;
 
 /*
  ***************************************************************************
@@ -104,12 +105,11 @@ void set_output_unit(void)
  * SIGALRM signal handler.
  *
  * IN:
- * @sig        Signal number. Set to 0 for the first time, then to SIGALRM.
+ * @sig        Signal number.
  ***************************************************************************
  */
 void alarm_handler(int sig)
 {
-       signal(SIGALRM, alarm_handler);
        alarm(interval);
 }
 
@@ -740,7 +740,10 @@ int main(int argc, char **argv)
        printf("\n");
 
        /* Set a handler for SIGALRM */
-       alarm_handler(0);
+       memset(&alrm_act, 0, sizeof(alrm_act));
+       alrm_act.sa_handler = (void *) alarm_handler;
+       sigaction(SIGALRM, &alrm_act, NULL);
+       alarm(interval);
 
        /* Main loop */
        rw_io_stat_loop(count, &rectime);
index 63f1ac6c1a3cbc1a28c025b82816e5ccf8f1a030..23c245a12c1936df3dec0e10a25f8c8d7c1375af 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -64,6 +64,8 @@ long count = 0;
 unsigned int pidflag = 0;      /* General flags */
 unsigned int tskflag = 0;      /* TASK/CHILD stats */
 unsigned int actflag = 0;      /* Activity flag */
+
+struct sigaction alrm_act, int_act;
 int sigint_caught = 0;
 
 /*
@@ -88,7 +90,7 @@ void usage(char *progname)
 
 /*
  ***************************************************************************
- * SIGALRM signal handler.
+ * SIGALRM signal handler. No need to resert the handler here.
  *
  * IN:
  * @sig        Signal number.
@@ -96,7 +98,6 @@ void usage(char *progname)
  */
 void alarm_handler(int sig)
 {
-       signal(SIGALRM, alarm_handler);
        alarm(interval);
 }
 
@@ -1919,7 +1920,10 @@ void rw_pidstat_loop(int dis_hdr, int rows)
        }
 
        /* Set a handler for SIGALRM */
-       alarm_handler(0);
+       memset(&alrm_act, 0, sizeof(alrm_act));
+       alrm_act.sa_handler = (void *) alarm_handler;
+       sigaction(SIGALRM, &alrm_act, NULL);
+       alarm(interval);
 
        /* Save the first stats collected. Will be used to compute the average */
        ps_tstamp[2] = ps_tstamp[0];
@@ -1928,7 +1932,9 @@ void rw_pidstat_loop(int dis_hdr, int rows)
        memcpy(st_pid_list[2], st_pid_list[0], PID_STATS_SIZE * pid_nr);
 
        /* Set a handler for SIGINT */
-       signal(SIGINT, int_handler);
+       memset(&int_act, 0, sizeof(int_act));
+       int_act.sa_handler = (void *) int_handler;
+       sigaction(SIGINT, &int_act, NULL);
 
        /* Wait for SIGALRM (or possibly SIGINT) signal */
        pause();
diff --git a/sadc.c b/sadc.c
index 5f6674de340b3931f9d7d3a15ee24e40a723df4e..4f35e09ab698bf4586fdeae12cc3952c8c4108fb 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -69,6 +69,8 @@ unsigned int id_seq[NR_ACT];
 
 extern struct activity *act[];
 
+struct sigaction alrm_act, int_act;
+
 /*
  ***************************************************************************
  * Print usage and exit.
@@ -202,7 +204,7 @@ void parse_sadc_S_option(char *argv[], int opt)
 
 /*
  ***************************************************************************
- * SIGALRM signal handler.
+ * SIGALRM signal handler. No need to reset handler here.
  *
  * IN:
  * @sig        Signal number.
@@ -210,7 +212,6 @@ void parse_sadc_S_option(char *argv[], int opt)
  */
 void alarm_handler(int sig)
 {
-       signal(SIGALRM, alarm_handler);
        alarm(interval);
 }
 
@@ -906,7 +907,9 @@ void rw_sa_stat_loop(long count, struct tm *rectime, int stdfd, int ofd,
        new_ofile[0] = '\0';
        
        /* Set a handler for SIGINT */
-       signal(SIGINT, int_handler);
+       memset(&int_act, 0, sizeof(int_act));
+       int_act.sa_handler = (void *) int_handler;
+       sigaction(SIGINT, &int_act, NULL);
 
        /* Main loop */
        do {
@@ -1186,7 +1189,10 @@ int main(int argc, char **argv)
        }
 
        /* Set a handler for SIGALRM */
-       alarm_handler(0);
+       memset(&alrm_act, 0, sizeof(alrm_act));
+       alrm_act.sa_handler = (void *) alarm_handler;
+       sigaction(SIGALRM, &alrm_act, NULL);
+       alarm(interval);
 
        /* Main loop */
        rw_sa_stat_loop(count, &rectime, stdfd, ofd, ofile);
diff --git a/sar.c b/sar.c
index 4d10bb39160936190838f8f2b13aa6dca9206f68..1acef196f063dbbbd802a9df7941fd32260a70ac 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -78,6 +78,7 @@ char *args[MAX_ARGV_NR];
 
 extern struct activity *act[];
 
+struct sigaction int_act;
 int sigint_caught = 0;
 
 /*
@@ -1057,7 +1058,10 @@ void read_stats(void)
        copy_structures(act, id_seq, record_hdr, 2, 0);
 
        /* Set a handler for SIGINT */
-       signal(SIGINT, int_handler);
+       memset(&int_act, 0, sizeof(int_act));
+       int_act.sa_handler = (void *) int_handler;
+       int_act.sa_flags = SA_RESTART;
+       sigaction(SIGINT, &int_act, NULL);
 
        /* Main loop */
        do {