New upstream version 2.94
Dmitry Bogatov
5 years ago
0 | sysvinit (2.94) unreleased; urgency=low | |
1 | ||
2 | [ Jesse Smith ] | |
3 | ||
4 | * When the halt command is called with the -p flag (or as poweroff) | |
5 | the command now passes the "-h -P" flags to shutdown. This | |
6 | in turn sets the INIT_HALT environment variable to POWEROFF. | |
7 | Assuming this value is checked by initscripts during the | |
8 | shutting down procedure, it should cause the system to | |
9 | be powered off. | |
10 | If halt is called without -p then the value of INIT_HALT | |
11 | is not set and the default action (often set in /etc/defaut/halt) | |
12 | is taken. | |
13 | * Removed unnecessary malloc.h includes. Memory allocation | |
14 | and freeing is now handled in stdlib.h | |
15 | * Added defines for FreeBSD to make some components compile | |
16 | on FreeBSD 11. | |
17 | * Increased the size of the kernel command line buffer in bootlogd | |
18 | from 256 characters to 4096. This size is defined in KERNEL_COMMAND_LENGTH | |
19 | for easy modification downstream. | |
20 | * Added logsave.c and logsave.8 manual page from e2fsprogs to make | |
21 | sure logsave is available to initscripts. | |
22 | * Updated src/Makefile to make sure bootlogd compiles with Clang. | |
23 | * Use defined constants for password length in sulogin. Makes | |
24 | it easier to update/patch later. | |
25 | * Minor code fixes across multiple source files to avoid buffer | |
26 | overflows, or uninitialized strings. | |
27 | * Changed the way the "when" variable is used internally in shutdown.c. | |
28 | It starts as a NULL pointer, then might get set as a pointer to optarg, | |
29 | then it might get set to point to an argv parameter, then it might have | |
30 | a string value copied into it, over-writing the original data. We should | |
31 | not risk over-writing internal variables which might get used for something | |
32 | else (it's rude and security risk). Set up "when" as its own buffer | |
33 | that has data from optargs and/or argv copied into it. | |
34 | * Fixed typo in init.8 manual page. | |
35 | * Updated text of fstab-decode to explain what the utility does. | |
36 | ||
37 | ||
0 | 38 | sysvinit (2.93) released; urgency=low |
1 | 39 | |
2 | 40 | [ Jesse Smith ] |
4 | 42 | * Fixed typo in pidof which would prevent the -o (omit PID) |
5 | 43 | flag from working. |
6 | 44 | Fixes Debian bug ##913394. |
45 | * Fixed error where pidof would not omit checking PIDs passed | |
46 | to it when the -o flag was used. | |
47 | Fixes Debian bug #913394. | |
48 | ||
7 | 49 | |
8 | 50 | sysvinit (2.92) released; urgency=low |
9 | 51 |
26 | 26 | |
27 | 27 | .SH DESCRIPTION |
28 | 28 | .B fstab-decode |
29 | decodes escapes in the specified \fIARGUMENT\fRs | |
29 | decodes escapes (such as newline characters) in the specified \fIARGUMENT\fRs | |
30 | 30 | and uses them to run \fICOMMAND\fR. |
31 | 31 | The argument escaping uses the same rules as path escaping in |
32 | 32 | \fB/etc/fstab\fR, |
33 | 33 | .B /etc/mtab |
34 | 34 | and \fB/proc/mtab\fR. |
35 | ||
36 | In essence fstab-decode can be used anytime we want to pass multiple | |
37 | parameters to a command as a list of command line argments. It turns output | |
38 | like this: | |
39 | ||
40 | .nf | |
41 | /root | |
42 | /mnt/remote-disk | |
43 | /home | |
44 | ||
45 | Into one long list of parameters, "/root /mnt/remote-disk /home". This | |
46 | can be useful when trying to work with multiple filesystems at once. For | |
47 | instance, we can use it to unmount multiple NFS shares. | |
35 | 48 | |
36 | 49 | .SH EXIT STATUS |
37 | 50 | .B fstab-decode |
42 | 55 | |
43 | 56 | .SH EXAMPLES |
44 | 57 | .nf |
58 | The following example reads fstab, finds all instances of VFAT filesystems and | |
59 | prints their mount points (argument 2 in the fstab file). fstab-decode then runs | |
60 | the specified program, umount, and passes it the list of VFAT mountpoints. | |
61 | This unmounts all VFAT partitions. | |
62 | ||
63 | ||
45 | 64 | .B fstab-decode umount $(awk \[aq]$3 == \[dq]vfat\[dq] { print $2 }\[aq] /etc/fstab) |
46 | 65 | .fi |
0 | '\" -*- coding: UTF-8 -*- | |
1 | .\" A man page for fstab-decode(8). | |
2 | .\" | |
3 | .\" Copyright (C) 2006 Red Hat, Inc. All rights reserved. | |
4 | .\" | |
5 | .\" This copyrighted material is made available to anyone wishing to use, | |
6 | .\" modify, copy, or redistribute it subject to the terms and conditions of the | |
7 | .\" GNU General Public License v.2. | |
8 | .\" | |
9 | .\" This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | .\" more details. | |
13 | .\" | |
14 | .\" You should have received a copy of the GNU General Public License along | |
15 | .\" with this program; if not, write to the Free Software Foundation, Inc., | |
16 | .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | .\" | |
18 | .\" Author: Miloslav Trmac <mitr@redhat.com> | |
19 | .TH fstab-decode 8 "May 2006" | |
20 | ||
21 | .SH NAME | |
22 | fstab-decode \- run a command with fstab-encoded arguments | |
23 | ||
24 | .SH SYNOPSIS | |
25 | \fBfstab-decode\fR \fICOMMAND\fR [\fIARGUMENT\fR]... | |
26 | ||
27 | .SH DESCRIPTION | |
28 | .B fstab-decode | |
29 | decodes escapes in the specified \fIARGUMENT\fRs | |
30 | and uses them to run \fICOMMAND\fR. | |
31 | The argument escaping uses the same rules as path escaping in | |
32 | \fB/etc/fstab\fR, | |
33 | .B /etc/mtab | |
34 | and \fB/proc/mtab\fR. | |
35 | ||
36 | .SH EXIT STATUS | |
37 | .B fstab-decode | |
38 | exits with status 127 if | |
39 | .I COMMAND | |
40 | can't be run. | |
41 | Otherwise it exits with the status returned by \fICOMMAND\fR. | |
42 | ||
43 | .SH EXAMPLES | |
44 | .nf | |
45 | .B fstab-decode umount $(awk \[aq]$3 == \[dq]vfat\[dq] { print $2 }\[aq] /etc/fstab) | |
46 | .fi |
275 | 275 | .TP 0.5i |
276 | 276 | .B SIGUSR2 |
277 | 277 | When init receives SIGUSR2, init closes and leaves the control fifo, |
278 | \fB/run/initctl\f\P, closed. This may be used to make sure init is not | |
278 | \fB/run/initctl\fP, closed. This may be used to make sure init is not | |
279 | 279 | holding open any files. However, it also prevents init from switching |
280 | 280 | runlevels. Which means commands like shutdown no longer work. |
281 | 281 | The fifo can be re-opened by sending init the SIGUSR1 signal. |
0 | .\" -*- nroff -*- | |
1 | .\" Copyright 2003 by Theodore Ts'o. All Rights Reserved. | |
2 | .\" This file may be copied under the terms of the GNU Public License. | |
3 | .\" | |
4 | .TH LOGSAVE 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@" | |
5 | .SH NAME | |
6 | logsave \- save the output of a command in a logfile | |
7 | .SH SYNOPSIS | |
8 | .B logsave | |
9 | [ | |
10 | .B \-asv | |
11 | ] | |
12 | .I logfile cmd_prog [ ... ] | |
13 | .SH DESCRIPTION | |
14 | The | |
15 | .B logsave | |
16 | program will execute | |
17 | .I cmd_prog | |
18 | with the specified argument(s), and save a copy of its output to | |
19 | .IR logfile . | |
20 | If the containing directory for | |
21 | .I logfile | |
22 | does not exist, | |
23 | .B logsave | |
24 | will accumulate the output in memory until it can be written out. | |
25 | A copy of the output will also be written to standard output. | |
26 | .PP | |
27 | If | |
28 | .I cmd_prog | |
29 | is a single hyphen ('-'), then instead of executing a program, | |
30 | .B logsave | |
31 | will take its input from standard input and save it in | |
32 | .I logfile | |
33 | .PP | |
34 | .B logsave | |
35 | is useful for saving the output of initial boot scripts | |
36 | until the /var partition is mounted, so the output can be written to | |
37 | /var/log. | |
38 | .SH OPTIONS | |
39 | .TP | |
40 | .B \-a | |
41 | This option will cause the output to be appended to | |
42 | .IR logfile , | |
43 | instead of replacing its current contents. | |
44 | .TP | |
45 | .B \-s | |
46 | This option will cause | |
47 | .B logsave | |
48 | to skip writing to the log file text which is bracketed with a control-A | |
49 | (ASCII 001 or Start of Header) and control-B (ASCII 002 or Start of | |
50 | Text). This allows progress bar information to be visible to the user | |
51 | on the console, while not being written to the log file. | |
52 | .TP | |
53 | .B \-v | |
54 | This option will make | |
55 | .B logsave | |
56 | to be more verbose in its output to the user. | |
57 | .SH AUTHOR | |
58 | Theodore Ts'o (tytso@mit.edu) | |
59 | .SH SEE ALSO | |
60 | .BR fsck (8) |
22 | 22 | |
23 | 23 | # For some known distributions we do not build all programs, otherwise we do. |
24 | 24 | BIN = |
25 | SBIN = init halt shutdown runlevel killall5 fstab-decode | |
25 | SBIN = init halt shutdown runlevel killall5 fstab-decode logsave | |
26 | 26 | USRBIN = last mesg readbootlog |
27 | 27 | |
28 | 28 | MAN1 = last.1 lastb.1 mesg.1 readbootlog.1 |
29 | 29 | MAN5 = initscript.5 inittab.5 initctl.5 |
30 | 30 | MAN8 = halt.8 init.8 killall5.8 pidof.8 poweroff.8 reboot.8 runlevel.8 |
31 | MAN8 += shutdown.8 telinit.8 fstab-decode.8 | |
31 | MAN8 += shutdown.8 telinit.8 fstab-decode.8 logsave.8 | |
32 | 32 | |
33 | 33 | ifeq ($(DISTRO),) |
34 | 34 | SBIN += sulogin bootlogd |
114 | 114 | last: LDLIBS += $(STATIC) |
115 | 115 | last: last.o |
116 | 116 | |
117 | logsave: LDLIBS += $(STATIC) | |
118 | logsave: logsave.o | |
119 | ||
117 | 120 | mesg: LDLIBS += $(STATIC) |
118 | 121 | mesg: mesg.o |
119 | 122 | |
136 | 139 | shutdown: dowall.o shutdown.o utmp.o |
137 | 140 | |
138 | 141 | bootlogd: LDLIBS += -lutil $(STATIC) |
139 | bootlogd: bootlogd.o bootlogd.h | |
142 | bootlogd: bootlogd.o | |
140 | 143 | |
141 | 144 | readbootlog: LDLIBS += $(STATIC) |
142 | readbootlog: readbootlog.o bootlogd.h | |
145 | readbootlog: readbootlog.o | |
143 | 146 | |
144 | 147 | fstab-decode: LDLIBS += $(STATIC) |
145 | 148 | fstab-decode: fstab-decode.o |
150 | 153 | runlevellog.o: runlevellog.h runlevellog.c paths.h |
151 | 154 | |
152 | 155 | init.o: CPPFLAGS += $(SELINUX_DEF) |
153 | init.o: init.c init.h initreq.h paths.h reboot.h runlevellog.h runlevellog.c set.h paths.h | |
156 | init.o: init.c init.h initreq.h paths.h reboot.h runlevellog.h runlevellog.c set.h | |
154 | 157 | |
155 | 158 | utmp.o: |
156 | 159 | |
158 | 161 | init_utmp.o: utmp.c init.h initreq.h paths.h |
159 | 162 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< |
160 | 163 | |
164 | bootlogd.o: bootlogd.c bootlogd.h | |
165 | ||
166 | readbootlog.o: readbootlog.c | |
167 | ||
161 | 168 | utmpdump.o: utmpdump.c oldutmp.h |
162 | 169 | |
163 | 170 | shutdown.o: shutdown.c paths.h reboot.h initreq.h init.h |
165 | 172 | halt.o: halt.c reboot.h paths.h runlevellog.c runlevellog.h |
166 | 173 | |
167 | 174 | last.o: last.c oldutmp.h |
175 | ||
176 | logsave.o: logsave.c | |
168 | 177 | |
169 | 178 | consoles.o: consoles.c consoles.h |
170 | 179 |
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
25 | 25 | * |
26 | * *NOTE* *NOTE* *NOTE* | |
27 | * This is a PROOF OF CONCEPT IMPLEMENTATION | |
28 | * | |
29 | * I have bigger plans for Debian, but for now | |
30 | * this has to do ;) | |
31 | * | |
32 | 26 | */ |
33 | 27 | |
34 | 28 | #include <sys/types.h> |
39 | 33 | #include <time.h> |
40 | 34 | #include <stdio.h> |
41 | 35 | #include <errno.h> |
42 | #include <malloc.h> | |
43 | 36 | #include <stdlib.h> |
44 | 37 | #include <unistd.h> |
45 | 38 | #include <string.h> |
47 | 40 | #include <getopt.h> |
48 | 41 | #include <dirent.h> |
49 | 42 | #include <fcntl.h> |
43 | #ifdef __linux__ | |
50 | 44 | #include <pty.h> |
45 | #endif | |
46 | ||
47 | #ifdef __FreeBSD__ | |
48 | #include <termios.h> | |
49 | #include <libutil.h> | |
50 | #endif | |
51 | ||
51 | 52 | #include <ctype.h> |
52 | 53 | #ifdef __linux__ |
53 | 54 | #include <sys/mount.h> |
55 | 56 | #include "bootlogd.h" |
56 | 57 | |
57 | 58 | #define MAX_CONSOLES 16 |
59 | #define KERNEL_COMMAND_LENGTH 4096 | |
58 | 60 | |
59 | 61 | char ringbuf[32768]; |
60 | 62 | char *endptr = ringbuf + sizeof(ringbuf); |
249 | 251 | /* This appears to be unused. unsigned int kdev; */ |
250 | 252 | #endif |
251 | 253 | struct stat st, st2; |
252 | char buf[256]; | |
254 | char buf[KERNEL_COMMAND_LENGTH]; | |
253 | 255 | char *p; |
254 | 256 | int didmount = 0; |
255 | 257 | int n; |
278 | 280 | perror("bootlogd: /proc/cmdline"); |
279 | 281 | } else { |
280 | 282 | buf[0] = 0; |
281 | if ((n = read(fd, buf, sizeof(buf) - 1)) < 0) | |
283 | if ((n = read(fd, buf, KERNEL_COMMAND_LENGTH - 1)) < 0) | |
282 | 284 | perror("bootlogd: /proc/cmdline"); |
283 | 285 | close(fd); |
284 | 286 | } |
285 | 287 | if (didmount) umount("/proc"); |
286 | 288 | |
287 | ||
288 | 289 | if (n < 0) return 0; |
289 | ||
290 | ||
291 | 290 | |
292 | 291 | /* |
293 | 292 | * OK, so find console= in /proc/cmdline. |
154 | 154 | /* |
155 | 155 | * Switch to another runlevel. |
156 | 156 | */ |
157 | void do_shutdown(char *fl, char *tm) | |
157 | void do_shutdown(char *fl, int should_poweroff, char *tm) | |
158 | 158 | { |
159 | char *args[8]; | |
159 | char *args[9]; | |
160 | 160 | int i = 0; |
161 | 161 | |
162 | 162 | args[i++] = "shutdown"; |
163 | 163 | args[i++] = fl; |
164 | if ( (! strcmp(fl, "-h") ) && (should_poweroff) ) | |
165 | args[i++] = "-P"; | |
164 | 166 | if (tm) { |
165 | 167 | args[i++] = "-t"; |
166 | 168 | args[i++] = tm; |
258 | 260 | */ |
259 | 261 | c = get_runlevel(); |
260 | 262 | if (c != '0' && c != '6') |
261 | do_shutdown(do_reboot ? "-r" : "-h", tm); | |
263 | do_shutdown(do_reboot ? "-r" : "-h", do_poweroff, tm); | |
262 | 264 | } |
263 | 265 | |
264 | 266 | /* |
12 | 12 | Version information is not placed in the top-level Makefile by default |
13 | 13 | */ |
14 | 14 | #ifndef VERSION |
15 | #define VERSION "2.91" | |
15 | #define VERSION "2.94" | |
16 | 16 | #endif |
17 | 17 | /* |
18 | 18 | * This file is part of the sysvinit suite, |
19 | 19 | * Copyright (C) 1991-2004 Miquel van Smoorenburg. |
20 | * Copyright (C) 2017-2019 Jesse Smith | |
20 | 21 | * |
21 | 22 | * This program is free software; you can redistribute it and/or modify |
22 | 23 | * it under the terms of the GNU General Public License as published by |
51 | 52 | #include <string.h> |
52 | 53 | #include <signal.h> |
53 | 54 | #include <termios.h> |
55 | #ifdef __FreeBSD__ | |
56 | #include <utmpx.h> | |
57 | #else | |
54 | 58 | #include <utmp.h> |
59 | #endif | |
55 | 60 | #include <ctype.h> |
56 | 61 | #include <stdarg.h> |
57 | 62 | #include <sys/ttydefaults.h> |
60 | 65 | |
61 | 66 | #ifdef WITH_SELINUX |
62 | 67 | # include <selinux/selinux.h> |
68 | #endif | |
69 | #ifdef __FreeBSD__ | |
70 | extern char **environ; | |
63 | 71 | #endif |
64 | 72 | |
65 | 73 | #ifdef __i386__ |
132 | 140 | int wrote_utmp_reboot = 1; /* Set when we wrote the reboot record */ |
133 | 141 | int wrote_wtmp_rlevel = 1; /* Set when we wrote the runlevel record */ |
134 | 142 | int wrote_utmp_rlevel = 1; /* Set when we wrote the runlevel record */ |
135 | int sltime = WAIT_BETWEEN_SIGNALS; /* Sleep time between TERM and KILL */ | |
143 | int sleep_time = WAIT_BETWEEN_SIGNALS; /* Sleep time between TERM and KILL */ | |
136 | 144 | char *argv0; /* First arguments; show up in ps listing */ |
137 | 145 | int maxproclen; /* Maximal length of argv[0] with \0 */ |
138 | 146 | struct utmp utproto; /* Only used for sizeof(utproto.ut_id) */ |
143 | 151 | |
144 | 152 | /* Used by re-exec part */ |
145 | 153 | int reload = 0; /* Should we do initialization stuff? */ |
146 | char *myname="/sbin/init"; /* What should we exec */ | |
154 | char *myname=INIT; /* What should we exec */ | |
147 | 155 | int oops_error; /* Used by some of the re-exec code. */ |
148 | 156 | const char *Signature = "12567362"; /* Signature for re-exec fd */ |
149 | 157 | |
287 | 295 | fprintf(fp, "-SI%u\n", got_signals); |
288 | 296 | fprintf(fp, "-WR%d\n", wrote_wtmp_reboot); |
289 | 297 | fprintf(fp, "-WU%d\n", wrote_utmp_reboot); |
290 | fprintf(fp, "-ST%d\n", sltime); | |
298 | fprintf(fp, "-ST%d\n", sleep_time); | |
291 | 299 | fprintf(fp, "-DB%d\n", did_boot); |
292 | 300 | |
293 | 301 | for (p = family; p; p = p->next) { |
415 | 423 | } |
416 | 424 | break; |
417 | 425 | case D_SLTIME: |
418 | if (fscanf(f, "%d\n", &sltime) == EOF && errno != 0) { | |
426 | if (fscanf(f, "%d\n", &sleep_time) == EOF && errno != 0) { | |
419 | 427 | fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno)); |
420 | 428 | } |
421 | 429 | break; |
520 | 528 | * Set the process title. |
521 | 529 | */ |
522 | 530 | #ifdef __GNUC__ |
531 | #ifndef __FreeBSD__ | |
523 | 532 | __attribute__ ((format (printf, 1, 2))) |
524 | 533 | #endif |
534 | #endif | |
535 | /* This function already exists on FreeBSD. No need to delcare it. */ | |
536 | #ifndef __FreeBSD__ | |
525 | 537 | static int setproctitle(char *fmt, ...) |
526 | 538 | { |
527 | 539 | va_list ap; |
541 | 553 | |
542 | 554 | return len; |
543 | 555 | } |
556 | #endif | |
544 | 557 | |
545 | 558 | /* |
546 | 559 | * Set console_dev to a working console. |
1704 | 1717 | /* |
1705 | 1718 | * Yup, but check every second if we still have children. |
1706 | 1719 | */ |
1707 | for(f = 0; f < sltime; f++) { | |
1720 | for(f = 0; f < sleep_time; f++) { | |
1708 | 1721 | for(ch = family; ch; ch = ch->next) { |
1709 | 1722 | if (!(ch->flags & KILLME)) continue; |
1710 | 1723 | if ((ch->flags & RUNNING) && !(ch->flags & ZOMBIE)) |
1958 | 1971 | foo = arg; |
1959 | 1972 | ok = 1; |
1960 | 1973 | } |
1961 | if (ok == 2) sltime = st; | |
1974 | if (ok == 2) sleep_time = st; | |
1962 | 1975 | |
1963 | 1976 | #endif /* INITLVL */ |
1964 | 1977 | |
2159 | 2172 | |
2160 | 2173 | /* |
2161 | 2174 | * Attempt to re-exec. |
2162 | */ | |
2163 | static | |
2164 | void re_exec(void) | |
2175 | * Renaming to my_re_exec since re_exec is now a common function name | |
2176 | * which conflicts. | |
2177 | */ | |
2178 | static | |
2179 | void my_re_exec(void) | |
2165 | 2180 | { |
2166 | 2181 | CHILD *ch; |
2167 | 2182 | sigset_t mask, oldset; |
2278 | 2293 | runlevel = read_level(level); |
2279 | 2294 | if (runlevel == 'U') { |
2280 | 2295 | runlevel = oldlevel; |
2281 | re_exec(); | |
2296 | my_re_exec(); | |
2282 | 2297 | } else { |
2283 | 2298 | if (oldlevel != 'S' && runlevel == 'S') console_stty(); |
2284 | 2299 | if (runlevel == '6' || runlevel == '0' || |
2459 | 2474 | } |
2460 | 2475 | switch(request.cmd) { |
2461 | 2476 | case INIT_CMD_RUNLVL: |
2462 | sltime = request.sleeptime; | |
2477 | sleep_time = request.sleeptime; | |
2463 | 2478 | fifo_new_level(request.runlevel); |
2464 | 2479 | quit = 1; |
2465 | 2480 | break; |
2466 | 2481 | case INIT_CMD_POWERFAIL: |
2467 | sltime = request.sleeptime; | |
2482 | sleep_time = request.sleeptime; | |
2468 | 2483 | do_power_fail('F'); |
2469 | 2484 | quit = 1; |
2470 | 2485 | break; |
2471 | 2486 | case INIT_CMD_POWERFAILNOW: |
2472 | sltime = request.sleeptime; | |
2487 | sleep_time = request.sleeptime; | |
2473 | 2488 | do_power_fail('L'); |
2474 | 2489 | quit = 1; |
2475 | 2490 | break; |
2476 | 2491 | case INIT_CMD_POWEROK: |
2477 | sltime = request.sleeptime; | |
2492 | sleep_time = request.sleeptime; | |
2478 | 2493 | do_power_fail('O'); |
2479 | 2494 | quit = 1; |
2480 | 2495 | break; |
2680 | 2695 | #endif |
2681 | 2696 | if (runlevel == 'U') { |
2682 | 2697 | runlevel = oldlevel; |
2683 | re_exec(); | |
2698 | my_re_exec(); | |
2684 | 2699 | } else { |
2685 | 2700 | if (oldlevel != 'S' && runlevel == 'S') console_stty(); |
2686 | 2701 | if (runlevel == '6' || runlevel == '0' || |
2901 | 2916 | |
2902 | 2917 | while ((f = getopt(argc, argv, "t:e:")) != EOF) switch(f) { |
2903 | 2918 | case 't': |
2904 | sltime = atoi(optarg); | |
2919 | sleep_time = atoi(optarg); | |
2905 | 2920 | break; |
2906 | 2921 | case 'e': |
2907 | 2922 | if (env == NULL) |
2934 | 2949 | usage(progname); |
2935 | 2950 | request.cmd = INIT_CMD_RUNLVL; |
2936 | 2951 | request.runlevel = argv[optind][0]; |
2937 | request.sleeptime = sltime; | |
2952 | request.sleeptime = sleep_time; | |
2938 | 2953 | } |
2939 | 2954 | |
2940 | 2955 | /* Change to the root directory. */ |
2976 | 2991 | progname, INITLVL); |
2977 | 2992 | exit(1); |
2978 | 2993 | } |
2979 | fprintf(fp, "%s %d", argv[optind], sltime); | |
2994 | fprintf(fp, "%s %d", argv[optind], sleep_time); | |
2980 | 2995 | fclose(fp); |
2981 | 2996 | |
2982 | 2997 | /* And tell init about the pending runlevel change. */ |
153 | 153 | #define D_WROTE_WTMP_RLEVEL -16 |
154 | 154 | #define D_WROTE_UTMP_RLEVEL -17 |
155 | 155 | |
156 | #ifdef __FreeBSD__ | |
157 | #define UTMP_FILE "/var/run/utmp" | |
158 | #define RUN_LVL 1 | |
159 | struct utmp | |
160 | { | |
161 | char ut_id[4]; | |
162 | }; | |
163 | #endif | |
164 |
57 | 57 | #include <sys/wait.h> |
58 | 58 | #include <unistd.h> |
59 | 59 | |
60 | char *Version = "@(#)killall5 2.86 31-Jul-2004 miquels@cistron.nl"; | |
61 | ||
62 | 60 | #ifndef PATH_MAX |
63 | 61 | # ifdef MAXPATHLEN |
64 | 62 | # define PATH_MAX MAXPATHLEN |
434 | 432 | |
435 | 433 | } while (1); |
436 | 434 | |
437 | if (real) strcpy(real, curr); | |
435 | if (real) /* real is defined elsewhere as being PATH_MAX + 1 */ | |
436 | { | |
437 | memset(real, '\0', PATH_MAX + 1); | |
438 | strncpy(real, curr, PATH_MAX); | |
439 | } | |
438 | 440 | |
439 | 441 | if (errno == EINVAL) { |
440 | 442 | const size_t nlen = strlen(curr); |
33 | 33 | #include <ctype.h> |
34 | 34 | #include <utmp.h> |
35 | 35 | #include <errno.h> |
36 | #include <malloc.h> | |
37 | 36 | #include <stdlib.h> |
38 | 37 | #include <unistd.h> |
39 | 38 | #include <string.h> |
46 | 45 | |
47 | 46 | #ifndef SHUTDOWN_TIME |
48 | 47 | # define SHUTDOWN_TIME 254 |
48 | #endif | |
49 | ||
50 | #ifndef PATH_MAX | |
51 | #define PATH_MAX 2048 | |
49 | 52 | #endif |
50 | 53 | |
51 | 54 | char *Version = "@(#) last 2.85 31-Apr-2004 miquels"; |
253 | 256 | #define BTMP_FILE getbtmp() |
254 | 257 | char *getbtmp() |
255 | 258 | { |
256 | static char btmp[128]; | |
259 | static char btmp[PATH_MAX + 5]; /* max path + btmp + null terminator */ | |
257 | 260 | char *p; |
258 | 261 | |
259 | strcpy(btmp, WTMP_FILE); | |
262 | memset(btmp, '\0', PATH_MAX + 5); | |
263 | strncpy(btmp, WTMP_FILE, PATH_MAX); | |
260 | 264 | if ((p = strrchr(btmp, '/')) == NULL) |
261 | 265 | p = btmp; |
262 | 266 | else |
841 | 845 | switch (ut.ut_type) { |
842 | 846 | case SHUTDOWN_TIME: |
843 | 847 | if (extended) { |
844 | strcpy(ut.ut_line, "system down"); | |
848 | strncpy(ut.ut_line, "system down", OLD_LINESIZE - 1); | |
845 | 849 | quit = list(&ut, lastboot, R_NORMAL); |
846 | 850 | } |
847 | 851 | lastdown = lastrch = ut.ut_time; |
850 | 854 | case OLD_TIME: |
851 | 855 | case NEW_TIME: |
852 | 856 | if (extended) { |
853 | strcpy(ut.ut_line, | |
857 | strncpy(ut.ut_line, | |
854 | 858 | ut.ut_type == NEW_TIME ? "new time" : |
855 | "old time"); | |
859 | "old time", OLD_LINESIZE - 1); | |
856 | 860 | quit = list(&ut, lastdown, R_TIMECHANGE); |
857 | 861 | } |
858 | 862 | break; |
859 | 863 | case BOOT_TIME: |
860 | strcpy(ut.ut_line, "system boot"); | |
864 | strncpy(ut.ut_line, "system boot", OLD_LINESIZE - 1); | |
861 | 865 | quit = list(&ut, lastdown, R_REBOOT); |
862 | 866 | lastboot = ut.ut_time; |
863 | 867 | down = 1; |
0 | /* | |
1 | * logsave.c --- A program which saves the output of a program until | |
2 | * /var/log is mounted. | |
3 | * | |
4 | * Copyright (C) 2003 Theodore Ts'o. | |
5 | * | |
6 | * %Begin-Header% | |
7 | * This file may be redistributed under the terms of the GNU Public | |
8 | * License. | |
9 | * %End-Header% | |
10 | */ | |
11 | ||
12 | #ifndef _XOPEN_SOURCE | |
13 | #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */ | |
14 | #endif | |
15 | #ifndef HAVE_SIGNAL_H | |
16 | #define HAVE_SIGNAL_H | |
17 | #endif | |
18 | ||
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <unistd.h> | |
22 | #include <string.h> | |
23 | #include <sys/types.h> | |
24 | #include <sys/wait.h> | |
25 | #include <fcntl.h> | |
26 | #include <time.h> | |
27 | #include <errno.h> | |
28 | #ifdef HAVE_SIGNAL_H | |
29 | #include <signal.h> | |
30 | #endif | |
31 | #ifdef HAVE_GETOPT_H | |
32 | #include <getopt.h> | |
33 | #else | |
34 | extern char *optarg; | |
35 | extern int optind; | |
36 | #endif | |
37 | ||
38 | static int outfd = -1; | |
39 | static int outbufsize = 0; | |
40 | static void *outbuf = 0; | |
41 | static int verbose = 0; | |
42 | static int do_skip = 0; | |
43 | static int skip_mode = 0; | |
44 | static pid_t child_pid = -1; | |
45 | ||
46 | static void usage(char *progname) | |
47 | { | |
48 | printf("Usage: %s [-asv] logfile program\n", progname); | |
49 | exit(1); | |
50 | } | |
51 | ||
52 | #define SEND_LOG 0x01 | |
53 | #define SEND_CONSOLE 0x02 | |
54 | #define SEND_BOTH 0x03 | |
55 | ||
56 | /* | |
57 | * Helper function that does the right thing if write returns a | |
58 | * partial write, or an EAGAIN/EINTR error. | |
59 | */ | |
60 | static int write_all(int fd, const char *buf, size_t count) | |
61 | { | |
62 | ssize_t ret; | |
63 | int c = 0; | |
64 | ||
65 | while (count > 0) { | |
66 | ret = write(fd, buf, count); | |
67 | if (ret < 0) { | |
68 | if ((errno == EAGAIN) || (errno == EINTR)) | |
69 | continue; | |
70 | return -1; | |
71 | } | |
72 | count -= ret; | |
73 | buf += ret; | |
74 | c += ret; | |
75 | } | |
76 | return c; | |
77 | } | |
78 | ||
79 | static void send_output(const char *buffer, int c, int flag) | |
80 | { | |
81 | const char *cp; | |
82 | char *n; | |
83 | int cnt, d, del; | |
84 | ||
85 | if (c == 0) | |
86 | c = strlen(buffer); | |
87 | ||
88 | if (flag & SEND_CONSOLE) { | |
89 | cnt = c; | |
90 | cp = buffer; | |
91 | while (cnt) { | |
92 | del = 0; | |
93 | for (d=0; d < cnt; d++) { | |
94 | if (skip_mode && | |
95 | (cp[d] == '\001' || cp[d] == '\002')) { | |
96 | del = 1; | |
97 | break; | |
98 | } | |
99 | } | |
100 | write_all(1, cp, d); | |
101 | if (del) | |
102 | d++; | |
103 | cnt -= d; | |
104 | cp += d; | |
105 | } | |
106 | } | |
107 | if (!(flag & SEND_LOG)) | |
108 | return; | |
109 | if (outfd > 0) | |
110 | write_all(outfd, buffer, c); | |
111 | else { | |
112 | n = realloc(outbuf, outbufsize + c); | |
113 | if (n) { | |
114 | outbuf = n; | |
115 | memcpy(((char *)outbuf)+outbufsize, buffer, c); | |
116 | outbufsize += c; | |
117 | } | |
118 | } | |
119 | } | |
120 | ||
121 | static int do_read(int fd) | |
122 | { | |
123 | int c; | |
124 | char buffer[4096], *cp, *sep; | |
125 | ||
126 | c = read(fd, buffer, sizeof(buffer)-1); | |
127 | if (c <= 0) | |
128 | return c; | |
129 | if (do_skip) { | |
130 | send_output(buffer, c, SEND_CONSOLE); | |
131 | buffer[c] = 0; | |
132 | cp = buffer; | |
133 | while (*cp) { | |
134 | if (skip_mode) { | |
135 | cp = strchr(cp, '\002'); | |
136 | if (!cp) | |
137 | return 0; | |
138 | cp++; | |
139 | skip_mode = 0; | |
140 | continue; | |
141 | } | |
142 | sep = strchr(cp, '\001'); | |
143 | if (sep) | |
144 | *sep = 0; | |
145 | send_output(cp, 0, SEND_LOG); | |
146 | if (sep) { | |
147 | cp = sep + 1; | |
148 | skip_mode = 1; | |
149 | } else | |
150 | break; | |
151 | } | |
152 | } else | |
153 | send_output(buffer, c, SEND_BOTH); | |
154 | return c; | |
155 | } | |
156 | ||
157 | static void signal_term(int sig) | |
158 | { | |
159 | if (child_pid > 0) | |
160 | kill(child_pid, sig); | |
161 | } | |
162 | ||
163 | static int run_program(char **argv) | |
164 | { | |
165 | int fds[2]; | |
166 | int status, rc, pid; | |
167 | char buffer[80]; | |
168 | #ifdef HAVE_SIGNAL_H | |
169 | struct sigaction sa; | |
170 | #endif | |
171 | ||
172 | if (pipe(fds) < 0) { | |
173 | perror("pipe"); | |
174 | exit(1); | |
175 | } | |
176 | ||
177 | #ifdef HAVE_SIGNAL_H | |
178 | memset(&sa, 0, sizeof(struct sigaction)); | |
179 | sa.sa_handler = signal_term; | |
180 | sigaction(SIGINT, &sa, 0); | |
181 | sigaction(SIGTERM, &sa, 0); | |
182 | #ifdef SA_RESTART | |
183 | sa.sa_flags = SA_RESTART; | |
184 | #endif | |
185 | #endif | |
186 | ||
187 | pid = fork(); | |
188 | if (pid < 0) { | |
189 | perror("vfork"); | |
190 | exit(1); | |
191 | } | |
192 | if (pid == 0) { | |
193 | dup2(fds[1],1); /* fds[1] replaces stdout */ | |
194 | dup2(fds[1],2); /* fds[1] replaces stderr */ | |
195 | close(fds[0]); /* don't need this here */ | |
196 | close(fds[1]); | |
197 | ||
198 | execvp(argv[0], argv); | |
199 | perror(argv[0]); | |
200 | exit(1); | |
201 | } | |
202 | child_pid = pid; | |
203 | close(fds[1]); | |
204 | ||
205 | while (!(waitpid(pid, &status, WNOHANG ))) { | |
206 | do_read(fds[0]); | |
207 | } | |
208 | child_pid = -1; | |
209 | do_read(fds[0]); | |
210 | close(fds[0]); | |
211 | ||
212 | if ( WIFEXITED(status) ) { | |
213 | rc = WEXITSTATUS(status); | |
214 | if (rc) { | |
215 | send_output(argv[0], 0, SEND_BOTH); | |
216 | sprintf(buffer, " exited with status code %d\n", rc); | |
217 | send_output(buffer, 0, SEND_BOTH); | |
218 | } | |
219 | } else { | |
220 | if (WIFSIGNALED(status)) { | |
221 | send_output(argv[0], 0, SEND_BOTH); | |
222 | sprintf(buffer, "died with signal %d\n", | |
223 | WTERMSIG(status)); | |
224 | send_output(buffer, 0, SEND_BOTH); | |
225 | return 1; | |
226 | } | |
227 | rc = 0; | |
228 | } | |
229 | return rc; | |
230 | } | |
231 | ||
232 | static int copy_from_stdin(void) | |
233 | { | |
234 | int c, bad_read = 0; | |
235 | ||
236 | while (1) { | |
237 | c = do_read(0); | |
238 | if ((c == 0 ) || | |
239 | ((c < 0) && ((errno == EAGAIN) || (errno == EINTR)))) { | |
240 | if (bad_read++ > 3) | |
241 | break; | |
242 | continue; | |
243 | } | |
244 | if (c < 0) { | |
245 | perror("read"); | |
246 | exit(1); | |
247 | } | |
248 | bad_read = 0; | |
249 | } | |
250 | return 0; | |
251 | } | |
252 | ||
253 | ||
254 | ||
255 | int main(int argc, char **argv) | |
256 | { | |
257 | int c, pid, rc; | |
258 | char *outfn, **cpp; | |
259 | int openflags = O_CREAT|O_WRONLY|O_TRUNC; | |
260 | int send_flag = SEND_LOG; | |
261 | int do_stdin; | |
262 | time_t t; | |
263 | ||
264 | while ((c = getopt(argc, argv, "+asv")) != EOF) { | |
265 | switch (c) { | |
266 | case 'a': | |
267 | openflags &= ~O_TRUNC; | |
268 | openflags |= O_APPEND; | |
269 | break; | |
270 | case 's': | |
271 | do_skip = 1; | |
272 | break; | |
273 | case 'v': | |
274 | verbose++; | |
275 | send_flag |= SEND_CONSOLE; | |
276 | break; | |
277 | } | |
278 | } | |
279 | if (optind == argc || optind+1 == argc) | |
280 | usage(argv[0]); | |
281 | outfn = argv[optind]; | |
282 | optind++; | |
283 | argv += optind; | |
284 | /* argc -= optind; - this is not used */ | |
285 | ||
286 | outfd = open(outfn, openflags, 0644); | |
287 | do_stdin = !strcmp(argv[0], "-"); | |
288 | ||
289 | send_output("Log of ", 0, send_flag); | |
290 | if (do_stdin) | |
291 | send_output("stdin", 0, send_flag); | |
292 | else { | |
293 | for (cpp = argv; *cpp; cpp++) { | |
294 | send_output(*cpp, 0, send_flag); | |
295 | send_output(" ", 0, send_flag); | |
296 | } | |
297 | } | |
298 | send_output("\n", 0, send_flag); | |
299 | t = time(0); | |
300 | send_output(ctime(&t), 0, send_flag); | |
301 | send_output("\n", 0, send_flag); | |
302 | ||
303 | if (do_stdin) | |
304 | rc = copy_from_stdin(); | |
305 | else | |
306 | rc = run_program(argv); | |
307 | ||
308 | send_output("\n", 0, send_flag); | |
309 | t = time(0); | |
310 | send_output(ctime(&t), 0, send_flag); | |
311 | send_output("----------------\n", 0, send_flag); | |
312 | ||
313 | if (outbuf) { | |
314 | pid = fork(); | |
315 | if (pid < 0) { | |
316 | perror("fork"); | |
317 | exit(1); | |
318 | } | |
319 | if (pid) { | |
320 | if (verbose) | |
321 | printf("Backgrounding to save %s later\n", | |
322 | outfn); | |
323 | exit(rc); | |
324 | } | |
325 | setsid(); /* To avoid getting killed by init */ | |
326 | while (outfd < 0) { | |
327 | outfd = open(outfn, openflags, 0644); | |
328 | sleep(1); | |
329 | } | |
330 | write_all(outfd, outbuf, outbufsize); | |
331 | free(outbuf); | |
332 | } | |
333 | if (outfd >= 0) | |
334 | close(outfd); | |
335 | ||
336 | exit(rc); | |
337 | } |
30 | 30 | #include <stdarg.h> |
31 | 31 | #include <getopt.h> |
32 | 32 | #include <stdio.h> |
33 | ||
34 | #ifndef PATH_MAX | |
35 | #define PATH_MAX 2048 | |
36 | #endif | |
33 | 37 | |
34 | 38 | int dostat(char *path, struct stat *st, int do_lstat, int quiet) |
35 | 39 | { |
104 | 108 | int main(int argc, char **argv) |
105 | 109 | { |
106 | 110 | struct stat st, st2; |
107 | char buf[256]; | |
111 | char buf[PATH_MAX + 1]; | |
108 | 112 | char *path; |
109 | 113 | int quiet = 0; |
110 | 114 | int showdev = 0; |
162 | 166 | |
163 | 167 | memset(buf, 0, sizeof(buf)); |
164 | 168 | strncpy(buf, path, sizeof(buf) - 4); |
165 | strcat(buf, "/.."); | |
169 | strncat(buf, "/..", 3); | |
166 | 170 | if (dostat(buf, &st2, 0, quiet) < 0) |
167 | 171 | return 1; |
168 | 172 |
53 | 53 | #include <signal.h> |
54 | 54 | #include <fcntl.h> |
55 | 55 | #include <stdarg.h> |
56 | #ifdef __FreeBSD__ | |
57 | #include <utmpx.h> | |
58 | #else | |
56 | 59 | #include <utmp.h> |
60 | #endif | |
57 | 61 | #include <syslog.h> |
58 | 62 | #include "paths.h" |
59 | 63 | #include "reboot.h" |
60 | 64 | #include "initreq.h" |
61 | 65 | #include "init.h" |
62 | 66 | |
67 | #ifdef __FreeBSD__ | |
68 | extern char **environ; | |
69 | #endif | |
63 | 70 | |
64 | 71 | #define MESSAGELEN 256 |
72 | #define STATELEN 64 | |
73 | #define WHEN_SIZE 64 | |
65 | 74 | |
66 | 75 | /* Whether we should warn system is shutting down */ |
67 | 76 | #define QUIET_FULL 2 |
75 | 84 | int forcefsck = 0; /* Force fsck on reboot */ |
76 | 85 | char message[MESSAGELEN]; /* Warning message */ |
77 | 86 | char *sltime = 0; /* Sleep time */ |
78 | char newstate[64]; /* What are we gonna do */ | |
87 | char newstate[STATELEN]; /* What are we gonna do */ | |
79 | 88 | int doself = 0; /* Don't use init */ |
80 | 89 | int got_alrm = 0; |
81 | 90 | |
224 | 233 | */ |
225 | 234 | void issue_warn(int mins) |
226 | 235 | { |
227 | char buf[MESSAGELEN + sizeof(newstate)]; | |
236 | char buf[MESSAGELEN + sizeof(newstate) + 1]; | |
228 | 237 | int len; |
229 | 238 | |
230 | 239 | buf[0] = 0; |
231 | strncat(buf, message, sizeof(buf) - 1); | |
240 | strncpy(buf, message, MESSAGELEN); | |
232 | 241 | len = strlen(buf); |
233 | 242 | |
234 | 243 | if (mins == 0) |
511 | 520 | char buf[128]; |
512 | 521 | char term[UT_LINESIZE + 6]; |
513 | 522 | char *sp; |
514 | char *when = NULL; | |
523 | char when[WHEN_SIZE]; | |
515 | 524 | int c, i, wt; |
516 | 525 | int hours, mins; |
517 | 526 | int didnolog = 0; |
539 | 548 | } |
540 | 549 | strcpy(down_level, "1"); |
541 | 550 | halttype = NULL; |
551 | memset(when, '\0', WHEN_SIZE); | |
542 | 552 | |
543 | 553 | /* Process the options. */ |
544 | 554 | while((c = getopt(argc, argv, "HPacqQkrhnfFyt:g:i:")) != EOF) { |
585 | 595 | case 'y': /* Ignored for sysV compatibility */ |
586 | 596 | break; |
587 | 597 | case 'g': /* sysv style to specify time. */ |
588 | when = optarg; | |
598 | strncpy(when, optarg, WHEN_SIZE - 1); | |
589 | 599 | break; |
590 | 600 | case 'i': /* Level to go to. */ |
591 | 601 | if (!strchr("0156aAbBcCsS", optarg[0])) { |
671 | 681 | |
672 | 682 | /* Read remaining words, skip time if needed. */ |
673 | 683 | message[0] = 0; |
674 | for(c = optind + (!cancel && !when); c < argc; c++) { | |
684 | for(c = optind + (!cancel && !when[0]); c < argc; c++) { | |
675 | 685 | if (strlen(message) + strlen(argv[c]) + 4 > MESSAGELEN) |
676 | 686 | break; |
677 | 687 | strcat(message, argv[c]); |
696 | 706 | } |
697 | 707 | |
698 | 708 | /* Check syntax. */ |
699 | if (when == NULL) { | |
709 | if (when[0] == '\0') { | |
700 | 710 | if (optind == argc) usage(); |
701 | when = argv[optind++]; | |
711 | strncpy(when, argv[optind++], WHEN_SIZE - 1); | |
702 | 712 | } |
703 | 713 | |
704 | 714 | /* See if we are already running. */ |
717 | 727 | /* Tell users what we're gonna do. */ |
718 | 728 | switch(down_level[0]) { |
719 | 729 | case '0': |
720 | strcpy(newstate, "for system halt"); | |
730 | strncpy(newstate, "for system halt", STATELEN); | |
721 | 731 | break; |
722 | 732 | case '6': |
723 | strcpy(newstate, "for reboot"); | |
733 | strncpy(newstate, "for reboot", STATELEN); | |
724 | 734 | break; |
725 | 735 | case '1': |
726 | strcpy(newstate, "to maintenance mode"); | |
736 | strncpy(newstate, "to maintenance mode", STATELEN); | |
727 | 737 | break; |
728 | 738 | default: |
729 | sprintf(newstate, "to runlevel %s", down_level); | |
739 | snprintf(newstate, STATELEN, "to runlevel %s", down_level); | |
730 | 740 | break; |
731 | 741 | } |
732 | 742 | |
764 | 774 | |
765 | 775 | /* Alias now and take care of old '+mins' notation. */ |
766 | 776 | if (!strcmp(when, "now")) strcpy(when, "0"); |
767 | if (when[0] == '+') when++; | |
768 | ||
777 | ||
778 | sp = when; | |
779 | if (when[0] == '+') sp++; | |
769 | 780 | /* Decode shutdown time. */ |
770 | for (sp = when; *sp; sp++) { | |
781 | for ( ; *sp; sp++) { | |
771 | 782 | if (*sp != ':' && (*sp < '0' || *sp > '9')) |
772 | 783 | usage(); |
773 | 784 | } |
71 | 71 | # include <selinux/get_context_list.h> |
72 | 72 | #endif |
73 | 73 | |
74 | #define PASSWORD_LENGTH 256 | |
75 | ||
74 | 76 | #include "consoles.h" |
75 | 77 | #define CONMAX 16 |
76 | 78 | |
417 | 419 | struct passwd *pw; |
418 | 420 | struct spwd *spw; |
419 | 421 | FILE *fp; |
420 | static char line[256]; | |
421 | static char sline[256]; | |
422 | static char line[PASSWORD_LENGTH]; | |
423 | static char sline[PASSWORD_LENGTH]; | |
422 | 424 | char *p; |
423 | 425 | |
424 | 426 | /* |
452 | 454 | /* |
453 | 455 | * Find root in the password file. |
454 | 456 | */ |
455 | while((p = fgets(line, 256, fp)) != NULL) { | |
457 | while((p = fgets(line, PASSWORD_LENGTH, fp)) != NULL) { | |
456 | 458 | if (strncmp(line, "root:", 5) != 0) |
457 | 459 | continue; |
458 | 460 | p += 5; |
486 | 488 | fprintf(stderr, "sulogin: %s: root password garbled\n\r", F_PASSWD); |
487 | 489 | return &pwd; |
488 | 490 | } |
489 | while((p = fgets(sline, 256, fp)) != NULL) { | |
491 | while((p = fgets(sline, PASSWORD_LENGTH, fp)) != NULL) { | |
490 | 492 | if (strncmp(sline, "root:", 5) != 0) |
491 | 493 | continue; |
492 | 494 | p += 5; |
31 | 31 | #include <time.h> |
32 | 32 | #include <fcntl.h> |
33 | 33 | #include <string.h> |
34 | #ifdef __FreeBSD__ | |
35 | #include <utmpx.h> | |
36 | #else | |
34 | 37 | #include <utmp.h> |
38 | #endif | |
35 | 39 | |
36 | 40 | #include "init.h" |
37 | 41 | #include "initreq.h" |
33 | 33 | |
34 | 34 | |
35 | 35 | #define MAXLEN 4096 |
36 | #define LINE_SIZE 80 | |
36 | 37 | #define MAXLINES 20 |
37 | 38 | |
38 | 39 | int main(int argc, char **argv) |
39 | 40 | { |
40 | 41 | char buf[MAXLEN]; |
41 | char line[83]; | |
42 | char line[LINE_SIZE + 3]; /* leave room for \r\n\0 */ | |
42 | 43 | int i, f, ch; |
43 | 44 | int len = 0; |
44 | 45 | int remote = 0; |
80 | 81 | if ((argc - optind) > 0) { |
81 | 82 | for(f = optind; f < argc; f++) { |
82 | 83 | len += strlen(argv[f]) + 1; |
83 | if (len >= MAXLEN-2) break; | |
84 | if (len >= MAXLEN-4) break; | |
84 | 85 | strcat(buf, argv[f]); |
85 | 86 | if (f < argc-1) strcat(buf, " "); |
86 | 87 | } |