aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-05-29 14:20:10 +0100
committerRon Yorston <rmy@pobox.com>2017-05-29 14:34:28 +0100
commitda4f331955bed8afda670afcd58d524a04a0faa9 (patch)
treef6a3879aefdd714240f8c022375f687b512d2238 /init
parent74163a535fd21f5fcca4c052d2e7c192d3e264fa (diff)
parent6683d1cbb44859f549f87f882545b84b9369585c (diff)
downloadbusybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.tar.gz
busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.tar.bz2
busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'init')
-rw-r--r--init/init.c40
-rw-r--r--init/mesg.c76
2 files changed, 22 insertions, 94 deletions
diff --git a/init/init.c b/init/init.c
index 833759341..4d6355167 100644
--- a/init/init.c
+++ b/init/init.c
@@ -73,6 +73,10 @@
73//config: bool "Enable init to write to syslog" 73//config: bool "Enable init to write to syslog"
74//config: default y 74//config: default y
75//config: depends on INIT || LINUXRC 75//config: depends on INIT || LINUXRC
76//config: help
77//config: If selected, some init messages are sent to syslog.
78//config: Otherwise, they are sent to VT #5 if linux virtual tty is detected
79//config: (if not, no separate logging is done).
76//config: 80//config:
77//config:config FEATURE_INIT_QUIET 81//config:config FEATURE_INIT_QUIET
78//config: bool "Be quiet on boot (no 'init started:' message)" 82//config: bool "Be quiet on boot (no 'init started:' message)"
@@ -212,7 +216,9 @@ struct init_action {
212 216
213static struct init_action *init_action_list = NULL; 217static struct init_action *init_action_list = NULL;
214 218
219#if !ENABLE_FEATURE_INIT_SYSLOG
215static const char *log_console = VC_5; 220static const char *log_console = VC_5;
221#endif
216 222
217enum { 223enum {
218 L_LOG = 0x1, 224 L_LOG = 0x1,
@@ -251,17 +257,16 @@ static void message(int where, const char *fmt, ...)
251 msg[l++] = '\n'; 257 msg[l++] = '\n';
252 msg[l] = '\0'; 258 msg[l] = '\0';
253#else 259#else
254 { 260 msg[l++] = '\n';
255 static int log_fd = -1; 261 msg[l] = '\0';
256 262 if (where & L_LOG) {
257 msg[l++] = '\n';
258 msg[l] = '\0';
259 /* Take full control of the log tty, and never close it. 263 /* Take full control of the log tty, and never close it.
260 * It's mine, all mine! Muhahahaha! */ 264 * It's mine, all mine! Muhahahaha! */
265 static int log_fd = -1;
266
261 if (log_fd < 0) { 267 if (log_fd < 0) {
262 if (!log_console) { 268 log_fd = STDERR_FILENO;
263 log_fd = STDERR_FILENO; 269 if (log_console) {
264 } else {
265 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY); 270 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
266 if (log_fd < 0) { 271 if (log_fd < 0) {
267 bb_error_msg("can't log to %s", log_console); 272 bb_error_msg("can't log to %s", log_console);
@@ -271,11 +276,9 @@ static void message(int where, const char *fmt, ...)
271 } 276 }
272 } 277 }
273 } 278 }
274 if (where & L_LOG) { 279 full_write(log_fd, msg, l);
275 full_write(log_fd, msg, l); 280 if (log_fd == STDERR_FILENO)
276 if (log_fd == STDERR_FILENO) 281 return; /* don't print dup messages */
277 return; /* don't print dup messages */
278 }
279 } 282 }
280#endif 283#endif
281 284
@@ -325,8 +328,9 @@ static void console_init(void)
325 * if TERM is set to linux (the default) */ 328 * if TERM is set to linux (the default) */
326 if (!s || strcmp(s, "linux") == 0) 329 if (!s || strcmp(s, "linux") == 0)
327 putenv((char*)"TERM=vt102"); 330 putenv((char*)"TERM=vt102");
328 if (!ENABLE_FEATURE_INIT_SYSLOG) 331# if !ENABLE_FEATURE_INIT_SYSLOG
329 log_console = NULL; 332 log_console = NULL;
333# endif
330 } else 334 } else
331#endif 335#endif
332 if (!s) 336 if (!s)
@@ -541,8 +545,8 @@ static pid_t run(const struct init_action *a)
541 } 545 }
542 546
543 /* Log the process name and args */ 547 /* Log the process name and args */
544 message(L_LOG, "starting pid %d, tty '%s': '%s'", 548 message(L_LOG, "starting pid %u, tty '%s': '%s'",
545 getpid(), a->terminal, a->command); 549 (int)getpid(), a->terminal, a->command);
546 550
547 /* Now run it. The new program will take over this PID, 551 /* Now run it. The new program will take over this PID,
548 * so nothing further in init.c should be run. */ 552 * so nothing further in init.c should be run. */
@@ -757,7 +761,7 @@ static void run_shutdown_and_kill_processes(void)
757 761
758 /* Send signals to every process _except_ pid 1 */ 762 /* Send signals to every process _except_ pid 1 */
759 kill(-1, SIGTERM); 763 kill(-1, SIGTERM);
760 message(L_CONSOLE | L_LOG, "Sent SIG%s to all processes", "TERM"); 764 message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
761 sync(); 765 sync();
762 sleep(1); 766 sleep(1);
763 767
diff --git a/init/mesg.c b/init/mesg.c
deleted file mode 100644
index 45c13b8e0..000000000
--- a/init/mesg.c
+++ /dev/null
@@ -1,76 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * mesg implementation for busybox
4 *
5 * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9
10//config:config MESG
11//config: bool "mesg"
12//config: default y
13//config: help
14//config: Mesg controls access to your terminal by others. It is typically
15//config: used to allow or disallow other users to write to your terminal
16//config:
17//config:config FEATURE_MESG_ENABLE_ONLY_GROUP
18//config: bool "Enable writing to tty only by group, not by everybody"
19//config: default y
20//config: depends on MESG
21//config: help
22//config: Usually, ttys are owned by group "tty", and "write" tool is
23//config: setgid to this group. This way, "mesg y" only needs to enable
24//config: "write by owning group" bit in tty mode.
25//config:
26//config: If you set this option to N, "mesg y" will enable writing
27//config: by anybody at all. This is not recommended.
28
29//applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP))
30
31//kbuild:lib-$(CONFIG_MESG) += mesg.o
32
33//usage:#define mesg_trivial_usage
34//usage: "[y|n]"
35//usage:#define mesg_full_usage "\n\n"
36//usage: "Control write access to your terminal\n"
37//usage: " y Allow write access to your terminal\n"
38//usage: " n Disallow write access to your terminal"
39
40#include "libbb.h"
41
42#if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP
43#define S_IWGRP_OR_S_IWOTH S_IWGRP
44#else
45#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
46#endif
47
48int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
49int mesg_main(int argc UNUSED_PARAM, char **argv)
50{
51 struct stat sb;
52 mode_t m;
53 char c = 0;
54
55 argv++;
56
57 if (argv[0]
58 && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n'))
59 ) {
60 bb_show_usage();
61 }
62
63 if (!isatty(STDIN_FILENO))
64 bb_error_msg_and_die("not a tty");
65
66 xfstat(STDIN_FILENO, &sb, "stderr");
67 if (c == 0) {
68 puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
69 return EXIT_SUCCESS;
70 }
71 m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
72 : sb.st_mode & ~(S_IWGRP|S_IWOTH);
73 if (fchmod(STDIN_FILENO, m) != 0)
74 bb_perror_nomsg_and_die();
75 return EXIT_SUCCESS;
76}