Message ID | 20170912083718.1272-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | core: properly handle failed spawn | expand |
Hi Christian, On 12/09/2017 10:37, Christian Storm wrote: > Spawning has failed. This may happen if > (1) a swupdate_process start() method unexpectedly returned or > (2) execvp() failed, e.g., if the executable file is not found. Right. > In this case, exit this (child) process to not continue initialization > in this and the main process as the two share .text > Agree. > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > core/pctl.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/core/pctl.c b/core/pctl.c > index 182cb60..6a2822e 100644 > --- a/core/pctl.c > +++ b/core/pctl.c > @@ -160,8 +160,13 @@ static int spawn_process(struct swupdate_task *task, > > if (start) > return (*start)(cfgname, ac, av); > - else > - return execvp(cmdline, av); > + else { > + if (execvp(cmdline, av) == -1) { > + INFO("Spawning process %s failed: %s", av[0], strerror(errno)); > + return -1; > + } > + return 0; > + } > } > > static void start_swupdate_subprocess(sourcetype type, > @@ -177,8 +182,8 @@ static void start_swupdate_subprocess(sourcetype type, > procs[nprocs].name = name; > procs[nprocs].type = type; > if (spawn_process(&procs[nprocs], uid, gid, cfgfile, argc, argv, start, cmdline) < 0) { > - ERROR("SPAWN %s failed, exiting...\n", name); > - return; > + ERROR("Spawning %s failed, exiting process...\n", name); > + exit(1); > } > > TRACE("Started %s with pid %d and fd %d", name, procs[nprocs].pid, procs[nprocs].pipe); > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano
diff --git a/core/pctl.c b/core/pctl.c index 182cb60..6a2822e 100644 --- a/core/pctl.c +++ b/core/pctl.c @@ -160,8 +160,13 @@ static int spawn_process(struct swupdate_task *task, if (start) return (*start)(cfgname, ac, av); - else - return execvp(cmdline, av); + else { + if (execvp(cmdline, av) == -1) { + INFO("Spawning process %s failed: %s", av[0], strerror(errno)); + return -1; + } + return 0; + } } static void start_swupdate_subprocess(sourcetype type, @@ -177,8 +182,8 @@ static void start_swupdate_subprocess(sourcetype type, procs[nprocs].name = name; procs[nprocs].type = type; if (spawn_process(&procs[nprocs], uid, gid, cfgfile, argc, argv, start, cmdline) < 0) { - ERROR("SPAWN %s failed, exiting...\n", name); - return; + ERROR("Spawning %s failed, exiting process...\n", name); + exit(1); } TRACE("Started %s with pid %d and fd %d", name, procs[nprocs].pid, procs[nprocs].pipe);
Spawning has failed. This may happen if (1) a swupdate_process start() method unexpectedly returned or (2) execvp() failed, e.g., if the executable file is not found. In this case, exit this (child) process to not continue initialization in this and the main process as the two share .text Signed-off-by: Christian Storm <christian.storm@siemens.com> --- core/pctl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)