Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selfExeDir doesn't always work #2570

Open
daurnimator opened this issue May 28, 2019 · 1 comment
Open

selfExeDir doesn't always work #2570

daurnimator opened this issue May 28, 2019 · 1 comment
Labels
os-linux standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@daurnimator
Copy link
Contributor

check that stack overflow link wink

I didn't see the answer in there.
FWIW I tried it with the following C program:

#define _GNU_SOURCE
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>

char elf[] = {
#include "elf.xxd"
};

int main() {
	int fd = memfd_create("foo", MFD_CLOEXEC);
	if (fd==-1) return 1;
	if (write(fd, elf, sizeof elf) < 0) return 2;
	if (fd != 3) return 3;
	fd = open("/proc/self/fd/3", O_RDONLY);
	if (-1 == fd) return 4;
	if (-1 == close(3)) return 5;
	char *cmd[] = { "ls", "-l", "/proc/self/fd/", "/proc/self/exe", NULL };
	char *env[] = { NULL };
	if (-1 == fexecve(fd, cmd, env)) return 6;
	return 7;
}

Where elf.xxd is created with xxd -i < /usr/bin/ls > elf.xxd

And I see:

lrwxrwxrwx 1 root root 0 May 27 16:15 /proc/self/exe -> '/memfd:foo (deleted)'

/proc/self/fd:
total 0
lrwx------ 1 root root 64 May 27 16:15 0 -> /dev/pts/1
lrwx------ 1 root root 64 May 27 16:15 1 -> /dev/pts/1
lrwx------ 1 root root 64 May 27 16:15 2 -> /dev/pts/1
lr-x------ 1 root root 64 May 27 16:15 3 -> /proc/18364/fd
lr-x------ 1 root root 64 May 27 16:15 4 -> '/memfd:foo (deleted)'

Originally posted by @daurnimator in #2527

@andrewrk andrewrk added this to the 0.6.0 milestone May 28, 2019
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels May 28, 2019
@shawnl
Copy link
Contributor

shawnl commented May 30, 2019

/memfd:foo

What a horrible design decision on the behalf of Linux (and Lennart Poettering/Greg KH that overlooked kdbus that memfd came from).... There should be two forward slashes // so that this is not ambiguous....., or perhaps start with a null byte, but that can be problematic even if it is not ambiguous.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 5, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 30, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.8.1 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.8.1, 0.9.1 Sep 1, 2021
@andrewrk andrewrk modified the milestones: 0.9.1, 0.9.0, 0.10.0 Nov 20, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
@andrewrk andrewrk added os-linux and removed bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Jul 26, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, unplanned Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os-linux standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants