summaryrefslogtreecommitdiff
path: root/exec
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2023-05-05 12:10:14 +0800
committerPo Lu <luangruo@yahoo.com>2023-05-05 12:10:14 +0800
commit2ba6c5035c904426d564eac47381480158cbbb9e (patch)
treeb576d09ca7ae39e22e52c4004a8b02f0e833c3d7 /exec
parentd5414f1797467b00ca4f75faf39c774b150fc509 (diff)
downloademacs-2ba6c5035c904426d564eac47381480158cbbb9e.tar.gz
Update Android port
* doc/emacs/android.texi (Android Environment): Document lossage with SIGSTOP. * exec/exec.c (exec_0): Check X_OK on file being opened. Also handle /proc/self/exe.
Diffstat (limited to 'exec')
-rw-r--r--exec/exec.c76
1 files changed, 46 insertions, 30 deletions
diff --git a/exec/exec.c b/exec/exec.c
index 17051428658..a15386b51bb 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -961,52 +961,68 @@ exec_0 (char *name, struct exec_tracee *tracee,
ssize_t link_size;
size_t remaining;
- /* If name is not absolute, then make it relative to TRACEE's
- cwd. Use stpcpy, as sprintf is not reentrant. */
+ /* If the process is trying to run /proc/self/exe, make it run
+ itself instead. */
- if (name[0] && name[0] != '/')
+ if (!strcmp (name, "/proc/self/exe") && tracee->exec_file)
{
- /* Clear `buffer'. */
- memset (buffer, 0, sizeof buffer);
- memset (buffer1, 0, sizeof buffer);
+ strncpy (name, tracee->exec_file, PATH_MAX - 1);
+ name[PATH_MAX] = '\0';
+ }
+ else
+ {
+ /* If name is not absolute, then make it relative to TRACEE's
+ cwd. Use stpcpy, as sprintf is not reentrant. */
- /* Copy over /proc, the PID, and /cwd/. */
- rewrite = stpcpy (buffer, "/proc/");
- rewrite = format_pid (rewrite, tracee->pid);
- stpcpy (rewrite, "/cwd");
+ if (name[0] && name[0] != '/')
+ {
+ /* Clear `buffer'. */
+ memset (buffer, 0, sizeof buffer);
+ memset (buffer1, 0, sizeof buffer);
- /* Resolve this symbolic link. */
+ /* Copy over /proc, the PID, and /cwd/. */
+ rewrite = stpcpy (buffer, "/proc/");
+ rewrite = format_pid (rewrite, tracee->pid);
+ stpcpy (rewrite, "/cwd");
- link_size = readlink (buffer, buffer1,
- PATH_MAX + 1);
+ /* Resolve this symbolic link. */
- if (link_size < 0)
- return NULL;
+ link_size = readlink (buffer, buffer1,
+ PATH_MAX + 1);
- /* Check that the name is a reasonable size. */
+ if (link_size < 0)
+ return NULL;
- if (link_size > PATH_MAX)
- {
- /* The name is too long. */
- errno = ENAMETOOLONG;
- return NULL;
- }
+ /* Check that the name is a reasonable size. */
+
+ if (link_size > PATH_MAX)
+ {
+ /* The name is too long. */
+ errno = ENAMETOOLONG;
+ return NULL;
+ }
- /* Add a directory separator if necessary. */
+ /* Add a directory separator if necessary. */
- if (!link_size || buffer1[link_size - 1] != '/')
- buffer1[link_size] = '/', link_size++;
+ if (!link_size || buffer1[link_size - 1] != '/')
+ buffer1[link_size] = '/', link_size++;
- rewrite = buffer1 + link_size;
- remaining = buffer1 + sizeof buffer1 - rewrite - 1;
- rewrite = stpncpy (rewrite, name, remaining);
+ rewrite = buffer1 + link_size;
+ remaining = buffer1 + sizeof buffer1 - rewrite - 1;
+ rewrite = stpncpy (rewrite, name, remaining);
- /* Replace name with buffer1. */
+ /* Replace name with buffer1. */
#ifndef REENTRANT
- strcpy (name, buffer1);
+ strcpy (name, buffer1);
#endif /* REENTRANT */
+ }
}
+ /* Check that the file is accessible and executable. */
+
+ if (access (name, X_OK))
+ return NULL;
+
fd = open (name, O_RDONLY);
if (fd < 0)
return NULL;