
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define PM2_BINDIR "@l_prefix@/bin"
#define PM2_VARDIR "@l_prefix@/var/pm2/run"
#define PM2_BIN    "@l_prefix@/bin/pm2"

int main(int argn, char **argv)
{
    static char *env[] = {
        "PATH=/bin:/usr/bin:/sbin:/usr/sbin:" PM2_BINDIR,
        "HOME=" PM2_VARDIR,
        NULL
    };
    if (setuid(geteuid()) == -1) {
        perror("setuid");
        exit(1);
    }
    if (setgid(getegid()) == -1) {
        perror("setgid");
        exit(1);
    }
    argv[0] = PM2_BIN;
    if (execve(argv[0], argv, env) == -1)
        abort();
    return 0;
}

