forked from brummer10/nosuspend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nosuspend.c
34 lines (32 loc) · 848 Bytes
/
nosuspend.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
/* gcc -o nosuspend nosuspend.c */
/* chown -v root:root ./nosuspend */
/* chmod -v 4755 ./nosuspend */
int main(int argc,char* argv[]){
if(argc<2) return 0;
if(fork() == 0){
int status;
char uname[100];
getlogin_r(uname,100);
char cmd[5000];
const char* cmd1 = "systemd-inhibit --why='User application run' su ";
const char* cmd2 = " -c '";
strcat(cmd, cmd1);
strcat(cmd,uname);
strcat(cmd, cmd2);
for (int i = 1; i < argc; ++i)
{
strcat(cmd, argv[i]);
strcat(cmd, " ");
}
strcat(cmd, " '");
setuid(0);
status = system(cmd);
exit(0);
}
return 0;
}