Browse Source

Code for session management

master
Daniel Hillerström 5 years ago
parent
commit
2a50b7402c
  1. 5
      macros.tex
  2. 53
      thesis.tex

5
macros.tex

@ -348,6 +348,9 @@
\newcommand{\Root}{\dec{Root}} \newcommand{\Root}{\dec{Root}}
\newcommand{\User}{\dec{User}} \newcommand{\User}{\dec{User}}
\newcommand{\environment}{\dec{env}} \newcommand{\environment}{\dec{env}}
\newcommand{\EnvE}{\dec{Env}}
\newcommand{\EnvE}{\dec{Session}}
\newcommand{\Ask}{\dec{Ask}} \newcommand{\Ask}{\dec{Ask}}
\newcommand{\whoami}{\dec{whoami}} \newcommand{\whoami}{\dec{whoami}}
\newcommand{\Su}{\dec{Su}}
\newcommand{\su}{\dec{su}}
\newcommand{\sessionmgr}{\dec{sessionmgr}}

53
thesis.tex

@ -2185,11 +2185,11 @@ For simplicity we will fix the users to be root, Alice, and Bob.
Our environment will only support a single environment variable Our environment will only support a single environment variable
intended to store the name of the current user. The value of this intended to store the name of the current user. The value of this
variable can be accessed via an operation $\Ask$.
variable can be accessed via an operation $\Ask : \UnitType \opto \String$.
% %
\[
\EnvE \defas \{\Ask : \UnitType \opto \String\}
\]
% \[
% \EnvE \defas \{\Ask : \UnitType \opto \String\}
% \]
% %
Using this operation we can readily implement the \emph{whoami} Using this operation we can readily implement the \emph{whoami}
utility from the GNU coreutils~\cite[Section~20.3]{MacKenzieMPPBYS20}, utility from the GNU coreutils~\cite[Section~20.3]{MacKenzieMPPBYS20},
@ -2197,7 +2197,7 @@ which returns the name of the current user.
% %
\[ \[
\bl \bl
\whoami : \UnitType \to \String \eff \EnvE\\
\whoami : \UnitType \to \String \eff \{\Ask : \UnitType \opto \String\}\\
\whoami~\Unit \defas \Do\;\Ask~\Unit \whoami~\Unit \defas \Do\;\Ask~\Unit
\el \el
\] \]
@ -2206,7 +2206,7 @@ The following handler implements the environment.
% %
\[ \[
\bl \bl
\environment : \Record{\User;\UnitType \to \alpha \eff \EnvE} \to \alpha\\
\environment : \Record{\User;\UnitType \to \alpha \eff \{\Ask : \UnitType \opto \String\}} \to \alpha\\
\environment~\Record{user;m} \defas \environment~\Record{user;m} \defas
\ba[t]{@{~}l} \ba[t]{@{~}l}
\Handle\;m\,\Unit\;\With\\ \Handle\;m\,\Unit\;\With\\
@ -2245,7 +2245,48 @@ embrace UNIX's laissez-faire attitude and resume with the empty
string. string.
\paragraph{Session management} \paragraph{Session management}
%
\[
\EnvE \defas \{\Ask : \UnitType \opto \String;\Su : \User \opto \UnitType\}
\]
\[
\bl
\su : \User \to \UnitType \eff \{\Su : \User \opto \UnitType\}\\
\su~user \defas \Do\;\Su~user
\el
\]
\[
\bl
\sessionmgr : \Record{\User; \UnitType \to \alpha \eff \EnvE} \to \alpha\\
\sessionmgr~\Record{user;m} \defas
\environment\,\langle{}user;(\lambda\Unit.
\ba[t]{@{~}l}
\Handle\;m\,\Unit\;\With\\
~\ba{@{~}l@{~}c@{~}l}
\Return\;res &\mapsto& res\\
\Su~user'~resume &\mapsto& \environment\,\Record{user';resume})\rangle
\ea
\ea
\el
\]
\[
\ba{@{~}l@{~}l}
&\bl
\basicIO\,(\lambda\Unit.\\
\qquad\sessionmgr\,\Record{\Root;\lambda\Unit.\\
\qquad\qquad\status\,(\lambda\Unit.
\ba[t]{@{}l@{~}l}
\su~\Alice;&\fwrite\,\Record{\stdout;\whoami\,\Unit};~\fwrite\,\Record{\stdout;\texttt{" "}};\\
\su~\Bob;&\fwrite\,\Record{\stdout;\whoami\,\Unit};~\fwrite\,\Record{\stdout;\texttt{" "}};\\
\su~\Root;&\fwrite\,\Record{\stdout;\whoami\,\Unit})})
\ea
\el \smallskip\\
\reducesto^+& \Record{0;\texttt{"alice bob root"}} : \Record{\Int;\UFile}
\ea
\]
\subsection{Nondeterminism: time sharing} \subsection{Nondeterminism: time sharing}
\label{sec:tiny-unix-time} \label{sec:tiny-unix-time}

Loading…
Cancel
Save