View | Details | Raw Unified | Return to bug 47345
Collapse All | Expand All

(-)rotatelogs.c.org (-1 / +61 lines)
Lines 44-49 Link Here
44
#include "apr_file_io.h"
44
#include "apr_file_io.h"
45
#include "apr_file_info.h"
45
#include "apr_file_info.h"
46
#include "apr_general.h"
46
#include "apr_general.h"
47
#include "apr_poll.h"
48
#include "apr_portable.h"
47
#include "apr_time.h"
49
#include "apr_time.h"
48
#include "apr_getopt.h"
50
#include "apr_getopt.h"
49
51
Lines 64-69 Link Here
64
#define MAX_PATH        1024
66
#define MAX_PATH        1024
65
#endif
67
#endif
66
68
69
#if APR_FILES_AS_SOCKETS
70
static apr_pollfd_t wait_pollfd;
71
static apr_status_t wait_for_io_or_timeout(apr_file_t *f,
72
                                           apr_interval_time_t timeout,
73
                                           apr_pool_t *pool)
74
{
75
    apr_int32_t  nd;
76
77
    if (!wait_pollfd.p) {
78
        wait_pollfd.p = pool;
79
    }
80
    wait_pollfd.desc_type = APR_POLL_FILE;
81
    wait_pollfd.reqevents = APR_POLLIN;
82
    wait_pollfd.desc.f    = f;
83
84
    return apr_poll(&wait_pollfd, 1, &nd, timeout);
85
}
86
#elif defined(WIN32)
87
static apr_status_t wait_for_io_or_timeout(apr_file_t *f,
88
                                           apr_interval_time_t timeout,
89
                                           apr_pool_t *pool)
90
{
91
    HANDLE h;
92
    char   c;
93
    DWORD  r;
94
    int    s = 0;
95
96
    apr_os_file_get(&h, f);
97
    while (PeekNamedPipe(h, &c, 1, &r, NULL, NULL)) {
98
        if (r == 1)
99
            break;
100
        if (s >= apr_time_msec(timeout))
101
            return APR_TIMEUP;
102
        Sleep(100);
103
        s += 100;
104
    }
105
    return APR_SUCCESS;
106
}
107
#else
108
static apr_status_t wait_for_io_or_timeout(apr_file_t *f,
109
                                           apr_interval_time_t timeout,
110
                                           apr_pool_t *pool)
111
{
112
    return APR_SUCCESS;
113
}
114
#endif /* APR_FILES_AS_SOCKETS */
115
67
static void usage(const char *argv0, const char *reason)
116
static void usage(const char *argv0, const char *reason)
68
{
117
{
69
    if (reason) {
118
    if (reason) {
Lines 198-204 Link Here
198
         * since we reset bypass_io after the 1st loop
247
         * since we reset bypass_io after the 1st loop
199
         */
248
         */
200
        if (!bypass_io) {
249
        if (!bypass_io) {
201
            if (apr_file_read(f_stdin, buf, &nRead) != APR_SUCCESS) {
250
            apr_status_t rv;
251
252
            rv = wait_for_io_or_timeout(f_stdin, apr_time_from_sec(1), pool);
253
            if (rv == APR_SUCCESS) {
254
                if (apr_file_read(f_stdin, buf, &nRead) != APR_SUCCESS) {
255
                    exit(3);
256
                }
257
            }
258
            else if (APR_STATUS_IS_TIMEUP(rv)) {
259
                nRead = 0;
260
            }
261
            else {
202
                exit(3);
262
                exit(3);
203
            }
263
            }
204
        }
264
        }

Return to bug 47345