aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h73
-rw-r--r--sysklogd/klogd.c13
-rw-r--r--util-linux/dmesg.c60
3 files changed, 77 insertions, 69 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 1adac8443..2593c3ad2 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -26,7 +26,6 @@
26#include <stdarg.h> 26#include <stdarg.h>
27#include <stddef.h> 27#include <stddef.h>
28#include <string.h> 28#include <string.h>
29/* #include <strings.h> - said to be obsolete */
30#include <sys/poll.h> 29#include <sys/poll.h>
31#include <sys/ioctl.h> 30#include <sys/ioctl.h>
32#include <sys/mman.h> 31#include <sys/mman.h>
@@ -40,6 +39,12 @@
40#include <time.h> 39#include <time.h>
41#include <unistd.h> 40#include <unistd.h>
42#include <utime.h> 41#include <utime.h>
42/* Try to pull in PATH_MAX */
43#include <limits.h>
44#include <sys/param.h>
45#ifndef PATH_MAX
46#define PATH_MAX 256
47#endif
43 48
44#if ENABLE_SELINUX 49#if ENABLE_SELINUX
45#include <selinux/selinux.h> 50#include <selinux/selinux.h>
@@ -62,14 +67,37 @@
62#include "shadow_.h" 67#include "shadow_.h"
63#endif 68#endif
64 69
65/* Try to pull in PATH_MAX */ 70#if defined(__GLIBC__) && __GLIBC__ < 2
66#include <limits.h> 71int vdprintf(int d, const char *format, va_list ap);
67#include <sys/param.h>
68#ifndef PATH_MAX
69#define PATH_MAX 256
70#endif 72#endif
73/* klogctl is in libc's klog.h, but we cheat and not #include that */
74int klogctl(int type, char *b, int len);
75/* This is declared here rather than #including <libgen.h> in order to avoid
76 * confusing the two versions of basename. See the dirname/basename man page
77 * for details. */
78char *dirname(char *path);
79/* Include our own copy of struct sysinfo to avoid binary compatibility
80 * problems with Linux 2.4, which changed things. Grumble, grumble. */
81struct sysinfo {
82 long uptime; /* Seconds since boot */
83 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
84 unsigned long totalram; /* Total usable main memory size */
85 unsigned long freeram; /* Available memory size */
86 unsigned long sharedram; /* Amount of shared memory */
87 unsigned long bufferram; /* Memory used by buffers */
88 unsigned long totalswap; /* Total swap space size */
89 unsigned long freeswap; /* swap space still available */
90 unsigned short procs; /* Number of current processes */
91 unsigned short pad; /* Padding needed for m68k */
92 unsigned long totalhigh; /* Total high memory size */
93 unsigned long freehigh; /* Available high memory size */
94 unsigned int mem_unit; /* Memory unit size in bytes */
95 char _f[20 - 2*sizeof(long) - sizeof(int)]; /* Padding: libc5 uses this.. */
96};
97int sysinfo(struct sysinfo* info);
98
71 99
72/* Tested to work correctly (IIRC :]) */ 100/* Tested to work correctly with all int types (IIRC :]) */
73#define MAXINT(T) (T)( \ 101#define MAXINT(T) (T)( \
74 ((T)-1) > 0 \ 102 ((T)-1) > 0 \
75 ? (T)-1 \ 103 ? (T)-1 \
@@ -83,7 +111,7 @@
83 ) 111 )
84 112
85/* Large file support */ 113/* Large file support */
86/* Note that CONFIG_LFS forces bbox to be built with all common ops 114/* Note that CONFIG_LFS=y forces bbox to be built with all common ops
87 * (stat, lseek etc) mapped to "largefile" variants by libc. 115 * (stat, lseek etc) mapped to "largefile" variants by libc.
88 * Practically it means that open() automatically has O_LARGEFILE added 116 * Practically it means that open() automatically has O_LARGEFILE added
89 * and all filesize/file_offset parameters and struct members are "large" 117 * and all filesize/file_offset parameters and struct members are "large"
@@ -167,7 +195,6 @@
167#endif 195#endif
168#endif 196#endif
169 197
170
171#if defined(__GLIBC__) 198#if defined(__GLIBC__)
172/* glibc uses __errno_location() to get a ptr to errno */ 199/* glibc uses __errno_location() to get a ptr to errno */
173/* We can just memorize it once - no multithreading in busybox :) */ 200/* We can just memorize it once - no multithreading in busybox :) */
@@ -176,33 +203,6 @@ extern int *const bb_errno;
176#define errno (*bb_errno) 203#define errno (*bb_errno)
177#endif 204#endif
178 205
179#if defined(__GLIBC__) && __GLIBC__ < 2
180int vdprintf(int d, const char *format, va_list ap);
181#endif
182// This is declared here rather than #including <libgen.h> in order to avoid
183// confusing the two versions of basename. See the dirname/basename man page
184// for details.
185char *dirname(char *path);
186/* Include our own copy of struct sysinfo to avoid binary compatibility
187 * problems with Linux 2.4, which changed things. Grumble, grumble. */
188struct sysinfo {
189 long uptime; /* Seconds since boot */
190 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
191 unsigned long totalram; /* Total usable main memory size */
192 unsigned long freeram; /* Available memory size */
193 unsigned long sharedram; /* Amount of shared memory */
194 unsigned long bufferram; /* Memory used by buffers */
195 unsigned long totalswap; /* Total swap space size */
196 unsigned long freeswap; /* swap space still available */
197 unsigned short procs; /* Number of current processes */
198 unsigned short pad; /* Padding needed for m68k */
199 unsigned long totalhigh; /* Total high memory size */
200 unsigned long freehigh; /* Available high memory size */
201 unsigned int mem_unit; /* Memory unit size in bytes */
202 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
203};
204int sysinfo(struct sysinfo* info);
205
206unsigned long long monotonic_us(void); 206unsigned long long monotonic_us(void);
207unsigned monotonic_sec(void); 207unsigned monotonic_sec(void);
208 208
@@ -788,7 +788,6 @@ extern int set_loop(char **devname, const char *file, unsigned long long offset)
788//TODO: pass buf pointer or return allocated buf (avoid statics)? 788//TODO: pass buf pointer or return allocated buf (avoid statics)?
789char *bb_askpass(int timeout, const char * prompt); 789char *bb_askpass(int timeout, const char * prompt);
790int bb_ask_confirmation(void); 790int bb_ask_confirmation(void);
791int klogctl(int type, char * b, int len);
792 791
793extern int bb_parse_mode(const char* s, mode_t* theMode); 792extern int bb_parse_mode(const char* s, mode_t* theMode);
794 793
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 11642461d..72f3b559c 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -24,16 +24,17 @@
24static void klogd_signal(int sig ATTRIBUTE_UNUSED) 24static void klogd_signal(int sig ATTRIBUTE_UNUSED)
25{ 25{
26 klogctl(7, NULL, 0); 26 klogctl(7, NULL, 0);
27 klogctl(0, 0, 0); 27 klogctl(0, NULL, 0);
28 syslog(LOG_NOTICE, "Kernel log daemon exiting"); 28 syslog(LOG_NOTICE, "klogd: exiting");
29 exit(EXIT_SUCCESS); 29 exit(EXIT_SUCCESS);
30} 30}
31 31
32#define OPT_LEVEL 1
33#define OPT_FOREGROUND 2
34
35#define KLOGD_LOGBUF_SIZE BUFSIZ
36#define log_buffer bb_common_bufsiz1 32#define log_buffer bb_common_bufsiz1
33enum {
34 KLOGD_LOGBUF_SIZE = sizeof(log_buffer),
35 OPT_LEVEL = (1 << 0),
36 OPT_FOREGROUND = (1 << 1),
37};
37 38
38int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 39int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
39int klogd_main(int argc, char **argv) 40int klogd_main(int argc, char **argv)
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index 90b327b4c..cdd385ede 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -15,40 +15,48 @@
15int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 15int dmesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16int dmesg_main(int argc, char **argv) 16int dmesg_main(int argc, char **argv)
17{ 17{
18 int len;
19 char *buf;
18 char *size, *level; 20 char *size, *level;
19 int flags = getopt32(argv, "cs:n:", &size, &level); 21 int flags = getopt32(argv, "cs:n:", &size, &level);
20 22
21 if (flags & 4) { 23 if (flags & 4) {
22 if (klogctl(8, NULL, xatoul_range(level, 0, 10))) 24 if (klogctl(8, NULL, xatoul_range(level, 0, 10)))
23 bb_perror_msg_and_die("klogctl"); 25 bb_perror_msg_and_die("klogctl");
24 } else { 26 return EXIT_SUCCESS;
25 int len; 27 }
26 char *buf;
27
28 len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384;
29 buf = xmalloc(len);
30 len = klogctl(3 + (flags & 1), buf, len);
31 if (len < 0)
32 bb_perror_msg_and_die("klogctl");
33
34 // Skip <#> at the start of lines, and make sure we end with a newline.
35
36 if (ENABLE_FEATURE_DMESG_PRETTY) {
37 int last = '\n';
38 int in;
39 28
40 for (in = 0; in<len;) { 29 len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384;
41 if (last == '\n' && buf[in] == '<') in += 3; 30 buf = xmalloc(len);
42 else bb_putchar(last = buf[in++]); 31 len = klogctl(3 + (flags & 1), buf, len);
32 if (len < 0)
33 bb_perror_msg_and_die("klogctl");
34 if (len == 0)
35 return EXIT_SUCCESS;
36
37 /* Skip <#> at the start of lines, and make sure we end with a newline. */
38
39 if (ENABLE_FEATURE_DMESG_PRETTY) {
40 int last = '\n';
41 int in = 0;
42
43 do {
44 if (last == '\n' && buf[in] == '<')
45 in += 3;
46 else {
47 last = buf[in++];
48 bb_putchar(last);
43 } 49 }
44 if (last != '\n') bb_putchar('\n'); 50 } while (in < len);
45 } else { 51 if (last != '\n')
46 write(1,buf,len); 52 bb_putchar('\n');
47 if (len && buf[len-1]!='\n') bb_putchar('\n'); 53 } else {
48 } 54 full_write(STDOUT_FILENO, buf, len);
49 55 if (buf[len-1] != '\n')
50 if (ENABLE_FEATURE_CLEAN_UP) free(buf); 56 bb_putchar('\n');
51 } 57 }
52 58
53 return 0; 59 if (ENABLE_FEATURE_CLEAN_UP) free(buf);
60
61 return EXIT_SUCCESS;
54} 62}