iv_popen(3)

✨ iv_popen β€” bestie edition ✨

okay so this is from the ivykis programmer's manual, and it's literally about IV_POPEN_REQUEST_INIT, iv_popen_request_submit, and iv_popen_request_close β€” which is just popen(3) but for ivykis apps 🫢


🌸 NAME 🌸

IV_POPEN_REQUEST_INIT, iv_popen_request_submit, iv_popen_request_close β€” it's giving popen(3) but make it for ivykis applications πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <iv_popen.h>

struct iv_popen_request {
        char            *file;
        char            **argv;
        char            *type;
};

void IV_POPEN_REQUEST_INIT(struct iv_popen_request *this);
int iv_popen_request_submit(struct iv_popen_request *this);
void iv_popen_request_close(struct iv_popen_request *this);

like. that's the whole vibe. no cap. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so iv_popen hands ivykis(3) applications an asynchronous version of popen(3) β€” and the way it's fully integrated with the ivykis event loop?? obsessed πŸ˜­πŸ’–

So here's the routine, bestie. First you initialise your struct iv_popen_request object using IV_POPEN_REQUEST_INIT, and you assign its ->file, ->argv, and ->type members. Once that's done, you can call iv_popen_request_submit on it. What happens next is:

  • it forks off a child process 🌱
  • that child will call execvp(2) on ->file and ->argv
  • meanwhile, back in the parent process, you get returned a file descriptor that's connected to the child's standard input (if ->type equals "w") or the child's standard output (if ->type equals "r")

so basically you get a pipe to your new little buddy. iconic.


When your application is done with the child process, it should call iv_popen_request_close and close the file descriptor that iv_popen_request_submit returned. and listen β€” that close is not done automatically, okay?? not me forgetting to close my fd πŸ™ˆ you have to do it yourself, fr fr.


Also, iv_popen keeps monitoring the child's process state the whole time it's running, by registering an iv_wait(3) interest for its process ID. main character energy: it never stops watching πŸ‘‘


Now for the part where we get a lil serious. If the child process hasn't terminated yet when iv_popen_request_close is called, iv_popen will attempt to terminate that child process in the background by sending it a series of SIGTERM and SIGKILL signals. πŸ’€ so yeah, it will absolutely end things if it has to.

🚨 important bestie alert: iv_popen_request_close must be called from the same thread that iv_popen_request_submit was called from on this object. like, same thread, same object, no switching up. periodt.

πŸ’œ SEE ALSO πŸ’œ

go read them, iykyk 🧚


okay that's the whole page, bestie!! this one's from the ivykis manual, dated 2010-09-04 β€” and yeah it's been serving since 2010, we love a vintage slay 🌈✨ mwah, go fork something responsibly πŸ’…πŸ’–