source:
patches/sysklogd-1.4.1-fixes-1.patch@
5832ebe
Last change on this file since 5832ebe was 69cde8d, checked in by , 19 years ago | |
---|---|
|
|
File size: 27.4 KB |
-
CHANGES
Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes) Date: 2005-01-23 Initial Package Version: 1.4.1 Upstream Status: Not submitted Origin: http://www.infodrom.org/projects/sysklogd/cvs.php3 Description: This patch is a cvs snapshot update as of 20050123. Minus the debain and CVS directories. See the CHANGES. diff -Naur sysklogd-1.4.1/CHANGES sysklogd-20050123/CHANGES
old new 1 Version 1.4.2 2 3 . Dmitry V. Levin <ldv@altlinux.org> 4 - Close file descriptor in FindSymbolFile() in ksym.c in order not to 5 leak file descriptors. 6 . Solar Designer <solar@openwall.com> 7 - improve crunch_list() 8 - Prevent potential buffer overflow in reading messages from the 9 kernel log ringbuffer. 10 - Ensure that "len" is not placed in a register, and that the 11 endtty() signal handler is not installed too early which could 12 cause a segmentation fault or worse. 13 . Steve Grubb <linux_4ever@yahoo.com> 14 - fix memory calculation in crunch_list() 15 . Martin Schulze <joey@infodrom.org> 16 - klogd will reconnect to the logger (mostly syslogd) after it went 17 away 18 - On heavily loaded system syslog will not spit out error messages 19 anymore when recvfrom() results in EAGAIN 20 - Makefile improvements 21 - Local copy of module.h 22 - Improved sysklogd.8 23 - Always log with syslogd's timezone and locale 24 - Remove trailing newline when forwarding messages 25 . Jon Burgess <Jon_Burgess@eur.3com.com> 26 - Moved the installation of the signal handler up a little bit so it 27 guaranteed to be available when the child is forked, hence, fixing a 28 race condition. This used to create problems with UML and fast 29 machines. 30 . Greg Trounson <gregt@maths.otago.ac.nz> 31 - Improved README.linux 32 . Ulf Härnhammar <Ulf.Harnhammar.9485@student.uu.se> 33 - Bondary check for fscanf() in InitKsyms() and CheckMapVersion() 34 . Colin Phipps <cph@cph.demon.co.uk> 35 - Don't block on the network socket in case of package los 36 . Dirk Mueller <mueller@kde.org> 37 - Don't crash when filesize limit is reached (e.g. without LFS) 38 39 1 40 Version 1.4.1 2 41 3 42 . klogd will set the console log level only if `-c' is given on the … … 30 69 . Olaf Kirch <okir@caldera.de> 31 70 - Remove Unix Domain Sockets and switch to Datagram Unix Sockets 32 71 . Several bugfixes and improvements, please refer to the .c files 72 73 74 Local variables: 75 mode: indented-text 76 fill-column: 72 77 End: -
klogd.8
diff -Naur sysklogd-1.4.1/klogd.8 sysklogd-20050123/klogd.8
old new 321 321 .B klogd 322 322 to reload the module symbol information whenever a protection fault 323 323 is detected. Caution should be used before invoking the program in 324 \ 'paranoid\' mode. The stability of the kernel and the operating324 \&'paranoid\&' mode. The stability of the kernel and the operating 325 325 environment is always under question when a protection fault occurs. 326 326 Since the klogd daemon must execute system calls in order to read the 327 327 module symbol information there is the possibility that the system may -
klogd.c
diff -Naur sysklogd-1.4.1/klogd.c sysklogd-20050123/klogd.c
old new 243 243 * people have submitted patches: Troels Walsted Hansen 244 244 * <troels@thule.no>, Wolfgang Oertl <Wolfgang.Oertl@uibk.ac.at> 245 245 * and Thomas Roessler. 246 * Thu Apr 29 15:24:07 2004: Solar Designer <solar@openwall.com> 247 * Prevent potential buffer overflow in reading messages from the 248 * kernel log rinbuffer. 246 249 */ 247 250 248 251 … … 938 941 * messages into this fresh buffer. 939 942 */ 940 943 memset(log_buffer, '\0', sizeof(log_buffer)); 941 if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer) )) < 0 )944 if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer)-1)) < 0 ) 942 945 { 943 946 if ( errno == EINTR ) 944 947 return; -
ksym.c
diff -Naur sysklogd-1.4.1/ksym.c sysklogd-20050123/ksym.c
old new 105 105 * 106 106 * Tue Sep 12 23:48:12 CEST 2000: Martin Schulze <joey@infodrom.ffis.de> 107 107 * Close symbol file in InitKsyms() when an error occurred. 108 * 109 * Thu Apr 29 18:07:16 CEST 2004: Dmitry Levin <ldv@altlinux.org> 110 * Close file descriptor in FindSymbolFile() in order not to leak 111 * file descriptors. 112 * 113 * Fri Jul 16 08:32:49 CEST 2004: Ulf Härnhammar <Ulf.Harnhammar.9485@student.uu.se> 114 * Added boundary check for fscanf() in InitKsyms() and 115 * CheckMapVersion() to prevent an unintended crash when reading 116 * an incorrect System.map. 108 117 */ 109 118 110 119 … … 236 245 */ 237 246 while ( !feof(sym_file) ) 238 247 { 239 if ( fscanf(sym_file, "%lx %c % s\n", &address, &type, sym)248 if ( fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym) 240 249 != 3 ) 241 250 { 242 251 Syslog(LOG_ERR, "Error in symbol table input (#1)."); … … 344 353 if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) { 345 354 if (CheckMapVersion(symfile) == 1) 346 355 file = symfile; 356 fclose (sym_file); 347 357 } 348 358 if (sym_file == (FILE *) 0 || file == (char *) 0) { 349 359 sprintf (symfile, "%s", *mf); … … 352 362 if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) { 353 363 if (CheckMapVersion(symfile) == 1) 354 364 file = symfile; 365 fclose (sym_file); 355 366 } 356 367 } 357 368 … … 533 544 version = 0; 534 545 while ( !feof(sym_file) && (version == 0) ) 535 546 { 536 if ( fscanf(sym_file, "%lx %c % s\n", &address, \547 if ( fscanf(sym_file, "%lx %c %511s\n", &address, \ 537 548 &type, sym) != 3 ) 538 549 { 539 550 Syslog(LOG_ERR, "Error in symbol table input (#2)."); … … 899 910 return; 900 911 } 901 912 #endif 913 914 /* 915 * Local variables: 916 * c-indent-level: 8 917 * c-basic-offset: 8 918 * tab-width: 8 919 * End: 920 */ -
ksym_mod.c
diff -Naur sysklogd-1.4.1/ksym_mod.c sysklogd-20050123/ksym_mod.c
old new 78 78 * 79 79 * Tue Sep 12 23:11:13 CEST 2000: Martin Schulze <joey@infodrom.ffis.de> 80 80 * Changed llseek() to lseek64() in order to skip a libc warning. 81 * 82 * Wed Mar 31 17:35:01 CEST 2004: Martin Schulze <joey@infodrom.org> 83 * Removed references to <linux/module.h> since it doesn't work 84 * anymore with its recent content from Linux 2.4/2.6, created 85 * module.h locally instead. 81 86 */ 82 87 83 88 … … 89 94 #include <errno.h> 90 95 #include <sys/fcntl.h> 91 96 #include <sys/stat.h> 97 #include "module.h" 92 98 #if !defined(__GLIBC__) 93 99 #include <linux/time.h> 94 #include <linux/ module.h>100 #include <linux/linkage.h> 95 101 #else /* __GLIBC__ */ 96 #include <linux/ module.h>102 #include <linux/linkage.h> 97 103 extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence)); 98 104 extern int get_kernel_syms __P ((struct kernel_sym *__table)); 99 105 #endif /* __GLIBC__ */ … … 107 113 108 114 #if !defined(__GLIBC__) 109 115 /* 110 * The following bit uses some kernel/library magic to produc twhat116 * The following bit uses some kernel/library magic to produce what 111 117 * looks like a function call to user level code. This function is 112 118 * actually a system call in disguise. The purpose of the getsyms 113 119 * call is to return a current copy of the in-kernel symbol table. -
Makefile
diff -Naur sysklogd-1.4.1/Makefile sysklogd-20050123/Makefile
old new 4 4 #CFLAGS= -g -DSYSV -Wall 5 5 #LDFLAGS= -g 6 6 CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce 7 # -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 7 8 LDFLAGS= -s 8 9 9 10 # Look where your install program is. 10 11 INSTALL = /usr/bin/install 11 BINDIR = /usr/sbin 12 MANDIR = /usr/man 12 13 # Destination paths, set prefix=/opt if required 14 BINDIR = $(prefix)/usr/sbin 15 MANDIR = $(prefix)/usr/share/man 13 16 14 17 # There is one report that under an all ELF system there may be a need to 15 18 # explicilty link with libresolv.a. If linking syslogd fails you may wish … … 34 37 # The following define establishes ownership for the man pages. 35 38 # Avery tells me that there is a difference between Debian and 36 39 # Slackware. Rather than choose sides I am leaving it up to the user. 37 MAN_OWNER = root 38 # MAN_OWNER = man 40 MAN_USER = root 41 MAN_GROUP = root 42 MAN_PERMS = 644 39 43 40 44 # The following define establishes the name of the pid file for the 41 45 # syslogd daemon. The library include file (paths.h) defines the … … 116 120 ${INSTALL} -m 500 -s klogd ${BINDIR}/klogd 117 121 118 122 install_man: 119 ${INSTALL} -o ${MAN_ OWNER} -g ${MAN_OWNER} -m 644sysklogd.8 ${MANDIR}/man8/sysklogd.8120 ${INSTALL} -o ${MAN_ OWNER} -g ${MAN_OWNER} -m 644syslogd.8 ${MANDIR}/man8/syslogd.8121 ${INSTALL} -o ${MAN_ OWNER} -g ${MAN_OWNER} -m 644syslog.conf.5 ${MANDIR}/man5/syslog.conf.5122 ${INSTALL} -o ${MAN_ OWNER} -g ${MAN_OWNER} -m 644klogd.8 ${MANDIR}/man8/klogd.8123 ${INSTALL} -o ${MAN_USER} -g ${MAN_GROUP} -m ${MAN_PERMS} sysklogd.8 ${MANDIR}/man8/sysklogd.8 124 ${INSTALL} -o ${MAN_USER} -g ${MAN_GROUP} -m ${MAN_PERMS} syslogd.8 ${MANDIR}/man8/syslogd.8 125 ${INSTALL} -o ${MAN_USER} -g ${MAN_GROUP} -m ${MAN_PERMS} syslog.conf.5 ${MANDIR}/man5/syslog.conf.5 126 ${INSTALL} -o ${MAN_USER} -g ${MAN_GROUP} -m ${MAN_PERMS} klogd.8 ${MANDIR}/man8/klogd.8 -
module.h
diff -Naur sysklogd-1.4.1/module.h sysklogd-20050123/module.h
old new 1 /* 2 module.h - Miscellaneous module definitions 3 Copyright (c) 1996 Richard Henderson <rth@tamu.edu> 4 Copyright (c) 2004 Martin Schulze <joey@infodrom.org> 5 6 This file is part of the sysklogd package. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 23 /* ChangeLog: 24 * 25 * Wed Mar 31 17:35:01 CEST 2004: Martin Schulze <joey@infodrom.org> 26 * Created local copy of module.h based on the content of Linux 27 * 2.2 since <linux/module.h> doesn't work anymore with its 28 * recent content from Linux 2.4/2.6. 29 */ 30 31 #include <asm/atomic.h> 32 33 #define MODULE_NAME_LEN 60 34 35 struct kernel_sym 36 { 37 unsigned long value; 38 char name[MODULE_NAME_LEN]; 39 }; 40 41 42 struct list_head { 43 struct list_head *next, *prev; 44 }; 45 46 47 struct module_info 48 { 49 unsigned long addr; 50 unsigned long size; 51 unsigned long flags; 52 long usecount; 53 }; 54 55 56 struct module 57 { 58 unsigned long size_of_struct; /* == sizeof(module) */ 59 struct module *next; 60 const char *name; 61 unsigned long size; 62 63 union 64 { 65 int usecount; 66 long pad; 67 } uc; /* Needs to keep its size - so says rth */ 68 69 unsigned long flags; /* AUTOCLEAN et al */ 70 71 unsigned nsyms; 72 unsigned ndeps; 73 74 struct module_symbol *syms; 75 struct module_ref *deps; 76 struct module_ref *refs; 77 int (*init)(void); 78 void (*cleanup)(void); 79 const struct exception_table_entry *ex_table_start; 80 const struct exception_table_entry *ex_table_end; 81 #ifdef __alpha__ 82 unsigned long gp; 83 #endif 84 /* Members past this point are extensions to the basic 85 module support and are optional. Use mod_opt_member() 86 to examine them. */ 87 const struct module_persist *persist_start; 88 const struct module_persist *persist_end; 89 int (*can_unload)(void); 90 }; -
pidfile.c
diff -Naur sysklogd-1.4.1/pidfile.c sysklogd-20050123/pidfile.c
old new 87 87 int fd; 88 88 int pid; 89 89 90 if ( ((fd = open(pidfile, O_RDWR|O_CREAT , 0644)) == -1)90 if ( ((fd = open(pidfile, O_RDWR|O_CREAT|O_TRUNC, 0644)) == -1) 91 91 || ((f = fdopen(fd, "r+")) == NULL) ) { 92 92 fprintf(stderr, "Can't open or create %s.\n", pidfile); 93 93 return 0; -
README.1st
diff -Naur sysklogd-1.4.1/README.1st sysklogd-20050123/README.1st
old new 1 Very important information before using version 1.3 2 --------------------- ------------------------------1 Important information 2 --------------------- 3 3 4 4 The included version of syslogd behaves in a slightly different manner 5 5 to the one in former releases. Please review the following important … … 63 63 these scripts should remove all old .pid files found in /var/run. 64 64 This will insure that klogd and syslogd start properly even if prior 65 65 executions have been terminated harshly. 66 67 * Large file support, i.e. support to write to log files that are 68 larger than 2 GB is not part of syslogd, but a matter of the Glibc 69 emitting different system calls to the kernel interface. To support 70 large files you'll have to compile syslogd with the compiler defines 71 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE so that glibc adjusts the 72 system calls. -
README.linux
diff -Naur sysklogd-1.4.1/README.linux sysklogd-20050123/README.linux
old new 40 40 a useful addition to the software gene pool. 41 41 42 42 There is a mailing list covering this package and syslog in general. 43 The lists address is sysklogd@Infodrom.North.DE. To subscribe send a44 mail to Majordomo@Infodrom.North.DE with a line "subscribesysklogd"43 The lists address is infodrom-sysklogd@lists.infodrom.org . To subscribe send a 44 mail to majordomo@lists.infodrom.org with a line "subscribe infodrom-sysklogd" 45 45 in the message body. 46 46 47 New versions of this package will be available at Joey's ftp server. 48 ftp://ftp.infodrom.north.de/pub/people/joey/sysklogd/ 47 A second mailing list exists as infodrom-sysklogd-cvs@lists.infodrom.org. Only 48 CVS messages and diffs are distributed there. Whenever new code is added to 49 sysklogd, CVS generates a mail from these changes which will be sent to 50 this list. Discussions will take place on the first list. 51 52 The latest version of this software can be found at: 53 http://www.infodrom.org/projects/sysklogd/download.php3 49 54 50 55 Best regards, 51 56 … … 67 72 68 73 Martin Schulze 69 74 Infodrom Oldenburg 70 joey@ linux.de75 joey@infodrom.org 71 76 72 And a hostof bug reporters whose contributions cannot be underestimated.77 And a number of bug reporters whose contributions cannot be underestimated. -
sysklogd.8
diff -Naur sysklogd-1.4.1/sysklogd.8 sysklogd-20050123/sysklogd.8
old new 84 84 .B MAXFUNIX 85 85 within the syslogd.c source file. An example for a chroot() daemon is 86 86 described by the people from OpenBSD at 87 http://www.psionic.com/papers/dns.html.87 <http://www.guides.sk/psionic/dns/>. 88 88 .TP 89 89 .B "\-d" 90 90 Turns on debug mode. Using this the daemon will not proceed a … … 117 117 between two \fI-- MARK --\fR lines is 20 minutes. This can be changed 118 118 with this option. Setting the 119 119 .I interval 120 to zero turns it off entirely. 120 to zero turns it off entirely. Depending on other log messages 121 generated these lines may not be written consecutively. 121 122 .TP 122 123 .B "\-n" 123 124 Avoid auto-backgrounding. This is needed especially if the … … 364 365 365 366 To avoid this in further times no messages that were received from a 366 367 remote host are sent out to another (or the same) remote host 367 anymore. If there are scenarios where this doesn't make sense, please 368 drop me (Joey) a line. 368 anymore. If you experience are setup in which this doesn't make 369 sense, please use the 370 .B \-h 371 commandline switch. 369 372 370 373 If the remote host is located in the same domain as the host, 371 374 .B syslogd -
syslog.c
diff -Naur sysklogd-1.4.1/syslog.c sysklogd-20050123/syslog.c
old new 47 47 * Sun Mar 11 20:23:44 CET 2001: Martin Schulze <joey@infodrom.ffis.de> 48 48 * Use SOCK_DGRAM for loggin, renables it to work. 49 49 * 50 * Wed Aug 27 17:48:16 CEST 2003: Martin Schulze <joey@Infodrom.org> 51 * Improved patch by Michael Pomraning <mjp@securepipe.com> to 52 * reconnect klogd to the logger after it went away. 50 53 */ 51 54 52 55 #include <sys/types.h> … … 98 101 register char *p; 99 102 time_t now; 100 103 int fd, saved_errno; 104 int result; 101 105 char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0; 102 106 103 107 saved_errno = errno; … … 167 171 } 168 172 169 173 /* output the message to the local logger */ 170 if (write(LogFile, tbuf, cnt + 1) >= 0 || !(LogStat&LOG_CONS)) 174 result = write(LogFile, tbuf, cnt + 1); 175 176 if (result == -1 177 && (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) { 178 closelog(); 179 openlog(LogTag, LogStat | LOG_NDELAY, LogFacility); 180 result = write(LogFile, tbuf, cnt + 1); 181 } 182 183 if (result >= 0 || !(LogStat&LOG_CONS)) 171 184 return; 172 185 173 186 /* -
syslog.conf.5
diff -Naur sysklogd-1.4.1/syslog.conf.5 sysklogd-20050123/syslog.conf.5
old new 64 64 The 65 65 .I facility 66 66 is one of the following keywords: 67 .BR auth ", " authpriv ", " cron ", " daemon ", " kern ", " lpr ", "67 .BR auth ", " authpriv ", " cron ", " daemon ", " ftp ", " kern ", " lpr ", " 68 68 .BR mail ", " mark ", " news ", " security " (same as " auth "), " 69 69 .BR syslog ", " user ", " uucp " and " local0 " through " local7 . 70 70 The keyword … … 121 121 122 122 This 123 123 .BR syslogd (8) 124 has a syntax extension to the original BSD source, thatmakes its use124 has a syntax extension to the original BSD source, which makes its use 125 125 more intuitively. You may precede every priority with an equation sign 126 (``='') to specify only this single priority and not any of the 127 above. You may also (both is valid, too) precede the priority with an 128 exclamation mark (``!'') to ignore all that priorities, either exact 129 this one or this and any higher priority. If you use both extensions 126 (``='') to specify that 127 .B syslogd 128 should only refer to this single priority and not this priority and 129 all higher priorities. 130 131 You may also precide the priority with an exclamation mark (``!'') if 132 you want 133 .B syslogd 134 to ignore this priority and all higher priorities. 135 You may even use both, the exclamation mark and the equation sign if 136 you want 137 .B syslogd 138 to ignore only this single priority. If you use both extensions 130 139 than the exclamation mark must occur before the equation sign, just 131 140 use it intuitively. 132 141 … … 300 309 .B syslogd 301 310 log all messages that come with either the 302 311 .BR info " or the " notice 303 facility into the file312 priority into the file 304 313 .IR /var/log/messages , 305 314 except for all messages that use the 306 315 .B mail -
syslogd.c
diff -Naur sysklogd-1.4.1/syslogd.c sysklogd-20050123/syslogd.c
old new 441 441 * Don't return a closed fd if `-a' is called with a wrong path. 442 442 * Thanks to Bill Nottingham <notting@redhat.com> for providing 443 443 * a patch. 444 * Thu Apr 13 05:08:10 CEST 2001: Jon Burgess <Jon_Burgess@eur.3com.com> 445 * Moved the installation of the signal handler up a little bit 446 * so it guaranteed to be available when the child is forked, 447 * hence, fixing a race condition. This used to create problems 448 * with UML and fast machines. 449 * 450 * Sat Apr 17 18:03:05 CEST 2004: Steve Grubb <linux_4ever@yahoo.com> 451 * Correct memory allocation for for commandline arguments in 452 * crunch_list(). 453 * 454 * Thu Apr 29 12:38:39 CEST 2004: Solar Designer <solar@openwall.com> 455 * Applied Openwall paranoia patches to improve crunch_list(). 456 * 457 * Tue May 4 16:47:30 CEST 2004: Solar Designer <solar@openwall.com> 458 * Ensure that "len" is not placed in a register, and that the 459 * endtty() signal handler is not installed too early which could 460 * cause a segmentation fault or worse. 461 * 462 * Tue May 4 16:52:01 CEST 2004: Solar Designer <solar@openwall.com> 463 * Adjust the size of a variable to prevent a buffer overflow 464 * should _PATH_DEV ever contain something different than "/dev/". 465 * 466 * Tue Nov 2 20:28:23 CET 2004: Colin Phipps <cph@cph.demon.co.uk> 467 * Don't block on the network socket, in case a packet gets lost 468 * between select and recv. 469 * 470 * Sun Nov 7 12:28:47 CET 2004: Martin Schulze <joey@infodrom.org> 471 * Discard any timestamp information found in received syslog 472 * messages. This will affect local messages sent from a 473 * different timezone. 474 * 475 * Sun Nov 7 13:47:00 CET 2004: Martin Schulze <joey@infodrom.org> 476 * Remove trailing newline when forwarding messages. 444 477 */ 445 478 446 479 … … 890 923 dprintf("Checking pidfile.\n"); 891 924 if (!check_pid(PidFile)) 892 925 { 926 signal (SIGTERM, doexit); 893 927 if (fork()) { 894 928 /* 895 929 * Parent process 896 930 */ 897 signal (SIGTERM, doexit);898 931 sleep(300); 899 932 /* 900 933 * Not reached unless something major went wrong. 5 … … 992 1025 (void) signal(SIGCHLD, reapchild); 993 1026 (void) signal(SIGALRM, domark); 994 1027 (void) signal(SIGUSR1, Debug ? debug_switch : SIG_IGN); 1028 (void) signal(SIGXFSZ, SIG_IGN); 995 1029 (void) alarm(TIMERINTVL); 996 1030 997 1031 /* Create a partial message table for all file descriptors. */ … … 1141 1175 */ 1142 1176 printchopped(from, line, \ 1143 1177 i + 2, finet); 1144 } else if (i < 0 && errno != EINTR ) {1178 } else if (i < 0 && errno != EINTR && errno != EAGAIN) { 1145 1179 dprintf("INET socket error: %d = %s.\n", \ 1146 1180 errno, strerror(errno)); 1147 1181 logerror("recvfrom inet"); 1148 1182 /* should be harmless now that we set 1149 1183 * BSDCOMPAT on the socket */ 1150 sleep(1 0);1184 sleep(1); 1151 1185 } 1152 1186 } 1153 1187 #endif … … 1216 1250 { 1217 1251 int fd, on = 1; 1218 1252 struct sockaddr_in sin; 1253 int sockflags; 1219 1254 1220 1255 fd = socket(AF_INET, SOCK_DGRAM, 0); 1221 1256 if (fd < 0) { … … 1241 1276 close(fd); 1242 1277 return -1; 1243 1278 } 1279 /* We must not block on the network socket, in case a packet 1280 * gets lost between select and recv, otherise the process 1281 * will stall until the timeout, and other processes trying to 1282 * log will also stall. 1283 */ 1284 if ((sockflags = fcntl(fd, F_GETFL)) != -1) { 1285 sockflags |= O_NONBLOCK; 1286 /* 1287 * SETFL could fail too, so get it caught by the subsequent 1288 * error check. 1289 */ 1290 sockflags = fcntl(fd, F_SETFL, sockflags); 1291 } 1292 if (sockflags == -1) { 1293 logerror("fcntl(O_NONBLOCK), suspending inet"); 1294 close(fd); 1295 return -1; 1296 } 1244 1297 if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) { 1245 1298 logerror("bind, suspending inet"); 1246 1299 close(fd); … … 1254 1307 crunch_list(list) 1255 1308 char *list; 1256 1309 { 1257 int count, i;1310 int i, m, n; 1258 1311 char *p, *q; 1259 1312 char **result = NULL; 1260 1313 1261 1314 p = list; 1262 1315 1263 1316 /* strip off trailing delimiters */ 1264 while (p[strlen(p)-1] == LIST_DELIMITER) { 1265 count--; 1317 while (*p && p[strlen(p)-1] == LIST_DELIMITER) 1266 1318 p[strlen(p)-1] = '\0'; 1267 }1268 1319 /* cut off leading delimiters */ 1269 while (p[0] == LIST_DELIMITER) { 1270 count--; 1320 while (p[0] == LIST_DELIMITER) 1271 1321 p++; 1272 }1273 1322 1274 /* count delimiters to calculate elements */1275 for ( count=i=0; p[i]; i++)1276 if (p[i] == LIST_DELIMITER) count++;1323 /* count delimiters to calculate the number of elements */ 1324 for (n = i = 0; p[i]; i++) 1325 if (p[i] == LIST_DELIMITER) n++; 1277 1326 1278 if ((result = (char **)malloc(sizeof(char *) * count+2)) == NULL) {1327 if ((result = (char **)malloc(sizeof(char *) * (n + 2))) == NULL) { 1279 1328 printf ("Sorry, can't get enough memory, exiting.\n"); 1280 exit( 0);1329 exit(1); 1281 1330 } 1282 1331 1283 1332 /* … … 1285 1334 * characters are different from any delimiters, 1286 1335 * so we don't have to care about this. 1287 1336 */ 1288 count= 0;1289 while ((q =strchr(p, LIST_DELIMITER))) {1290 result[ count] = (char *) malloc((q - p + 1) * sizeof(char));1291 if (result[ count] == NULL) {1337 m = 0; 1338 while ((q = strchr(p, LIST_DELIMITER)) && m < n) { 1339 result[m] = (char *) malloc((q - p + 1) * sizeof(char)); 1340 if (result[m] == NULL) { 1292 1341 printf ("Sorry, can't get enough memory, exiting.\n"); 1293 exit( 0);1342 exit(1); 1294 1343 } 1295 strncpy(result[count], p, q - p);1296 result[ count][q - p] = '\0';1344 memcpy(result[m], p, q - p); 1345 result[m][q - p] = '\0'; 1297 1346 p = q; p++; 1298 count++;1347 m++; 1299 1348 } 1300 if ((result[count] = \ 1301 (char *)malloc(sizeof(char) * strlen(p) + 1)) == NULL) { 1349 if ((result[m] = strdup(p)) == NULL) { 1302 1350 printf ("Sorry, can't get enough memory, exiting.\n"); 1303 exit( 0);1351 exit(1); 1304 1352 } 1305 strcpy(result[count],p); 1306 result[++count] = NULL; 1353 result[++m] = NULL; 1307 1354 1308 1355 #if 0 1309 count=0;1310 while (result[ count])1311 dprintf ("#%d: %s\n", count, StripDomains[count++]);1356 m = 0; 1357 while (result[m]) 1358 dprintf ("#%d: %s\n", m, result[m++]); 1312 1359 #endif 1313 1360 return result; 1314 1361 } … … 1548 1595 1549 1596 /* 1550 1597 * Check to see if msg looks non-standard. 1598 * 1599 * A message looks like 1600 * Nov 17 11:42:33 CRON[ 1601 * 01234567890123456 1602 * ^ ^ ^ ^ ^ 1603 * 1604 * Remote messages are not accompanied by a timestamp. 1605 * Local messages are accompanied by a timestamp (program's timezone) 1551 1606 */ 1552 1607 msglen = strlen(msg); 1553 if (msglen < 16 || msg[3] != ' ' || msg[6] != ' ' || 1554 msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') 1555 flags |= ADDDATE; 1556 1557 (void) time(&now); 1558 if (flags & ADDDATE) 1559 timestamp = ctime(&now) + 4; 1560 else { 1561 timestamp = msg; 1608 if (!(msglen < 16 || msg[3] != ' ' || msg[6] != ' ' || 1609 msg[9] != ':' || msg[12] != ':' || msg[15] != ' ')) { 1562 1610 msg += 16; 1563 1611 msglen -= 16; 1564 1612 } 1565 1613 1614 (void) time(&now); 1615 timestamp = ctime(&now) + 4; 1616 1566 1617 /* extract facility and priority level */ 1567 1618 if (flags & MARK) 1568 1619 fac = LOG_NFACILITIES; … … 1771 1822 dprintf("Not sending message to remote.\n"); 1772 1823 else { 1773 1824 f->f_time = now; 1774 (void) snprintf(line, sizeof(line), "<%d>%s \n", f->f_prevpri, \1825 (void) snprintf(line, sizeof(line), "<%d>%s", f->f_prevpri, \ 1775 1826 (char *) iov[4].iov_base); 1776 1827 l = strlen(line); 1777 1828 if (l > MAXLINE) … … 1815 1866 v->iov_len = 1; 1816 1867 } 1817 1868 again: 1818 /* f->f_file == -1 is an indicator that thewe couldn't1869 /* f->f_file == -1 is an indicator that we couldn't 1819 1870 open the file at startup. */ 1820 1871 if (f->f_file == -1) 1821 1872 break; … … 1852 1903 errno = e; 1853 1904 logerror(f->f_un.f_fname); 1854 1905 } 1855 } else if (f->f_ flags & SYNC_FILE)1906 } else if (f->f_type == F_FILE && (f->f_flags & SYNC_FILE)) 1856 1907 (void) fsync(f->f_file); 1857 1908 break; 1858 1909 … … 1891 1942 register struct filed *f; 1892 1943 struct iovec *iov; 1893 1944 { 1894 char p[ 6+ UNAMESZ];1945 char p[sizeof (_PATH_DEV) + UNAMESZ]; 1895 1946 register int i; 1896 1947 int ttyf, len; 1897 1948 static int reenter = 0; … … 1899 1950 struct utmp *uptr; 1900 1951 char greetings[200]; 1901 1952 1953 (void) &len; 1954 1902 1955 if (reenter++) 1903 1956 return; 1904 1957 … … 1913 1966 if (fork() == 0) { 1914 1967 (void) signal(SIGTERM, SIG_DFL); 1915 1968 (void) alarm(0); 1916 (void) signal(SIGALRM, endtty);1917 1969 #ifndef SYSV 1918 1970 (void) signal(SIGTTOU, SIG_IGN); 1919 1971 (void) sigsetmask(0); … … 1929 1981 /* is this slot used? */ 1930 1982 if (ut.ut_name[0] == '\0') 1931 1983 continue; 1932 if (ut.ut_type == LOGIN_PROCESS)1984 if (ut.ut_type != USER_PROCESS) 1933 1985 continue; 1934 1986 if (!(strcmp (ut.ut_name,"LOGIN"))) /* paranoia */ 1935 1987 continue; … … 1959 2011 iov[1].iov_len = 0; 1960 2012 } 1961 2013 if (setjmp(ttybuf) == 0) { 2014 (void) signal(SIGALRM, endtty); 1962 2015 (void) alarm(15); 1963 2016 /* open the terminal */ 1964 2017 ttyf = open(p, O_WRONLY|O_NOCTTY);
Note:
See TracBrowser
for help on using the repository browser.