Clean up code style

This commit is contained in:
madmaurice 2021-01-15 20:22:22 +01:00
parent 6bd03ad564
commit b94fa5bfcf

18
main.c
View file

@ -12,7 +12,8 @@
pid_t pid_child;
void drop_root(void) {
void drop_root(void)
{
uid_t uid = getuid();
// Drop root privileges
if (setresuid(-1,uid,uid) == -1)
@ -31,7 +32,8 @@ void drop_root(void) {
}
// sanity check
if(seteuid(0) != -1) {
if (seteuid(0) != -1)
{
printf("Sanity check failed. I was able to regain root.\n");
exit(1);
}
@ -39,7 +41,8 @@ void drop_root(void) {
void forward_signal(int sig)
{
if(kill(pid_child, sig) == -1) {
if (kill(pid_child, sig) == -1)
{
printf("Unable to forward signal %d to child\n", sig);
if (sig == SIGTERM)
exit(1);
@ -59,7 +62,8 @@ char** argdup(int argc, const char** argv)
int main(int argc, const char** argv)
{
if(argc == 1) {
if (argc == 1)
{
printf("Usage: pidjail PROGRAM ARGUMENTS...\n"
"Run command within its own pid namespace. Integrated init process.\n");
return 0;
@ -90,7 +94,8 @@ int main(int argc, const char** argv)
// Setup signal handler to forward SIGTERM
pid_child = pid;
if(signal(SIGTERM, forward_signal) == SIG_ERR) {
if (signal(SIGTERM, forward_signal) == SIG_ERR)
{
printf("Unable to setup signal handler in head\n");
}
// parent waits for child then exits
@ -122,7 +127,8 @@ int main(int argc, const char** argv)
// Setup forward for SIGTERM
pid_child = first_child;
if(signal(SIGTERM, forward_signal) == SIG_ERR) {
if (signal(SIGTERM, forward_signal) == SIG_ERR)
{
printf("Unable to setup signal forward in init. Aborting.\n");
return 1;
}