forked from mirrors/tftp-hpa-google
Fork before performing tcpwrappers check.
Don't rely on nonstandard bsd_signal() function, instead require that the platform has sigaction(). This is 2001, after all. This may resolve some potential portability problems. Log a message if memory allocation fails, instead of dying silently. Clean up the main dispatch loop. Use <sysexits.h> for exit codes, if it exists. Reformat tftpd.c to match the other files.
This commit is contained in:
parent
e4650ab86f
commit
81822ea738
10 changed files with 862 additions and 711 deletions
71
tftpd/misc.c
Normal file
71
tftpd/misc.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* $Id$ */
|
||||
/* ----------------------------------------------------------------------- *
|
||||
*
|
||||
* Copyright 2001 H. Peter Anvin - All Rights Reserved
|
||||
*
|
||||
* This program is free software available under the same license
|
||||
* as the "OpenBSD" operating system, distributed at
|
||||
* http://www.openbsd.org/.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* misc.c
|
||||
*
|
||||
* Minor help routines.
|
||||
*/
|
||||
|
||||
#include <syslog.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include "tftpd.h"
|
||||
|
||||
/*
|
||||
* Set the signal handler and flags. Basically a user-friendly
|
||||
* wrapper around sigaction().
|
||||
*/
|
||||
void set_signal(int signum, void (*handler)(int), int flags)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&sa, 0, sizeof sa);
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = flags;
|
||||
|
||||
if ( sigaction(signum, &sa, NULL) ) {
|
||||
syslog(LOG_ERR, "sigaction: %m");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* malloc() that syslogs an error message and bails if it fails.
|
||||
*/
|
||||
void *tfmalloc(size_t size)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
|
||||
if ( !p ) {
|
||||
syslog(LOG_ERR, "malloc: %m");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* strdup() that does the equivalent
|
||||
*/
|
||||
char *tfstrdup(const char *str)
|
||||
{
|
||||
char *p = strdup(str);
|
||||
|
||||
if ( !p ) {
|
||||
syslog(LOG_ERR, "strdup: %m");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue