~ubuntu-branches/ubuntu/trusty/uwsgi/trusty

« back to all changes in this revision

Viewing changes to plugins/rsyslog/rsyslog_plugin.c

  • Committer: Package Import Robot
  • Author(s): Janos Guljas
  • Date: 2012-02-13 03:43:28 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120213034328-d02hz8m5pon6kaxf
Tags: 1.0.3+dfsg-1
* New upstream version.
* Adjust rack plugin LD_RUN_PATH patch.
* Adjust patch for uWSGI Control Center jQuery links in templates.
* Remove '-fno-strict-aliasing' CFLAG patch as it is implemented upstream.
* Remove fix indentation of uwsgidecorators_py patch as implemented upstream.
* Adjust init scripts to use top-bottom options order, as --inherit option
  is not working as in earlier versions. 
* Update debian/copyright file.
* Add LSB Description field to debian/uwsgi.init.d.
* Set Architecture to "all" for binary package uwsgi-extra because
  it contains no architecture dependent files.
* Change uwsgi description. (Closes: #640698)
* New binary packages:
  - uwsgi-plugin-carbon
  - uwsgi-plugin-graylog2
  - uwsgi-plugin-logsocket
  - uwsgi-plugin-probeconnect
  - uwsgi-plugin-probepg
  - uwsgi-plugin-rrdtool
  - uwsgi-plugin-rsyslog
  - uwsgi-plugin-signal
  - uwsgi-plugin-symcall
  - uwsgi-plugin-syslog
* python-uwsgidecorators:
  - fix binary-install rule to call dh_python2
  - remove debian/source.lintian-overrides
* uwsgi-plugin-jvm-openjdk-6:
  - fix FTBFS on armel and powerpc (Closes: #656280)
* uwsgi-plugin-python:
  - document issue "ImportError: No module named site" when using
    virtualenv with Python 2.6 in README.Debian (Closes: #654333)
* Adjust debian/watch uversionmangle option.
* Repack upstram source to remove minimized jQuery and jQuery UI JavaScript
  libraries:
  - add get-orig-source rule to debian/rules
  - append +dfsg to upstream version
  - update debian/watch with dversionmangle option

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "../../uwsgi.h"
 
2
 
 
3
extern struct uwsgi_server uwsgi;
 
4
 
 
5
#define MAX_SYSLOG_PKT 1024
 
6
 
 
7
ssize_t uwsgi_rsyslog_logger(struct uwsgi_logger *ul, char *message, size_t len) {
 
8
 
 
9
        char buf[MAX_SYSLOG_PKT];
 
10
        time_t current_time;
 
11
        int portn = 514;
 
12
        int rlen;
 
13
 
 
14
        if (!ul->configured) {
 
15
 
 
16
                if (!uwsgi.choosen_logger_arg) {
 
17
                        uwsgi_log_safe("invalid rsyslog syntax\n");
 
18
                        exit(1);
 
19
                }
 
20
 
 
21
                ul->fd = socket(AF_INET, SOCK_DGRAM, 0);
 
22
                if (ul->fd < 0) {
 
23
                        uwsgi_error_safe("socket()");
 
24
                        exit(1);
 
25
                }
 
26
 
 
27
                uwsgi_socket_nb(ul->fd);
 
28
 
 
29
                char *comma = strchr(uwsgi.choosen_logger_arg, ',');
 
30
                if (comma) {
 
31
                        ul->data = comma+1;
 
32
                        *comma = 0;
 
33
                }
 
34
                else {
 
35
                        ul->data = uwsgi_concat2(uwsgi.hostname," uwsgi");
 
36
                }
 
37
 
 
38
 
 
39
                char *port = strchr(uwsgi.choosen_logger_arg, ':');
 
40
                if (port) {
 
41
                        portn = atoi(port+1);
 
42
                        *port = 0;
 
43
                }
 
44
 
 
45
                ul->addr_len = socket_to_in_addr(uwsgi.choosen_logger_arg, NULL, portn, &ul->addr.sa_in);
 
46
 
 
47
                if (port) *port = ':';
 
48
                if (comma) *comma = ',';
 
49
 
 
50
                ul->configured = 1;
 
51
        }
 
52
 
 
53
 
 
54
        current_time = time(NULL);
 
55
 
 
56
        // drop newline
 
57
        if (message[len-1] == '\n') len--;
 
58
 
 
59
        rlen = snprintf(buf, MAX_SYSLOG_PKT, "<29>%.*s %s: %.*s", 15, ctime(&current_time)+4, (char *) ul->data, (int) len, message);
 
60
        if (rlen > 0) {
 
61
                return sendto(ul->fd, buf, rlen, 0, (const struct sockaddr *) &ul->addr, ul->addr_len);
 
62
        }
 
63
        return -1;
 
64
 
 
65
}
 
66
 
 
67
void uwsgi_rsyslog_register() {
 
68
        uwsgi_register_logger("rsyslog", uwsgi_rsyslog_logger);
 
69
}
 
70
 
 
71
int uwsgi_rsyslog_init() {
 
72
        return 0;
 
73
}
 
74
 
 
75
struct uwsgi_plugin rsyslog_plugin = {
 
76
 
 
77
        .name = "rsyslog",
 
78
        .on_load = uwsgi_rsyslog_register,
 
79
        .init = uwsgi_rsyslog_init
 
80
 
 
81
};
 
82