-/* vi: set sw=4 ts=4: */\r
-/*\r
- * circular buffer syslog implementation for busybox\r
- *\r
- * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com>\r
- *\r
- * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- */\r
-\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <sys/ipc.h>\r
-#include <sys/types.h>\r
-#include <sys/sem.h>\r
-#include <sys/shm.h>\r
-#include <signal.h>\r
-#include <setjmp.h>\r
-#include "busybox.h"\r
-\r
-/* Stupid libc doesn't have a reliable way for use to know \r
- * that libc5 is being used. Assume this is good enough */ \r
-#if ! defined __GLIBC__ && ! defined __UCLIBC__\r
-#error Sorry. Looks like you are using libc5. \r
-#error libc5 shm support isnt good enough.\r
-#error Please disable BB_FEATURE_IPC_SYSLOG \r
-#endif \r
-\r
-\r
-static const long KEY_ID = 0x414e4547; /*"GENA"*/\r
-\r
-static struct shbuf_ds {\r
- int size; // size of data written\r
- int head; // start of message list\r
- int tail; // end of message list\r
- char data[1]; // data/messages\r
-} *buf = NULL; // shared memory pointer\r
-\r
-\r
-// Semaphore operation structures\r
-static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup\r
-static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn\r
-\r
-static int shmid = -1; // ipc shared memory id\r
-static int semid = -1; // ipc semaphore id\r
-static jmp_buf jmp_env;\r
-\r
-static void error_exit(const char *str);\r
-static void interrupted(int sig);\r
-\r
-/*\r
- * sem_up - up()'s a semaphore.\r
- */\r
-static inline void sem_up(int semid)\r
-{\r
- if ( semop(semid, SMrup, 1) == -1 ) \r
- error_exit("semop[SMrup]");\r
-}\r
-\r
-/*\r
- * sem_down - down()'s a semaphore\r
- */ \r
-static inline void sem_down(int semid)\r
-{\r
- if ( semop(semid, SMrdn, 2) == -1 )\r
- error_exit("semop[SMrdn]");\r
-}\r
-\r
-extern int logread_main(int argc, char **argv)\r
-{\r
- int i;\r
- \r
- /* no options, no getopt */\r
- if (argc > 1)\r
- show_usage();\r
- \r
- // handle intrrupt signal\r
- if (setjmp(jmp_env)) goto output_end;\r
- \r
- // attempt to redefine ^C signal\r
- signal(SIGINT, interrupted);\r
- \r
- if ( (shmid = shmget(KEY_ID, 0, 0)) == -1)\r
- error_exit("Can't find circular buffer");\r
- \r
- // Attach shared memory to our char*\r
- if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL)\r
- error_exit("Can't get access to circular buffer from syslogd");\r
-\r
- if ( (semid = semget(KEY_ID, 0, 0)) == -1)\r
- error_exit("Can't get access to semaphone(s) for circular buffer from syslogd");\r
-\r
- sem_down(semid); \r
- // Read Memory \r
- i=buf->head;\r
-\r
- //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size);\r
- if (buf->head == buf->tail) {\r
- printf("<empty syslog>\n");\r
- }\r
- \r
- while ( i != buf->tail) {\r
- printf("%s", buf->data+i);\r
- i+= strlen(buf->data+i) + 1;\r
- if (i >= buf->size )\r
- i=0;\r
- }\r
- sem_up(semid);\r
-\r
-output_end:\r
- if (shmid != -1) \r
- shmdt(buf);\r
- \r
- return EXIT_SUCCESS; \r
-}\r
-\r
-static void interrupted(int sig){\r
- signal(SIGINT, SIG_IGN);\r
- longjmp(jmp_env, 1);\r
-}\r
-\r
-static void error_exit(const char *str){\r
- perror(str);\r
- //release all acquired resources\r
- if (shmid != -1) \r
- shmdt(buf);\r
-\r
- exit(1);\r
-}\r
+/* vi: set sw=4 ts=4: */
+/*
+ * circular buffer syslog implementation for busybox
+ *
+ * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com>
+ *
+ * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA
+ *
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ipc.h>
+#include <sys/types.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
+#include <signal.h>
+#include <setjmp.h>
+#include "busybox.h"
+
+/* Stupid libc doesn't have a reliable way for use to know
+ * that libc5 is being used. Assume this is good enough */
+#if ! defined __GLIBC__ && ! defined __UCLIBC__
+#error Sorry. Looks like you are using libc5.
+#error libc5 shm support isnt good enough.
+#error Please disable BB_FEATURE_IPC_SYSLOG
+#endif
+
+
+static const long KEY_ID = 0x414e4547; /*"GENA"*/
+
+static struct shbuf_ds {
+ int size; // size of data written
+ int head; // start of message list
+ int tail; // end of message list
+ char data[1]; // data/messages
+} *buf = NULL; // shared memory pointer
+
+
+// Semaphore operation structures
+static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup
+static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn
+
+static int shmid = -1; // ipc shared memory id
+static int semid = -1; // ipc semaphore id
+static jmp_buf jmp_env;
+
+static void error_exit(const char *str);
+static void interrupted(int sig);
+
+/*
+ * sem_up - up()'s a semaphore.
+ */
+static inline void sem_up(int semid)
+{
+ if ( semop(semid, SMrup, 1) == -1 )
+ error_exit("semop[SMrup]");
+}
+
+/*
+ * sem_down - down()'s a semaphore
+ */
+static inline void sem_down(int semid)
+{
+ if ( semop(semid, SMrdn, 2) == -1 )
+ error_exit("semop[SMrdn]");
+}
+
+extern int logread_main(int argc, char **argv)
+{
+ int i;
+
+ /* no options, no getopt */
+ if (argc > 1)
+ show_usage();
+
+ // handle intrrupt signal
+ if (setjmp(jmp_env)) goto output_end;
+
+ // attempt to redefine ^C signal
+ signal(SIGINT, interrupted);
+
+ if ( (shmid = shmget(KEY_ID, 0, 0)) == -1)
+ error_exit("Can't find circular buffer");
+
+ // Attach shared memory to our char*
+ if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL)
+ error_exit("Can't get access to circular buffer from syslogd");
+
+ if ( (semid = semget(KEY_ID, 0, 0)) == -1)
+ error_exit("Can't get access to semaphone(s) for circular buffer from syslogd");
+
+ sem_down(semid);
+ // Read Memory
+ i=buf->head;
+
+ //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size);
+ if (buf->head == buf->tail) {
+ printf("<empty syslog>\n");
+ }
+
+ while ( i != buf->tail) {
+ printf("%s", buf->data+i);
+ i+= strlen(buf->data+i) + 1;
+ if (i >= buf->size )
+ i=0;
+ }
+ sem_up(semid);
+
+output_end:
+ if (shmid != -1)
+ shmdt(buf);
+
+ return EXIT_SUCCESS;
+}
+
+static void interrupted(int sig){
+ signal(SIGINT, SIG_IGN);
+ longjmp(jmp_env, 1);
+}
+
+static void error_exit(const char *str){
+ perror(str);
+ //release all acquired resources
+ if (shmid != -1)
+ shmdt(buf);
+
+ exit(1);
+}
-/* vi: set sw=4 ts=4: */\r
-/*\r
- * circular buffer syslog implementation for busybox\r
- *\r
- * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com>\r
- *\r
- * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- */\r
-\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <sys/ipc.h>\r
-#include <sys/types.h>\r
-#include <sys/sem.h>\r
-#include <sys/shm.h>\r
-#include <signal.h>\r
-#include <setjmp.h>\r
-#include "busybox.h"\r
-\r
-/* Stupid libc doesn't have a reliable way for use to know \r
- * that libc5 is being used. Assume this is good enough */ \r
-#if ! defined __GLIBC__ && ! defined __UCLIBC__\r
-#error Sorry. Looks like you are using libc5. \r
-#error libc5 shm support isnt good enough.\r
-#error Please disable BB_FEATURE_IPC_SYSLOG \r
-#endif \r
-\r
-\r
-static const long KEY_ID = 0x414e4547; /*"GENA"*/\r
-\r
-static struct shbuf_ds {\r
- int size; // size of data written\r
- int head; // start of message list\r
- int tail; // end of message list\r
- char data[1]; // data/messages\r
-} *buf = NULL; // shared memory pointer\r
-\r
-\r
-// Semaphore operation structures\r
-static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup\r
-static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn\r
-\r
-static int shmid = -1; // ipc shared memory id\r
-static int semid = -1; // ipc semaphore id\r
-static jmp_buf jmp_env;\r
-\r
-static void error_exit(const char *str);\r
-static void interrupted(int sig);\r
-\r
-/*\r
- * sem_up - up()'s a semaphore.\r
- */\r
-static inline void sem_up(int semid)\r
-{\r
- if ( semop(semid, SMrup, 1) == -1 ) \r
- error_exit("semop[SMrup]");\r
-}\r
-\r
-/*\r
- * sem_down - down()'s a semaphore\r
- */ \r
-static inline void sem_down(int semid)\r
-{\r
- if ( semop(semid, SMrdn, 2) == -1 )\r
- error_exit("semop[SMrdn]");\r
-}\r
-\r
-extern int logread_main(int argc, char **argv)\r
-{\r
- int i;\r
- \r
- /* no options, no getopt */\r
- if (argc > 1)\r
- show_usage();\r
- \r
- // handle intrrupt signal\r
- if (setjmp(jmp_env)) goto output_end;\r
- \r
- // attempt to redefine ^C signal\r
- signal(SIGINT, interrupted);\r
- \r
- if ( (shmid = shmget(KEY_ID, 0, 0)) == -1)\r
- error_exit("Can't find circular buffer");\r
- \r
- // Attach shared memory to our char*\r
- if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL)\r
- error_exit("Can't get access to circular buffer from syslogd");\r
-\r
- if ( (semid = semget(KEY_ID, 0, 0)) == -1)\r
- error_exit("Can't get access to semaphone(s) for circular buffer from syslogd");\r
-\r
- sem_down(semid); \r
- // Read Memory \r
- i=buf->head;\r
-\r
- //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size);\r
- if (buf->head == buf->tail) {\r
- printf("<empty syslog>\n");\r
- }\r
- \r
- while ( i != buf->tail) {\r
- printf("%s", buf->data+i);\r
- i+= strlen(buf->data+i) + 1;\r
- if (i >= buf->size )\r
- i=0;\r
- }\r
- sem_up(semid);\r
-\r
-output_end:\r
- if (shmid != -1) \r
- shmdt(buf);\r
- \r
- return EXIT_SUCCESS; \r
-}\r
-\r
-static void interrupted(int sig){\r
- signal(SIGINT, SIG_IGN);\r
- longjmp(jmp_env, 1);\r
-}\r
-\r
-static void error_exit(const char *str){\r
- perror(str);\r
- //release all acquired resources\r
- if (shmid != -1) \r
- shmdt(buf);\r
-\r
- exit(1);\r
-}\r
+/* vi: set sw=4 ts=4: */
+/*
+ * circular buffer syslog implementation for busybox
+ *
+ * Copyright (C) 2000 by Gennady Feldman <gfeldman@cachier.com>
+ *
+ * Maintainer: Gennady Feldman <gena01@cachier.com> as of Mar 12, 2001
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA
+ *
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ipc.h>
+#include <sys/types.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
+#include <signal.h>
+#include <setjmp.h>
+#include "busybox.h"
+
+/* Stupid libc doesn't have a reliable way for use to know
+ * that libc5 is being used. Assume this is good enough */
+#if ! defined __GLIBC__ && ! defined __UCLIBC__
+#error Sorry. Looks like you are using libc5.
+#error libc5 shm support isnt good enough.
+#error Please disable BB_FEATURE_IPC_SYSLOG
+#endif
+
+
+static const long KEY_ID = 0x414e4547; /*"GENA"*/
+
+static struct shbuf_ds {
+ int size; // size of data written
+ int head; // start of message list
+ int tail; // end of message list
+ char data[1]; // data/messages
+} *buf = NULL; // shared memory pointer
+
+
+// Semaphore operation structures
+static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup
+static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn
+
+static int shmid = -1; // ipc shared memory id
+static int semid = -1; // ipc semaphore id
+static jmp_buf jmp_env;
+
+static void error_exit(const char *str);
+static void interrupted(int sig);
+
+/*
+ * sem_up - up()'s a semaphore.
+ */
+static inline void sem_up(int semid)
+{
+ if ( semop(semid, SMrup, 1) == -1 )
+ error_exit("semop[SMrup]");
+}
+
+/*
+ * sem_down - down()'s a semaphore
+ */
+static inline void sem_down(int semid)
+{
+ if ( semop(semid, SMrdn, 2) == -1 )
+ error_exit("semop[SMrdn]");
+}
+
+extern int logread_main(int argc, char **argv)
+{
+ int i;
+
+ /* no options, no getopt */
+ if (argc > 1)
+ show_usage();
+
+ // handle intrrupt signal
+ if (setjmp(jmp_env)) goto output_end;
+
+ // attempt to redefine ^C signal
+ signal(SIGINT, interrupted);
+
+ if ( (shmid = shmget(KEY_ID, 0, 0)) == -1)
+ error_exit("Can't find circular buffer");
+
+ // Attach shared memory to our char*
+ if ( (buf = shmat(shmid, NULL, SHM_RDONLY)) == NULL)
+ error_exit("Can't get access to circular buffer from syslogd");
+
+ if ( (semid = semget(KEY_ID, 0, 0)) == -1)
+ error_exit("Can't get access to semaphone(s) for circular buffer from syslogd");
+
+ sem_down(semid);
+ // Read Memory
+ i=buf->head;
+
+ //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size);
+ if (buf->head == buf->tail) {
+ printf("<empty syslog>\n");
+ }
+
+ while ( i != buf->tail) {
+ printf("%s", buf->data+i);
+ i+= strlen(buf->data+i) + 1;
+ if (i >= buf->size )
+ i=0;
+ }
+ sem_up(semid);
+
+output_end:
+ if (shmid != -1)
+ shmdt(buf);
+
+ return EXIT_SUCCESS;
+}
+
+static void interrupted(int sig){
+ signal(SIGINT, SIG_IGN);
+ longjmp(jmp_env, 1);
+}
+
+static void error_exit(const char *str){
+ perror(str);
+ //release all acquired resources
+ if (shmid != -1)
+ shmdt(buf);
+
+ exit(1);
+}