utils: Add a hackish "logout" command
All checks were successful
Build and test / build (push) Successful in 1m45s
All checks were successful
Build and test / build (push) Successful in 1m45s
This commit is contained in:
parent
e7d361ca51
commit
bbe1eca711
@ -34,3 +34,4 @@ luna_utility(touch.cpp touch)
|
||||
luna_utility(free.cpp free)
|
||||
luna_utility(sha256sum.cpp sha256sum)
|
||||
luna_utility(arch.cpp arch)
|
||||
luna_utility(logout.cpp logout)
|
||||
|
28
utils/logout.cpp
Normal file
28
utils/logout.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#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/launch")) { kill(ps.ps_pid, SIGTERM); }
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user