Skip to content

Commit

Permalink
Fix crash in recovery that occurs during backup.
Browse files Browse the repository at this point in the history
Change-Id: I8d13646eede75c64878b50a8b6f4617a48e10b32
  • Loading branch information
koush committed Dec 13, 2012
1 parent 950f487 commit 0c27228
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions libcrecovery/popen.c
Expand Up @@ -50,13 +50,16 @@ static struct pid {
pid_t pid;
} *pidlist;

extern char **environ;

FILE *
__popen(const char *program, const char *type)
{
struct pid * volatile cur;
FILE *iop;
int pdes[2];
pid_t pid;
char *argp[] = {"sh", "-c", NULL, NULL};

if ((*type != 'r' && *type != 'w') || type[1] != '\0') {
errno = EINVAL;
Expand All @@ -71,7 +74,7 @@ __popen(const char *program, const char *type)
return (NULL);
}

switch (pid = vfork()) {
switch (pid = fork()) {
case -1: /* Error. */
(void)close(pdes[0]);
(void)close(pdes[1]);
Expand All @@ -82,24 +85,17 @@ __popen(const char *program, const char *type)
{
struct pid *pcur;
/*
* because vfork() instead of fork(), must leak FILE *,
* but luckily we are terminally headed for an execl()
* We fork()'d, we got our own copy of the list, no
* contention.
*/
for (pcur = pidlist; pcur; pcur = pcur->next)
close(fileno(pcur->fp));

if (*type == 'r') {
int tpdes1 = pdes[1];

(void) close(pdes[0]);
/*
* We must NOT modify pdes, due to the
* semantics of vfork.
*/
if (tpdes1 != STDOUT_FILENO) {
(void)dup2(tpdes1, STDOUT_FILENO);
(void)close(tpdes1);
tpdes1 = STDOUT_FILENO;
if (pdes[1] != STDOUT_FILENO) {
(void)dup2(pdes[1], STDOUT_FILENO);
(void)close(pdes[1]);
}
} else {
(void)close(pdes[1]);
Expand All @@ -108,7 +104,8 @@ __popen(const char *program, const char *type)
(void)close(pdes[0]);
}
}
execl(_PATH_BSHELL, "sh", "-c", program, (char *)NULL);
argp[2] = (char *)program;
execve(_PATH_BSHELL, argp, environ);
_exit(127);
/* NOTREACHED */
}

This comment has been minimized.

Copy link
@SWQJueLian

SWQJueLian Dec 15, 2012

HI, I was a kid,come from china, I have a question, and I hope to get your reply,how to prevent the automatic shutdown(restart) of the recovery,About 2 min,the recovery will be shutdown or restart. my english is not good.so i hope you not mind. oh,restore is bug, tips is MD5 not true.hope your fix

This comment has been minimized.

Copy link
@koush

koush Dec 15, 2012

Author

You may have a watchdogd issue.

This comment has been minimized.

Copy link
@SWQJueLian

SWQJueLian Dec 16, 2012

thank you for the answer, this is a problem of the kernel, I read some articles. ZTE not open source。。alas。last wish a happy work

Expand Down

2 comments on commit 0c27228

@ryangay
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fix the crash I reported on your G+ Community the other day (Ryan Gay)?

@koush
Copy link
Author

@koush koush commented on 0c27228 Dec 17, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryangay can you link the issue? It may.

Please sign in to comment.