vsftpd/vsftpd-2.1.1-daemonize_plus.patch
2009-05-04 14:37:06 +00:00

152 lines
4.1 KiB
Diff

diff -up vsftpd-2.1.1/standalone.c.daemonize_plus vsftpd-2.1.1/standalone.c
--- vsftpd-2.1.1/standalone.c.daemonize_plus 2009-05-04 16:18:30.000000000 +0200
+++ vsftpd-2.1.1/standalone.c 2009-05-04 16:18:30.000000000 +0200
@@ -26,6 +26,8 @@ static unsigned int s_ipaddr_size;
static void handle_sigchld(void* duff);
static void handle_sighup(void* duff);
+static void handle_sigusr1(int sig);
+static void handle_sigalrm(int sig);
static void prepare_child(int sockfd);
static unsigned int handle_ip_count(void* p_raw_addr);
static void drop_ip_count(void* p_raw_addr);
@@ -50,7 +52,13 @@ vsf_standalone_main(void)
if (forkret > 0)
{
/* Parent, just exit */
- vsf_sysutil_exit(0);
+ vsf_sysutil_sigaction(kVSFSysUtilSigALRM, handle_sigalrm);
+ vsf_sysutil_sigaction(kVSFSysUtilSigUSR1, handle_sigusr1);
+
+ vsf_sysutil_set_alarm(3);
+ vsf_sysutil_pause();
+
+ vsf_sysutil_exit(1);
}
/* Son, close standard FDs to avoid SSH hang-on-exit */
vsf_sysutil_reopen_standard_fds();
@@ -98,6 +106,10 @@ vsf_standalone_main(void)
{
die("could not bind listening IPv4 socket");
}
+ else
+ {
+ vsf_sysutil_kill(vsf_sysutil_getppid(), kVSFSysUtilSigUSR1);
+ }
}
else
{
@@ -127,6 +139,10 @@ vsf_standalone_main(void)
{
die("could not bind listening IPv6 socket");
}
+ else
+ {
+ vsf_sysutil_kill(vsf_sysutil_getppid(), kVSFSysUtilSigUSR1);
+ }
}
vsf_sysutil_close(0);
vsf_sysutil_close(1);
@@ -252,6 +268,20 @@ handle_sighup(void* duff)
vsf_parseconf_load_file(0, 0);
}
+static void
+handle_sigalrm(int sig)
+{
+ (void)sig; // avoid unused parameter error
+ vsf_sysutil_exit(1);
+}
+
+static void
+handle_sigusr1(int sig)
+{
+ (void)sig; // avoid unused parameter error
+ vsf_sysutil_exit(0);
+}
+
static unsigned int
hash_ip(unsigned int buckets, void* p_key)
{
diff -up vsftpd-2.1.1/sysutil.c.daemonize_plus vsftpd-2.1.1/sysutil.c
--- vsftpd-2.1.1/sysutil.c.daemonize_plus 2009-05-04 16:18:30.000000000 +0200
+++ vsftpd-2.1.1/sysutil.c 2009-05-04 16:18:30.000000000 +0200
@@ -201,6 +201,9 @@ vsf_sysutil_translate_sig(const enum EVS
case kVSFSysUtilSigHUP:
realsig = SIGHUP;
break;
+ case kVSFSysUtilSigUSR1:
+ realsig = SIGUSR1;
+ break;
default:
bug("unknown signal in vsf_sysutil_translate_sig");
break;
@@ -538,6 +541,12 @@ vsf_sysutil_getpid(void)
return (unsigned int) s_current_pid;
}
+unsigned int
+vsf_sysutil_getppid(void)
+{
+ return (unsigned int)getppid();
+}
+
int
vsf_sysutil_fork(void)
{
@@ -2786,3 +2795,23 @@ vsf_sysutil_set_no_fds()
die("setrlimit NOFILE");
}
}
+
+void
+vsf_sysutil_sigaction(const enum EVSFSysUtilSignal sig, void (*p_handlefunc)(int))
+{
+ int realsig = vsf_sysutil_translate_sig(sig);
+ vsf_sysutil_set_sighandler(realsig, p_handlefunc);
+}
+
+int
+vsf_sysutil_kill(int pid, int sig)
+{
+ int realsig = vsf_sysutil_translate_sig(sig);
+ return kill(pid, realsig);
+}
+
+int
+vsf_sysutil_pause()
+{
+ return pause();
+}
diff -up vsftpd-2.1.1/sysutil.h.daemonize_plus vsftpd-2.1.1/sysutil.h
--- vsftpd-2.1.1/sysutil.h.daemonize_plus 2009-05-04 16:18:30.000000000 +0200
+++ vsftpd-2.1.1/sysutil.h 2009-05-04 16:23:47.000000000 +0200
@@ -29,7 +29,8 @@ enum EVSFSysUtilSignal
kVSFSysUtilSigCHLD,
kVSFSysUtilSigPIPE,
kVSFSysUtilSigURG,
- kVSFSysUtilSigHUP
+ kVSFSysUtilSigHUP,
+ kVSFSysUtilSigUSR1
};
enum EVSFSysUtilInterruptContext
{
@@ -164,6 +165,7 @@ void vsf_sysutil_free(void* p_ptr);
/* Process creation/exit/process handling */
unsigned int vsf_sysutil_getpid(void);
+unsigned int vsf_sysutil_getppid(void);
int vsf_sysutil_fork(void);
int vsf_sysutil_fork_failok(void);
void vsf_sysutil_exit(int exit_code);
@@ -180,6 +182,9 @@ int vsf_sysutil_wait_exited_normally(
const struct vsf_sysutil_wait_retval* p_waitret);
int vsf_sysutil_wait_get_exitcode(
const struct vsf_sysutil_wait_retval* p_waitret);
+void vsf_sysutil_sigaction(const enum EVSFSysUtilSignal sig, void (*p_handlefunc)(int));
+int vsf_sysutil_kill(int pid, int sig);
+int vsf_sysutil_pause();
/* Various string functions */
unsigned int vsf_sysutil_strlen(const char* p_text);