convert calloc to xzalloc
fix sleep-on-die option
This commit is contained in:
parent
bb3d0fab3b
commit
9b1381fd2f
@ -397,6 +397,7 @@ extern const char *msg_eol;
|
|||||||
extern int logmode;
|
extern int logmode;
|
||||||
extern int die_sleep;
|
extern int die_sleep;
|
||||||
extern int xfunc_error_retval;
|
extern int xfunc_error_retval;
|
||||||
|
extern void sleep_and_die(void) ATTRIBUTE_NORETURN;
|
||||||
extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
|
extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||||
extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
|
extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
|
extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
|
||||||
|
50
init/init.c
50
init/init.c
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "init_shared.h"
|
#include "init_shared.h"
|
||||||
|
|
||||||
#ifdef CONFIG_SYSLOGD
|
#if ENABLE_SYSLOGD
|
||||||
# include <sys/syslog.h>
|
# include <sys/syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ struct serial_struct {
|
|||||||
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
|
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined CONFIG_FEATURE_INIT_COREDUMPS
|
#if ENABLE_FEATURE_INIT_COREDUMPS
|
||||||
/*
|
/*
|
||||||
* When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
|
* When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
|
||||||
* before processes are spawned to set core file size as unlimited.
|
* before processes are spawned to set core file size as unlimited.
|
||||||
@ -121,7 +121,7 @@ struct init_action {
|
|||||||
static struct init_action *init_action_list = NULL;
|
static struct init_action *init_action_list = NULL;
|
||||||
static char console[CONSOLE_BUFF_SIZE] = CONSOLE_DEV;
|
static char console[CONSOLE_BUFF_SIZE] = CONSOLE_DEV;
|
||||||
|
|
||||||
#ifndef CONFIG_SYSLOGD
|
#if !ENABLE_SYSLOGD
|
||||||
static char *log_console = VC_5;
|
static char *log_console = VC_5;
|
||||||
#endif
|
#endif
|
||||||
#if !ENABLE_DEBUG_INIT
|
#if !ENABLE_DEBUG_INIT
|
||||||
@ -132,7 +132,7 @@ enum {
|
|||||||
LOG = 0x1,
|
LOG = 0x1,
|
||||||
CONSOLE = 0x2,
|
CONSOLE = 0x2,
|
||||||
|
|
||||||
#if defined CONFIG_FEATURE_EXTRA_QUIET
|
#if ENABLE_FEATURE_EXTRA_QUIET
|
||||||
MAYBE_CONSOLE = 0x0,
|
MAYBE_CONSOLE = 0x0,
|
||||||
#else
|
#else
|
||||||
MAYBE_CONSOLE = CONSOLE,
|
MAYBE_CONSOLE = CONSOLE,
|
||||||
@ -162,11 +162,13 @@ static int waitfor(const struct init_action *a, pid_t pid);
|
|||||||
static void shutdown_signal(int sig);
|
static void shutdown_signal(int sig);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !ENABLE_DEBUG_INIT
|
||||||
static void loop_forever(void)
|
static void loop_forever(void)
|
||||||
{
|
{
|
||||||
while (1)
|
while (1)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Print a message to the specified device.
|
/* Print a message to the specified device.
|
||||||
* Device may be bitwise-or'd from LOG | CONSOLE */
|
* Device may be bitwise-or'd from LOG | CONSOLE */
|
||||||
@ -182,7 +184,7 @@ static void message(int device, const char *fmt, ...)
|
|||||||
va_list arguments;
|
va_list arguments;
|
||||||
int l;
|
int l;
|
||||||
RESERVE_CONFIG_BUFFER(msg, 1024);
|
RESERVE_CONFIG_BUFFER(msg, 1024);
|
||||||
#ifndef CONFIG_SYSLOGD
|
#if !ENABLE_SYSLOGD
|
||||||
static int log_fd = -1;
|
static int log_fd = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -191,7 +193,7 @@ static void message(int device, const char *fmt, ...)
|
|||||||
l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1;
|
l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1;
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
|
|
||||||
#ifdef CONFIG_SYSLOGD
|
#if ENABLE_SYSLOGD
|
||||||
/* Log the message to syslogd */
|
/* Log the message to syslogd */
|
||||||
if (device & LOG) {
|
if (device & LOG) {
|
||||||
/* don`t out "\r\n" */
|
/* don`t out "\r\n" */
|
||||||
@ -313,7 +315,7 @@ static void console_init(void)
|
|||||||
}
|
}
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
/* Perhaps we should panic here? */
|
/* Perhaps we should panic here? */
|
||||||
#ifndef CONFIG_SYSLOGD
|
#if !ENABLE_SYSLOGD
|
||||||
log_console =
|
log_console =
|
||||||
#endif
|
#endif
|
||||||
safe_strncpy(console, bb_dev_null, sizeof(console));
|
safe_strncpy(console, bb_dev_null, sizeof(console));
|
||||||
@ -325,7 +327,7 @@ static void console_init(void)
|
|||||||
* if TERM is set to linux (the default) */
|
* if TERM is set to linux (the default) */
|
||||||
if (s == NULL || strcmp(s, "linux") == 0)
|
if (s == NULL || strcmp(s, "linux") == 0)
|
||||||
putenv("TERM=vt102");
|
putenv("TERM=vt102");
|
||||||
#ifndef CONFIG_SYSLOGD
|
#if !ENABLE_SYSLOGD
|
||||||
log_console = console;
|
log_console = console;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@ -510,7 +512,7 @@ static pid_t run(const struct init_action *a)
|
|||||||
cmd[0][0] = '-';
|
cmd[0][0] = '-';
|
||||||
strcpy(cmd[0] + 1, s);
|
strcpy(cmd[0] + 1, s);
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_FEATURE_INIT_SCTTY
|
#if ENABLE_FEATURE_INIT_SCTTY
|
||||||
/* Establish this process as session leader and
|
/* Establish this process as session leader and
|
||||||
* (attempt) to make the tty (if any) a controlling tty.
|
* (attempt) to make the tty (if any) a controlling tty.
|
||||||
*/
|
*/
|
||||||
@ -543,7 +545,7 @@ static pid_t run(const struct init_action *a)
|
|||||||
message(LOG, "Starting pid %d, console %s: '%s'",
|
message(LOG, "Starting pid %d, console %s: '%s'",
|
||||||
getpid(), a->terminal, cmdpath);
|
getpid(), a->terminal, cmdpath);
|
||||||
|
|
||||||
#if defined CONFIG_FEATURE_INIT_COREDUMPS
|
#if ENABLE_FEATURE_INIT_COREDUMPS
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
||||||
@ -622,7 +624,8 @@ static void init_reboot(unsigned long magic)
|
|||||||
/* We have to fork here, since the kernel calls do_exit(0) in
|
/* We have to fork here, since the kernel calls do_exit(0) in
|
||||||
* linux/kernel/sys.c, which can cause the machine to panic when
|
* linux/kernel/sys.c, which can cause the machine to panic when
|
||||||
* the init process is killed.... */
|
* the init process is killed.... */
|
||||||
if ((pid = fork()) == 0) {
|
pid = vfork();
|
||||||
|
if (pid == 0) { /* child */
|
||||||
reboot(magic);
|
reboot(magic);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
@ -746,7 +749,6 @@ static void shutdown_signal(int sig)
|
|||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
init_reboot(rb);
|
init_reboot(rb);
|
||||||
|
|
||||||
loop_forever();
|
loop_forever();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,11 +787,7 @@ static void new_init_action(int action, const char *command, const char *cons)
|
|||||||
if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
|
if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new_action = calloc((size_t) (1), sizeof(struct init_action));
|
new_action = xzalloc(sizeof(struct init_action));
|
||||||
if (!new_action) {
|
|
||||||
message(LOG | CONSOLE, "Memory allocation failure");
|
|
||||||
loop_forever();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Append to the end of the list */
|
/* Append to the end of the list */
|
||||||
for (a = last = init_action_list; a; a = a->next) {
|
for (a = last = init_action_list; a; a = a->next) {
|
||||||
@ -841,7 +839,7 @@ static void delete_init_action(struct init_action *action)
|
|||||||
*/
|
*/
|
||||||
static void parse_inittab(void)
|
static void parse_inittab(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_FEATURE_USE_INITTAB
|
#if ENABLE_FEATURE_USE_INITTAB
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE];
|
char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE];
|
||||||
char tmpConsole[CONSOLE_BUFF_SIZE];
|
char tmpConsole[CONSOLE_BUFF_SIZE];
|
||||||
@ -870,7 +868,7 @@ static void parse_inittab(void)
|
|||||||
new_init_action(SYSINIT, INIT_SCRIPT, "");
|
new_init_action(SYSINIT, INIT_SCRIPT, "");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
#ifdef CONFIG_FEATURE_USE_INITTAB
|
#if ENABLE_FEATURE_USE_INITTAB
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) {
|
while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) {
|
||||||
@ -941,10 +939,10 @@ static void parse_inittab(void)
|
|||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
return;
|
||||||
#endif /* CONFIG_FEATURE_USE_INITTAB */
|
#endif /* FEATURE_USE_INITTAB */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_USE_INITTAB
|
#if ENABLE_FEATURE_USE_INITTAB
|
||||||
static void reload_signal(int sig ATTRIBUTE_UNUSED)
|
static void reload_signal(int sig ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
struct init_action *a, *tmp;
|
struct init_action *a, *tmp;
|
||||||
@ -969,13 +967,15 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED)
|
|||||||
run_actions(RESPAWN);
|
run_actions(RESPAWN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_USE_INITTAB */
|
#endif /* FEATURE_USE_INITTAB */
|
||||||
|
|
||||||
int init_main(int argc, char **argv)
|
int init_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct init_action *a;
|
struct init_action *a;
|
||||||
pid_t wpid;
|
pid_t wpid;
|
||||||
|
|
||||||
|
die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
|
||||||
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "-q")) {
|
if (argc > 1 && !strcmp(argv[1], "-q")) {
|
||||||
return kill(1,SIGHUP);
|
return kill(1,SIGHUP);
|
||||||
}
|
}
|
||||||
@ -1062,7 +1062,7 @@ int init_main(int argc, char **argv)
|
|||||||
parse_inittab();
|
parse_inittab();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SELINUX
|
#if ENABLE_SELINUX
|
||||||
if (getenv("SELINUX_INIT") == NULL) {
|
if (getenv("SELINUX_INIT") == NULL) {
|
||||||
int enforce = 0;
|
int enforce = 0;
|
||||||
|
|
||||||
@ -1092,12 +1092,12 @@ int init_main(int argc, char **argv)
|
|||||||
/* Next run anything to be run only once */
|
/* Next run anything to be run only once */
|
||||||
run_actions(ONCE);
|
run_actions(ONCE);
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_USE_INITTAB
|
#if ENABLE_FEATURE_USE_INITTAB
|
||||||
/* Redefine SIGHUP to reread /etc/inittab */
|
/* Redefine SIGHUP to reread /etc/inittab */
|
||||||
signal(SIGHUP, reload_signal);
|
signal(SIGHUP, reload_signal);
|
||||||
#else
|
#else
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
#endif /* CONFIG_FEATURE_USE_INITTAB */
|
#endif /* FEATURE_USE_INITTAB */
|
||||||
|
|
||||||
|
|
||||||
/* Now run the looping stuff for the rest of forever */
|
/* Now run the looping stuff for the rest of forever */
|
||||||
|
@ -15,6 +15,13 @@
|
|||||||
|
|
||||||
int die_sleep;
|
int die_sleep;
|
||||||
|
|
||||||
|
void sleep_and_die(void)
|
||||||
|
{
|
||||||
|
if (die_sleep)
|
||||||
|
sleep(die_sleep);
|
||||||
|
exit(xfunc_error_retval);
|
||||||
|
}
|
||||||
|
|
||||||
void bb_error_msg_and_die(const char *s, ...)
|
void bb_error_msg_and_die(const char *s, ...)
|
||||||
{
|
{
|
||||||
va_list p;
|
va_list p;
|
||||||
@ -22,7 +29,5 @@ void bb_error_msg_and_die(const char *s, ...)
|
|||||||
va_start(p, s);
|
va_start(p, s);
|
||||||
bb_verror_msg(s, p, NULL);
|
bb_verror_msg(s, p, NULL);
|
||||||
va_end(p);
|
va_end(p);
|
||||||
if (die_sleep)
|
sleep_and_die();
|
||||||
sleep(die_sleep);
|
|
||||||
exit(xfunc_error_retval);
|
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,7 @@
|
|||||||
|
|
||||||
void fflush_stdout_and_exit(int retval)
|
void fflush_stdout_and_exit(int retval)
|
||||||
{
|
{
|
||||||
if (fflush(stdout)) {
|
if (fflush(stdout))
|
||||||
retval = xfunc_error_retval;
|
sleep_and_die();
|
||||||
}
|
|
||||||
if (die_sleep)
|
|
||||||
sleep(die_sleep);
|
|
||||||
exit(retval);
|
exit(retval);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,5 @@ void bb_herror_msg_and_die(const char *s, ...)
|
|||||||
va_start(p, s);
|
va_start(p, s);
|
||||||
bb_vherror_msg(s, p);
|
bb_vherror_msg(s, p);
|
||||||
va_end(p);
|
va_end(p);
|
||||||
if (die_sleep)
|
sleep_and_die();
|
||||||
sleep(die_sleep);
|
|
||||||
exit(xfunc_error_retval);
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,5 @@ void bb_perror_msg_and_die(const char *s, ...)
|
|||||||
va_start(p, s);
|
va_start(p, s);
|
||||||
bb_vperror_msg(s, p);
|
bb_vperror_msg(s, p);
|
||||||
va_end(p);
|
va_end(p);
|
||||||
if (die_sleep)
|
sleep_and_die();
|
||||||
sleep(die_sleep);
|
|
||||||
exit(xfunc_error_retval);
|
|
||||||
}
|
}
|
||||||
|
@ -542,7 +542,7 @@ static void SynchronizeFile(const char *fileName)
|
|||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
|
|
||||||
if (fstat(fileno(fi), &sbuf) == 0 && sbuf.st_uid == DaemonUid) {
|
if (fstat(fileno(fi), &sbuf) == 0 && sbuf.st_uid == DaemonUid) {
|
||||||
CronFile *file = calloc(1, sizeof(CronFile));
|
CronFile *file = xzalloc(sizeof(CronFile));
|
||||||
CronLine **pline;
|
CronLine **pline;
|
||||||
|
|
||||||
file->cf_User = strdup(fileName);
|
file->cf_User = strdup(fileName);
|
||||||
@ -586,7 +586,7 @@ static void SynchronizeFile(const char *fileName)
|
|||||||
|
|
||||||
FixDayDow(&line);
|
FixDayDow(&line);
|
||||||
|
|
||||||
*pline = calloc(1, sizeof(CronLine));
|
*pline = xzalloc(sizeof(CronLine));
|
||||||
**pline = line;
|
**pline = line;
|
||||||
|
|
||||||
/* copy command */
|
/* copy command */
|
||||||
|
@ -499,7 +499,7 @@ static void parse_conf(const char *path, int flag)
|
|||||||
continue;
|
continue;
|
||||||
if (*p0 == 'A' || *p0 == 'D') {
|
if (*p0 == 'A' || *p0 == 'D') {
|
||||||
/* storing current config IP line */
|
/* storing current config IP line */
|
||||||
pip = calloc(1, sizeof(Htaccess_IP));
|
pip = xzalloc(sizeof(Htaccess_IP));
|
||||||
if (pip) {
|
if (pip) {
|
||||||
if (scan_ip_mask(c, &(pip->ip), &(pip->mask))) {
|
if (scan_ip_mask(c, &(pip->ip), &(pip->mask))) {
|
||||||
/* syntax IP{/mask} error detected, protect all */
|
/* syntax IP{/mask} error detected, protect all */
|
||||||
@ -570,7 +570,7 @@ static void parse_conf(const char *path, int flag)
|
|||||||
|| ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES \
|
|| ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES \
|
||||||
|| ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
|
|| ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
|
||||||
/* storing current config line */
|
/* storing current config line */
|
||||||
cur = calloc(1, sizeof(Htaccess) + strlen(p0));
|
cur = xzalloc(sizeof(Htaccess) + strlen(p0));
|
||||||
if (cur) {
|
if (cur) {
|
||||||
cf = strcpy(cur->before_colon, p0);
|
cf = strcpy(cur->before_colon, p0);
|
||||||
c = strchr(cf, ':');
|
c = strchr(cf, ':');
|
||||||
|
@ -869,7 +869,7 @@ sgi_set_xcyl(void)
|
|||||||
static sgiinfo *
|
static sgiinfo *
|
||||||
fill_sgiinfo(void)
|
fill_sgiinfo(void)
|
||||||
{
|
{
|
||||||
sgiinfo *info = calloc(1, sizeof(sgiinfo));
|
sgiinfo *info = xzalloc(sizeof(sgiinfo));
|
||||||
|
|
||||||
info->magic = SGI_SSWAP32(SGI_INFO_MAGIC);
|
info->magic = SGI_SSWAP32(SGI_INFO_MAGIC);
|
||||||
info->b1 = SGI_SSWAP32(-1);
|
info->b1 = SGI_SSWAP32(-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user