From 1468e9a310c4de86ab4530398fc7a4afa9f65a54 Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 26 Jan 2014 22:38:20 +0000 Subject: [PATCH] explain why forks fail --- bin/sh/eval.c | 10 ++++++---- bin/sh/jobs.c | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 0686374d47ad..8b7f44e3c786 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.107 2013/06/27 23:22:04 yamt Exp $ */ +/* $NetBSD: eval.c,v 1.108 2014/01/26 22:38:20 christos Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.107 2013/06/27 23:22:04 yamt Exp $"); +__RCSID("$NetBSD: eval.c,v 1.108 2014/01/26 22:38:20 christos Exp $"); #endif #endif /* not lint */ @@ -845,15 +845,17 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd) */ if (cmdentry.cmdtype == CMDNORMAL) { pid_t pid; + int serrno; savelocalvars = localvars; localvars = NULL; vforked = 1; switch (pid = vfork()) { case -1: - TRACE(("Vfork failed, errno=%d\n", errno)); + serrno = errno; + TRACE(("Vfork failed, errno=%d\n", serrno)); INTON; - error("Cannot vfork"); + error("Cannot vfork (%s)", strerror(serrno)); break; case 0: /* Make sure that exceptions only unwind to diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index 515d458e5ae6..458b3ebf1769 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.71 2012/12/31 14:10:15 dsl Exp $ */ +/* $NetBSD: jobs.c,v 1.72 2014/01/26 22:38:20 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: jobs.c,v 1.71 2012/12/31 14:10:15 dsl Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.72 2014/01/26 22:38:20 christos Exp $"); #endif #endif /* not lint */ @@ -858,14 +858,16 @@ makejob(union node *node, int nprocs) int forkshell(struct job *jp, union node *n, int mode) { - int pid; + pid_t pid; + int serrno; TRACE(("forkshell(%%%d, %p, %d) called\n", jp - jobtab, n, mode)); switch ((pid = fork())) { case -1: - TRACE(("Fork failed, errno=%d\n", errno)); + serrno = errno; + TRACE(("Fork failed, errno=%d\n", serrno)); INTON; - error("Cannot fork"); + error("Cannot fork (%s)", strerror(serrno)); break; case 0: forkchild(jp, n, mode, 0);