~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to clamd/others.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

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) {
553
557
        }
554
558
    } while (retval == -1 && !check_signals && errno == EINTR);
555
559
#else
 
560
    {
556
561
    fd_set rfds;
557
562
    struct timeval tv;
558
563
    int maxfd = -1;
630
635
            continue;
631
636
        }
632
637
    } while (retval == -1 && !check_signals && errno == EINTR);
 
638
    }
633
639
#endif
634
640
 
635
641
    if (retval == -1 && errno != EINTR) {