Initial commit.
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
commit
44227dc1c2
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tmhd
|
||||||
|
|
26
LICENSE.md
Normal file
26
LICENSE.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# DON'T BE A DICK PUBLIC LICENSE
|
||||||
|
|
||||||
|
> Version 1.1, December 2016
|
||||||
|
|
||||||
|
> Copyright (C) 2023 Slendi <slendi@socopon.com>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document.
|
||||||
|
|
||||||
|
> DON'T BE A DICK PUBLIC LICENSE
|
||||||
|
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
1. Do whatever you like with the original work, just don't be a dick.
|
||||||
|
|
||||||
|
Being a dick includes - but is not limited to - the following instances:
|
||||||
|
|
||||||
|
1a. Outright copyright infringement - Don't just copy this and change the name.
|
||||||
|
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
|
||||||
|
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
|
||||||
|
|
||||||
|
2. If you become rich through modifications, related works/services, or supporting the original work,
|
||||||
|
share the love. Only a dick would make loads off this work and not buy the original work's
|
||||||
|
creator(s) a pint.
|
||||||
|
|
||||||
|
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
|
||||||
|
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
|
6
makefile
Normal file
6
makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
CFLAGS=$(shell pkg-config --libs --cflags libnotify)
|
||||||
|
tmhd: tmhd.c
|
||||||
|
cc $(CFLAGS) tmhd.c -o tmhd
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f tmhd
|
152
tmhd.c
Normal file
152
tmhd.c
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
// Two Minutes Hate Daemon (tmhd) for Linux systems.
|
||||||
|
//
|
||||||
|
// Runs as a daemon. Everyday, at a programmed time, CPU goes to 100% and the
|
||||||
|
// computer starts hating processes running on the system.
|
||||||
|
|
||||||
|
#define HOUR 14
|
||||||
|
#define MINUTE 27
|
||||||
|
#define DELAY 5
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <libnotify/notify.h>
|
||||||
|
|
||||||
|
#define MESSAGES_LEN 8
|
||||||
|
static char const *MESSAGES[MESSAGES_LEN] = {
|
||||||
|
"I fucking hate %s!",
|
||||||
|
"%s fucking sucks!",
|
||||||
|
"Down with %s!",
|
||||||
|
"Boo! Boo!",
|
||||||
|
"AAAAAAAAAAAAAAAAAAA",
|
||||||
|
"%s should cease to exist!",
|
||||||
|
"%s was programmed by a retard!",
|
||||||
|
"The pinacle of stupidity is %s!",
|
||||||
|
};
|
||||||
|
|
||||||
|
bool program_running = true;
|
||||||
|
bool hogging_cpu = false;
|
||||||
|
void *cpu_hog_thread(void *_)
|
||||||
|
{
|
||||||
|
while (program_running)
|
||||||
|
if (!hogging_cpu) usleep(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_numeric(const char *str)
|
||||||
|
{
|
||||||
|
for (int i = 0; str[i] != '\0'; i++)
|
||||||
|
if (!isdigit(str[i])) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has_slash(char *str)
|
||||||
|
{
|
||||||
|
for (char *ptr = str; *ptr != '\0'; ptr++)
|
||||||
|
if (*ptr == '/') return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char process_name_buf[256];
|
||||||
|
char *get_random_process_name()
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *entry;
|
||||||
|
|
||||||
|
dir = opendir("/proc");
|
||||||
|
if (dir == NULL) {
|
||||||
|
perror("opendir");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
int num_proc = 0;
|
||||||
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
|
if (entry->d_type == DT_DIR && is_numeric(entry->d_name)
|
||||||
|
&& atoi(entry->d_name) != 0) {
|
||||||
|
num_proc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
dir = opendir("/proc");
|
||||||
|
if (dir == NULL) {
|
||||||
|
perror("opendir");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int random_index = rand() % num_proc;
|
||||||
|
int current_index = 0;
|
||||||
|
explicit_bzero(process_name_buf, sizeof(process_name_buf));
|
||||||
|
|
||||||
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
|
if (entry->d_type == DT_DIR && is_numeric(entry->d_name)
|
||||||
|
&& atoi(entry->d_name) != 0) {
|
||||||
|
if (current_index == random_index) {
|
||||||
|
pid_t pid = atoi(entry->d_name);
|
||||||
|
char path[256];
|
||||||
|
snprintf(path, sizeof(path) - 1, "/proc/%d/status", pid);
|
||||||
|
FILE *fp = fopen(path, "r");
|
||||||
|
if (!fp) break;
|
||||||
|
fscanf(fp, "Name:\t%s\n", process_name_buf);
|
||||||
|
fclose(fp);
|
||||||
|
if (has_slash(process_name_buf)) {
|
||||||
|
closedir(dir);
|
||||||
|
return get_random_process_name();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
return process_name_buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_hate()
|
||||||
|
{
|
||||||
|
NotifyNotification *n;
|
||||||
|
for (unsigned i = 0; i < 60 * 2 && program_running; i += DELAY) {
|
||||||
|
char hate_msg[256];
|
||||||
|
snprintf(hate_msg, sizeof(hate_msg), MESSAGES[rand() % MESSAGES_LEN],
|
||||||
|
get_random_process_name());
|
||||||
|
n = notify_notification_new("AAAAAAAAAAAAAAAAAAAAAAA", hate_msg, NULL);
|
||||||
|
notify_notification_show(n, NULL);
|
||||||
|
sleep(DELAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void int_handler(int _)
|
||||||
|
{
|
||||||
|
program_running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
puts("Starting daemon.");
|
||||||
|
srand(time(NULL));
|
||||||
|
signal(SIGINT, int_handler);
|
||||||
|
signal(SIGTERM, int_handler);
|
||||||
|
|
||||||
|
notify_init("tmhd");
|
||||||
|
|
||||||
|
while (program_running) {
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm *timeinfo;
|
||||||
|
time(&rawtime);
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
if (timeinfo->tm_hour == HOUR && timeinfo->tm_min == MINUTE) do_hate();
|
||||||
|
}
|
||||||
|
notify_uninit();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user