/* Simple syslog proxy for Linux and FreeBSD * * (c) 2004 MadCamel - Public Domain, use at your own risk. * * This program creates a log socket and proxies syslog messages to the real * log socket. Useful for chroot stuff. */ #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ # define LOG_PATH "/var/run/log" #endif #ifdef __LINUX__ # define LOG_PATH "/dev/log" #endif int main(int argc, char **argv) { struct sockaddr_un sa; int readsock, writesock, nread; char buf[8192]; if (argc < 2) { printf("usage: %s \n", argv[0]); exit(1); } memset(&buf, 0, sizeof(buf)); /* Setup listen socket */ if ((readsock = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) { perror("socket"); exit(1); } sa.sun_family = AF_UNIX; if (snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", argv[1]) < 0) { fprintf(stderr, "Socket name too long\n"); exit(1); } unlink(sa.sun_path); if (bind(readsock, (struct sockaddr *)&sa, (socklen_t)sizeof(sa)) < 0) { perror("bind"); exit(1); } /* Connect to log socket */ if ((writesock = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) { perror("socket"); exit(1); } sa.sun_family = AF_UNIX; sprintf(sa.sun_path, "%s", LOG_PATH); if (connect(writesock, (struct sockaddr *)&sa, (socklen_t)sizeof(sa)) < 0) { perror("connect"); exit(1); } daemon(0,0); /* Pass data */ while ( ( nread = read(readsock, &buf, sizeof(buf)-2) ) > -1) { write(writesock, &buf, nread); } }