Use the correct pid when substituting PROCESSID.

Problem reported by: Amedeo Beck Peccoz <gea@gressoney.it>
This commit is contained in:
Brian Somers 1999-06-09 08:47:36 +00:00
parent 24c56392de
commit 8fb106c674
5 changed files with 22 additions and 18 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chap.c,v 1.50 1999/05/08 11:06:15 brian Exp $
* $Id: chap.c,v 1.51 1999/06/02 15:58:55 brian Exp $
*
* TODO:
*/
@ -197,6 +197,7 @@ chap_StartChild(struct chap *chap, char *prog, const char *name)
char *argv[MAXARGS], *nargv[MAXARGS];
int argc, fd;
int in[2], out[2];
pid_t pid;
if (chap->child.fd != -1) {
log_Printf(LogWARN, "Chap: %s: Program already running\n", prog);
@ -215,6 +216,7 @@ chap_StartChild(struct chap *chap, char *prog, const char *name)
return;
}
pid = getpid();
switch ((chap->child.pid = fork())) {
case -1:
log_Printf(LogERROR, "Chap: fork: %s\n", strerror(errno));
@ -247,7 +249,7 @@ chap_StartChild(struct chap *chap, char *prog, const char *name)
setuid(geteuid());
argc = command_Interpret(prog, strlen(prog), argv);
command_Expand(nargv, argc, (char const *const *)argv,
chap->auth.physical->dl->bundle, 0);
chap->auth.physical->dl->bundle, 0, pid);
execvp(nargv[0], nargv);
log_Printf(LogWARN, "exec() of %s failed: %s\n",

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: chat.c,v 1.55 1999/05/08 11:06:18 brian Exp $
* $Id: chat.c,v 1.56 1999/05/27 09:50:10 brian Exp $
*/
#include <sys/param.h>
@ -683,7 +683,7 @@ ExecStr(struct physical *physical, char *command, char *out, int olen)
log_Printf(LogCHAT, "Exec: %s\n", command);
argc = MakeArgs(command, vector, VECSIZE(vector));
command_Expand(argv, argc, (char const *const *)vector,
physical->dl->bundle, 0);
physical->dl->bundle, 0, getpid());
if (pipe(fids) < 0) {
log_Printf(LogCHAT, "Unable to create pipe in ExecStr: %s\n",

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.198 1999/06/05 21:35:48 brian Exp $
* $Id: command.c,v 1.199 1999/06/08 20:11:57 brian Exp $
*
*/
#include <sys/param.h>
@ -143,7 +143,7 @@
#define NEG_DNS 52
const char Version[] = "2.22";
const char VersionDate[] = "$Date: 1999/06/05 21:35:48 $";
const char VersionDate[] = "$Date: 1999/06/08 20:11:57 $";
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
@ -395,10 +395,10 @@ subst(char *tgt, const char *oldstr, const char *newstr)
void
command_Expand(char **nargv, int argc, char const *const *oargv,
struct bundle *bundle, int inc0)
struct bundle *bundle, int inc0, pid_t pid)
{
int arg;
char pid[12];
char pidstr[12];
if (inc0)
arg = 0; /* Start at arg 0 */
@ -406,7 +406,7 @@ command_Expand(char **nargv, int argc, char const *const *oargv,
nargv[0] = strdup(oargv[0]);
arg = 1;
}
snprintf(pid, sizeof pid, "%d", getpid());
snprintf(pidstr, sizeof pidstr, "%d", (int)pid);
for (; arg < argc; arg++) {
nargv[arg] = strdup(oargv[arg]);
nargv[arg] = subst(nargv[arg], "HISADDR",
@ -423,7 +423,7 @@ command_Expand(char **nargv, int argc, char const *const *oargv,
mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,
bundle->ncp.mp.cfg.enddisc.address,
bundle->ncp.mp.cfg.enddisc.len));
nargv[arg] = subst(nargv[arg], "PROCESSID", pid);
nargv[arg] = subst(nargv[arg], "PROCESSID", pidstr);
nargv[arg] = subst(nargv[arg], "LABEL", bundle_GetLabel(bundle));
}
nargv[arg] = NULL;
@ -433,7 +433,7 @@ static int
ShellCommand(struct cmdargs const *arg, int bg)
{
const char *shell;
pid_t shpid;
pid_t shpid, pid;
#ifdef SHELL_ONLY_INTERACTIVELY
/* we're only allowed to shell when we run ppp interactively */
@ -459,6 +459,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
}
}
pid = getpid();
if ((shpid = fork()) == 0) {
int i, fd;
@ -489,7 +490,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
argc = sizeof argv / sizeof argv[0] - 1;
log_Printf(LogWARN, "Truncating shell command to %d args\n", argc);
}
command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0);
command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0, pid);
if (bg) {
pid_t p;
@ -2537,7 +2538,7 @@ SetProcTitle(struct cmdargs const *arg)
argc = sizeof argv / sizeof argv[0] - 1;
log_Printf(LogWARN, "Truncating proc title to %d args\n", argc);
}
command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1);
command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid());
ptr = title;
remaining = sizeof title - 1;

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.h,v 1.15 1998/06/15 19:06:06 brian Exp $
* $Id: command.h,v 1.16 1999/02/11 10:14:08 brian Exp $
*
* TODO:
*/
@ -55,7 +55,7 @@ extern const char Version[];
extern const char VersionDate[];
extern void command_Expand(char **, int, char const *const *, struct bundle *,
int);
int, pid_t);
extern int command_Interpret(char *, int, char *vector[MAXARGS]);
extern void command_Run(struct bundle *, int, char const *const *,
struct prompt *, const char *, struct datalink *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: exec.c,v 1.4 1999/06/01 19:08:57 brian Exp $
* $Id: exec.c,v 1.5 1999/06/05 21:35:50 brian Exp $
*/
#include <sys/param.h>
@ -118,7 +118,7 @@ exec_Create(struct physical *p)
strerror(errno));
else {
int stat, argc;
pid_t pid;
pid_t pid, realpid;
char *argv[MAXARGS];
stat = fcntl(fids[0], F_GETFL, 0);
@ -126,6 +126,7 @@ exec_Create(struct physical *p)
stat |= O_NONBLOCK;
fcntl(fids[0], F_SETFL, stat);
}
realpid = getpid();
switch ((pid = fork())) {
case -1:
log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
@ -156,7 +157,7 @@ exec_Create(struct physical *p)
log_Printf(LogDEBUG, "Exec'ing ``%s''\n", p->name.base);
argc = MakeArgs(p->name.base, argv, VECSIZE(argv));
command_Expand(argv, argc, (char const *const *)argv,
p->dl->bundle, 0);
p->dl->bundle, 0, realpid);
execvp(*argv, argv);
fprintf(stderr, "execvp failed: %s: %s\r\n", *argv, strerror(errno));
_exit(127);