was causing some confusing and unexpected behavior.
* Added klogd to syslogd, so now the log will contain both system and
kernel messages.
-
+ * syslogd now creates the /dev/log socket to make sure it is there, and
+ is actually a socket with the right permissions.
+ * I've taken a first step to making busybox not need the /proc filesystem.
+ Most apps don't need it. Those that _require_ it, will complain
+ if you enable them when you disable BB_FEATURE_USE_PROCFS.
+
-Erik Andrsen
0.37
// pretty/useful).
//
//
+// enable features that use the /proc filesystem
+#define BB_FEATURE_USE_PROCFS
//Enable init being called as /linuxrc
#define BB_FEATURE_LINUXRC
// Use termios to manipulate the screen ('more' is prettier with this on)
#include <sys/syslog.h>
#endif
+#if ! defined BB_FEATURE_USE_PROCFS
+#error Sorry, I depend on the /proc filesystem right now.
+#endif
+
+
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
#define VT_LOG "/dev/tty3" /* Virtual console */
#include <sys/syslog.h>
#endif
+#if ! defined BB_FEATURE_USE_PROCFS
+#error Sorry, I depend on the /proc filesystem right now.
+#endif
+
+
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
#define VT_LOG "/dev/tty3" /* Virtual console */
char buf[255];
+#if defined BB_FEATURE_USE_PROCFS
if (strcmp(filesystemType, "auto") == 0) {
FILE *f = fopen ("/proc/filesystems", "r");
}
}
fclose (f);
- } else {
+ } else
+#endif
+ {
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab,
fakeIt, mtab_opts);
FILE *mountTable = setmntent(mtab_file, "r");
struct mntent * m;
- if ( mountTable == 0
- && (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
+ /* Check if reading the mtab file failed */
+ if ( mountTable == 0
+#if ! defined BB_FEATURE_USE_PROCFS
+ ) {
+#else
+ /* Bummer. fall back on trying the /proc filesystem */
+ && (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
+#endif
perror(mtab_file);
return;
}
if ( length > 1 && directory[length - 1] == '/' )
directory[length - 1] = '\0';
+#ifdef BB_FEATURE_USE_PROCFS
if ( filesystemType == 0 ) {
- struct mntent * p
- = findMountPoint(blockDevice, "/proc/mounts");
+ struct mntent *p = findMountPoint(blockDevice, "/proc/mounts");
if ( p && p->mnt_type )
filesystemType = p->mnt_type;
}
+#endif
m.mnt_fsname = blockDevice;
m.mnt_dir = directory;
m.mnt_type = filesystemType ? filesystemType : "default";
#include <fcntl.h>
#include <ctype.h>
+#if ! defined BB_FEATURE_USE_PROCFS
+#error Sorry, I depend on the /proc filesystem right now.
+#endif
typedef struct proc_s {
char
#include <fcntl.h>
#include <ctype.h>
+#if ! defined BB_FEATURE_USE_PROCFS
+#error Sorry, I depend on the /proc filesystem right now.
+#endif
typedef struct proc_s {
char
static const char syslogd_usage[] =
"syslogd [OPTION]...\n\n"
- "Linux system logging utility.\n\n"
+ "Linux system and kernel (provides klogd) logging utility.\n"
+ "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n"
"Options:\n"
"\t-m\tChange the mark timestamp interval. default=20min. 0=off\n"
"\t-n\tDo not fork into the background (for when run by init)\n"
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
-static int kmsg;
/* try to open up the specified device */
static int device_open(char *device, int mode)
static void klogd_signal(int sig)
{
- //ksyslog(7, NULL, 0);
- //ksyslog(0, 0, 0);
+ ksyslog(7, NULL, 0);
+ ksyslog(0, 0, 0);
logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon exiting.");
- close( kmsg);
exit( TRUE);
}
static void doKlogd(void)
{
int priority=LOG_INFO;
- struct stat sb;
char log_buffer[4096];
char *logp;
"BusyBox v" BB_VER " (" BB_BT ")");
ksyslog(1, NULL, 0);
- if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ||
- ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) {
- char message[80];
- snprintf(message, 79, "klogd: Cannot open %s, " \
- "%d - %s.\n", _PATH_KLOG, errno, strerror(errno));
- logMessage(LOG_SYSLOG|LOG_ERR, message);
- klogd_signal(0);
- }
+
while (1) {
+ /* Use kernel syscalls */
memset(log_buffer, '\0', sizeof(log_buffer));
- if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) {
- char message[80];
- if ( errno == EINTR )
- continue;
- snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n",
- errno, strerror(errno));
- logMessage(LOG_SYSLOG|LOG_ERR, message);
- klogd_signal(0);
- }
-#if 0
if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) {
char message[80];
if ( errno == EINTR )
logMessage(LOG_SYSLOG|LOG_ERR, message);
exit(1);
}
-#endif
logp=log_buffer;
if ( *log_buffer == '<' )
{
static const char syslogd_usage[] =
"syslogd [OPTION]...\n\n"
- "Linux system logging utility.\n\n"
+ "Linux system and kernel (provides klogd) logging utility.\n"
+ "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n"
"Options:\n"
"\t-m\tChange the mark timestamp interval. default=20min. 0=off\n"
"\t-n\tDo not fork into the background (for when run by init)\n"
"\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
-static int kmsg;
/* try to open up the specified device */
static int device_open(char *device, int mode)
static void klogd_signal(int sig)
{
- //ksyslog(7, NULL, 0);
- //ksyslog(0, 0, 0);
+ ksyslog(7, NULL, 0);
+ ksyslog(0, 0, 0);
logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon exiting.");
- close( kmsg);
exit( TRUE);
}
static void doKlogd(void)
{
int priority=LOG_INFO;
- struct stat sb;
char log_buffer[4096];
char *logp;
"BusyBox v" BB_VER " (" BB_BT ")");
ksyslog(1, NULL, 0);
- if ( ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ||
- ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) ) {
- char message[80];
- snprintf(message, 79, "klogd: Cannot open %s, " \
- "%d - %s.\n", _PATH_KLOG, errno, strerror(errno));
- logMessage(LOG_SYSLOG|LOG_ERR, message);
- klogd_signal(0);
- }
+
while (1) {
+ /* Use kernel syscalls */
memset(log_buffer, '\0', sizeof(log_buffer));
- if ( read(kmsg, log_buffer, sizeof(log_buffer)-1) < 0 ) {
- char message[80];
- if ( errno == EINTR )
- continue;
- snprintf(message, 79, "klogd: Cannot read proc file system: %d - %s.\n",
- errno, strerror(errno));
- logMessage(LOG_SYSLOG|LOG_ERR, message);
- klogd_signal(0);
- }
-#if 0
if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) {
char message[80];
if ( errno == EINTR )
logMessage(LOG_SYSLOG|LOG_ERR, message);
exit(1);
}
-#endif
logp=log_buffer;
if ( *log_buffer == '<' )
{
char buf[255];
+#if defined BB_FEATURE_USE_PROCFS
if (strcmp(filesystemType, "auto") == 0) {
FILE *f = fopen ("/proc/filesystems", "r");
}
}
fclose (f);
- } else {
+ } else
+#endif
+ {
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab,
fakeIt, mtab_opts);
#include <unistd.h>
#include <ctype.h>
-#ifdef BB_MTAB
-const char mtab_file[] = "/etc/mtab";
-#else
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
+# if defined BB_FEATURE_USE_PROCFS
const char mtab_file[] = "/proc/mounts";
-#endif
+# else
+# if defined BB_MTAB
+const char mtab_file[] = "/etc/mtab";
+# else
+# error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or BB_FEATURE_USE_PROCFS
+# endif
+# endif
#endif
#if defined (BB_INIT) || defined (BB_PS)
+#if ! defined BB_FEATURE_USE_PROCFS
+#error Sorry, I depend on the /proc filesystem right now.
+#endif
/* Returns kernel version encoded as major*65536 + minor*256 + patch,
* so, for example, to check if the kernel is greater than 2.2.11:
* if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }