Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/sysklogd/logread.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/sysklogd/logread.c
r3232 r3621 9 9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 10 */ 11 //config:config LOGREAD 12 //config: bool "logread" 13 //config: default y 14 //config: depends on FEATURE_IPC_SYSLOG 15 //config: help 16 //config: If you enabled Circular Buffer support, you almost 17 //config: certainly want to enable this feature as well. This 18 //config: utility will allow you to read the messages that are 19 //config: stored in the syslogd circular buffer. 20 //config: 21 //config:config FEATURE_LOGREAD_REDUCED_LOCKING 22 //config: bool "Double buffering" 23 //config: default y 24 //config: depends on LOGREAD 25 //config: help 26 //config: 'logread' ouput to slow serial terminals can have 27 //config: side effects on syslog because of the semaphore. 28 //config: This option make logread to double buffer copy 29 //config: from circular buffer, minimizing semaphore 30 //config: contention at some minor memory expense. 31 //config: 32 33 //applet:IF_LOGREAD(APPLET(logread, BB_DIR_SBIN, BB_SUID_DROP)) 34 35 //kbuild:lib-$(CONFIG_LOGREAD) += logread.o 11 36 12 37 //usage:#define logread_trivial_usage 13 //usage: "[-f ]"38 //usage: "[-fF]" 14 39 //usage:#define logread_full_usage "\n\n" 15 40 //usage: "Show messages in syslogd's circular buffer\n" 16 41 //usage: "\n -f Output data as log grows" 42 //usage: "\n -F Same as -f, but dump buffer first" 17 43 18 44 #include "libbb.h" 45 #include "common_bufsiz.h" 19 46 #include <sys/ipc.h> 20 47 #include <sys/sem.h> … … 42 69 struct shbuf_ds *shbuf; 43 70 } FIX_ALIASING; 44 #define G (*(struct globals*) &bb_common_bufsiz1)71 #define G (*(struct globals*)bb_common_bufsiz1) 45 72 #define SMrup (G.SMrup) 46 73 #define SMrdn (G.SMrdn) 47 74 #define shbuf (G.shbuf) 48 75 #define INIT_G() do { \ 76 setup_common_bufsiz(); \ 49 77 memcpy(SMrup, init_sem, sizeof(init_sem)); \ 50 78 } while (0) 51 79 80 #if 0 52 81 static void error_exit(const char *str) NORETURN; 53 82 static void error_exit(const char *str) 54 83 { 55 / /release all acquired resources84 /* Release all acquired resources */ 56 85 shmdt(shbuf); 57 86 bb_perror_msg_and_die(str); 58 87 } 88 #else 89 /* On Linux, shmdt is not mandatory on exit */ 90 # define error_exit(str) bb_perror_msg_and_die(str) 91 #endif 59 92 60 93 /* … … 67 100 } 68 101 69 static void interrupted(int sig UNUSED_PARAM) 70 { 71 signal(SIGINT, SIG_IGN); 72 shmdt(shbuf); 73 exit(EXIT_SUCCESS); 102 static void interrupted(int sig) 103 { 104 /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */ 105 kill_myself_with_sig(sig); 74 106 } 75 107 … … 80 112 int log_semid; /* ipc semaphore id */ 81 113 int log_shmid; /* ipc shared memory id */ 82 smallint follow = getopt32(argv, "f");114 int follow = getopt32(argv, "fF"); 83 115 84 116 INIT_G(); … … 86 118 log_shmid = shmget(KEY_ID, 0, 0); 87 119 if (log_shmid == -1) 88 bb_perror_msg_and_die("can't find syslogd buffer");120 bb_perror_msg_and_die("can't %s syslogd buffer", "find"); 89 121 90 122 /* Attach shared memory to our char* */ 91 123 shbuf = shmat(log_shmid, NULL, SHM_RDONLY); 92 124 if (shbuf == NULL) 93 bb_perror_msg_and_die("can't access syslogd buffer");125 bb_perror_msg_and_die("can't %s syslogd buffer", "access"); 94 126 95 127 log_semid = semget(KEY_ID, 0, 0); … … 97 129 error_exit("can't get access to semaphores for syslogd buffer"); 98 130 99 signal(SIGINT, interrupted);131 bb_signals(BB_FATAL_SIGS, interrupted); 100 132 101 133 /* Suppose atomic memory read */ … … 103 135 cur = shbuf->tail; 104 136 105 /* Loop for logread -f, one pass if there was no -f*/137 /* Loop for -f or -F, one pass otherwise */ 106 138 do { 107 139 unsigned shbuf_size; … … 123 155 124 156 if (DEBUG) 125 printf("cur:% d tail:%i size:%i\n",157 printf("cur:%u tail:%u size:%u\n", 126 158 cur, shbuf_tail, shbuf_size); 127 159 128 if (!follow) { 160 if (!(follow & 1)) { /* not -f */ 161 /* if -F, "convert" it to -f, so that we dont 162 * dump the entire buffer on each iteration 163 */ 164 follow >>= 1; 165 129 166 /* advance to oldest complete message */ 130 167 /* find NUL */ … … 139 176 if (cur >= shbuf_size) /* last byte in buffer? */ 140 177 cur = 0; 141 } else { /* logread-f */178 } else { /* -f */ 142 179 if (cur == shbuf_tail) { 143 180 sem_up(log_semid); … … 184 221 free(copy); 185 222 #endif 223 fflush_all(); 186 224 } while (follow); 187 225 188 shmdt(shbuf);226 /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */ 189 227 190 228 fflush_stdout_and_exit(EXIT_SUCCESS);
Note:
See TracChangeset
for help on using the changeset viewer.