Make case_N.h more generic.
authorWayne Davison <wayned@samba.org>
Thu, 26 Aug 2010 17:13:04 +0000 (10:13 -0700)
committerWayne Davison <wayned@samba.org>
Thu, 26 Aug 2010 18:13:02 +0000 (11:13 -0700)
case_N.h
cleanup.c

index eb31663d11955d53189f07793cfd68cddd5add8a..52bd4ecab4500054cfc2b11b4ea6709860d0654b 100644 (file)
--- a/case_N.h
+++ b/case_N.h
@@ -1,7 +1,7 @@
 /*
 /*
- * End-of-run cleanup helper code used by cleanup.c.
+ * Allow an arbitrary sequence of case labels.
  *
  *
- * Copyright (C) 2006-2008 Wayne Davison
+ * Copyright (C) 2006-2010 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * with this program; if not, visit the http://fsf.org website.
  */
 
  * with this program; if not, visit the http://fsf.org website.
  */
 
-/* This is included by cleanup.c multiple times, once for every segement in
- * the _exit_cleanup() code.  This produces the next "case N:" statement in
- * sequence and increments the cleanup_step variable by 1.  This ensures that
- * our case statements never get out of whack due to added/removed steps. */
+/* This is included multiple times, once for every segement in a switch statement.
+ * This produces the next "case N:" statement in sequence. */
 
 
-#if !defined EXIT_CLEANUP_CASE_0
-#define EXIT_CLEANUP_CASE_0
+#if !defined CASE_N_STATE_0
+#define CASE_N_STATE_0
        case 0:
        case 0:
-#elif !defined EXIT_CLEANUP_CASE_1
-#define EXIT_CLEANUP_CASE_1
+#elif !defined CASE_N_STATE_1
+#define CASE_N_STATE_1
        case 1:
        case 1:
-#elif !defined EXIT_CLEANUP_CASE_2
-#define EXIT_CLEANUP_CASE_2
+#elif !defined CASE_N_STATE_2
+#define CASE_N_STATE_2
        case 2:
        case 2:
-#elif !defined EXIT_CLEANUP_CASE_3
-#define EXIT_CLEANUP_CASE_3
+#elif !defined CASE_N_STATE_3
+#define CASE_N_STATE_3
        case 3:
        case 3:
-#elif !defined EXIT_CLEANUP_CASE_4
-#define EXIT_CLEANUP_CASE_4
+#elif !defined CASE_N_STATE_4
+#define CASE_N_STATE_4
        case 4:
        case 4:
-#elif !defined EXIT_CLEANUP_CASE_5
-#define EXIT_CLEANUP_CASE_5
+#elif !defined CASE_N_STATE_5
+#define CASE_N_STATE_5
        case 5:
        case 5:
-#elif !defined EXIT_CLEANUP_CASE_6
-#define EXIT_CLEANUP_CASE_6
+#elif !defined CASE_N_STATE_6
+#define CASE_N_STATE_6
        case 6:
        case 6:
-#elif !defined EXIT_CLEANUP_CASE_7
-#define EXIT_CLEANUP_CASE_7
+#elif !defined CASE_N_STATE_7
+#define CASE_N_STATE_7
        case 7:
        case 7:
-#elif !defined EXIT_CLEANUP_CASE_8
-#define EXIT_CLEANUP_CASE_8
+#elif !defined CASE_N_STATE_8
+#define CASE_N_STATE_8
        case 8:
        case 8:
-#elif !defined EXIT_CLEANUP_CASE_9
-#define EXIT_CLEANUP_CASE_9
+#elif !defined CASE_N_STATE_9
+#define CASE_N_STATE_9
        case 9:
        case 9:
-#elif !defined EXIT_CLEANUP_CASE_10
-#define EXIT_CLEANUP_CASE_10
+#elif !defined CASE_N_STATE_10
+#define CASE_N_STATE_10
        case 10:
        case 10:
-#elif !defined EXIT_CLEANUP_CASE_11
-#define EXIT_CLEANUP_CASE_11
+#elif !defined CASE_N_STATE_11
+#define CASE_N_STATE_11
        case 11:
        case 11:
-#elif !defined EXIT_CLEANUP_CASE_12
-#define EXIT_CLEANUP_CASE_12
+#elif !defined CASE_N_STATE_12
+#define CASE_N_STATE_12
        case 12:
        case 12:
-#elif !defined EXIT_CLEANUP_CASE_13
-#define EXIT_CLEANUP_CASE_13
+#elif !defined CASE_N_STATE_13
+#define CASE_N_STATE_13
        case 13:
        case 13:
-#elif !defined EXIT_CLEANUP_CASE_14
-#define EXIT_CLEANUP_CASE_14
+#elif !defined CASE_N_STATE_14
+#define CASE_N_STATE_14
        case 14:
        case 14:
-#elif !defined EXIT_CLEANUP_CASE_15
-#define EXIT_CLEANUP_CASE_15
+#elif !defined CASE_N_STATE_15
+#define CASE_N_STATE_15
        case 15:
        case 15:
-#elif !defined EXIT_CLEANUP_CASE_16
-#define EXIT_CLEANUP_CASE_16
+#elif !defined CASE_N_STATE_16
+#define CASE_N_STATE_16
        case 16:
 #else
 #error Need to add more case statements!
 #endif
        case 16:
 #else
 #error Need to add more case statements!
 #endif
-               cleanup_step++;
index dc18f72af9a36af3c5e38f5661c9c2f3bb6e80fe..cf5f2122b3745d8abb42ec3239826bca5712fb31 100644 (file)
--- a/cleanup.c
+++ b/cleanup.c
@@ -98,7 +98,7 @@ pid_t cleanup_child_pid = -1;
  **/
 NORETURN void _exit_cleanup(int code, const char *file, int line)
 {
  **/
 NORETURN void _exit_cleanup(int code, const char *file, int line)
 {
-       static int cleanup_step = 0;
+       static int switch_step = 0;
        static int exit_code = 0, exit_line = 0;
        static const char *exit_file = NULL;
        static int unmodified_code = 0;
        static int exit_code = 0, exit_line = 0;
        static const char *exit_file = NULL;
        static int unmodified_code = 0;
@@ -119,8 +119,9 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
        /* Some of our actions might cause a recursive call back here, so we
         * keep track of where we are in the cleanup and never repeat a step. */
 
        /* Some of our actions might cause a recursive call back here, so we
         * keep track of where we are in the cleanup and never repeat a step. */
-       switch (cleanup_step) {
-#include "case_N.h" /* case 0: cleanup_step++; */
+       switch (switch_step) {
+#include "case_N.h" /* case 0: */
+               switch_step++;
 
                exit_code = unmodified_code = code;
                exit_file = file;
 
                exit_code = unmodified_code = code;
                exit_file = file;
@@ -139,6 +140,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (cleanup_child_pid != -1) {
                        int status;
 
                if (cleanup_child_pid != -1) {
                        int status;
@@ -152,6 +154,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (cleanup_got_literal && cleanup_fname && cleanup_new_fname
                 && keep_partial && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
 
                if (cleanup_got_literal && cleanup_fname && cleanup_new_fname
                 && keep_partial && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
@@ -169,12 +172,14 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (!code || am_server || am_receiver)
                        io_flush(FULL_FLUSH);
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                if (!code || am_server || am_receiver)
                        io_flush(FULL_FLUSH);
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (cleanup_fname)
                        do_unlink(cleanup_fname);
 
                if (cleanup_fname)
                        do_unlink(cleanup_fname);
@@ -203,6 +208,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (DEBUG_GTE(EXIT, 1)) {
                        rprintf(FINFO,
 
                if (DEBUG_GTE(EXIT, 1)) {
                        rprintf(FINFO,
@@ -213,6 +219,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (exit_code && exit_code != RERR_SOCKETIO && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
                 && exit_code != RERR_TIMEOUT && !shutting_down && (protocol_version >= 31 || am_receiver)) {
 
                if (exit_code && exit_code != RERR_SOCKETIO && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
                 && exit_code != RERR_TIMEOUT && !shutting_down && (protocol_version >= 31 || am_receiver)) {
@@ -228,6 +235,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
 
                /* FALLTHROUGH */
 #include "case_N.h"
 
                /* FALLTHROUGH */
 #include "case_N.h"
+               switch_step++;
 
                if (am_server && code)
                        msleep(100);
 
                if (am_server && code)
                        msleep(100);