Tests: cleanly exit from test apps on reception of SIGTERM
[lttng-tools.git] / tests / utils / testapp / gen-ust-nevents / gen-ust-nevents.c
index c7a5e5fb7081c8270ae80abeb6796fc337f9b91e..17fd8626ca5e03b14852a5c1466313aa5fc5924b 100644 (file)
@@ -15,6 +15,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#define _LGPL_SOURCE
 #include <arpa/inet.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include "utils.h"
+#include "signal-helper.h"
 
 #define TRACEPOINT_DEFINE
 #include "tp.h"
 
 int main(int argc, char **argv)
 {
-       int i, netint;
+       int i, netint, ret = 0;
        long values[] = { 1, 2, 3 };
        char text[10] = "test";
        double dbl = 2.0;
@@ -38,6 +41,11 @@ int main(int argc, char **argv)
        unsigned int nr_iter = 100;
        useconds_t nr_usec = 0;
 
+       if (set_signal_handler()) {
+               ret = -1;
+               goto end;
+       }
+
        if (argc >= 2) {
                nr_iter = atoi(argv[1]);
        }
@@ -59,8 +67,17 @@ int main(int argc, char **argv)
                                dbl, flt);
                tracepoint(tp, tptest5, i, netint, values, text, strlen(text),
                                dbl, flt);
-               usleep(nr_usec);
+               if (nr_usec) {
+                       if (usleep_safe(nr_usec)) {
+                               ret = -1;
+                               goto end;
+                       }
+               }
+               if (should_quit) {
+                       break;
+               }
        }
 
-       return 0;
+end:
+        exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
 }
This page took 0.024839 seconds and 5 git commands to generate.