koraa / pipe_exec

Execute binaries from pipes, stdin and ttys
MIT License
66 stars 6 forks source link

It's kind of weird that this is written in C++ #1

Closed datenwolf closed 5 years ago

datenwolf commented 8 years ago

Hi,

nice thingy! But it's kind of weird that this is written in C++. Makes it quite non idiomatic in *nix terms. Also bloats the tools size, because of all the C++ template expansions.

Also since this is tied to Linux anyway (memfd_create is Linux proprietary) you could simply use splice(2) to copy the data from stdin to the memfd.

koraa commented 5 years ago

Using splice now. Splice has a disadvantage though, it only works for normal files and pipes; not for ptys (and potentially other types of files). So there is still a userspace copy implementation, but now it's using ftruncate, read and mmap instead of read+write.

I also endet up switching to C since after my refactoring I was no longer using any relevant C++ features. You may note though that the size of the program has not really changed; template expansion can eat quite a lot of space, but only if you use it a lot… C++ is still pay-what-you-use :)