Skip to content
Snippets Groups Projects
Commit e08b5aed authored by herkulessi's avatar herkulessi
Browse files

Merge branch 'tetris' into 'master'

Replace tetris script with a more colourful alternative

See merge request !3
parents 26909af4 c720489e
No related branches found
No related tags found
1 merge request!3Replace tetris script with a more colourful alternative
Pipeline #136285 passed
Führe zuerst das Programm Führe das Programm \texttt{/proj/ciptmp/fsi/linuxkurs/tetris} aus.
\texttt{/proj/ciptmp/fsi/linuxkurs/killme} aus. Öffne Öffne danach eine neue Shell und versuche das Programm zu beenden.
danach eine neue Shell und versuche das Programm zu beenden. \emph{Tipp: Lies \emph{Tipp: Lies dir die Ausgabe des Programms durch!} Falls du dich
dir die Ausgabe des Programms durch!} Falls du dich schon in dem Verzeichnis schon in dem Verzeichnis \texttt{/proj/ciptmp/fsi/linuxkurs}
\texttt{/proj/ciptmp/fsi/linuxkurs} befindest, kannst du das Programm mit befindest, kannst du das Programm mit \texttt{./killme} starten.
\texttt{./killme} starten.
Als n"achstes f"uhrst du das Programm Als nächstes führst du das Programm
\texttt{/proj/ciptmp/fsi/linuxkurs/tetris} aus. L"asst sich das Programm wie das \texttt{killme}-Programm beenden? \texttt{/proj/ciptmp/fsi/linuxkurs/tetris} aus. Lässt sich das
Wenn nein, dann erinner dich an die Vorlesungfolien\footnote{Tipp: \texttt{-9}}. Programm wie das \texttt{killme}-Programm beenden? Wenn nein, dann
erinner dich an die Vorlesungfolien\footnote{Tipp: \texttt{pkill}}.
Und die Moral von der Geschicht': Nicht einfach Programme von anderen Leuten Und die Moral von der Geschicht': Nicht einfach Programme von anderen
ausführen, wenn man nicht weiß, was sie tun. Manchmal tr"ugt der Schein. Leuten ausführen, wenn man nicht weiß, was sie tun. Manchmal trügt
\smiley\footnote{Falls es dich interessiert, beide Programme sind Skripte, die der Schein. \smiley\footnote{Falls es dich interessiert, beide
du mit \texttt{cat} betrachten kannst.} Programme sind Skripte, die du mit den gewohnten Werkzeugen betrachten
kannst.}
#!/bin/bash //usr/bin/env -S tcc -lm -lX11 -lXxf86vm -run "$0" "$@"; exit $?
/* Not Tetris, but a harmless trap (both for the students and NFS)
* $Id: ntetris.c,v 1.22 2024/04/04 12:09:01 oj14ozun Exp $
* https://wwwcip.cs.fau.de/~oj14ozun/src+etc/ntetris.c
* Distributed under https://creativecommons.org/public-domain/cc0/ */
verbose=false #include <stdio.h>
[ "$1" = -v ] || [ "$1" = --verbose ] && verbose=true #include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <signal.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <libgen.h>
#include <sys/prctl.h>
filenames=( {.config/,.local/,}.{remove,delete,del,abc,quotakiller,00deleteme,zzremovethis} ) #include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>
function getdir() { #define DELTA_T 1e-3
echo "$HOME/${filenames[$((RANDOM%${#filenames[@]}))]}" #define SLEEP 10000
#define MIN_CT 0.5
#define P_RE 71
#define P_GR 17
#define P_BL 97
#define SELF_NAME "tetris"
static Display *dpy;
static void cleanup(int sig)
{
static volatile bool caught = false;
if (!caught) { /* see (libc) Termination in Handler */
XF86VidModeSetGamma(dpy, DefaultScreen(dpy), &(XF86VidModeGamma){ 1, 1, 1 });
XCloseDisplay(dpy);
signal(sig, SIG_DFL);
}
raise(sig);
} }
function trykill() { int main()
echo -e "\nÄtsch" {
local size=50 int size;
echo -e "\e[1;31mDas macht ${size}MB Extra quota!!\e[0m" char *displayname;
local dir=$(getdir) unsigned short *rr, *gr, *br;
mkdir -p "$dir" unsigned short *rr0, *gr0, *br0;
local file="$dir/$((RANDOM))" sigset_t block, prev;
$verbose && echo "im file $file"
dd if=/dev/zero "of=$file" bs=1024 count=$((size*1000)) 2> /dev/null /* Daemonise into the background */
echo switch (fork()) {
echo "Was lernen wir daraus?" case -1:
echo -e "-> \e[0;31mNiemals\e[0m einfach so Programme von Fremden ausführen!" goto fail;
case 0: /* child */
break;
default: /* parent */
return EXIT_SUCCESS;
} }
/* Initialise X11 connection */
displayname = getenv("DISPLAY");
if (!(displayname && displayname[0]))
goto fail;
dpy = XOpenDisplay(displayname);
if (dpy == NULL)
goto fail;
XF86VidModeSetGamma(dpy, DefaultScreen(dpy), &(XF86VidModeGamma){ 1, 1, 1 });
/* Allocate storage for the gamma info */
XF86VidModeGetGammaRampSize(dpy, DefaultScreen(dpy), &size);
rr = calloc(sizeof(unsigned short), size);
if (NULL == rr)
goto fail;
gr = calloc(sizeof(unsigned short), size);
if (NULL == gr)
goto fail;
br = calloc(sizeof(unsigned short), size);
if (NULL == br)
goto fail;
XF86VidModeGetGammaRamp(dpy, DefaultScreen(dpy), size, rr, gr, br);
rr0 = calloc(sizeof(unsigned short), size);
if (NULL == rr0)
goto fail;
gr0 = calloc(sizeof(unsigned short), size);
if (NULL == gr0)
goto fail;
br0 = calloc(sizeof(unsigned short), size);
if (NULL == br0)
goto fail;
/* Μὴ μοῦ τοὺς κύκλους τάραττε. */
nice(19);
setsid();
signal(SIGHUP, SIG_IGN);
signal(SIGINT, cleanup);
signal(SIGTERM, cleanup);
sigemptyset(&block);
sigaddset(&block, SIGINT);
sigaddset(&block, SIGTERM);
trap "trykill" {0..32} /* Rename process to make it easier to find */
prctl(PR_SET_NAME, (unsigned long)SELF_NAME, 0, 0, 0);
# Immediately waste some space even if people don't press Ctrl-C. /* Oh boy fellas, let's rock this joint! */
trykill >/dev/null for (double t = 0;; t += DELTA_T) {
double f = 0.5;
for (int i = 0; i < size; i++) {
rr0[i] = rr[i] * ((1-f) + f * (1 + cos(t * P_RE)) / 2);
gr0[i] = gr[i] * ((1-f) + f * (1 + cos(t * P_GR)) / 2);
br0[i] = br[i] * ((1-f) + f * (1 + cos(t * P_BL)) / 2);
}
sigprocmask(SIG_BLOCK, &block, &prev);
XF86VidModeSetGammaRamp(dpy, DefaultScreen(dpy), size, rr0, gr0, br0);
usleep(SLEEP);
sigprocmask(SIG_SETMASK, &prev, NULL);
}
abort();
fail:
/* Intentionally obfuscate the error message */
fprintf(stderr, "Something went wrong, try again\n");
return EXIT_FAILURE;
}
while true ; do /* Local Variables: */
echo -e "Versuch mich doch abzubrechen! \e[0;32m:-)\e[0m" /* indent-tabs-mode: nil */
sleep 2 /* mode: c */
done /* End: */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment