~ubuntu-branches/ubuntu/maverick/clamav/maverick-backports

« back to all changes in this revision

Viewing changes to clamd/others.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran, Stephen Gran, Michael Tautschnig
  • Date: 2010-04-26 21:41:18 UTC
  • mfrom: (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100426214118-i6lo606wnh7ywfj6
Tags: 0.96+dfsg-4
[ Stephen Gran ]
* Fixed typo in clamav-milter's postinst

[ Michael Tautschnig ]
* Fixed typo in clamav-freshclam's postinst (closes: #579271)
* Debconf translation updates
  - Portuguese (closes: #579068)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  MA 02110-1301, USA.
19
19
 */
20
20
 
21
 
#ifdef  _MSC_VER
22
 
#include <winsock.h>
23
 
#endif
24
 
 
25
21
#if HAVE_CONFIG_H
26
22
#include "clamav-config.h"
27
23
#endif
39
35
#include <time.h>
40
36
#include <sys/stat.h>
41
37
#include <errno.h>
42
 
#ifndef C_WINDOWS
 
38
#ifndef _WIN32
43
39
#include <sys/time.h>
44
40
#include <sys/wait.h>
 
41
#include <sys/socket.h>
 
42
#include <sys/ioctl.h>
45
43
#endif
46
44
 
47
45
#if HAVE_SYS_PARAM_H
48
46
#include <sys/param.h>
49
47
#endif
50
48
 
51
 
#ifndef C_WINDOWS
52
 
#include <sys/socket.h>
53
 
#include <sys/ioctl.h>
54
 
#endif
55
 
 
56
49
#ifdef HAVE_SYS_TYPES_H
57
50
#include <sys/types.h>
58
51
#endif
61
54
#endif
62
55
 
63
56
#include <pthread.h>
64
 
/* submitted by breiter@wolfereiter.com: do not use poll(2) on Interix */
65
 
#ifdef C_INTERIX
66
 
#undef HAVE_POLL
67
 
#undef HAVE_POLL_H
68
 
#endif
69
57
 
70
58
#if HAVE_POLL
71
59
#if HAVE_POLL_H
72
60
#include <poll.h>
73
61
#else /* HAVE_POLL_H */
74
 
#undef HAVE_POLL
75
62
#if HAVE_SYS_SELECT_H
76
63
#include <sys/select.h>
77
64
#endif /* HAVE_SYS_SELECT_H */
81
68
#include <limits.h>
82
69
#include "shared/optparser.h"
83
70
#include "shared/output.h"
 
71
#include "shared/misc.h"
84
72
#include "libclamav/others.h"
85
73
 
86
74
#include "session.h"
87
75
#include "others.h"
88
 
#include "misc.h"
89
76
 
90
 
#ifdef  C_WINDOWS
 
77
#ifdef  _WIN32
91
78
void virusaction(const char *filename, const char *virname, const struct optstruct *opts)
92
79
{
93
80
    if(optget(opts, "VirusEvent")->enabled)
166
153
        free(buffer_file);
167
154
        free(buffer_vir);
168
155
}
169
 
#endif /* C_WINDOWS */
 
156
#endif /* _WIN32 */
170
157
 
171
158
/* Function: writen
172
159
        Try hard to write the specified number of bytes
220
207
    if (fds_add(&fds, fd, 1, timeout_sec) == -1)
221
208
        return -1;
222
209
    do {
223
 
        ret = fds_poll_recv(&fds, timeout_sec, check_signals);
 
210
        ret = fds_poll_recv(&fds, timeout_sec, check_signals, NULL);
224
211
    } while (ret == -1 && errno == EINTR);
225
212
    fds_free(&fds);
226
213
    return ret;
249
236
    logg("$Number of file descriptors polled: %u fds\n", (unsigned) data->nfds);
250
237
    /* Shrink buffer */
251
238
    newbuf = realloc(data->buf, j*sizeof(*newbuf));
252
 
    if (newbuf)
 
239
    if(!j)
 
240
        data->buf = NULL;
 
241
    else if (newbuf)
253
242
        data->buf = newbuf;/* non-fatal if shrink fails */
254
243
}
255
244
 
294
283
      n = recvmsg(buf->fd, &msg, 0);
295
284
      if (n < 0)
296
285
          return -1;
297
 
      if ((msg.msg_flags & MSG_TRUNC) || (msg.msg_flags & MSG_CTRUNC)) {
298
 
          logg("^Control message truncated");
 
286
      if (msg.msg_flags & MSG_TRUNC) {
 
287
          logg("^Message truncated at %d bytes\n", (int)n);
 
288
          return -1;
 
289
      }
 
290
      if (msg.msg_flags & MSG_CTRUNC) {
 
291
          if (msg.msg_controllen > 0)
 
292
              logg("^Control message truncated at %d bytes, %d data read\n",
 
293
                   (int)msg.msg_controllen, (int)n);
 
294
          else
 
295
              logg("^Control message truncated, no control data received, %d bytes read"
 
296
#ifdef C_LINUX
 
297
                   "(Is SELinux/AppArmor enabled, and blocking file descriptor passing?)"
 
298
#endif
 
299
                   "\n",
 
300
                   (int)n);
299
301
          return -1;
300
302
      }
301
303
      if (msg.msg_controllen) {
421
423
    fds_unlock(data);
422
424
}
423
425
 
424
 
#ifndef C_WINDOWS
425
 
#define closesocket(s)  close(s)
426
 
#endif
427
426
#define BUFFSIZE 1024
428
427
/* Wait till data is available to be read on any of the fds,
429
428
 * read available data on all fds, and mark them as appropriate.
434
433
 * Must be called with buf_mutex lock held.
435
434
 */
436
435
/* TODO: handle ReadTimeout */
437
 
int fds_poll_recv(struct fd_data *data, int timeout, int check_signals)
 
436
int fds_poll_recv(struct fd_data *data, int timeout, int check_signals, void *event)
438
437
{
439
438
    unsigned fdsok = data->nfds;
440
439
    size_t i;
443
442
 
444
443
    /* we must have at least one fd, the control fd! */
445
444
    fds_cleanup(data);
 
445
#ifndef _WIN32
446
446
    if (!data->nfds)
447
447
        return 0;
448
 
 
 
448
#endif
449
449
    for (i=0;i < data->nfds;i++) {
450
450
        data->buf[i].got_newdata = 0;
451
451
    }
499
499
        int n = data->nfds;
500
500
 
501
501
        fds_unlock(data);
 
502
#ifdef _WIN32
 
503
        retval = poll_with_event(data->poll_data, n, timeout, event);
 
504
#else
502
505
        retval = poll(data->poll_data, n, timeout);
 
506
#endif
503
507
        fds_lock(data);
504
508
 
505
509
        if (retval > 0) {
519
523
                if (revents & (POLLIN|POLLHUP)) {
520
524
                    logg("$Received POLLIN|POLLHUP on fd %d\n",data->poll_data[i].fd);
521
525
                }
 
526
#ifndef _WIN32
522
527
                if (revents & POLLHUP) {
523
528
                       /* avoid SHUT_WR problem on Mac OS X */
524
529
                       int ret = send(data->poll_data[i].fd, &n, 0, 0);
525
530
                       if (!ret || (ret == -1 && errno == EINTR))
526
531
                               revents &= ~POLLHUP;
527
532
                }
528
 
 
 
533
#endif
529
534
                if (revents & POLLIN) {
530
535
                    int ret = read_fd_data(&data->buf[i]);
531
536
                    /* Data available to be read */
553
558
        }
554
559
    } while (retval == -1 && !check_signals && errno == EINTR);
555
560
#else
 
561
    {
556
562
    fd_set rfds;
557
563
    struct timeval tv;
558
564
    int maxfd = -1;
630
636
            continue;
631
637
        }
632
638
    } while (retval == -1 && !check_signals && errno == EINTR);
 
639
    }
633
640
#endif
634
641
 
635
642
    if (retval == -1 && errno != EINTR) {