source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_fork.c @ 1448

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_fork.c
Revision 1448, 1.5 KB checked in by spascoe, 14 years ago (diff)

Implemented two hooks in the bbftpd source that allow
python code to be executed before and afer a fork(). This is needed
to reset python logging and will probably be usefull for other things
in the future.

Line 
1/*
2 * bbftpd/bbftpd_log.c
3 * Copyright (C) 2006, CCLRC
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20/**
21 * A drop-in replacement for fork() which calls hooks to do things before
22 * and afterwards.
23 *
24 * @author: Stephen Pascoe
25 */
26#include <bbftpd.h>
27#include <ndg.h>
28
29#include <bbftpd_private_fork.h>
30
31#include <sys/types.h>
32#include <unistd.h>
33#include <syslog.h>
34
35#include <bbftpd_private_log.h>
36
37#ifdef NDG_PYTHON_EMBED
38
39pid_t bbftpd_fork(void) {
40  pid_t pid;
41
42  char logmessage[NDG_MAX_LOGMESSAGE];
43
44  if (ndg_before_fork_hook(logmessage) != 0) {
45    bbftpd_log(LOG_ERR, "bbftpd_fork: %s", logmessage);
46  }
47
48  pid = fork();
49 
50  /* Don't call the after hook if fork() fails. */
51  if (pid != -1) {
52    if (ndg_after_fork_hook(logmessage) != 0) {
53      bbftpd_log(LOG_ERR, "bbftpd_fork: %s", logmessage);
54    }
55  }
56
57  return pid;
58}
59
60#endif // NDG_PYTHON_EMBED
Note: See TracBrowser for help on using the repository browser.