diff options
author | Daniel Robbins <drobbins@gentoo.org> | 2000-11-17 06:38:45 +0000 |
---|---|---|
committer | Daniel Robbins <drobbins@gentoo.org> | 2000-11-17 06:38:45 +0000 |
commit | c0c5de5e7e86080bd848cf494f30eb5125fb93f2 (patch) | |
tree | 8d9a5c8385ded1350d13b8a4a46fe2abf95c9d26 /sys-apps/gluelog | |
parent | This version works with glibc-2.2 (diff) | |
download | gentoo-2-c0c5de5e7e86080bd848cf494f30eb5125fb93f2.tar.gz gentoo-2-c0c5de5e7e86080bd848cf494f30eb5125fb93f2.tar.bz2 gentoo-2-c0c5de5e7e86080bd848cf494f30eb5125fb93f2.zip |
new gluelog stuff
Diffstat (limited to 'sys-apps/gluelog')
-rw-r--r-- | sys-apps/gluelog/files/glueklog.c | 87 | ||||
-rw-r--r-- | sys-apps/gluelog/files/gluelog.c | 91 |
2 files changed, 178 insertions, 0 deletions
diff --git a/sys-apps/gluelog/files/glueklog.c b/sys-apps/gluelog/files/glueklog.c new file mode 100644 index 000000000000..00e993ddc71b --- /dev/null +++ b/sys-apps/gluelog/files/glueklog.c @@ -0,0 +1,87 @@ +/* Syslog listener for systems where /dev/log is a Unix domain socket. */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/time.h> +#include <pwd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <sys/un.h> +#include <errno.h> + +#define SIZE 1024 +#define SOCKNAME "/dev/log" +#define RUNUSER "daemon" + +int main(int argc, char **argv){ + char buf[SIZE]; + ssize_t r, w; + struct sockaddr_un sa1; + int s1; + fd_set fs; + int fd[2]; + pid_t child; + struct passwd *userinfo; + + if(argc<2){ + fprintf(stderr, "No logger specified\n"); + exit(1); + } + + /* Assume that it's ok to grab /dev/log. */ + if ((s1 = open("/proc/kmsg",O_RDONLY)) == -1) { + perror("/proc/kmsg"); + exit(1); + } + /* Dropping privileges here + userinfo=getpwnam(RUNUSER); + if(userinfo){ + setuid(userinfo->pw_uid); + seteuid(userinfo->pw_uid); + } else { + fprintf(stderr, "No such user: %s\n", RUNUSER); + exit(1); + } +*/ + if(pipe(fd)==-1){ + perror("pipe"); + exit(1); + } + if((child=fork())==-1){ + perror("fork"); + exit(1); + } + if(child==0){ /* We are the child */ + close(fd[1]); /* Child will only be reading from, not writing to parent */ + dup2(fd[0], 0); + /* Execute logger */ + //execlp("multilog", "multilog", "/tmp/test", NULL); + argv++; + execvp(argv[0], argv); + } + + /* We are Parent */ + close(fd[0]); /* Write to the child */ + + for(;;) { + r = read(s1, buf, SIZE); + if (r < 0) { + if (errno!=EINTR) + perror("read"); + continue; + } + while (r) { + w = write(fd[1], buf, r); + if (w < 0) { + if (errno!=EINTR) + perror("write"); + exit(1); + } + r -= w; + } + } +} diff --git a/sys-apps/gluelog/files/gluelog.c b/sys-apps/gluelog/files/gluelog.c new file mode 100644 index 000000000000..5762c8f59c57 --- /dev/null +++ b/sys-apps/gluelog/files/gluelog.c @@ -0,0 +1,91 @@ +/* Syslog listener for systems where /dev/log is a Unix domain socket. */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/time.h> +#include <pwd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <sys/un.h> + +#define SIZE 1024 +#define SOCKNAME "/dev/log" +#define RUNUSER "daemon" + +int main(int argc, char **argv){ + char buf[SIZE]; + ssize_t r, w; + struct sockaddr_un sa1; + int s1; + fd_set fs; + int fd[2]; + pid_t child; + struct passwd *userinfo; + + if(argc<2){ + fprintf(stderr, "No logger specified\n"); + exit(1); + } + + /* Assume that it's ok to grab /dev/log. */ + if ((s1 = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) { + perror("socket"); + exit(1); + } + sa1.sun_family = AF_UNIX; + strcpy(sa1.sun_path, SOCKNAME); + unlink(SOCKNAME); + if (bind(s1, &sa1, sizeof(sa1)) == -1) { + perror("bind"); + exit(1); + } + + /* Dropping privileges here */ + userinfo=getpwnam(RUNUSER); + if(userinfo){ + setuid(userinfo->pw_uid); + seteuid(userinfo->pw_uid); + } else { + fprintf(stderr, "No such user: %s\n", RUNUSER); + exit(1); + } + + if(pipe(fd)==-1){ + perror("pipe"); + exit(1); + } + if((child=fork())==-1){ + perror("fork"); + exit(1); + } + if(child==0){ /* We are the child */ + close(fd[1]); /* Child will only be reading from, not writing to parent */ + dup2(fd[0], 0); + /* Execute logger */ + //execlp("multilog", "multilog", "/tmp/test", NULL); + argv++; + execvp(argv[0], argv); + } + + /* We are Parent */ + close(fd[0]); /* Write to the child */ + + for(;;) { + r = recvfrom(s1, buf, SIZE, 0, 0, 0); + if (r < 0) { + perror("recvfrom"); + continue; + } + while (r) { + w = write(fd[1], buf, r); + if (w < 0) { + perror("write"); + exit(1); + } + r -= w; + } + write(fd[1], "\n", 1); + } +} |