]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Replace usleep() with i_sleep*_usecs and i_sleep*_msecs().
authorStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 13 Dec 2018 09:23:44 +0000 (10:23 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 10 Sep 2019 07:01:47 +0000 (10:01 +0300)
This prevents overflows and makes sure signal interruptions are handled
appropriately.

15 files changed:
src/doveadm/doveadm-master.c
src/lib-http/test-http-client-errors.c
src/lib-http/test-http-server-errors.c
src/lib-imap-client/test-imapc-client.c
src/lib-master/test-event-stats.c
src/lib-smtp/test-smtp-client-errors.c
src/lib-smtp/test-smtp-server-errors.c
src/lib-smtp/test-smtp-submit.c
src/lib-storage/index/mbox/mbox-sync.c
src/lib-storage/list/mailbox-list-delete.c
src/lib/file-dotlock.c
src/lib/ioloop-epoll.c
src/lib/ioloop-kqueue.c
src/lib/test-file-create-locked.c
src/master/service-monitor.c

index 6e989dbc3852d508e45603bdca18cc4ef61a5681..66f39f70dd9e470728ca5fdcd79b930fc537d25a 100644 (file)
@@ -6,6 +6,7 @@
 #include "istream.h"
 #include "write-full.h"
 #include "master-service.h"
+#include "sleep.h"
 #include "doveadm.h"
 #include "doveadm-print.h"
 
@@ -68,14 +69,14 @@ void doveadm_master_send_signal(int signo)
 
        if (signo == SIGTERM) {
                /* wait for a while for the process to die */
-               usleep(1000);
+               i_sleep_msecs(1);
                for (i = 0; i < 30; i++) {
                        if (kill(pid, 0) < 0) {
                                if (errno != ESRCH)
                                        i_error("kill() failed: %m");
                                break;
                        }
-                       usleep(100000);
+                       i_sleep_msecs(100);
                }
        }
 }
index d6277d14acf7a8fd01e1ac149871d5d13ae38aa2..aa8d48e080dfbf73cb2016a8fed48ab827d21039 100644 (file)
@@ -8,6 +8,7 @@
 #include "istream-chain.h"
 #include "ostream.h"
 #include "time-util.h"
+#include "sleep.h"
 #include "connection.h"
 #include "test-common.h"
 #include "http-url.h"
@@ -1417,7 +1418,7 @@ test_early_success_input(struct server_connection *conn)
                "\r\n"
                "Everything is OK\r\n";
 
-       usleep(200000);
+       i_sleep_msecs(200);
        o_stream_nsend_str(conn->conn.output, resp);
        server_connection_deinit(&conn);
 }
@@ -3426,7 +3427,7 @@ static void test_run_client_server(
 
        /* parent: client */
 
-       usleep(100000); /* wait a little for server setup */
+       i_sleep_msecs(100); /* wait a little for server setup */
 
        ioloop = io_loop_create();
        test_client_run(client_test, client_set);
index 7f8d34be2a89944d66277d2b63350fcb71f022e6..2ac4c51982314e85749344681d9ac19d23e6ec2c 100644 (file)
@@ -7,6 +7,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "time-util.h"
+#include "sleep.h"
 #include "connection.h"
 #include "test-common.h"
 #include "http-url.h"
@@ -812,7 +813,8 @@ static void test_run_client_server(
                                if (debug)
                                        i_debug("client[%d]: PID=%s", i+1, my_pid);
                                /* child: client */
-                               usleep(100000); /* wait a little for server setup */
+                               /* wait a little for server setup */
+                               i_sleep_msecs(100);
                                i_close_fd(&fd_listen);
                                ioloop = io_loop_create();
                                client_test(i);
index 4f4da355ccaf96f1e9e49665b1061428e900a652..ea41239530b7689b5964cdfbc191796853862cfd 100644 (file)
@@ -8,6 +8,7 @@
 #include "ostream.h"
 #include "ioloop.h"
 #include "unlink-directory.h"
+#include "sleep.h"
 #include "test-common.h"
 #include "imapc-client-private.h"
 
@@ -152,7 +153,7 @@ static void test_run_client_server(
        }
        /* parent: client */
 
-       usleep(100000); /* wait a little for server setup */
+       i_sleep_msecs(100); /* wait a little for server setup */
 
        ioloop = io_loop_create();
        imapc_client = imapc_client_init(&client_set_copy);
index 7f6b3169d3c58bd3033520e0bb5bf7fdcbdeaa2d..fe250c3e1610c2f7a13ce55e93ecaa172856a88e 100644 (file)
@@ -5,6 +5,7 @@
 #include "time-util.h"
 #include "lib-event-private.h"
 #include "str.h"
+#include "sleep.h"
 #include "ioloop.h"
 #include "connection.h"
 #include "ostream.h"
@@ -199,7 +200,7 @@ static void wait_for_signal(const char *signal_file)
                i_fatal("gettimeofday() failed %m");
        }
        while (access(signal_file, F_OK) < 0) {
-               usleep(10000);
+               i_sleep_msecs(10);
                if (gettimeofday(&now, NULL) < 0) {
                        kill_stats_child();
                        i_fatal("gettimeofday() failed %m");
index 134a44e54d9bf4ce8f301b889352b30a80c2450d..ec190e000bd40f484bb88970f72ea596c44a7c75 100644 (file)
@@ -11,6 +11,7 @@
 #include "istream-failure-at.h"
 #include "ostream.h"
 #include "time-util.h"
+#include "sleep.h"
 #include "connection.h"
 #include "test-common.h"
 #include "smtp-client.h"
@@ -3877,7 +3878,7 @@ static void test_run_client_server(
 
        /* parent: client */
 
-       usleep(100000); /* wait a little for server setup */
+       i_sleep_msecs(100); /* wait a little for server setup */
 
        lib_signals_ignore(SIGPIPE, TRUE);
        ioloop = io_loop_create();
index 0870dbbae5bd59eb792cfd3f23f2bbea7ee316f6..d23b760f7f1d3e87d7417ab6654df377233581ed 100644 (file)
@@ -8,6 +8,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "time-util.h"
+#include "sleep.h"
 #include "connection.h"
 #include "test-common.h"
 #include "smtp-address.h"
@@ -2301,7 +2302,8 @@ static void test_run_client_server(
                                if (debug)
                                        i_debug("PID=%s", my_pid);
                                /* child: client */
-                               usleep(100000); /* wait a little for server setup */
+                               /* wait a little for server setup */
+                               i_sleep_msecs(100);
                                i_close_fd(&fd_listen);
                                ioloop = io_loop_create();
                                client_test(i);
index 99eff43ee50eacab6cd27a8c275b3f67d5e40d20..df22850b86038cff78777f23c4fe911a76fd5d40 100644 (file)
@@ -9,6 +9,7 @@
 #include "istream-chain.h"
 #include "ostream.h"
 #include "time-util.h"
+#include "sleep.h"
 #include "unlink-directory.h"
 #include "write-full.h"
 #include "connection.h"
@@ -2115,7 +2116,7 @@ static void test_run_client_server(
 
        /* parent: client */
 
-       usleep(100000); /* wait a little for server setup */
+       i_sleep_msecs(100); /* wait a little for server setup */
        server_port = 0;
 
        ioloop = io_loop_create();
index 6793d61c67e7925b39fa04604cca2b7617339e2d..1198610b30be1f02c5ab0c102bd305b650d92884 100644 (file)
@@ -41,6 +41,7 @@
 #include "str.h"
 #include "read-full.h"
 #include "write-full.h"
+#include "sleep.h"
 #include "message-date.h"
 #include "istream-raw-mbox.h"
 #include "mbox-storage.h"
@@ -1490,7 +1491,7 @@ static int mbox_sync_update_index_header(struct mbox_sync_context *sync_ctx)
                   performance problem and the consequences of being wrong are
                   quite minimal (an extra logged error message). */
                while (sync_ctx->orig_mtime == st->st_mtime) {
-                       usleep(500000);
+                       i_sleep_msecs(500);
                        if (utime(mailbox_get_path(&sync_ctx->mbox->box), NULL) < 0) {
                                mbox_set_syscall_error(sync_ctx->mbox,
                                                       "utime()");
index 6cfbd8b4ed59ebefafaa81dba8b9145515978e9f..ca773ee7277969f0ea14777b866b5c8c45e43a71 100644 (file)
@@ -5,6 +5,7 @@
 #include "hex-binary.h"
 #include "hostpid.h"
 #include "randgen.h"
+#include "sleep.h"
 #include "unlink-directory.h"
 #include "mailbox-list-private.h"
 #include "mailbox-list-delete.h"
@@ -232,7 +233,7 @@ int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list,
                           lying around. In case it's .nfs* files, retry after
                           waiting a bit. Hopefully all processes keeping those
                           files open will have closed them by then. */
-                       usleep(100000);
+                       i_sleep_msecs(100);
                        ret = rmdir(path);
                }
                if (rmdir(path) == 0)
index 4be06c43286dc164e7849b898d751bf0c0494457..b3e9d29b7fb224f41e1c3fb023135f2a6f7b1596 100644 (file)
@@ -11,6 +11,7 @@
 #include "safe-mkstemp.h"
 #include "nfs-workarounds.h"
 #include "file-dotlock.h"
+#include "sleep.h"
 
 #include <stdio.h>
 #include <signal.h>
@@ -198,7 +199,7 @@ static int dotlock_override(struct lock_info *lock_info)
           otherwise another process might try to override it at the same time
           and unlink our newly created dotlock. */
        if (lock_info->use_io_notify)
-               usleep(LOCK_RANDOM_USLEEP_TIME);
+               i_sleep_usecs(LOCK_RANDOM_USLEEP_TIME);
        return 0;
 }
 
@@ -433,7 +434,7 @@ static void dotlock_wait(struct lock_info *lock_info)
        struct timeout *to;
 
        if (!lock_info->use_io_notify) {
-               usleep(lock_info->wait_usecs);
+               i_sleep_usecs(lock_info->wait_usecs);
                return;
        }
 
@@ -450,7 +451,7 @@ static void dotlock_wait(struct lock_info *lock_info)
                /* listening for files not supported */
                io_loop_destroy(&ioloop);
                lock_info->use_io_notify = FALSE;
-               usleep(LOCK_RANDOM_USLEEP_TIME);
+               i_sleep_usecs(LOCK_RANDOM_USLEEP_TIME);
                return;
        }
        /* timeout after a random time even when using notify, since it
index 34e4098cae64c5b4b161ff21c87ed68a9c1d2199..ad4100865fad64c6610313ebba1de4d7c058e185 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "sleep.h"
 #include "ioloop-private.h"
 #include "ioloop-iolist.h"
 
@@ -186,7 +187,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
                /* no I/Os, but we should have some timeouts.
                   just wait for them. */
                i_assert(msecs >= 0);
-               usleep(msecs*1000);
+               i_sleep_intr_msecs(msecs);
                ret = 0;
        }
 
index 6b4db3f70918c62605c0c57c4e77b6b9e348826b..061b1b1315094b18bc02725ff901e29730093794 100644 (file)
@@ -9,6 +9,7 @@
 #ifdef IOLOOP_KQUEUE
 
 #include "array.h"
+#include "sleep.h"
 #include "ioloop-private.h"
 
 #include <unistd.h>
@@ -135,7 +136,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
                }
        } else {
                i_assert(msecs >= 0);
-               usleep(msecs * 1000);
+               i_sleep_intr_msecs(msecs);
                ret = 0;
        }
 
index 621d7331a355d21e8362b1d5c986c13e5edbb9f6..8bbefcf51114ade68f46bacab1dbf07c70ea5754 100644 (file)
@@ -3,6 +3,7 @@
 #include "test-lib.h"
 #include "unlink-directory.h"
 #include "file-create-locked.h"
+#include "sleep.h"
 
 #include <fcntl.h>
 #include <signal.h>
@@ -32,7 +33,7 @@ static bool wait_for_file(pid_t pid, const char *path)
                                return FALSE;
                        i_fatal("kill(SIGSRCH) failed: %m");
                }
-               usleep(10000);
+               i_sleep_msecs(10);
        }
        i_error("%s isn't being created", path);
        return FALSE;
index 5e4938d19527e7deaf3f0269cb2a6a84e6d58ab3..748727f2c11989d610c5fdfa4006398fd024feab 100644 (file)
@@ -7,6 +7,7 @@
 #include "str.h"
 #include "safe-mkstemp.h"
 #include "time-util.h"
+#include "sleep.h"
 #include "master-client.h"
 #include "service.h"
 #include "service-process.h"
@@ -587,7 +588,7 @@ static void services_monitor_wait(struct service_list *service_list)
                if (finished ||
                    timeval_diff_msecs(&ioloop_timeval, &tv_start) > MAX_DIE_WAIT_MSECS)
                        break;
-               usleep(100000);
+               i_sleep_msecs(100);
        }
 }
 
@@ -637,7 +638,7 @@ static void services_monitor_wait_and_kill(struct service_list *service_list)
        if (service_list_processes_close_listeners(service_list)) {
                /* SIGQUITs were sent. wait a little bit to make sure they're
                   also processed before quitting. */
-               usleep(1000000);
+               i_sleep_msecs(1000);
        }
 }