Tidy up the parent notification stuff for -background mode.

Remove extraneous extern decls of tun_{in,out} and netfd.
This commit is contained in:
Brian Somers 1998-03-25 18:38:59 +00:00
parent 75b8d2834b
commit 5cf4388bdf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=34888
5 changed files with 40 additions and 44 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.31 1998/03/20 19:47:40 brian Exp $
* $Id: bundle.c,v 1.1.2.32 1998/03/25 00:59:28 brian Exp $
*/
#include <sys/param.h>
@ -182,6 +182,19 @@ bundle_LayerStart(void *v, struct fsm *fp)
bundle_NewPhase(bundle, PHASE_ESTABLISH);
}
static void
bundle_Notify(struct bundle *bundle, char c)
{
if (bundle->notify.fd != -1) {
if (write(bundle->notify.fd, &c, 1) == 1)
LogPrintf(LogPHASE, "Parent notified of success.\n");
else
LogPrintf(LogPHASE, "Failed to notify parent of success.\n");
close(bundle->notify.fd);
bundle->notify.fd = -1;
}
}
static void
bundle_LayerUp(void *v, struct fsm *fp)
{
@ -204,16 +217,7 @@ bundle_LayerUp(void *v, struct fsm *fp)
if (fp->proto == PROTO_IPCP) {
bundle_StartIdleTimer(bundle);
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_NORMAL;
if (write(BGFiledes[1], &c, 1) == 1)
LogPrintf(LogPHASE, "Parent notified of success.\n");
else
LogPrintf(LogPHASE, "Failed to notify parent of success.\n");
close(BGFiledes[1]);
BGFiledes[1] = -1;
}
bundle_Notify(bundle, EX_NORMAL);
}
}
@ -477,9 +481,9 @@ bundle_Create(const char *prefix)
bundle.filter.dial.name = "DIAL";
bundle.filter.alive.name = "ALIVE";
bundle.filter.alive.logok = 1;
memset(&bundle.idle.timer, '\0', sizeof bundle.idle.timer);
bundle.idle.done = 0;
bundle.notify.fd = -1;
/* Clean out any leftover crud */
bundle_CleanInterface(&bundle);
@ -534,6 +538,8 @@ bundle_Destroy(struct bundle *bundle)
while (dl)
dl = datalink_Destroy(dl);
bundle_Notify(bundle, EX_ERRDEAD);
bundle->ifname = NULL;
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.19 1998/03/18 23:15:31 brian Exp $
* $Id: bundle.h,v 1.1.2.20 1998/03/20 19:47:42 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -71,6 +71,10 @@ struct bundle {
struct pppTimer timer; /* timeout after cfg.idle_timeout */
time_t done;
} idle;
struct {
int fd; /* write status here */
} notify;
};
#define descriptor2bundle(d) \

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: defs.c,v 1.11.4.3 1998/02/10 03:23:15 brian Exp $
* $Id: defs.c,v 1.11.4.4 1998/03/24 18:46:49 brian Exp $
*/
#include <sys/param.h>
@ -44,8 +44,6 @@
#include "vars.h"
int mode = MODE_INTER;
int BGFiledes[2] = { -1, -1 };
static char dstsystem[50];
void

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: defs.h,v 1.29.2.5 1998/03/09 19:24:56 brian Exp $
* $Id: defs.h,v 1.29.2.6 1998/03/09 19:26:37 brian Exp $
*
* TODO:
*/
@ -77,13 +77,8 @@
#define EX_NOLOGIN 13
extern int mode;
extern int BGFiledes[2];
extern int tun_in;
extern int tun_out;
extern int netfd;
extern void SetLabel(const char *);
extern const char *GetLabel(void);
extern void randinit(void);
extern int GetShortHost(void);
extern void DropClient(int);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.37 1998/03/25 00:59:38 brian Exp $
* $Id: main.c,v 1.121.2.38 1998/03/25 18:38:24 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -113,15 +113,6 @@ AbortProgram(int excode)
prompt_Drop(&prompt, 1);
ServerClose();
ID0unlink(pid_filename);
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_ERRDEAD;
if (write(BGFiledes[1], &c, 1) == 1)
LogPrintf(LogPHASE, "Parent notified of failure.\n");
else
LogPrintf(LogPHASE, "Failed to notify parent of failure.\n");
close(BGFiledes[1]);
}
LogPrintf(LogPHASE, "PPP Terminated (%s).\n", ex_desc(excode));
prompt_TtyOldMode(&prompt);
bundle_Close(SignalBundle, NULL, 1);
@ -421,26 +412,26 @@ main(int argc, char **argv)
}
if (mode & MODE_DAEMON) {
if (mode & MODE_BACKGROUND) {
if (pipe(BGFiledes)) {
LogPrintf(LogERROR, "pipe: %s\n", strerror(errno));
if (!(mode & MODE_DIRECT)) {
int bgpipe[2];
pid_t bgpid;
if (mode & MODE_BACKGROUND && pipe(bgpipe)) {
LogPrintf(LogERROR, "pipe: %s\n", strerror(errno));
Cleanup(EX_SOCK);
}
}
if (!(mode & MODE_DIRECT)) {
pid_t bgpid;
bgpid = fork();
if (bgpid == -1) {
LogPrintf(LogERROR, "fork: %s\n", strerror(errno));
Cleanup(EX_SOCK);
}
if (bgpid) {
char c = EX_NORMAL;
if (mode & MODE_BACKGROUND) {
close(BGFiledes[1]);
close(bgpipe[1]);
BGPid = bgpid;
/* If we get a signal, kill the child */
signal(SIGHUP, KillChild);
@ -449,7 +440,7 @@ main(int argc, char **argv)
signal(SIGQUIT, KillChild);
/* Wait for our child to close its pipe before we exit */
if (read(BGFiledes[0], &c, 1) != 1) {
if (read(bgpipe[0], &c, 1) != 1) {
prompt_Printf(&prompt, "Child exit, no status.\n");
LogPrintf(LogPHASE, "Parent: Child exit, no status.\n");
} else if (c == EX_NORMAL) {
@ -460,11 +451,13 @@ main(int argc, char **argv)
LogPrintf(LogPHASE, "Parent: Child failed (%s).\n",
ex_desc((int) c));
}
close(BGFiledes[0]);
close(bgpipe[0]);
}
return c;
} else if (mode & MODE_BACKGROUND)
close(BGFiledes[0]);
} else if (mode & MODE_BACKGROUND) {
close(bgpipe[0]);
bundle->notify.fd = bgpipe[1];
}
}
prompt_Init(&prompt, PROMPT_NONE);