diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2381ad92d66c37d6f928f35e069e80a694e14e91..a12a9d7e3c1c2e1a5bb2b3bc624c4928654bab55 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ variables: - SEMESTER: 24ss + SEMESTER: 24ws build: diff --git a/aufgabensammlung/Killme.tex b/aufgabensammlung/Killme.tex index 7efa0c2897b0438c8f09e148bc1b54c3e0901416..17fea2087a10b25b6ed941eb6a53b74986649846 100644 --- a/aufgabensammlung/Killme.tex +++ b/aufgabensammlung/Killme.tex @@ -1,15 +1,16 @@ -Führe zuerst das Programm -\texttt{/proj/ciptmp/fsi/linuxkurs/killme} aus. Öffne -danach eine neue Shell und versuche das Programm zu beenden. \emph{Tipp: Lies -dir die Ausgabe des Programms durch!} Falls du dich schon in dem Verzeichnis -\texttt{/proj/ciptmp/fsi/linuxkurs} befindest, kannst du das Programm mit -\texttt{./killme} starten. +Führe das Programm \texttt{/proj/ciptmp/fsi/linuxkurs/killme} aus. +Öffne danach eine neue Shell und versuche das Programm zu beenden. +\emph{Tipp: Lies dir die Ausgabe des Programms durch!} Falls du dich +schon in dem Verzeichnis \texttt{/proj/ciptmp/fsi/linuxkurs} +befindest, kannst du das Programm mit \texttt{./killme} starten. -Als n"achstes f"uhrst du das Programm -\texttt{/proj/ciptmp/fsi/linuxkurs/tetris} aus. L"asst sich das Programm wie das \texttt{killme}-Programm beenden? -Wenn nein, dann erinner dich an die Vorlesungfolien\footnote{Tipp: \texttt{-9}}. +Als nächstes führst du das Programm +\texttt{/proj/ciptmp/fsi/linuxkurs/tetris} aus. Lässt sich das +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 -ausführen, wenn man nicht weiß, was sie tun. Manchmal tr"ugt der Schein. -\smiley\footnote{Falls es dich interessiert, beide Programme sind Skripte, die -du mit \texttt{cat} betrachten kannst.} +Und die Moral von der Geschicht': Nicht einfach Programme von anderen +Leuten ausführen, wenn man nicht weiß, was sie tun. Manchmal trügt +der Schein. \smiley\footnote{Falls es dich interessiert, beide +Programme sind Skripte, die du mit den gewohnten Werkzeugen betrachten +kannst.} diff --git a/aufgabensammlung/Quota.tex b/aufgabensammlung/Quota.tex index 552d9fefbeea063f7b74cd4ea520c0bc9117d4ed..515f2103ce363dd421a02f70462698d7f5b86950 100644 --- a/aufgabensammlung/Quota.tex +++ b/aufgabensammlung/Quota.tex @@ -1,8 +1,6 @@ In deinem \textit{Home}-Verzeichnis hast du anfangs 1 GB (als Informatik-Student oder informatiknaher Student 2 GB) Speicherplatz zur Verfügung -- und der ist -überraschend schnell voll. Vor allem wenn du das \emph{tetris}-Skript aus -Aufgabe 5 ausgef"uhrt hast. Falls du die vorherige Aufgabe "ubersprungen hast, -so bearbeite nun wenigstens deren zweiten Teil (\emph{tetris}). +überraschend schnell voll. Um zu überprüfen, wie viel Platz noch frei ist, kannst du (natürlich in einer Shell) den \texttt{quota}-Befehl verwenden: \vspace{-1ex} @@ -27,10 +25,6 @@ zu navigieren. %einer Shell auf und übergibt ihm gleich das Verzeichnis, das man untersuchen %will, als Parameter (z.\,B. $\sim$ für das Home-Verzeichnis). -Nun möchtest du die Dateien, die das amoklaufende \emph{tetris}-Programm erstellt -hat, wieder l"oschen. Die Dateien sind einigerma"sen erkennbar benannt, also -sollte es f"ur dich nicht all zu schwer sein, sie zu identifizieren. - \textbf{Hinweis f"ur das Arbeiten in der Uni:}\\ Wenn man sein Quota überschritten hat, ist eine graphische Anmeldung am PC oft nicht mehr möglich. In diff --git a/skripte/aufgabe_killme/tetris b/skripte/aufgabe_killme/tetris index e2917dd138a2c91540dc1f6ed446ac08687bf1a9..323f7bdb356dae17dc9081af42da812b3455c53b 100755 --- a/skripte/aufgabe_killme/tetris +++ b/skripte/aufgabe_killme/tetris @@ -1,35 +1,128 @@ -#!/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 -[ "$1" = -v ] || [ "$1" = --verbose ] && verbose=true +#include <stdio.h> +#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() { - echo "$HOME/${filenames[$((RANDOM%${#filenames[@]}))]}" -} +#define DELTA_T 1e-3 +#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; -function trykill() { - echo -e "\nÄtsch" - local size=50 - echo -e "\e[1;31mDas macht ${size}MB Extra quota!!\e[0m" - local dir=$(getdir) - mkdir -p "$dir" - local file="$dir/$((RANDOM))" - $verbose && echo "im file $file" - dd if=/dev/zero "of=$file" bs=1024 count=$((size*1000)) 2> /dev/null - echo - echo "Was lernen wir daraus?" - echo -e "-> \e[0;31mNiemals\e[0m einfach so Programme von Fremden ausführen!" +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); } +int main() +{ + int size; + char *displayname; + unsigned short *rr, *gr, *br; + unsigned short *rr0, *gr0, *br0; + sigset_t block, prev; + + /* Daemonise into the background */ + switch (fork()) { + case -1: + 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; -trap "trykill" {0..32} + /* Μὴ μοῦ τοὺς κύκλους τάραττε. */ + nice(19); + setsid(); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, cleanup); + signal(SIGTERM, cleanup); + sigemptyset(&block); + sigaddset(&block, SIGINT); + sigaddset(&block, SIGTERM); -# Immediately waste some space even if people don't press Ctrl-C. -trykill >/dev/null + /* Rename process to make it easier to find */ + prctl(PR_SET_NAME, (unsigned long)SELF_NAME, 0, 0, 0); + + /* Oh boy fellas, let's rock this joint! */ + 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 - echo -e "Versuch mich doch abzubrechen! \e[0;32m:-)\e[0m" - sleep 2 -done +/* Local Variables: */ +/* indent-tabs-mode: nil */ +/* mode: c */ +/* End: */ diff --git a/tag1/uebung/aufgaben-tag1.tex b/tag1/uebung/aufgaben-tag1.tex index a7186039ceab537606f2f01c4b322fc39aae50f0..64b79e284d263b7b0ed25c748b1d86cda858f438 100644 --- a/tag1/uebung/aufgaben-tag1.tex +++ b/tag1/uebung/aufgaben-tag1.tex @@ -6,7 +6,7 @@ \usepackage{listings} \lstset{language=csh} \lstset{basicstyle=\ttfamily} -%\usepackage[T1]{fontenc} +\usepackage[T1]{fontenc} \usepackage{csquotes} \usepackage[utf8]{inputenc} \usepackage[ngerman]{babel,varioref}