Luna/utils/logout.cpp
apio ad3cea7e78
All checks were successful
Build and test / build (push) Successful in 1m42s
gui: Rename "launch" to "execd"
2024-12-11 20:34:47 +01:00

29 lines
687 B
C++

#include <errno.h>
#include <os/ArgumentParser.h>
#include <signal.h>
#include <sys/pstat.h>
// Very hackish. Will do for now.
Result<int> luna_main(int argc, char** argv)
{
os::ArgumentParser parser;
parser.add_description("Log out of a GUI session.");
parser.add_system_program_info("logout"_sv);
parser.parse(argc, argv);
pid_t last = pstat(-1, nullptr);
for (pid_t pid = 1; pid <= last; pid++)
{
static process ps;
if (pstat(pid, &ps) < 0)
{
if (errno == ESRCH) continue;
return err(errno);
}
if (strstr(ps.ps_name, "/usr/bin/execd")) { kill(ps.ps_pid, SIGTERM); }
}
return 0;
}