diff options
author | Mark Whitley <markw@lineo.com> | 2001-03-15 19:05:59 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2001-03-15 19:05:59 +0000 |
commit | b0c2b7dfe3222af79f9d830934cf92ee866834f6 (patch) | |
tree | 16a19b611a6064c0c50a08a4c0bd2932daad517a | |
parent | 2825ee8c2c3330b50a2666f04c6fcfa76cc9f57f (diff) | |
download | busybox-w32-b0c2b7dfe3222af79f9d830934cf92ee866834f6.tar.gz busybox-w32-b0c2b7dfe3222af79f9d830934cf92ee866834f6.tar.bz2 busybox-w32-b0c2b7dfe3222af79f9d830934cf92ee866834f6.zip |
dos2unix logread.c
-rw-r--r-- | logread.c | 292 | ||||
-rw-r--r-- | sysklogd/logread.c | 292 |
2 files changed, 292 insertions, 292 deletions
@@ -1,146 +1,146 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * circular buffer syslog implementation for busybox | 3 | * circular buffer syslog implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com> | 5 | * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com> |
6 | * | 6 | * |
7 | * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001 | 7 | * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001 |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | 13 | * |
14 | * This program is distributed in the hope that it will be useful, | 14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * General Public License for more details. | 17 | * General Public License for more details. |
18 | * | 18 | * |
19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software | 20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
22 | * 02111-1307 USA | 22 | * 02111-1307 USA |
23 | * | 23 | * |
24 | */ | 24 | */ |
25 | 25 | ||
26 | 26 | ||
27 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <sys/ipc.h> | 30 | #include <sys/ipc.h> |
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <sys/sem.h> | 32 | #include <sys/sem.h> |
33 | #include <sys/shm.h> | 33 | #include <sys/shm.h> |
34 | #include <signal.h> | 34 | #include <signal.h> |
35 | #include <setjmp.h> | 35 | #include <setjmp.h> |
36 | #include "busybox.h" | 36 | #include "busybox.h" |
37 | 37 | ||
38 | /* Stupid libc doesn't have a reliable way for use to know | 38 | /* Stupid libc doesn't have a reliable way for use to know |
39 | * that libc5 is being used. Assume this is good enough */ | 39 | * that libc5 is being used. Assume this is good enough */ |
40 | #if ! defined __GLIBC__ && ! defined __UCLIBC__ | 40 | #if ! defined __GLIBC__ && ! defined __UCLIBC__ |
41 | #error Sorry. Looks like you are using libc5. | 41 | #error Sorry. Looks like you are using libc5. |
42 | #error libc5 shm support isnt good enough. | 42 | #error libc5 shm support isnt good enough. |
43 | #error Please disable BB_FEATURE_IPC_SYSLOG | 43 | #error Please disable BB_FEATURE_IPC_SYSLOG |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | static const long KEY_ID = 0x414e4547; /*"GENA"*/ | 47 | static const long KEY_ID = 0x414e4547; /*"GENA"*/ |
48 | 48 | ||
49 | static struct shbuf_ds { | 49 | static struct shbuf_ds { |
50 | int size; // size of data written | 50 | int size; // size of data written |
51 | int head; // start of message list | 51 | int head; // start of message list |
52 | int tail; // end of message list | 52 | int tail; // end of message list |
53 | char data[1]; // data/messages | 53 | char data[1]; // data/messages |
54 | } *buf = NULL; // shared memory pointer | 54 | } *buf = NULL; // shared memory pointer |
55 | 55 | ||
56 | 56 | ||
57 | // Semaphore operation structures | 57 | // Semaphore operation structures |
58 | static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup | 58 | static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup |
59 | static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn | 59 | static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn |
60 | 60 | ||
61 | static int shmid = -1; // ipc shared memory id | 61 | static int shmid = -1; // ipc shared memory id |
62 | static int semid = -1; // ipc semaphore id | 62 | static int semid = -1; // ipc semaphore id |
63 | static jmp_buf jmp_env; | 63 | static jmp_buf jmp_env; |
64 | 64 | ||
65 | static void error_exit(const char *str); | 65 | static void error_exit(const char *str); |
66 | static void interrupted(int sig); | 66 | static void interrupted(int sig); |
67 | 67 | ||
68 | /* | 68 | /* |
69 | * sem_up - up()'s a semaphore. | 69 | * sem_up - up()'s a semaphore. |
70 | */ | 70 | */ |
71 | static inline void sem_up(int semid) | 71 | static inline void sem_up(int semid) |
72 | { | 72 | { |
73 | if ( semop(semid, SMrup, 1) == -1 ) | 73 | if ( semop(semid, SMrup, 1) == -1 ) |
74 | error_exit("semop[SMrup]"); | 74 | error_exit("semop[SMrup]"); |
75 | } | 75 | } |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * sem_down - down()'s a semaphore | 78 | * sem_down - down()'s a semaphore |
79 | */ | 79 | */ |
80 | static inline void sem_down(int semid) | 80 | static inline void sem_down(int semid) |
81 | { | 81 | { |
82 | if ( semop(semid, SMrdn, 2) == -1 ) | 82 | if ( semop(semid, SMrdn, 2) == -1 ) |
83 | error_exit("semop[SMrdn]"); | 83 | error_exit("semop[SMrdn]"); |
84 | } | 84 | } |
85 | 85 | ||
86 | extern int logread_main(int argc, char **argv) | 86 | extern int logread_main(int argc, char **argv) |
87 | { | 87 | { |
88 | int i; | 88 | int i; |
89 | 89 | ||
90 | /* no options, no getopt */ | 90 | /* no options, no getopt */ |
91 | if (argc > 1) | 91 | if (argc > 1) |
92 | show_usage(); | 92 | show_usage(); |
93 | 93 | ||
94 | // handle intrrupt signal | 94 | // handle intrrupt signal |
95 | if (setjmp(jmp_env)) goto output_end; | 95 | if (setjmp(jmp_env)) goto output_end; |
96 | 96 | ||
97 | // attempt to redefine ^C signal | 97 | // attempt to redefine ^C signal |
98 | signal(SIGINT, interrupted); | 98 | signal(SIGINT, interrupted); |
99 | 99 | ||
100 | if ( (shmid = shmget(KEY_ID, 0, 0)) == -1) | 100 | if ( (shmid = shmget(KEY_ID, 0, 0)) == -1) |
101 | error_exit("Can't find circular buffer"); | 101 | error_exit("Can't find circular buffer"); |
102 | 102 | ||
103 | // Attach shared memory to our char* | 103 | // Attach shared memory to our char* |
104 | if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL) | 104 | if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL) |
105 | error_exit("Can't get access to circular buffer from syslogd"); | 105 | error_exit("Can't get access to circular buffer from syslogd"); |
106 | 106 | ||
107 | if ( (semid = semget(KEY_ID, 0, 0)) == -1) | 107 | if ( (semid = semget(KEY_ID, 0, 0)) == -1) |
108 | error_exit("Can't get access to semaphone(s) for circular buffer from syslogd"); | 108 | error_exit("Can't get access to semaphone(s) for circular buffer from syslogd"); |
109 | 109 | ||
110 | sem_down(semid); | 110 | sem_down(semid); |
111 | // Read Memory | 111 | // Read Memory |
112 | i=buf->head; | 112 | i=buf->head; |
113 | 113 | ||
114 | //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size); | 114 | //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size); |
115 | if (buf->head == buf->tail) { | 115 | if (buf->head == buf->tail) { |
116 | printf("<empty syslog>\n"); | 116 | printf("<empty syslog>\n"); |
117 | } | 117 | } |
118 | 118 | ||
119 | while ( i != buf->tail) { | 119 | while ( i != buf->tail) { |
120 | printf("%s", buf->data+i); | 120 | printf("%s", buf->data+i); |
121 | i+= strlen(buf->data+i) + 1; | 121 | i+= strlen(buf->data+i) + 1; |
122 | if (i >= buf->size ) | 122 | if (i >= buf->size ) |
123 | i=0; | 123 | i=0; |
124 | } | 124 | } |
125 | sem_up(semid); | 125 | sem_up(semid); |
126 | 126 | ||
127 | output_end: | 127 | output_end: |
128 | if (shmid != -1) | 128 | if (shmid != -1) |
129 | shmdt(buf); | 129 | shmdt(buf); |
130 | 130 | ||
131 | return EXIT_SUCCESS; | 131 | return EXIT_SUCCESS; |
132 | } | 132 | } |
133 | 133 | ||
134 | static void interrupted(int sig){ | 134 | static void interrupted(int sig){ |
135 | signal(SIGINT, SIG_IGN); | 135 | signal(SIGINT, SIG_IGN); |
136 | longjmp(jmp_env, 1); | 136 | longjmp(jmp_env, 1); |
137 | } | 137 | } |
138 | 138 | ||
139 | static void error_exit(const char *str){ | 139 | static void error_exit(const char *str){ |
140 | perror(str); | 140 | perror(str); |
141 | //release all acquired resources | 141 | //release all acquired resources |
142 | if (shmid != -1) | 142 | if (shmid != -1) |
143 | shmdt(buf); | 143 | shmdt(buf); |
144 | 144 | ||
145 | exit(1); | 145 | exit(1); |
146 | } | 146 | } |
diff --git a/sysklogd/logread.c b/sysklogd/logread.c index 17f6a54d6..ea881e659 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c | |||
@@ -1,146 +1,146 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * circular buffer syslog implementation for busybox | 3 | * circular buffer syslog implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com> | 5 | * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com> |
6 | * | 6 | * |
7 | * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001 | 7 | * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001 |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | 13 | * |
14 | * This program is distributed in the hope that it will be useful, | 14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * General Public License for more details. | 17 | * General Public License for more details. |
18 | * | 18 | * |
19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software | 20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
22 | * 02111-1307 USA | 22 | * 02111-1307 USA |
23 | * | 23 | * |
24 | */ | 24 | */ |
25 | 25 | ||
26 | 26 | ||
27 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <sys/ipc.h> | 30 | #include <sys/ipc.h> |
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <sys/sem.h> | 32 | #include <sys/sem.h> |
33 | #include <sys/shm.h> | 33 | #include <sys/shm.h> |
34 | #include <signal.h> | 34 | #include <signal.h> |
35 | #include <setjmp.h> | 35 | #include <setjmp.h> |
36 | #include "busybox.h" | 36 | #include "busybox.h" |
37 | 37 | ||
38 | /* Stupid libc doesn't have a reliable way for use to know | 38 | /* Stupid libc doesn't have a reliable way for use to know |
39 | * that libc5 is being used. Assume this is good enough */ | 39 | * that libc5 is being used. Assume this is good enough */ |
40 | #if ! defined __GLIBC__ && ! defined __UCLIBC__ | 40 | #if ! defined __GLIBC__ && ! defined __UCLIBC__ |
41 | #error Sorry. Looks like you are using libc5. | 41 | #error Sorry. Looks like you are using libc5. |
42 | #error libc5 shm support isnt good enough. | 42 | #error libc5 shm support isnt good enough. |
43 | #error Please disable BB_FEATURE_IPC_SYSLOG | 43 | #error Please disable BB_FEATURE_IPC_SYSLOG |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | static const long KEY_ID = 0x414e4547; /*"GENA"*/ | 47 | static const long KEY_ID = 0x414e4547; /*"GENA"*/ |
48 | 48 | ||
49 | static struct shbuf_ds { | 49 | static struct shbuf_ds { |
50 | int size; // size of data written | 50 | int size; // size of data written |
51 | int head; // start of message list | 51 | int head; // start of message list |
52 | int tail; // end of message list | 52 | int tail; // end of message list |
53 | char data[1]; // data/messages | 53 | char data[1]; // data/messages |
54 | } *buf = NULL; // shared memory pointer | 54 | } *buf = NULL; // shared memory pointer |
55 | 55 | ||
56 | 56 | ||
57 | // Semaphore operation structures | 57 | // Semaphore operation structures |
58 | static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup | 58 | static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup |
59 | static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn | 59 | static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn |
60 | 60 | ||
61 | static int shmid = -1; // ipc shared memory id | 61 | static int shmid = -1; // ipc shared memory id |
62 | static int semid = -1; // ipc semaphore id | 62 | static int semid = -1; // ipc semaphore id |
63 | static jmp_buf jmp_env; | 63 | static jmp_buf jmp_env; |
64 | 64 | ||
65 | static void error_exit(const char *str); | 65 | static void error_exit(const char *str); |
66 | static void interrupted(int sig); | 66 | static void interrupted(int sig); |
67 | 67 | ||
68 | /* | 68 | /* |
69 | * sem_up - up()'s a semaphore. | 69 | * sem_up - up()'s a semaphore. |
70 | */ | 70 | */ |
71 | static inline void sem_up(int semid) | 71 | static inline void sem_up(int semid) |
72 | { | 72 | { |
73 | if ( semop(semid, SMrup, 1) == -1 ) | 73 | if ( semop(semid, SMrup, 1) == -1 ) |
74 | error_exit("semop[SMrup]"); | 74 | error_exit("semop[SMrup]"); |
75 | } | 75 | } |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * sem_down - down()'s a semaphore | 78 | * sem_down - down()'s a semaphore |
79 | */ | 79 | */ |
80 | static inline void sem_down(int semid) | 80 | static inline void sem_down(int semid) |
81 | { | 81 | { |
82 | if ( semop(semid, SMrdn, 2) == -1 ) | 82 | if ( semop(semid, SMrdn, 2) == -1 ) |
83 | error_exit("semop[SMrdn]"); | 83 | error_exit("semop[SMrdn]"); |
84 | } | 84 | } |
85 | 85 | ||
86 | extern int logread_main(int argc, char **argv) | 86 | extern int logread_main(int argc, char **argv) |
87 | { | 87 | { |
88 | int i; | 88 | int i; |
89 | 89 | ||
90 | /* no options, no getopt */ | 90 | /* no options, no getopt */ |
91 | if (argc > 1) | 91 | if (argc > 1) |
92 | show_usage(); | 92 | show_usage(); |
93 | 93 | ||
94 | // handle intrrupt signal | 94 | // handle intrrupt signal |
95 | if (setjmp(jmp_env)) goto output_end; | 95 | if (setjmp(jmp_env)) goto output_end; |
96 | 96 | ||
97 | // attempt to redefine ^C signal | 97 | // attempt to redefine ^C signal |
98 | signal(SIGINT, interrupted); | 98 | signal(SIGINT, interrupted); |
99 | 99 | ||
100 | if ( (shmid = shmget(KEY_ID, 0, 0)) == -1) | 100 | if ( (shmid = shmget(KEY_ID, 0, 0)) == -1) |
101 | error_exit("Can't find circular buffer"); | 101 | error_exit("Can't find circular buffer"); |
102 | 102 | ||
103 | // Attach shared memory to our char* | 103 | // Attach shared memory to our char* |
104 | if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL) | 104 | if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL) |
105 | error_exit("Can't get access to circular buffer from syslogd"); | 105 | error_exit("Can't get access to circular buffer from syslogd"); |
106 | 106 | ||
107 | if ( (semid = semget(KEY_ID, 0, 0)) == -1) | 107 | if ( (semid = semget(KEY_ID, 0, 0)) == -1) |
108 | error_exit("Can't get access to semaphone(s) for circular buffer from syslogd"); | 108 | error_exit("Can't get access to semaphone(s) for circular buffer from syslogd"); |
109 | 109 | ||
110 | sem_down(semid); | 110 | sem_down(semid); |
111 | // Read Memory | 111 | // Read Memory |
112 | i=buf->head; | 112 | i=buf->head; |
113 | 113 | ||
114 | //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size); | 114 | //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size); |
115 | if (buf->head == buf->tail) { | 115 | if (buf->head == buf->tail) { |
116 | printf("<empty syslog>\n"); | 116 | printf("<empty syslog>\n"); |
117 | } | 117 | } |
118 | 118 | ||
119 | while ( i != buf->tail) { | 119 | while ( i != buf->tail) { |
120 | printf("%s", buf->data+i); | 120 | printf("%s", buf->data+i); |
121 | i+= strlen(buf->data+i) + 1; | 121 | i+= strlen(buf->data+i) + 1; |
122 | if (i >= buf->size ) | 122 | if (i >= buf->size ) |
123 | i=0; | 123 | i=0; |
124 | } | 124 | } |
125 | sem_up(semid); | 125 | sem_up(semid); |
126 | 126 | ||
127 | output_end: | 127 | output_end: |
128 | if (shmid != -1) | 128 | if (shmid != -1) |
129 | shmdt(buf); | 129 | shmdt(buf); |
130 | 130 | ||
131 | return EXIT_SUCCESS; | 131 | return EXIT_SUCCESS; |
132 | } | 132 | } |
133 | 133 | ||
134 | static void interrupted(int sig){ | 134 | static void interrupted(int sig){ |
135 | signal(SIGINT, SIG_IGN); | 135 | signal(SIGINT, SIG_IGN); |
136 | longjmp(jmp_env, 1); | 136 | longjmp(jmp_env, 1); |
137 | } | 137 | } |
138 | 138 | ||
139 | static void error_exit(const char *str){ | 139 | static void error_exit(const char *str){ |
140 | perror(str); | 140 | perror(str); |
141 | //release all acquired resources | 141 | //release all acquired resources |
142 | if (shmid != -1) | 142 | if (shmid != -1) |
143 | shmdt(buf); | 143 | shmdt(buf); |
144 | 144 | ||
145 | exit(1); | 145 | exit(1); |
146 | } | 146 | } |