Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Linuxkurs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSI Informatik
Linuxkurs
Commits
c720489e
Commit
c720489e
authored
11 months ago
by
Philip Kaluđerčić
Browse files
Options
Downloads
Patches
Plain Diff
Replace tetris script with a more colourful alternative
parent
69cf7fc8
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
Replace tetris script with a more colourful alternative
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aufgabensammlung/Killme.tex
+14
-13
14 additions, 13 deletions
aufgabensammlung/Killme.tex
skripte/aufgabe_killme/tetris
+119
-26
119 additions, 26 deletions
skripte/aufgabe_killme/tetris
with
133 additions
and
39 deletions
aufgabensammlung/Killme.tex
+
14
−
13
View file @
c720489e
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/tetris
}
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.
}
This diff is collapsed.
Click to expand it.
skripte/aufgabe_killme/tetris
+
119
−
26
View file @
c720489e
#!/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: */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment