Stuf
This commit is contained in:
parent
14ec6cf3c2
commit
0ecb54a0f3
@ -8,7 +8,12 @@
|
||||
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
|
||||
|
@ -74,6 +74,8 @@
|
||||
// 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)
|
||||
|
5
init.c
5
init.c
@ -45,6 +45,11 @@
|
||||
#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 */
|
||||
|
@ -45,6 +45,11 @@
|
||||
#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 */
|
||||
|
5
mount.c
5
mount.c
@ -163,6 +163,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
|
||||
char buf[255];
|
||||
|
||||
#if defined BB_FEATURE_USE_PROCFS
|
||||
if (strcmp(filesystemType, "auto") == 0) {
|
||||
FILE *f = fopen ("/proc/filesystems", "r");
|
||||
|
||||
@ -189,7 +190,9 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
}
|
||||
}
|
||||
fclose (f);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
status = do_mount (blockDevice, directory, filesystemType,
|
||||
flags | MS_MGC_VAL, string_flags, useMtab,
|
||||
fakeIt, mtab_opts);
|
||||
|
15
mtab.c
15
mtab.c
@ -26,8 +26,14 @@ erase_mtab(const char * name)
|
||||
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;
|
||||
}
|
||||
@ -76,13 +82,14 @@ write_mtab(char* blockDevice, char* directory,
|
||||
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";
|
||||
|
@ -28,6 +28,9 @@
|
||||
#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
|
||||
|
3
ps.c
3
ps.c
@ -28,6 +28,9 @@
|
||||
#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
|
||||
|
@ -57,13 +57,13 @@ static char LocalHostName[32];
|
||||
|
||||
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)
|
||||
@ -253,10 +253,9 @@ static void doSyslogd(void)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -264,7 +263,6 @@ static void klogd_signal(int sig)
|
||||
static void doKlogd(void)
|
||||
{
|
||||
int priority=LOG_INFO;
|
||||
struct stat sb;
|
||||
char log_buffer[4096];
|
||||
char *logp;
|
||||
|
||||
@ -277,26 +275,10 @@ static void doKlogd(void)
|
||||
"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 )
|
||||
@ -306,7 +288,6 @@ static void doKlogd(void)
|
||||
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
logp=log_buffer;
|
||||
if ( *log_buffer == '<' )
|
||||
{
|
||||
|
31
syslogd.c
31
syslogd.c
@ -57,13 +57,13 @@ static char LocalHostName[32];
|
||||
|
||||
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)
|
||||
@ -253,10 +253,9 @@ static void doSyslogd(void)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -264,7 +263,6 @@ static void klogd_signal(int sig)
|
||||
static void doKlogd(void)
|
||||
{
|
||||
int priority=LOG_INFO;
|
||||
struct stat sb;
|
||||
char log_buffer[4096];
|
||||
char *logp;
|
||||
|
||||
@ -277,26 +275,10 @@ static void doKlogd(void)
|
||||
"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 )
|
||||
@ -306,7 +288,6 @@ static void doKlogd(void)
|
||||
logMessage(LOG_SYSLOG|LOG_ERR, message);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
logp=log_buffer;
|
||||
if ( *log_buffer == '<' )
|
||||
{
|
||||
|
@ -163,6 +163,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
|
||||
char buf[255];
|
||||
|
||||
#if defined BB_FEATURE_USE_PROCFS
|
||||
if (strcmp(filesystemType, "auto") == 0) {
|
||||
FILE *f = fopen ("/proc/filesystems", "r");
|
||||
|
||||
@ -189,7 +190,9 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
}
|
||||
}
|
||||
fclose (f);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
status = do_mount (blockDevice, directory, filesystemType,
|
||||
flags | MS_MGC_VAL, string_flags, useMtab,
|
||||
fakeIt, mtab_opts);
|
||||
|
15
utility.c
15
utility.c
@ -36,12 +36,16 @@
|
||||
#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
|
||||
|
||||
|
||||
@ -56,6 +60,9 @@ extern void usage(const char *usage)
|
||||
|
||||
#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> }
|
||||
|
Loading…
Reference in New Issue
Block a user