<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>funcptr</title>
    <subtitle>An engineer&#x27;s technical notebook</subtitle>
    <link rel="self" type="application/atom+xml" href="https://funcptr.net/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://funcptr.net/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2021-02-15T00:00:00+00:00</updated>
    <id>https://funcptr.net/atom.xml</id>
    <entry xml:lang="en">
        <title>Change one password</title>
        <published>2018-12-24T06:19:52+00:00</published>
        <updated>2018-12-24T06:19:52+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2018/change-one-password/"/>
        <id>https://funcptr.net/2018/change-one-password/</id>
        
        <content type="html" xml:base="https://funcptr.net/2018/change-one-password/">&lt;p&gt;It is that time of year where security professionals the world over end up
talking with friends and family about security. It will be inevitable, almost
as inevitable as someone wearing a stupid Christmas sweater they are a little
too proud of.&lt;&#x2F;p&gt;
&lt;p&gt;The standard advice we&#x27;ve been giving for years is pretty simple:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Don&#x27;t re-use your passwords across sites&lt;&#x2F;li&gt;
&lt;li&gt;Use a password manager&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Anyone that has done technical support for anyone that isn&#x27;t as familiar with
IT knows well that as soon as you complicate something, you end up getting
twice the calls, even for things that are not your fault; &quot;Well, since you
setup that password thing my printer won&#x27;t print&quot; ...&lt;&#x2F;p&gt;
&lt;p&gt;It is fantastic advice, it is where we should all strive to be, we should all
have password managers and should never re-use passwords.&lt;&#x2F;p&gt;
&lt;p&gt;However let&#x27;s change one single password. Start small.&lt;&#x2F;p&gt;
&lt;p&gt;There is likely to be a single account that is the root of trust for all other
accounts. An email address, either at an ISP somewhere (and maybe this is the
year you get them to switch from that old &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.earthlink.net&#x2F;&quot;&gt;Earthlink&lt;&#x2F;a&gt; email address?) or
more likely a free email provider.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s the account we want to target.&lt;&#x2F;p&gt;
&lt;p&gt;If we can secure the root of trust, the email address that can be used for
password reset emails and for phishing we&#x27;ve already won a large battle.
Individual accounts may still be &quot;vulnerable&quot;, but now we&#x27;ve closed one giant
hole.&lt;&#x2F;p&gt;
&lt;p&gt;After all, we all learn to walk before we learn how to run. This small step can
set the tone for even more and better security later.&lt;&#x2F;p&gt;
&lt;p&gt;Should we go further? Absolutely, identify the primary accounts that are high
risk, as an example:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.facebook.com&quot;&gt;Facebook&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.icloud.com&quot;&gt;Apple iCloud&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;account.microsoft.com&#x2F;&quot;&gt;Microsoft account&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Facebook Login&#x2F;Twitter is used across many different websites, Apple&#x27;s iCloud
allows remote wipe of devices, and Microsoft Account is used for access to
local machines and likely to OneDrive and other online accounts storing
personal documents and files.&lt;&#x2F;p&gt;
&lt;p&gt;There are many more that I am missing, those can be next, but even the above
tend to roll back up to a single email address.&lt;&#x2F;p&gt;
&lt;p&gt;There is nothing new under the sun, and password re-use is well known and
ridiculed, even Randall Munroe of &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;xkcd.com&#x2F;&quot;&gt;XKCD&lt;&#x2F;a&gt; fame published a comic about
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;xkcd.com&#x2F;792&#x2F;&quot;&gt;password re-use&lt;&#x2F;a&gt; a long time ago, however there is one comic that comes to
mind to help create better passwords:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;xkcd.com&#x2F;936&#x2F;&quot;&gt;correct horse battery staple&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Pick four random words from the English language, create a funny sentence and
you are off to the races. Don&#x27;t use &lt;code&gt;correct horse battery staple&lt;&#x2F;code&gt; as a
password, it&#x27;s a terrible password now, but the idea behind generating such a
password is fantastic.&lt;&#x2F;p&gt;
&lt;p&gt;Just changing one password can increase someones security posture just a little
bit, and who knows, next year you&#x27;ll have received less spam email that can be
traced back to their address book being siphoned off and then abused.&lt;&#x2F;p&gt;
&lt;p&gt;For bonus points, have them sign up for &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;haveibeenpwned.com&#x2F;&quot;&gt;&#x27;;--have i been pwned?&lt;&#x2F;a&gt;, now each
time a new service is breached your friends or relatives will get a little bit
of notice, and can get an idea for why different passwords are a necessity
these days, and maybe next year they will ask you to show them how to set up
that password manager so they can be even more secure!&lt;&#x2F;p&gt;
&lt;p&gt;Happy Holidays, and good luck with your IT help desk duties this year,
especially getting that printer driver installed, because lets be honest, we&#x27;ll
get blamed for the broken printer in two months whether we touched it or not.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Python Packaging and Distribution</title>
        <published>2018-05-21T14:00:00+00:00</published>
        <updated>2018-05-21T14:00:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2018/python-packaging/"/>
        <id>https://funcptr.net/2018/python-packaging/</id>
        
        <content type="html" xml:base="https://funcptr.net/2018/python-packaging/">&lt;p&gt;There&#x27;s been many a discussion online related to a variety of tools related to
Python packaging and distribution. There is &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pip.pypa.io&quot;&gt;pip&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.pipenv.org&quot;&gt;pipenv&lt;&#x2F;a&gt; and
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;poetry.eustace.io&quot;&gt;poetry&lt;&#x2F;a&gt; that have been the tools under discussion.&lt;&#x2F;p&gt;
&lt;p&gt;As an open source maintainer as part of the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pylonsproject.org&quot;&gt;Pylons Project&lt;&#x2F;a&gt;, while I would
love to be writing code I end up spending a lot of time dealing with user
questions around packaging&#x2F;distributing their source code using the software
I&#x27;ve helped build, and as we move forward myself and other maintainers were
wondering if we were actually helping users move forward in the best way
possible using best of breed tools.&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-201805tooldiscussionpyramid-1&quot;&gt;&lt;a href=&quot;#fn-201805tooldiscussionpyramid&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As the Python community has moved from &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20180527214739&#x2F;http:&#x2F;&#x2F;setuptools.readthedocs.io&#x2F;en&#x2F;latest&#x2F;easy_install.html#easy-install&quot;&gt;easy_install&lt;&#x2F;a&gt; to pip, we too have
kept the documentation up to date. We went from &lt;code&gt;python setup.py develop&lt;&#x2F;code&gt; to
&lt;code&gt;pip install -e .&lt;&#x2F;code&gt; to create editable installs of local projects, and try to
let people know the pitfalls of using both easy_install and pip in the same
project (mostly with an answer that falls in line with: remove your virtual
environment and start over, just use pip).&lt;&#x2F;p&gt;
&lt;p&gt;As part of &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;trypyramid.com&quot;&gt;Pyramid&lt;&#x2F;a&gt; we have developed and maintain various different
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;cookiecutter.readthedocs.io&#x2F;en&#x2F;latest&#x2F;&quot;&gt;cookiecutter&lt;&#x2F;a&gt; templates, and our goal is to attempt to provide templates
that are both useful, but also follow best practices that are being adopted
within the community at large so that newcomers can use their existing
skills&#x2F;knowledge and those that are starting with us walk away with a knowledge
and experience that applies not just to development of Pyramid applications,
but also applies to the broader community as a whole.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pip&quot;&gt;pip&lt;&#x2F;h2&gt;
&lt;p&gt;Pip is a great tool that has simplified installation of packages, it supports
using binary distributions named &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pypa&#x2F;wheel&quot;&gt;wheels&lt;&#x2F;a&gt; and has a way to easily install
software from the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pypi.org&quot;&gt;Python Packaging Index&lt;&#x2F;a&gt;. It has a rather naive
dependency resolution process, but for the most part it works and works well.
It replaced easy_install as the tool to use for installing packages.&lt;&#x2F;p&gt;
&lt;p&gt;While you can use a &lt;code&gt;requirements.txt&lt;&#x2F;code&gt; file with pip to install a &quot;blessed&quot;
list of software there is no good way to &quot;lock&quot; the dependencies of
dependencies without manually adding it to the list of requirements. This ends
up making it very difficult to manage, and it is very difficult to know that
what has been tested is what the user is actually going to get because packages
may be updated at anytime, and re-creating the same exact environment is
difficult and fraught with errors.&lt;&#x2F;p&gt;
&lt;p&gt;This is where &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pypa&#x2F;pipfile&quot;&gt;Pipfile&lt;&#x2F;a&gt; is supposed to help. This is a project to add a
new, more descriptive requirements file, as well as allowing for a lockfile
that would lock not just your primary packages you have listed, but also all
dependencies of dependencies all the way down the tree. This helps with
reproducibility and allows for the same installation on two different systems
to have the exact same software&#x2F;dependencies installed.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pipenv&quot;&gt;pipenv&lt;&#x2F;h2&gt;
&lt;p&gt;While pip is a great tool, and with the Pipfile changes it would allow for
locking of dependencies, there is one more puzzle piece missing. When
installing packages while you can install them into the global namespace, the
recommended way is to install all packages for a particular tool&#x2F;project into a
virtual environment.&lt;&#x2F;p&gt;
&lt;p&gt;Normally you&#x27;d invoke &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;virtualenv.pypa.io&#x2F;en&#x2F;stable&#x2F;&quot;&gt;virtualenv&lt;&#x2F;a&gt;, to create this environment and then
you&#x27;d make sure to install all packages within it, thereby isolating it from
the rest of the system.&lt;&#x2F;p&gt;
&lt;p&gt;pipenv automates this for you, as well as using &lt;code&gt;Pipfile&lt;&#x2F;code&gt; it also supports
locking using &lt;code&gt;Pipfile.lock&lt;&#x2F;code&gt; and provides a bunch of tooling around
adding&#x2F;removing dependencies from a local project.&lt;&#x2F;p&gt;
&lt;p&gt;pipenv allows you to easily create an environment and manage dependencies, but
it makes no effort to solve the problem of distributing and building a package
that may be installed by third parties.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;poetry&quot;&gt;poetry&lt;&#x2F;h2&gt;
&lt;p&gt;Poetry is a similar project to pipenv, with a major difference being that it
was built to help with distributing&#x2F;developing applications and building a
distributable package that may then be installed using pip.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of using a &lt;code&gt;Pipfile&lt;&#x2F;code&gt; it uses a recently standardised &lt;code&gt;pyproject.toml&lt;&#x2F;code&gt;
file instead. Like pipenv it also supports locking, and it provides tooling
around adding&#x2F;removing dependencies as well as managing what versions are
required.&lt;&#x2F;p&gt;
&lt;p&gt;Ultimately those dependencies are going to end up as metadata in a
distributable package.&lt;&#x2F;p&gt;
&lt;p&gt;Poetry makes it easier to manage a software development project, whether that
is for an application using various libraries for internal use, or for
libraries that are going to be distributed to other developers.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-divide&quot;&gt;The divide&lt;&#x2F;h2&gt;
&lt;p&gt;This is where the divide really starts, while you can use pipenv with a
standard &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;setuptools.readthedocs.io&#x2F;en&#x2F;latest&#x2F;&quot;&gt;setuptools&lt;&#x2F;a&gt; project, any dependencies you add to the Pipfile
using pipenv&#x27;s tooling will not be listed as a dependencies for your project
when you distribute it, this either means you need to duplicate the list in
both &lt;code&gt;setup.py&lt;&#x2F;code&gt; as well as the &lt;code&gt;Pipfile&lt;&#x2F;code&gt;, or you have to add your current
project as an editable install within your &lt;code&gt;Pipfile&lt;&#x2F;code&gt; which means your &lt;code&gt;Pipfile&lt;&#x2F;code&gt;
is now not as easily distributable.&lt;&#x2F;p&gt;
&lt;p&gt;There are work-arounds that people have used, such as having &lt;code&gt;setup.py&lt;&#x2F;code&gt; read a
&lt;code&gt;requirements.txt&lt;&#x2F;code&gt;, so that you could have all your requirements listed in a
text file, and not in &lt;code&gt;setup.py&lt;&#x2F;code&gt;, but asking to do the same with a &lt;code&gt;Pipfile&lt;&#x2F;code&gt; in
pipenv was met with a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20201020045235&#x2F;https:&#x2F;&#x2F;github.com&#x2F;pypa&#x2F;pipenv&#x2F;issues&#x2F;209#issuecomment-332553113&quot;&gt;&quot;Do not do this.&quot;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;poetry explicitly allows you to add dependencies in one place, and those
dependency listings are then automatically inserted into the package metadata
that is created when you build your distributable package.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-two-use-cases&quot;&gt;The two use cases&lt;&#x2F;h2&gt;
&lt;p&gt;There are two competing use cases, one is the deployment of software packages
and being able to run them, but not as a developer, the other is a developer of
software packages that needs to define dependencies for the project to run.&lt;&#x2F;p&gt;
&lt;p&gt;pipenv solves the deployment case. If I was a user I could very simply grab a
known good &lt;code&gt;Pipfile.lock&lt;&#x2F;code&gt; and use pipenv to install a known good set of
software, this is great when I am deploying a project. It is the use case that
many in the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.pypa.io&#x2F;en&#x2F;latest&#x2F;&quot;&gt;Python Packaging Authority&lt;&#x2F;a&gt; also seem to be optimizing for.&lt;&#x2F;p&gt;
&lt;p&gt;The other use case is for developers that are building new software, either by
using a list of existing packages and deploying privately, or people developing
software for other developers to be published on the Python Packaging Index.&lt;&#x2F;p&gt;
&lt;p&gt;This latter group of people is under represented due to it likely being much
smaller, and existing tools like &lt;code&gt;setuptools&lt;&#x2F;code&gt; and &lt;code&gt;setup.py&lt;&#x2F;code&gt; already providing
a &quot;good enough&quot; experience. Innovation in this area is something that readily
needs to be improved upon to make it easier to create new libraries&#x2F;packages
that follow best practices. The amount of copy and pastes people have done for
adding a &lt;code&gt;setup.py&lt;&#x2F;code&gt; to their projects or to make something work is long. It&#x27;s
all a little bit of black magic, and there is a great many things that have
been carried over because of cargo cult programming.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;explicit-mentions-by-the-python-packaging-authority&quot;&gt;Explicit mentions by the Python Packaging Authority&lt;&#x2F;h2&gt;
&lt;p&gt;Reading the packaging guide on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;packaging.python.org&#x2F;tutorials&#x2F;managing-dependencies&#x2F;&quot;&gt;managing dependencies&lt;&#x2F;a&gt;, pipenv is the
recommended tool:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;This tutorial walks you through the use of Pipenv to manage dependencies for
an application. It will show you how to install and use the necessary tools
and make strong recommendations on best practices.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;this language, along with what &lt;code&gt;packaging.python.org&lt;&#x2F;code&gt; implies as a URL makes it
difficult as a project maintainer to recommend alternate tools, becuase even if
those tools are superior for the use case we are recommending them for it is
always going to lead to questions from users, such as:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Why are you not using pipenv, the official tool recommended by Python.org?&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;We get similar questions about &lt;code&gt;easy_install&lt;&#x2F;code&gt; vs &lt;code&gt;pip&lt;&#x2F;code&gt; all of the time, as
well as why people should switch, and we can point to various bits of
documentation that explains why pip is a better choice.&lt;&#x2F;p&gt;
&lt;p&gt;If we were to recommend an alternate the appeal to authority that &lt;code&gt;python.org&lt;&#x2F;code&gt;
implies is going to make it much more difficult, and the question will become
&quot;why is the Pylons Project not using recommended tooling?&quot;&lt;&#x2F;p&gt;
&lt;p&gt;poetry is listed as a footnote on that page, alongside &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;jazzband&#x2F;pip-tools&quot;&gt;pip-tools&lt;&#x2F;a&gt; and
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ofek&#x2F;hatch&quot;&gt;hatch&lt;&#x2F;a&gt;, and is mentioned only for doing library development, with no
mention of other requirements that may make it a much better tool for
developing locally.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;deployment-is-not-development&quot;&gt;Deployment is not development&lt;&#x2F;h2&gt;
&lt;p&gt;If I am using pipenv with a non-installable project (no setup.py) I end up
having to figure out how to get the code, and the &lt;code&gt;Pipfile&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;Pipfile.lock&lt;&#x2F;code&gt; to
my environment I am deploying into. pipenv&#x27;s install provides a way to make
sure to only install if the &lt;code&gt;Pipfile.lock&lt;&#x2F;code&gt; is up to date or otherwise will fail
to continue. If you are using a local project though, and it uses &lt;code&gt;setup.py&lt;&#x2F;code&gt;
the only way that the &lt;code&gt;Pipfile.lock&lt;&#x2F;code&gt; will contain any sub-dependencies of your
&lt;code&gt;setup.py&lt;&#x2F;code&gt; project is if you install it as &lt;code&gt;editable&lt;&#x2F;code&gt;. Otherwise
sub-dependencies are not locked.&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-201805subdepends-1&quot;&gt;&lt;a href=&quot;#fn-201805subdepends&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If I am using poetry I get an pip installable project, but it doesn&#x27;t contain
any hard pins or lock files. I&#x27;d have to distribute &lt;code&gt;pyproject.lock&lt;&#x2F;code&gt; as well as
my wheel. This gets me a little closer, but still no lock file that includes my
newly produced wheel, and has all of its dependencies locked.&lt;&#x2F;p&gt;
&lt;p&gt;The Python Packaging Authority based on Twitter conversations with its members
and the documentation on &lt;code&gt;packaging.python.org&lt;&#x2F;code&gt; suggest using pipenv for
development. pipenv is particular ill-suited for development if the goal is to
create a package to be deployed to production. With two locations to define
dependencies it leaves people scratching their heads as to which is canonical,
and if a dependency is added to &lt;code&gt;Pipfile&lt;&#x2F;code&gt; but not &lt;code&gt;setup.py&lt;&#x2F;code&gt; it may leave a
developer thinking their package is ready for distribution when in reality it
is missing a dependency that is required to run&#x2F;use said distribution.&lt;&#x2F;p&gt;
&lt;p&gt;At this point using both projects seems like a win-win. Use poetry to
build&#x2F;develop a package, then use pipenv in the integration phase to create a
&lt;code&gt;Pipfile.lock&lt;&#x2F;code&gt; that is used to deploy in production. This way you get the best
of both worlds. A great tool that can help you register entry points and
another that can help you with deploying a known good set of dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;Interestingly, even the pipenv docs seem to agree that it is a deployment tool:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Specify your target Python version in your Pipfile’s [requires] section.
Ideally, you should only have one target Python version, as this is a
deployment tool.&lt;&#x2F;p&gt;
&lt;p&gt;-- &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.pipenv.org&#x2F;basics&#x2F;#general-recommendations-version-control&quot;&gt;Pipenv - General Recommendations &amp;amp; Version Control&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Use pipenv if you have a script that requires a couple of dependencies and
doesn&#x27;t need all of the extra overhead of packaging metadata&#x2F;packaging. Use
poetry if you want to build a distributable project that can easily be deployed
by others, and use both if you develop a project and need a known good
environment to deploy.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;in-summary&quot;&gt;In summary&lt;&#x2F;h2&gt;
&lt;p&gt;There will likely never be a time that one single tool is considered good
enough, and competition between tools is a way to keep advancing forward.
Packaging in the Python community for a long time has been difficult. Wheels
has made things a little better. pip has made management of installing new
packages easier and improved upon easy_install. Here&#x27;s to the next evolution.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Now, can we talk about standardising on &lt;code&gt;pyproject.toml&lt;&#x2F;code&gt; since that is already
where &quot;project&quot; metadata needs to go, might as well re-use the name instead of
having two different names&#x2F;files. Oh, and &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0517&#x2F;&quot;&gt;PEP 517&lt;&#x2F;a&gt; can&#x27;t come soon enough
so that alternate tools like &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;flit.readthedocs.io&#x2F;en&#x2F;latest&#x2F;&quot;&gt;flit&lt;&#x2F;a&gt; can be used instead of
setuptools&#x2F;&lt;code&gt;setup.py&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-201805tooldiscussionpyramid&quot;&gt;
&lt;p&gt;We created an issue named &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Pylons&#x2F;pyramid&#x2F;issues&#x2F;3270&quot;&gt;Support poetry,
flit, pipenv, or ...?&lt;&#x2F;a&gt; that attempts to go over the pros and cons of the
various tools and how we currently support our users in our documentation on
building projects using pyramid, including how to create a project that is
distributable.  Pyramid heavily uses &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;setuptools.readthedocs.io&#x2F;en&#x2F;latest&#x2F;pkg_resources.html&quot;&gt;&lt;code&gt;pkg_resources&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and entry
points.  The way to register the entry points is to have an installable
package. The framework is flexible enough that there is no requirement for
entry points, but at that point you are in territory where the default
tooling provided by the project will not work, and some of the convenience
tools&#x2F;functionality that Pyramid provides it&#x27;s users&#x2F;developers is not
available. &lt;a href=&quot;#fr-201805tooldiscussionpyramid-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-201805subdepends&quot;&gt;
&lt;p&gt;See documentation for &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.pipenv.org&#x2F;basics&#x2F;#editable-dependencies-e-g-e&quot;&gt;Editable Dependencies (e.g.  &lt;code&gt;-e   .&lt;&#x2F;code&gt;)&lt;&#x2F;a&gt; which as of this writing states: &lt;blockquote&gt;Sub-dependencies are &lt;strong&gt;not&lt;&#x2F;strong&gt; added to the Pipfile.lock if you leave the -e option out.&lt;&#x2F;blockquote&gt; &lt;a href=&quot;#fr-201805subdepends-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Mac OS X El Capitan Installer Removes Custom Group ID and Membership</title>
        <published>2015-10-02T01:23:45+00:00</published>
        <updated>2015-10-02T01:23:45+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2015/mac-os-x-el-capitan-removes-custom-group-id-and-membership/"/>
        <id>https://funcptr.net/2015/mac-os-x-el-capitan-removes-custom-group-id-and-membership/</id>
        
        <content type="html" xml:base="https://funcptr.net/2015/mac-os-x-el-capitan-removes-custom-group-id-and-membership/">&lt;p&gt;As always, after Apple releases their new operating system, my systems are
upgraded. This time the upgrade was less of a surprise in terms of what it
brings because I&#x27;d been beta testing the new release for the past couple of
weeks, however I was still caught off guard.&lt;&#x2F;p&gt;
&lt;p&gt;On OS X, by default all user accounts start at ID 501 and count up, so if you
have two accounts, you will have user ID 501 and 502 in use. For most people
they will most likely never change this, and all is well. The default group ID
for all new user accounts is &lt;code&gt;staff&lt;&#x2F;code&gt; which has a group ID of 20. So if you have
a single account named for example &lt;code&gt;janedoe&lt;&#x2F;code&gt; her user ID would be 501 and her
group ID would be 20 (&lt;code&gt;staff&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;Coming from a FreeBSD world and running a lot of FreeBSD systems, user accounts
start at 1001, and count up. When you create a new user account on FreeBSD, by
default that user is also added to a group with the same name as the username,
with the same ID. So you end up with an account with ID 1001 and default group
ID 1001. Using the same example, a user named &lt;code&gt;janedoe&lt;&#x2F;code&gt; would have a user ID of
1001, and a group ID of 1001 (&lt;code&gt;janedoe&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;When I first installed OS X, and almost every single new installation since, I
have followed these steps to change my user ID and group ID to match those on
my FreeBSD systems:&lt;&#x2F;p&gt;
&lt;ol start=&quot;0&quot;&gt;
&lt;li&gt;Assumption is that you have a separate user account other than the one you
are about to modify that you can temporarily use that has administrator
privileges on the local Mac; I create an &quot;Administrator&quot; account for that
reason.&lt;&#x2F;li&gt;
&lt;li&gt;System Preferences&lt;&#x2F;li&gt;
&lt;li&gt;Users and Groups&lt;&#x2F;li&gt;
&lt;li&gt;Click the &lt;code&gt;+&lt;&#x2F;code&gt; (You may need to click the lock in the bottom left first)&lt;&#x2F;li&gt;
&lt;li&gt;Change the dropdown to &lt;code&gt;group&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Enter Full Name: &lt;code&gt;janedoe&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create group&lt;&#x2F;li&gt;
&lt;li&gt;Right click on group (&lt;code&gt;janedoe&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;Advanced Options...&lt;&#x2F;li&gt;
&lt;li&gt;Change the Group ID to 1001&lt;&#x2F;li&gt;
&lt;li&gt;Okay&lt;&#x2F;li&gt;
&lt;li&gt;Right click on user (&lt;code&gt;janedoe&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;Advanced Options...&lt;&#x2F;li&gt;
&lt;li&gt;Change User ID from &lt;code&gt;501&lt;&#x2F;code&gt; to &lt;code&gt;1001&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Change Group from &lt;code&gt;staff&lt;&#x2F;code&gt; to &lt;code&gt;janedoe&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Okay&lt;&#x2F;li&gt;
&lt;li&gt;Close System Preferences&lt;&#x2F;li&gt;
&lt;li&gt;Open Terminal, become root user (sudo su)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cd &#x2F;Users&#x2F;janedoe&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;find . -uid 501 -print0 | xargs -0 chown 1001:1001&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;This allows me to have the same user ID and group ID on both my Mac OS X and on
FreeBSD, thereby making it easier to use tools like rsync that keeps ownership
and permissions, as well as using NFS. Other ways to do something similar is
using LDAP&#x2F;Kerberos with shared directory service, but that is a little heavy
handed for a home network.&lt;&#x2F;p&gt;
&lt;p&gt;This has worked for me without issues since OS X 10.8, even upgrading from 10.8 to
10.9 and then 10.10 did not change anything. However as soon as I did the
upgrade to El Capitan (10.11) I noticed that all of my &lt;code&gt;ls -lah&lt;&#x2F;code&gt; output looked
like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;drwxr-xr-x+  13 xistence  1001   442B Oct  1 16:58 Desktop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;drwx------+  28 xistence  1001   952B Aug 31 12:17 Documents&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;drwx------+  89 xistence  1001   3.0K Oct  1 15:56 Downloads&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;drwx------@  72 xistence  1001   2.4K Oct  2 00:16 Library&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and &lt;code&gt;id&lt;&#x2F;code&gt; provided this valuable output:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;uid=1001(xistence) gid=20(xistence) groups=20(xistence),12(everyone),61(localaccounts),399(com.apple.access_ssh),402(com.apple.sharepoint.group.2),401(com.apple.sharepoint.group.1),100(_lpoperator)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Wait, what happened to the &lt;code&gt;staff&lt;&#x2F;code&gt; group that I am supposed to be a member of,
and why is my &lt;code&gt;xistence&lt;&#x2F;code&gt; group ID now stating it is 20 and not 1001 as I was
expecting.&lt;&#x2F;p&gt;
&lt;p&gt;I wondered if the upgrade had messed up my group somehow, and it was
confirmed when I checked with &lt;code&gt;dscl&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ dscl . -read &#x2F;Groups&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[...]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Password: *&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PrimaryGroupID: 20&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RealName: xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RecordName: xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RecordType: dsRecTypeStandard:Groups&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Do note that the group &lt;code&gt;xistence&lt;&#x2F;code&gt; does not show up in &lt;em&gt;System Preferences&lt;&#x2F;em&gt; -&amp;gt;
&lt;em&gt;Users and Groups&lt;&#x2F;em&gt;, so we&#x27;ll have to do some command line magic.&lt;&#x2F;p&gt;
&lt;p&gt;Well, that&#x27;s worrisome, why is this matching a built-in group&#x27;s ID? Specifically
let&#x27;s check the &lt;code&gt;staff&lt;&#x2F;code&gt; group and make sure it still has the appropriate group
ID.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ dscl . -read &#x2F;Groups&#x2F;staff&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[...]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;GroupMembership: root&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Password: *&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PrimaryGroupID: 20&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RealName: Staff&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RecordName: staff BUILTIN\Users&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RecordType: dsRecTypeStandard:Groups&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Next I had to check to see what my user account was set to as the default group
ID:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ dscl . -read &#x2F;Users&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[...]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;NFSHomeDirectory: &#x2F;Users&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Password: ********&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PrimaryGroupID: 20&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RealName:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; Delta Regeer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RecordName: xistence delta@regeer.org com.apple.idms.appleid.prd.53696d524c62372b48344a53755864634e4f374b32513d3d&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RecordType: dsRecTypeStandard:Users&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;UniqueID: 1001&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;UserShell: &#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Well, that is not entirely what I was expecting either, at last it didn&#x27;t touch
my user ID. Time to fix things.&lt;&#x2F;p&gt;
&lt;p&gt;First let&#x27;s change the &lt;code&gt;xistence&lt;&#x2F;code&gt; group&#x27;s group ID to 1001, and then change the
Primary Group ID for the user &lt;code&gt;xistence&lt;&#x2F;code&gt; to group ID 1001.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;dscl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -change&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;Groups&#x2F;xistence PrimaryGroupID&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 20 1001&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;dscl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -change&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;Users&#x2F;xistence PrimaryGroupID&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 20 1001&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After that &lt;code&gt;id&lt;&#x2F;code&gt; looked a little bit more sane:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;uid=1001(xistence) gid=1001(xistence) groups=1001(xistence),12(everyone),61(localaccounts),399(com.apple.access_ssh),402(com.apple.sharepoint.group.2),401(com.apple.sharepoint.group.1),100(_lpoperator)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However now the group &lt;code&gt;staff&lt;&#x2F;code&gt; is missing from the list of groups that the user
&lt;code&gt;xistence&lt;&#x2F;code&gt; is a member of, which I don&#x27;t think will hurt anything, but we still
want to be able to read&#x2F;write any folders that are designated as &lt;code&gt;staff&lt;&#x2F;code&gt;
elsewhere in the OS, and any other privileges that entails. So let&#x27;s add the
user &lt;code&gt;xistence&lt;&#x2F;code&gt; to the &lt;code&gt;staff&lt;&#x2F;code&gt; group:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;dscl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -append&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;Groups&#x2F;staff GroupMembership xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s verify, and check &lt;code&gt;id&lt;&#x2F;code&gt; again:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;uid=1001(xistence) gid=1001(xistence) groups=1001(xistence),12(everyone),20(staff),61(localaccounts),399(com.apple.access_ssh),402(com.apple.sharepoint.group.2),401(com.apple.sharepoint.group.1),100(_lpoperator)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For this to fully take effect, log out and log back in. This will make sure
that all new files have the correct user ID&#x2F;group ID set.&lt;&#x2F;p&gt;
&lt;p&gt;After the change to the Group ID, the group still doesn&#x27;t show up in &lt;em&gt;System
Preferences&lt;&#x2F;em&gt; -&amp;gt; &lt;em&gt;Users and Groups&lt;&#x2F;em&gt;, which I find weird since it is not a
built-in group.&lt;&#x2F;p&gt;
&lt;p&gt;Luckily everything is back to the way it was before the upgrade, and my backup
scripts and NFS shares work again without issues.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Cobbler with CentOS 7 failure to boot&#x2F;kickstart</title>
        <published>2015-07-08T19:54:43+00:00</published>
        <updated>2015-07-08T19:54:43+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2015/cobbler-with-centos-7-failure-to-boot/"/>
        <id>https://funcptr.net/2015/cobbler-with-centos-7-failure-to-boot/</id>
        
        <content type="html" xml:base="https://funcptr.net/2015/cobbler-with-centos-7-failure-to-boot/">&lt;p&gt;Over the past week I&#x27;ve been working on building out an instance of Cobbler and
testing some of the provisioning that it is able to do. One of the operating
systems that I wanted to deploy is CentOS 7.&lt;&#x2F;p&gt;
&lt;p&gt;After I imported the system into cobbler, it correctly showed up in the
pxelinux boot menu and it would happily load the kernel and the initrd, however
after initial bootup it would throw the following error message:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dracut-initqueue[867]: Warning: Could not boot.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dracut-initqueue[867]: Warning: &#x2F;dev&#x2F;root does not exist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;         Starting Dracut Emergency Shell...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Warning: &#x2F;dev&#x2F;root does not exist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Generating &amp;quot;&#x2F;run&#x2F;initramfs&#x2F;rdsosreport.txt&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Entering emergency mode. Exit the shell to continue.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Type &amp;quot;journalctl&amp;quot; to view the system logs.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;You might want to save &amp;quot;&#x2F;run&#x2F;initramfs&#x2F;rdsosreport.txt&amp;quot; to a USB stick or &#x2F;boot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;after mounting them and attach it to a bug report&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After that it gives you a root shell.&lt;&#x2F;p&gt;
&lt;p&gt;Some Google searching led me to an &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20160202155132&#x2F;https:&#x2F;&#x2F;lists.fedorahosted.org&#x2F;pipermail&#x2F;cobbler&#x2F;2014-August&#x2F;009647.html&quot;&gt;mailing list post for Cobbler&lt;&#x2F;a&gt; where
someone mentioned that adding &lt;code&gt;ksdevice=link&lt;&#x2F;code&gt; to the Cobbler profile allowed
the system to boot without issues.&lt;&#x2F;p&gt;
&lt;p&gt;However before I just implement a change I want to know why that fixes the
issue, so I searched Google for &quot;kickstart ksdevice&quot; and found &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20150923201114&#x2F;https:&#x2F;&#x2F;access.redhat.com&#x2F;documentation&#x2F;en-US&#x2F;Red_Hat_Enterprise_Linux&#x2F;6&#x2F;html&#x2F;Installation_Guide&#x2F;s1-kickstart2-startinginstall.html&quot;&gt;Red Hat&#x27;s
documentation on starting a kickstart&lt;&#x2F;a&gt;. Searching that page for &quot;ksdevice&quot;
led me to this section:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;ksdevice=&amp;lt;device&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The installation program uses this network device to connect to the network. You can specify the device in one of five ways:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;the device name of the interface, for example, &lt;code&gt;eth0&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;the MAC address of the interface, for example, &lt;code&gt;00:12:34:56:78:9a&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;the keyword &lt;code&gt;link&lt;&#x2F;code&gt;, which specifies the first interface with its link in the up state&lt;&#x2F;li&gt;
&lt;li&gt;the keyword &lt;code&gt;bootif&lt;&#x2F;code&gt;, which uses the MAC address that pxelinux set in the
BOOTIF variable. Set IPAPPEND 2 in your pxelinux.cfg file to have pxelinux
set the BOOTIF variable.&lt;&#x2F;li&gt;
&lt;li&gt;the keyword &lt;code&gt;ibft&lt;&#x2F;code&gt;, which uses the MAC address of the interface specified by iBFT&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;For example, consider a system connected to an NFS server through the eth1
device. To perform a kickstart installation on this system using a kickstart
file from the NFS server, you would use the command &lt;code&gt;ks=nfs:&amp;lt;server&amp;gt;:&#x2F;&amp;lt;path&amp;gt; ksdevice=eth1&lt;&#x2F;code&gt; at the boot: prompt.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;While &lt;code&gt;ksdevice=link&lt;&#x2F;code&gt; would work for some of the machines I am deploying, it
wouldn&#x27;t work for most since they have multiple interfaces and each one of
those interfaces would have link, what I really wanted was &lt;code&gt;ksdevice=bootif&lt;&#x2F;code&gt;,
which is the most sensible default.&lt;&#x2F;p&gt;
&lt;p&gt;So I modified the profile with &lt;code&gt;ksdevice=link&lt;&#x2F;code&gt; just to test, and that worked
without issues, so then I modified the profile and added &lt;code&gt;ksdevice=link&lt;&#x2F;code&gt;, and
this failed.&lt;&#x2F;p&gt;
&lt;p&gt;I figured I should check the &lt;code&gt;pxelinux.cfg&#x2F;default&lt;&#x2F;code&gt; file that Cobbler generates
upon issuing a &lt;code&gt;cobbler sync&lt;&#x2F;code&gt; and verify that &lt;code&gt;ksdevice=bootif&lt;&#x2F;code&gt; is actually
listed correctly.&lt;&#x2F;p&gt;
&lt;p&gt;What I found was this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;LABEL CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        kernel &#x2F;images&#x2F;CentOS-7.1-x86_64&#x2F;vmlinuz&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        MENU LABEL CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        append initrd=&#x2F;images&#x2F;CentOS-7.1-x86_64&#x2F;initrd.img ksdevice=${net0&#x2F;mac} lang=  kssendmac text  ks=http:&#x2F;&#x2F;10.10.10.1&#x2F;cblr&#x2F;svc&#x2F;op&#x2F;ks&#x2F;profile&#x2F;CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ipappend 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This has a &lt;code&gt;ksdevice=${net0&#x2F;mac}&lt;&#x2F;code&gt; which is not what I had put in the profile,
overwriting &lt;code&gt;ksdevice&lt;&#x2F;code&gt; in the profile with &lt;code&gt;ksdevice=link&lt;&#x2F;code&gt; did correctly put
that into the &lt;code&gt;pxelinux.cfg&#x2F;default&lt;&#x2F;code&gt; file, so Cobbler was overwriting my change
somehow.&lt;&#x2F;p&gt;
&lt;p&gt;A quick search of &lt;code&gt;${net0&#x2F;mac}&lt;&#x2F;code&gt; led me to a page about &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;etherboot.org&#x2F;wiki&#x2F;commandline&quot;&gt;gPXE commandline
items&lt;&#x2F;a&gt; that contained the same variable. At which point I remembered that in
Cobbler you set up your profile to be gPXE enabled or not. The default when you
import an image is to enable gPXE support.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cobbler profile report  --name=CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Name                           : CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TFTP Boot Files                : {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Comment                        : &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DHCP Tag                       : default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Distribution                   : CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Enable gPXE?                   : True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Enable PXE Menu?               : 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[...]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So let&#x27;s modify the profile to disable gPXE support:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;cobbler&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; profile edit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; --name=CentOS-7.1-x86_64 --enable-gpxe=False&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;cobbler&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; sync&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Verify that the change was made:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cobbler profile report  --name=CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[...]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Enable gPXE?                   : False&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[...]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then let&#x27;s take a look at our &lt;code&gt;pxelinux.cfg&#x2F;default&lt;&#x2F;code&gt; file and make sure that it
looks correct:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;LABEL CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        kernel &#x2F;images&#x2F;CentOS-7.1-x86_64&#x2F;vmlinuz&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        MENU LABEL CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        append initrd=&#x2F;images&#x2F;CentOS-7.1-x86_64&#x2F;initrd.img ksdevice=bootif lang=  kssendmac text  ks=http:&#x2F;&#x2F;10.10.10.1&#x2F;cblr&#x2F;svc&#x2F;op&#x2F;ks&#x2F;profile&#x2F;CentOS-7.1-x86_64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ipappend 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This time our ksdevice is correctly set. Upon rebooting my PXE booted server it
picked up the correct interface, made a DHCP request and kickstarted the server
using the provided kickstart file, and installation completed successfully.&lt;&#x2F;p&gt;
&lt;p&gt;So unless you chain-boot gPXE from pxelinux by default, make sure that your
profiles are not set to be gPXE enabled if you want to use them directly from
the pxelinux menu.&lt;&#x2F;p&gt;
&lt;p&gt;While researching more about this article, I found a blog post by &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20160507142852&#x2F;https:&#x2F;&#x2F;blog.vladionescu.com&#x2F;pxe-installing-rhel-7-from-cobbler-2-6&#x2F;&quot;&gt;Vlad Ionescu
about PXE installing RHEL 7 from Cobbler&lt;&#x2F;a&gt; where he suggests disabling
&lt;code&gt;ksdevice&lt;&#x2F;code&gt; entirely and adding an extra &lt;code&gt;inst.repo&lt;&#x2F;code&gt; variable to the kernel
command line, however on older versions of CentOS 7 and Red Hat Enterprise
Linux 7 there is a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;bugzilla.redhat.com&#x2F;show_bug.cgi?id=1096846&quot;&gt;bug report&lt;&#x2F;a&gt; that shows that an empty &lt;code&gt;ksdevice&lt;&#x2F;code&gt; could
cause anaconda to crash, and setting a manual &lt;code&gt;inst.repo&lt;&#x2F;code&gt; for every profile
seems like overkill when just disabling gPXE for the profile also solves the
problem.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Neutron L3 agent with multiple provider networks</title>
        <published>2014-09-29T18:11:00+00:00</published>
        <updated>2014-09-29T18:11:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2014/neutron-l3-agent-multiple-provider-networks/"/>
        <id>https://funcptr.net/2014/neutron-l3-agent-multiple-provider-networks/</id>
        
        <content type="html" xml:base="https://funcptr.net/2014/neutron-l3-agent-multiple-provider-networks/">&lt;p&gt;Due to requirements outside of my control, there was a requirement to run
multiple &quot;provider&quot; networks each with each providing their own floating
address pool from a single network node, I wanted to do this as simply as
possible using a single l3 agent rather than having to figure out how to get
systemd to start multiple with different configuration files.&lt;&#x2F;p&gt;
&lt;p&gt;Currently I&#x27;ve installed and configured an OpenStack instance that looks like
this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+---------------------+&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|                     |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|                  +--+----+&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|                  |       |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|      +-----------+-+  +--+----------+&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|      | Compute     |  | Compute     |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|      |     01      |  |     02      |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|      +------+------+  +-----+-------+&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|             |               |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|             |               +----------+&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|             +------------+--+          |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|                          |             |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;| +-------------+    +-----+-------+     |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;| | Controller  |    |   Network   |     |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;| |             |    |             |     +---+  Tenant Networks (vlan tagged) (vlan ID&amp;#39;s 350 - 400)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;| +-----+----+--+    +------+----+-+&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|       |    |              |    |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|       |    |              |    +-----------+  Floating Networks (vlan tagged) (vlan ID&amp;#39;s 340 - 349)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|       |    |              |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;|       |    |              |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+------------+--------------+----------------+  Management Network (10.5.2.0&#x2F;25)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        +------------------------------------+  External API Network (10.5.2.128&#x2F;25)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There are two compute nodes, a controller node that runs all of the API
services, and a network node that is strictly used for providing network
functions (routers, load balancers, firewalls, all that fun stuff!).&lt;&#x2F;p&gt;
&lt;p&gt;There are two flat networks that provide the following:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;External API access&lt;&#x2F;li&gt;
&lt;li&gt;A management network that OpenStack uses internally to communicate between
instances and to manage it, which is not accessible from the other three
networks.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;The other two networks are both vlan tagged:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Tenant networks, with the possibility of 50 vlan ID&#x27;s&lt;&#x2F;li&gt;
&lt;li&gt;Floating networks, with existing vlan ID&#x27;s for existing networks&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Since the OpenStack Icehouse release, the l3 agent has supported the ability to
use the Open vSwitch configuration to specify how traffic should be routed
rather than statically defining that a single l3 agent routes certain traffic
to a single Linux bridge. Setting this up is fairly simple if you follow the
documentation, with one caveat, variables you think would be defined to no
value, actually have a value and thus need to be explicitly zeroed out.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;on-the-network-node&quot;&gt;On the network node&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to configure the l3 agent, so let&#x27;s set some extra variables in
&lt;code&gt;&#x2F;etc&#x2F;neutron&#x2F;l3-agent.ini&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;gateway_external_network_id&lt;&#x2F;span&gt;&lt;span&gt; =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;external_network_bridge&lt;&#x2F;span&gt;&lt;span&gt; =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It is important that these two are set, not left commented out, unfortunately
when commented out they have some defaults set and it will fail to work, so
explicitly setting them to blank will fix that issue.&lt;&#x2F;p&gt;
&lt;p&gt;Next, we need to set up our Open vSwitch configuration. In
&lt;code&gt;&#x2F;etc&#x2F;neutron&#x2F;plugin.ini&lt;&#x2F;code&gt; the following needs to be configured:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;bridge_mappings&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;network_vlan_ranges&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Note, that these may already be configured, in which case there is nothing left
to do. Mine currently looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;bridge_mappings&lt;&#x2F;span&gt;&lt;span&gt; = tenant1:br-tnt,provider1:br-ex&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This basically specifies that any networks created under &quot;provider name&quot;
&lt;code&gt;tenant1&lt;&#x2F;code&gt; are going to be mapped to the Open vSwitch bridge &lt;code&gt;br-tnt&lt;&#x2F;code&gt; and any
networks with &quot;provider name&quot; &lt;code&gt;provider1&lt;&#x2F;code&gt; will be mapped to &lt;code&gt;br-ex&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;br-tnt&lt;&#x2F;code&gt; is mapped to my tenant network and on the switch has vlan ID&#x27;s 350 -
400 assigned, and &lt;code&gt;br-ex&lt;&#x2F;code&gt; has vlan ID&#x27;s 340 - 349 assigned.&lt;&#x2F;p&gt;
&lt;p&gt;Following the above knowledge, my &lt;code&gt;network_vlan_ranges&lt;&#x2F;code&gt; is configured as such:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;network_vlan_ranges&lt;&#x2F;span&gt;&lt;span&gt; = tenant1:350:400,provider1:340:349&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Make sure to restart all neutron services:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;openstack-service&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; restart neutron&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;on-the-controller-where-neutron-server-lives&quot;&gt;On the controller (where &lt;code&gt;neutron-server&lt;&#x2F;code&gt; lives)&lt;&#x2F;h2&gt;
&lt;p&gt;On the controller we just need to make sure that our &lt;code&gt;network_vlan_ranges&lt;&#x2F;code&gt;
matches what is on the network node, with one exception, we do not list our
&lt;code&gt;provider1&lt;&#x2F;code&gt; vlan ranges since we don&#x27;t want to make those available to
accidentally be assigned when a regular tenant creates a new network.&lt;&#x2F;p&gt;
&lt;p&gt;So our configuration should list:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;network_vlan_ranges&lt;&#x2F;span&gt;&lt;span&gt; = tenant1:350:400&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Make sure that all neutron services are restarted:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;openstack-service&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; restart neutron&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;create-the-neutron-networks&quot;&gt;Create the Neutron networks&lt;&#x2F;h2&gt;
&lt;p&gt;Now, as an administrative user we need to create the provider networks.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;source&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; ~&#x2F;keystonerc_admin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;neutron&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; net-create&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;192.168.1.0&#x2F;24-floating&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --router:external&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; True&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --provider:network_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; vlan&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --provider:physical_network&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; provider1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --provider:segmentation_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 340&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;neutron&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; net-create&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;192.168.2.0&#x2F;24-floating&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --router:external&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; True&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --provider:network_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; vlan&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --provider:physical_network&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; provider1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --provider:segmentation_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 341&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Notice how we&#x27;ve created two networks, given them each individual names (I like
to use the name of the network they are going to be used for) and have been
attached to the &lt;code&gt;provider1&lt;&#x2F;code&gt;. Note that &lt;code&gt;provider1&lt;&#x2F;code&gt; is completely
administratively defined, and could just as well have been &lt;code&gt;physnet1&lt;&#x2F;code&gt;, so long
as it is consistent across all of the configuration files.&lt;&#x2F;p&gt;
&lt;p&gt;Now let&#x27;s create subnets on this network:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;neutron&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; subnet-create&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;192.168.1.0&#x2F;24-floating&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; 192.168.1.0&#x2F;24&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --allocation-pool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; start=192.168.1.4,end=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;192.168.1.254 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --disable-dhcp --gateway&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 192.168.1.1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;neutron&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; subnet-create&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;192.168.2.0&#x2F;24-floating&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; 192.168.2.0&#x2F;24&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --allocation-pool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; start=192.168.2.4,end=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;192.168.2.254 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    --disable-dhcp --gateway&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 192.168.2.1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now that these networks are defined, you should be able to have tenants create
routers and set their gateways to either of these new networks by selecting
from the drop-down in Horizon or by calling &lt;code&gt;neutron router-gateway-set &amp;lt;router id&amp;gt; &amp;lt;network id&amp;gt;&lt;&#x2F;code&gt; on the command line.&lt;&#x2F;p&gt;
&lt;p&gt;The l3 agent will automatically configure and set up the router as required on
the network node, and traffic will flow to either vlan 340 or vlan 341 as
defined above depending on what floating network the user uses as a gateway.&lt;&#x2F;p&gt;
&lt;p&gt;This drastically simplifies the configuration of multiple floating IP networks
since no longer is there a requirement to start up and configure multiple l3
agents each with their own network ID configured. This makes configuration less
brittle and easier to maintain over time.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>OpenStack resizing of instances</title>
        <published>2014-09-29T17:10:00+00:00</published>
        <updated>2014-09-29T17:10:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2014/openstack-resizing-instances/"/>
        <id>https://funcptr.net/2014/openstack-resizing-instances/</id>
        
        <content type="html" xml:base="https://funcptr.net/2014/openstack-resizing-instances/">&lt;p&gt;One thing that is not always adequately explained in the OpenStack
documentation is how exactly instance resizing works, and what is required,
especially while using KVM as the virtualisation provider, with multiple
compute nodes.&lt;&#x2F;p&gt;
&lt;p&gt;You might find something similiar to the following in your logs, and no good
documentation on how to fix it.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ERROR nova.compute.manager [req-7cb1c029-beb4-4905-a9d9-62d488540eda f542d1b5afeb4908b8b132c4486f9fa8 c2bfab5ad24642359f43cdff9bb00047] [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Setting instance vm_state to ERROR&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Traceback (most recent call last):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &amp;quot;&#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;site-packages&#x2F;nova&#x2F;compute&#x2F;manager.py&amp;quot;, line 5596, in _error_out_instance_on_exception&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     yield&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &amp;quot;&#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;site-packages&#x2F;nova&#x2F;compute&#x2F;manager.py&amp;quot;, line 3459, in resize_instance&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     block_device_info)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &amp;quot;&#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;site-packages&#x2F;nova&#x2F;virt&#x2F;libvirt&#x2F;driver.py&amp;quot;, line 4980, in migrate_disk_and_power_off&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     utils.execute(&amp;#39;ssh&amp;#39;, dest, &amp;#39;mkdir&amp;#39;, &amp;#39;-p&amp;#39;, inst_base)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &amp;quot;&#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;site-packages&#x2F;nova&#x2F;utils.py&amp;quot;, line 165, in execute&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     return processutils.execute(*cmd, **kwargs)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &amp;quot;&#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;site-packages&#x2F;nova&#x2F;openstack&#x2F;common&#x2F;processutils.py&amp;quot;, line 193, in execute&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     cmd=&amp;#39; &amp;#39;.join(cmd))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] ProcessExecutionError: Unexpected error while running command.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Command: ssh 10.5.2.20 mkdir -p &#x2F;var&#x2F;lib&#x2F;nova&#x2F;instances&#x2F;99736f90-db0f-4cba-8f44-a73a603eee0b&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Exit code: 255&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Stdout: &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Stderr: &amp;#39;Host key verification failed.\r\n&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ERROR oslo.messaging.rpc.dispatcher [-] Exception during message handling: Unexpected error while running command.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Command: ssh 10.5.2.20 mkdir -p &#x2F;var&#x2F;lib&#x2F;nova&#x2F;instances&#x2F;99736f90-db0f-4cba-8f44-a73a603eee0b&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Exit code: 255&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Stdout: &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Stderr: &amp;#39;Host key verification failed.\r\n&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When OpenStack&#x27;s nova is instructed to resize an instance it will also change
the host it is running on, almost never will it schedule the instance on the
same host and do the resize on the same host it already exists. There is a
configuration flag to change this, however in my case I would rather the
scheduler be run again, especially if the instance size is changing
drastically. During the resize process, the node where the instance is
currently running will use SSH to connect to the instance where the resized
instance will live, and copy over the instance and associated files.&lt;&#x2F;p&gt;
&lt;p&gt;There are a couple of assumptions I will be making:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Your &lt;code&gt;nova&lt;&#x2F;code&gt;, and &lt;code&gt;qemu&lt;&#x2F;code&gt; user both have the same UID on all compute nodes&lt;&#x2F;li&gt;
&lt;li&gt;The path for your instances is the same on all of your compute nodes&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;configure-the-nova-user&quot;&gt;Configure the nova user&lt;&#x2F;h2&gt;
&lt;p&gt;First things first, let&#x27;s make sure our &lt;code&gt;nova&lt;&#x2F;code&gt; user has an appropriate shell set:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;cat&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;etc&#x2F;passwd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; nova&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Verify that the last entry is &lt;code&gt;&#x2F;bin&#x2F;bash&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If not, let&#x27;s modify the user and make it so:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;usermod&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;bin&#x2F;bash nova&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;generate-ssh-key-and-configuration&quot;&gt;Generate SSH key and configuration&lt;&#x2F;h2&gt;
&lt;p&gt;After doing this the next steps are all run as the &lt;code&gt;nova&lt;&#x2F;code&gt; user.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;su&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; - nova&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We need to generate an SSH key:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;ssh-keygen&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; rsa&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Follow the directions, and save the key WITHOUT a passphrase.&lt;&#x2F;p&gt;
&lt;p&gt;Next up we need to configure SSH to not do host key verification, unless you
want to manually SSH to all compute nodes that exist and accept the key (and
continue to do so for each new compute node you add).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;cat&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; EOF&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; ~&#x2F;.ssh&#x2F;config&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Host *&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    StrictHostKeyChecking no&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    UserKnownHostsFile=&#x2F;dev&#x2F;null&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;EOF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Next we need to make sure we copy the the contents of &lt;code&gt;id_rsa.pub&lt;&#x2F;code&gt; to
&lt;code&gt;authorized_keys&lt;&#x2F;code&gt; and set the mode on it correctly.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;cat&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; ~&#x2F;.ssh&#x2F;id_rsa.pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .ssh&#x2F;authorized_keys&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;chmod&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 600&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .ssh&#x2F;authorized_keys&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This should be all the configuration for SSH you need to do. Now comes the
import part, you will need to tar up and copy the &lt;code&gt;~nova&#x2F;.ssh&lt;&#x2F;code&gt; directory to
every single compute node you have provisioned. This way all compute nodes will
be able to SSH to the remote host to run the commands required to copy an
instance over, and resize it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reset-state-on-existing-error-ed-instances&quot;&gt;Reset state on existing ERROR&#x27;ed instances&lt;&#x2F;h2&gt;
&lt;p&gt;If you have any instances that are currently in the &lt;code&gt;ERROR&lt;&#x2F;code&gt; state due to a
failed resize, you will be able to issue the following command to reset the
state back to running and try again:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;nova&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; reset-state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; --active&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;ID of instanc&lt;&#x2F;span&gt;&lt;span&gt;e&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will start the instance, and you will be able to once again issue the
resize command to resize the instance.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Build numbers in binaries using waf</title>
        <published>2014-06-10T17:32:03+00:00</published>
        <updated>2014-06-10T17:32:03+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2014/build-numbers-in-binaries-using-waf/"/>
        <id>https://funcptr.net/2014/build-numbers-in-binaries-using-waf/</id>
        
        <content type="html" xml:base="https://funcptr.net/2014/build-numbers-in-binaries-using-waf/">&lt;p&gt;My build system of choice these days for any C++ project is &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;waf.io&quot;&gt;waf&lt;&#x2F;a&gt;. One of
the things I always like havig is the build number included in the final
binary, so that with a simple &lt;code&gt;.&#x2F;binary --version&lt;&#x2F;code&gt; or even &lt;code&gt;.&#x2F;binary&lt;&#x2F;code&gt; the
version is printed that it was built from. This can make it much simpler to
debug any potential issues, especially if fixes may have already been made but
a bad binary was deployed.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;setup-the-wscript&quot;&gt;Setup the wscript&lt;&#x2F;h2&gt;
&lt;p&gt;Make sure that your wscript somewhere near the top contains the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;APPNAME&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;myapp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;VERSION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;0.0.0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then in your &lt;code&gt;configure(cfg)&lt;&#x2F;code&gt; add the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cfg.env.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;VERSION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; VERSION&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cfg.env.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;APPNAME&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; APPNAME&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git_version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt; try_git_version&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; git_version:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cfg.env.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;VERSION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; git_version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;code&gt;try_git_version()&lt;&#x2F;code&gt; function is fairly simple and looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; try_git_version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;()&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    import&lt;&#x2F;span&gt;&lt;span&gt; os&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    import&lt;&#x2F;span&gt;&lt;span&gt; sys&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    try&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; os.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;popen&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;git describe --always --dirty --long&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;read&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;strip&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    except&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; Exception&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span&gt; e:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        print&lt;&#x2F;span&gt;&lt;span&gt; e&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It runs &lt;code&gt;git describe --always --dirty --long&lt;&#x2F;code&gt; which will return something
along these lines: &lt;code&gt;401b85f-dirty&lt;&#x2F;code&gt;. If you have any annoted tags, it will
return the tag name as well.&lt;&#x2F;p&gt;
&lt;p&gt;If &lt;code&gt;git&lt;&#x2F;code&gt; is not installed, or it is not a valid &lt;code&gt;git&lt;&#x2F;code&gt; directory, then it will
simply return &lt;code&gt;None&lt;&#x2F;code&gt;. At that point all we have to go on is the &lt;code&gt;VERSION&lt;&#x2F;code&gt;
variable set at the top of the wscript.&lt;&#x2F;p&gt;
&lt;p&gt;Now that we have our configuration environment set up with the &lt;code&gt;VERSION&lt;&#x2F;code&gt; we
want to get that into a file that we can then include in our C++ source code.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;create-a-build-version-h-in-file&quot;&gt;Create a &lt;code&gt;build_version.h.in&lt;&#x2F;code&gt; file&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;ifndef&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;font-style: italic;&quot;&gt; BUILD_VERSION_H_IN_941AD1F24D0A9D&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;define&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;font-style: italic;&quot;&gt; BUILD_VERSION_H_IN_941AD1F24D0A9D&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt; VERSION[] &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;@VERSION@&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;endif&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; &#x2F;* BUILD_VERSION_H_IN_941AD1F24D0A9D *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;add-the-following-to-build-ctx&quot;&gt;Add the following to &lt;code&gt;build(ctx)&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;ctx&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;subst&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        source&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;build_version.h.in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        target&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;build_version.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        VERSION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; ctx.env&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;VERSION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This uses the substitution feature to transform &lt;code&gt;build_version.h.in&lt;&#x2F;code&gt; into
&lt;code&gt;build_version.h&lt;&#x2F;code&gt;, while inserting the version into the file.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;include-build-version-h-in-your-source-code&quot;&gt;Include &lt;code&gt;build_version.h&lt;&#x2F;code&gt; in your source code&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;build_version.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And add something along these lines to your &lt;code&gt;main()&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;std::cerr &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Version: &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; VERSION &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; std::endl;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will print out the &lt;code&gt;VERSION&lt;&#x2F;code&gt; that has been stored in &lt;code&gt;build_version.h&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;full-example&quot;&gt;Full example&lt;&#x2F;h2&gt;
&lt;p&gt;Check out my &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;digitalresistor&#x2F;mdns-announce&quot;&gt;mdns-announce&lt;&#x2F;a&gt; project on Github for an example of how this is
implemented.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Tamper proof session cookies and session storage</title>
        <published>2014-06-10T17:09:45+00:00</published>
        <updated>2014-06-10T17:09:45+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2014/secure-cookies-for-secure-session-information/"/>
        <id>https://funcptr.net/2014/secure-cookies-for-secure-session-information/</id>
        
        <content type="html" xml:base="https://funcptr.net/2014/secure-cookies-for-secure-session-information/">&lt;p&gt;As a follow-up to my previous article regarding &lt;a href=&quot;&#x2F;2013&#x2F;user-sessions-and-the-data-to-be-stored&#x2F;&quot;&gt;User sessions, what data
should be stored where?&lt;&#x2F;a&gt;, I wanted to discuss how to store the session, and
how to generate cookies that are tamper proof.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-are-we-trying-to-accomplish&quot;&gt;What are we trying to accomplish?&lt;&#x2F;h2&gt;
&lt;p&gt;Ultimately we want to be able to have X amount pieces of data that are tied to
a particular user. Unfortunately due the fact that HTTP is a stateless protocol
we have to use cookies. Cookies are small little pieces of data that are
transmitted from the server to the client (generally done once), and then upon
the user coming back to the website they are transmitted from the client to the
server. This allows us to uniquely track a single user across connections to
our website.&lt;&#x2F;p&gt;
&lt;p&gt;If the website allows a user to authenticate and the fact that they are
authenticated is stored in the session, we also want to make sure that we can
aggressively expire a session, if this is possible depends on our session
storage.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;session-storage&quot;&gt;Session storage&lt;&#x2F;h2&gt;
&lt;p&gt;There are a multitude of ways to store the session data, but it ultimately
boils down to server-side or client-side. Server-side can be done in Cassandra,
Memcache, Redis or even in a SQL database.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;server-side-storage&quot;&gt;Server-side storage&lt;&#x2F;h3&gt;
&lt;p&gt;The main one that has
been used for years is to use server side storage. Storing a small file on the
servers hard drive that contains the data, and the client is sent a cookie that
contains a unique identifier that is linked to the on-disk storage.&lt;&#x2F;p&gt;
&lt;p&gt;For example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;1 =&amp;gt; &#x2F;tmp&#x2F;session_1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2 =&amp;gt; &#x2F;tmp&#x2F;session_2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;N =&amp;gt; &#x2F;tmp&#x2F;session_N&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;easily-expire-sessions&quot;&gt;Easily expire sessions&lt;&#x2F;h4&gt;
&lt;p&gt;The upside to server-side storage is that it is possible for us to very easily
expire a session, simply remove the associated file&#x2F;data that is stored and the
users session has now become invalid.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;client-side-storage&quot;&gt;Client-side storage&lt;&#x2F;h3&gt;
&lt;p&gt;The other method that has recently started being used more to make it easier to
scale the server side is to store session data encoded in base64 in the cookie
itself. In this case there is no unique session ID, and no data is stored
server side.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;expiration-is-more-difficult&quot;&gt;Expiration is more difficult&lt;&#x2F;h4&gt;
&lt;p&gt;The downside to using client-side storage is that there is no way, short of the
expiration on the cookie itself for the website to expire a session. There are
work-arounds, but they all require storing state server-side. A hybrid approach
for example is possible, store a unique ID along with the session data, and
store that unique ID server side, but none of the extra data. Remove the unique
ID server side and if we receive a session that contains a unique ID we don&#x27;t
recognise, we simply clear the session.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;expiration-why-do-i-care&quot;&gt;Expiration, why do I care?&lt;&#x2F;h2&gt;
&lt;p&gt;Being able to easily expire a users sessions allows for extra security
measures. For example in Google Mail it is possible to sign out all other
locations, this forces those other locations to re-authenticate before gaining
access to your account.&lt;&#x2F;p&gt;
&lt;p&gt;This is a good security measure to have, so that if a users cookie is stolen,
or their credentials are compromised upon changing their password all their
sessions are invalidated and an attacker using an old cookie&#x2F;session ID can&#x27;t
continue to wreak havoc on the users account.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;cookie-format&quot;&gt;Cookie format&lt;&#x2F;h2&gt;
&lt;p&gt;If we are just storing a session ID, or the full session the cookie should be
hardened so that it can not be tampered with by a client. Even if you are
protecting the cookie using SSL, we still don&#x27;t want to allow a malicious user
to modify the cookie to change the session ID or the session itself.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;signing-your-cookie&quot;&gt;Signing your cookie&lt;&#x2F;h3&gt;
&lt;p&gt;The single best way to make sure your cookie has not been tampered with is to
cryptographically sign your cookie, and upon receiving the cookie from the
client verifying that the signature matches what you are expecting. This is
especially important if you are using client-side storage, because you don&#x27;t
want someone to be able to change the user ID from 950 to 1 and suddenly
impersonate a different user.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;use-an-hmac&quot;&gt;Use an HMAC&lt;&#x2F;h4&gt;
&lt;p&gt;HMAC (Hash-based message authentication code) is an cryptographic construct
that uses a hashing algorithm (SHA-1, SHA-256, SHA-3) to create a MAC (message
authentication code) with a secret key. It is very easy given the secret key
and the original data to create the MAC, but it is very difficult if not
impossible to take the original data, and MAC and get the secret key.&lt;&#x2F;p&gt;
&lt;p&gt;This allows us to do the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data = &amp;quot;Hello World&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mac = HMAC(data, sha256, &amp;quot;SEEKRIT&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Our &lt;code&gt;mac&lt;&#x2F;code&gt; would now be equal to:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;e655f98cb9b3c02f45576f7906d64b0b7f8731f25a5319c42ca666917aca45a4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If we now create our cookie as follows:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cookie = mac + &amp;quot; &amp;quot; + data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It would look as follows:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cookie = e655f98cb9b3c02f45576f7906d64b0b7f8731f25a5319c42ca666917aca45a4 Hello World&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can then send that to the client that requested the page. Once the client
visits the next page, their browser will send that same cookie back to use. If
we split the mac from the data, we can then do the following operation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cookie = e655f98cb9b3c02f45576f7906d64b0b7f8731f25a5319c42ca666917aca45a4 Hello World&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data = &amp;quot;Hello World&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mac = e655f98cb9b3c02f45576f7906d64b0b7f8731f25a5319c42ca666917aca45a4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mac_verify = HMAC(data, sha256, &amp;quot;SEEKRIT&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mac_verify == mac&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If and only if &lt;code&gt;mac_verify&lt;&#x2F;code&gt; and &lt;code&gt;mac&lt;&#x2F;code&gt; are the same can we be sure that the
cookie has not been tampered with.&lt;&#x2F;p&gt;
&lt;p&gt;This requires that the client is NEVER aware of what we are using as our secret
key. In the above exmaples that is &quot;SEEKRIT&quot;. In your web application you will
be required to make this a configuration variable, and you will have to take
care not to commit that configuration variable to a git repository and upload
it to github (for example).&lt;&#x2F;p&gt;
&lt;h4 id=&quot;do-not-use-a-bare-hash-algorithm&quot;&gt;Do not use a bare hash algorithm&lt;&#x2F;h4&gt;
&lt;p&gt;Using a bare hash algorithm allows for &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Length_extension_attack&quot;&gt;length extension attacks&lt;&#x2F;a&gt; if used
incorrectly, this would allow an attacker to concatenate extra data to the end
of our existing data, modify the &quot;MAC&quot; and the server would accept it.&lt;&#x2F;p&gt;
&lt;p&gt;This construct is thus very dangerous:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data = &amp;quot;Hello World&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;key = &amp;quot;SEEKRIT&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mac = SHA1(key + data)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The following construct is still not recommended, but is not nearly as
dangerous:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mac = SHA1(data + key)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Due to the key being last, this is not vulnerable to a length extension attack,
however please don&#x27;t do this, instead stick to using an HMAC instead.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;encrypting-session-data&quot;&gt;Encrypting session data&lt;&#x2F;h2&gt;
&lt;p&gt;When using client-side storage, it may be beneficial to encrypt the data to add
an extra layer of security. Even if encrypting the data you need to continue
using a MAC.&lt;&#x2F;p&gt;
&lt;p&gt;Using just encryption will not protect you against decrypting bad data because
an attacker decided to provide invalid data. Signing the cookie data with a MAC
makes sure that the attacker is not able to mess with the ciphertext.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-are-web-frameworks-languages-doing-by-default&quot;&gt;What are web frameworks&#x2F;languages doing by default?&lt;&#x2F;h2&gt;
&lt;p&gt;I am most familiar with the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.pylonsproject.org&#x2F;projects&#x2F;pyramid&#x2F;about&quot;&gt;Pylons Project&#x27;s Pyramid Web Framework&lt;&#x2F;a&gt;, the
default session implementation that is provided by the project is named
&lt;code&gt;SignedCookieSessionFactory&lt;&#x2F;code&gt;, as the name implies this uses a client-side
cookie to store the session data, which is signed using a secret key that is
provided upon instantiation of the factory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;flask.pocoo.org&#x2F;docs&#x2F;quickstart&#x2F;#sessions&quot;&gt;Flask sessions&lt;&#x2F;a&gt; also uses a signed cookie for client-side session storage.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;api.rubyonrails.org&#x2F;classes&#x2F;ActionDispatch&#x2F;Session&#x2F;CookieStore.html&quot;&gt;Ruby on Rails&lt;&#x2F;a&gt; uses a signed&#x2F;encrypted cookie for client-side session
storage by default.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;php.net&quot;&gt;PHP&lt;&#x2F;a&gt; does not by default sign the session cookie, it does however use
server-side storage for session data by default. However extra security can be
added by installing &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.hardened-php.net&#x2F;suhosin.127.html&quot;&gt;PHP SuHoSin&lt;&#x2F;a&gt; which adds session cookie
encryption&#x2F;signing.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Building custom ports with Poudriere and Portshaker</title>
        <published>2013-12-11T00:10:11+00:00</published>
        <updated>2013-12-11T00:10:11+00:00</updated>
        
        <author>
          <name>
            Scott Sturdivant
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2013/using-portshaker-with-poudriere/"/>
        <id>https://funcptr.net/2013/using-portshaker-with-poudriere/</id>
        
        <content type="html" xml:base="https://funcptr.net/2013/using-portshaker-with-poudriere/">&lt;p&gt;&lt;em&gt;Guest post by &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ScottSturdivant&quot;&gt;Scott Sturdivant&lt;&#x2F;a&gt;.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Maintaining custom ports and integrating them into your build process doesn&#x27;t
need to be difficult.  The documentation surrounding this process however is
either non-existent, or lacking in its clarity.  At the end of the day, it really
is as simple as maintaining a repository whose structure matches the ports tree
layout, then managing that repository and the standard ports tree
with &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freshports.org&#x2F;ports-mgmt&#x2F;portshaker&#x2F;&quot;&gt;portshaker&lt;&#x2F;a&gt;, and finally handing the end result off to &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20140108191325&#x2F;https:&#x2F;&#x2F;fossil.etoilebsd.net&#x2F;poudriere&#x2F;doc&#x2F;trunk&#x2F;doc&#x2F;index.wiki&quot;&gt;poudriere&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;your-custom-repository&quot;&gt;Your Custom Repository&lt;&#x2F;h2&gt;
&lt;p&gt;For this example, we&#x27;ll assume a &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;git-scm.com&quot;&gt;git&lt;&#x2F;a&gt; repo is used and that you&#x27;re already
familiar with how to build &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;&quot;&gt;FreeBSD&lt;&#x2F;a&gt; &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;ports&#x2F;&quot;&gt;ports&lt;&#x2F;a&gt;.  We&#x27;ll also assume that we
have but a single port that we&#x27;re maintaining and that it is called &lt;code&gt;myport&lt;&#x2F;code&gt;.
The hierarchy of your repo should simply be &lt;code&gt;category&#x2F;myport&lt;&#x2F;code&gt;.  We&#x27;ll refer to
this repo simply as &lt;code&gt;myrepo&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;portshaker&quot;&gt;Portshaker&lt;&#x2F;h2&gt;
&lt;p&gt;Portshaker is the tool responsible for taking multiple ports sources and then
merging them down into a single target.  In our case, we have two sources: our
git repo (&lt;code&gt;myrepo&lt;&#x2F;code&gt;) containing &lt;code&gt;myport&lt;&#x2F;code&gt;, and the standard FreeBSD ports tree.
We aim to merge this down into a single ports tree that poudriere will then use
for its builds.&lt;&#x2F;p&gt;
&lt;p&gt;To configure portshaker, add the following to the
&lt;code&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;portshaker.conf&lt;&#x2F;code&gt; file:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# vim:set syntax=sh:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# $Id: portshaker.conf.sample 116 2008-09-30 16:15:02Z romain.tartiere $&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#---[ Base directory for mirrored Ports Trees ]---&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;mirror_base_dir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;&#x2F;var&#x2F;cache&#x2F;portshaker&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#---[ Directories where to merge ports ]---&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;ports_trees&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;use_zfs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;no&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;poudriere_ports_mountpoint&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;&#x2F;usr&#x2F;local&#x2F;poudriere&#x2F;ports&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;default_poudriere_tree&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;default_merge_from&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;freebsd myrepo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Some key points here are that the two items listed in for the
&lt;code&gt;default_merge_from&lt;&#x2F;code&gt; argument need to have scripts present in the
&lt;code&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;portshaker.d&lt;&#x2F;code&gt; directory.  Further more, the combination of the
&lt;code&gt;poudriere_ports_mountpoint&lt;&#x2F;code&gt; and &lt;code&gt;default_poudriere_tree&lt;&#x2F;code&gt; needs to be a ports
tree that is then registered with poudriere.&lt;&#x2F;p&gt;
&lt;p&gt;Next, we need to tell portshaker how to go off and fetch our two types of ports
trees, &lt;code&gt;freebsd&lt;&#x2F;code&gt; and &lt;code&gt;myrepo&lt;&#x2F;code&gt;.  For the &lt;code&gt;freebsd&lt;&#x2F;code&gt; ports tree, create
&lt;code&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;portshaker.d&#x2F;freebsd&lt;&#x2F;code&gt; with the following contents and make it
executable:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;share&#x2F;portshaker&#x2F;portshaker.subr&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;method&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;portsnap&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;run_portshaker_command&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; $*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Next, create a similar script to handle our repository containing our custom
port.  &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;portshaker.d&#x2F;myrepo&lt;&#x2F;code&gt; should contain the following and
similarly be executable:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;share&#x2F;portshaker&#x2F;portshaker.subr&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;method&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;git_clone_uri&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;http:&#x2F;&#x2F;github.com&#x2F;scottsturdivant&#x2F;packaging.git&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;git_branch&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;master&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;run_portshaker_command&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; $*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Obviously replace the &lt;code&gt;git_clone_uri&lt;&#x2F;code&gt; and &lt;code&gt;git_branch&lt;&#x2F;code&gt; variables to reflect
your actual configuration.  For more information about the values and what they
can contain, consult &lt;code&gt;man portshaker.d&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now, portshaker should be all set.  Execute &lt;code&gt;portshaker -U&lt;&#x2F;code&gt; to update your
&lt;code&gt;merge_from&lt;&#x2F;code&gt; ports trees (&lt;code&gt;freebsd&lt;&#x2F;code&gt; and &lt;code&gt;myrepo&lt;&#x2F;code&gt;).  You&#x27;ll see the standard
&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=portsnap&amp;amp;sektion=8&quot;&gt;portsnap&lt;&#x2F;a&gt; fetch and extract process as well as a git clone.  After a good
bit of time, these will both be present in the &lt;code&gt;&#x2F;var&#x2F;cache&#x2F;portshaker&lt;&#x2F;code&gt;
directory.  Go ahead and merge them together by executing &lt;code&gt;portshaker -M&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Hooray!  You now have &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;poudriere&#x2F;ports&#x2F;default&#x2F;ports&lt;&#x2F;code&gt; that is a
combination of the normal ports tree and your custom one.&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;re effectively complete with configuring portshaker.  Whenever your port is
updated, just re-run &lt;code&gt;portshaker -U&lt;&#x2F;code&gt; and &lt;code&gt;portshaker -M&lt;&#x2F;code&gt; to grab the latest
changes and perform the merge.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;poudriere&quot;&gt;Poudriere&lt;&#x2F;h2&gt;
&lt;p&gt;Poudriere is a good tool for building ports.  We will use it to handle our
merged directory.  Begin by configuring poudriere
(&lt;code&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;poudriere.conf&lt;&#x2F;code&gt;):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;NO_ZFS&lt;&#x2F;span&gt;&lt;span&gt;=yes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;FREEBSD_HOST&lt;&#x2F;span&gt;&lt;span&gt;=ftp:&#x2F;&#x2F;ftp.freebsd.org&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;RESOLV_CONF&lt;&#x2F;span&gt;&lt;span&gt;=&#x2F;etc&#x2F;resolv.conf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;BASEFS&lt;&#x2F;span&gt;&lt;span&gt;=&#x2F;usr&#x2F;local&#x2F;poudriere&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;USE_PORTLINT&lt;&#x2F;span&gt;&lt;span&gt;=no&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;USE_TMPFS&lt;&#x2F;span&gt;&lt;span&gt;=yes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;DISTFILES_CACHE&lt;&#x2F;span&gt;&lt;span&gt;=&#x2F;usr&#x2F;ports&#x2F;distfiles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;CHECK_CHANGED_OPTIONS&lt;&#x2F;span&gt;&lt;span&gt;=yes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Really there&#x27;s nothing here that is specific to the problem at hand, so feel
free to consult the provided configuration file to tune it to your needs.&lt;&#x2F;p&gt;
&lt;p&gt;Now, the step that &lt;em&gt;is&lt;&#x2F;em&gt; specific is to set poudriere up with a ports tree that
it does not manage, specifically our resultant merged directory.  If you
consult &lt;code&gt;man poudriere&lt;&#x2F;code&gt;, it specifies that for the &lt;code&gt;ports&lt;&#x2F;code&gt; subcommand, there is
a &lt;code&gt;-m method&lt;&#x2F;code&gt; switch which controls the methodology used to create the ports
tree.  By default, it is portsnap.  This is confusing as in our case, we do not
want poudriere to actually do anything.  We want it to just use an existing
path.  Fortunately, there is a way!&lt;&#x2F;p&gt;
&lt;p&gt;The poudriere wiki has an entry for using the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20130817160004&#x2F;https:&#x2F;&#x2F;fossil.etoilebsd.net&#x2F;poudriere&#x2F;doc&#x2F;trunk&#x2F;doc&#x2F;use_system_ports_tree.wiki&quot;&gt;system ports tree&lt;&#x2F;a&gt;, so we
adopt it for our needs by executing:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;poudriere&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; ports&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -c -F -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; none&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -M&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;poudriere&#x2F;ports&#x2F;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;    -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you&#x27;ve consulted the poudriere manpage, you&#x27;ll see that the &lt;code&gt;-F&lt;&#x2F;code&gt; and &lt;code&gt;-f&lt;&#x2F;code&gt;
switches both reference ZFS in their help.  As we&#x27;re not using ZFS, it&#x27;s not
clear how they will behave.  However, in conjunction with the custom mountpoint
(&lt;code&gt;-M &#x2F;usr&#x2F;local&#x2F;poudriere&#x2F;ports&#x2F;default&lt;&#x2F;code&gt;), we ultimately wind up with what we
want, a ports tree that poudriere can use, but does not manage:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# poudriere ports -l&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PORTSTREE            METHOD     PATH&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;default              -          &#x2F;usr&#x2F;local&#x2F;poudriere&#x2F;ports&#x2F;default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note that this resulting PATH is the combination of the
&lt;code&gt;poudriere_ports_mountpoint&lt;&#x2F;code&gt; and &lt;code&gt;default_poudriere_tree&lt;&#x2F;code&gt; variables present in
our &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;portshaker.conf&lt;&#x2F;code&gt; configuration file.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;building-software-from-your-custom-ports-tree&quot;&gt;Building software from your custom ports tree&lt;&#x2F;h2&gt;
&lt;p&gt;Go ahead and create your jail(s) like you normally would (i.e.
&lt;code&gt;poudriere -c -j 92amd64 -V 9.2-RELEASE -a amd64&lt;&#x2F;code&gt;) and any other configuration
you would like, and then go ahead and build &lt;code&gt;myport&lt;&#x2F;code&gt; with
&lt;code&gt;poudriere bulk -j 92amd64 -p default category&#x2F;myport&lt;&#x2F;code&gt;.  Success!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>User sessions, what data should be stored where?</title>
        <published>2013-08-25T13:05:00+00:00</published>
        <updated>2013-08-25T13:05:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2013/user-sessions-and-the-data-to-be-stored/"/>
        <id>https://funcptr.net/2013/user-sessions-and-the-data-to-be-stored/</id>
        
        <content type="html" xml:base="https://funcptr.net/2013/user-sessions-and-the-data-to-be-stored/">&lt;p&gt;&lt;em&gt;This article has been updated. For the old version please check
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20130826031727&#x2F;http:&#x2F;&#x2F;funcptr.net&#x2F;2013&#x2F;08&#x2F;25&#x2F;user-sessions,-what-data-should-be-stored-where-&#x2F;&quot;&gt;Archive.org&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;A couple of days ago on &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;reddit.com&#x2F;&quot;&gt;reddit.com&lt;&#x2F;a&gt;&#x27;s &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;reddit.com&#x2F;r&#x2F;netsec&#x2F;&quot;&gt;&#x2F;r&#x2F;netsec&lt;&#x2F;a&gt; a poster by the name
of &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;danweber.blogspot.com&#x2F;&quot;&gt;Dan Weber&lt;&#x2F;a&gt; posted what he believed to be an attack on PHP sessions:
&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;danweber.blogspot.com&#x2F;2013&#x2F;08&#x2F;hacking-php-sessions-by-running-out-of.html&quot;&gt;Hacking PHP sessions by running out of memory&lt;&#x2F;a&gt; &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;netsec&#x2F;comments&#x2F;1k7khy&#x2F;i_know_its_not_that_hard_but_i_think_i_found_a&#x2F;&quot;&gt;(reddit link)&lt;&#x2F;a&gt;. The way
the &quot;attack&quot; works is as follows:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new session&lt;&#x2F;li&gt;
&lt;li&gt;Assign some new data to the session, in this case a username which is used
to signify that the user is logged in.&lt;&#x2F;li&gt;
&lt;li&gt;Check to verify that the user should be logged in&lt;&#x2F;li&gt;
&lt;li&gt;If the user should not be logged in, destroy the session.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;The &quot;attack&quot; would be to run the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;php.net&#x2F;&quot;&gt;PHP&lt;&#x2F;a&gt; script out of memory on number 3, since
once something is set on the session it is immediately stored, so even if the
user is not supposed to be logged in, they are now logged in since their
session says they are.&lt;&#x2F;p&gt;
&lt;p&gt;I wouldn&#x27;t necessarily call this a PHP hack, this is really just bad practice
in terms of programming, the logic should be reversed.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new session&lt;&#x2F;li&gt;
&lt;li&gt;Verify the user should be logged in&lt;&#x2F;li&gt;
&lt;li&gt;If so, set the session data&lt;&#x2F;li&gt;
&lt;li&gt;If the user should not be logged in, don&#x27;t set the session data&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;That would solve the problem at hand, and now there is no way for the user to
trick the PHP script into believing she is logged in when that is not the case.&lt;&#x2F;p&gt;
&lt;p&gt;However as the discussion went on on Reddit, it became even more clear that
there are no good resources on what you should store in the user session, and
what you shouldn&#x27;t store in the user session. Some of these things may seem
like common knowledge, but sadly this is something every single new person to
programming has to learn on their own.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;some-assumptions&quot;&gt;Some assumptions&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s get this out of the way, this is in no way limited to PHP, but it is the
one I will be using as an example. This can all apply to Ruby (&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;rubyonrails.org&quot;&gt;Ruby on
Rails&lt;&#x2F;a&gt;), Python (&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.pylonsproject.org&quot;&gt;Pyramid&lt;&#x2F;a&gt;) or many other frameworks.&lt;&#x2F;p&gt;
&lt;p&gt;The basic problem is that generally writing to the session is not an atomic
transaction based on the page accessed, so the assumption made in this article
is that when you write to the session it is instantly committed, and there is
no way to roll it back upon failure. If there was, our first example listed
wouldn&#x27;t be able to occur since upon running out of memory at step 3, the
session would have been rolled back and cleaned up.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-should-you-store-in-the-users-session&quot;&gt;What should you store in the users session?&lt;&#x2F;h2&gt;
&lt;p&gt;You should only really store anything in the session that if it were made
public it would do very little harm.&lt;&#x2F;p&gt;
&lt;p&gt;Really the list of items to be stored in a session are as follows:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;The users unique id (The ID that allows you to retrieve the users
information from storage)&lt;&#x2F;li&gt;
&lt;li&gt;Temporary state (i.e. Flash messages)&lt;&#x2F;li&gt;
&lt;li&gt;CSRF token&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;More importantly, don&#x27;t store permission bits, or group memberships, or
anything that is used to allow&#x2F;deny access to particular resources. You want to
store just enough information that upon a user accessing your site you are able
to retrieve the users information from storage, and based upon that information
from storage you then make decisions such as permissions&#x2F;group memberships.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;why-is-this-important&quot;&gt;Why is this important?&lt;&#x2F;h3&gt;
&lt;p&gt;One of the things that Dan Weber brought up in the Reddit post was storing the
users permission level and group membership in the session. If your code is
then relying on the session to always contain the right permission level, then
there is no way to expire someones access to the data.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;A user logs in&lt;&#x2F;li&gt;
&lt;li&gt;A user gets various permissions, and they are set in the session&lt;&#x2F;li&gt;
&lt;li&gt;The user has been fired from his job, and an administrator removes the
users permissions&lt;&#x2F;li&gt;
&lt;li&gt;Since the user is still logged in, the users permission bits are still
set, and he continues to have access to parts of the site&#x2F;information he
shouldn&#x27;t have access to.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;If instead on every page visit we simply pull out the users unique id and
verify the permissions upon access, as soon as the permissions are revoked by
the administrator the user no longer has access to the various resources.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;temporary-state&quot;&gt;Temporary state&lt;&#x2F;h3&gt;
&lt;p&gt;There has to be an easy way to remember something from page visit to page visit
that isn&#x27;t considered detrimental if the information gets lost. One of those
things is flash messages. Flash messages are generally used to provide the user
indication that something has changed, they are shown once and then never
again.&lt;&#x2F;p&gt;
&lt;p&gt;Storing these as session data makes sense. If the flash message gets set,
great, if it doesn&#x27;t get set, it doesn&#x27;t matter. Flash messages are simply a
notification tool, if the user misses them it isn&#x27;t important.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-you-shouldn-t-store-in-the-session&quot;&gt;What you shouldn&#x27;t store in the session&lt;&#x2F;h2&gt;
&lt;p&gt;Definitely don&#x27;t store any kind of permission bits, groups a user is a part of
or anything that would allow the user access that they normally would not be
able to access.&lt;&#x2F;p&gt;
&lt;p&gt;On each page access check what permissions the user has. While it may mean a
little more heavy lifting server side it provides extra security, and the means
to enforce changes in permissions instantly.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;good-secure-programming-practices&quot;&gt;Good secure programming practices&lt;&#x2F;h2&gt;
&lt;p&gt;Keep secure programming practices in mind at all times, always consider how the
information you are storing&#x2F;processing is accessed&#x2F;viewed&#x2F;administered. More
importantly think about the access controls that are in place, and how one
could expire access to a particular resource without requiring a co-operative
client.&lt;&#x2F;p&gt;
&lt;p&gt;The ordering of how variables are set, and when they are set are very
important.  &lt;code&gt;$_SESSION[&#x27;isadmin&#x27;] = True&lt;&#x2F;code&gt; at the top of a PHP script, and then
removing it by checking to see if the user is actually an administrator later
on in the script is a bad idea.&lt;&#x2F;p&gt;
&lt;p&gt;Always order your code so that if a failure does occur there is no chance that
a critical section of your code is executed by accident, or that information is
stored in a half-verified state. This is especially important for access
control.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Embedding ZeroMQ in the libev Event Loop</title>
        <published>2013-04-20T18:22:00+00:00</published>
        <updated>2013-04-20T18:22:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2013/embedding-zeromq-in-the-libev-event-loop/"/>
        <id>https://funcptr.net/2013/embedding-zeromq-in-the-libev-event-loop/</id>
        
        <content type="html" xml:base="https://funcptr.net/2013/embedding-zeromq-in-the-libev-event-loop/">&lt;p&gt;In a &lt;a href=&quot;&#x2F;2012&#x2F;zeromq-edge-triggered&#x2F;&quot;&gt;previous article on ZeroMQ&lt;&#x2F;a&gt; we went over how ZeroMQ is triggered when
you use the socket that ZeroMQ returns, in that article there was some
discussion of embedding ZeroMQ into another event loop. Let&#x27;s do that.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;software.schmorp.de&#x2F;pkg&#x2F;libev.html&quot;&gt;libev&lt;&#x2F;a&gt; is an absolutely fantastic library that helps make it easy to write
evented programs. Evented programs work by getting notified that an action has
happened, and acting upon it. Unlike threaded where multiple pieces of work are
being executed at the same time, in an evented system you move every item that
could block to an event loop, that then calls back into user code with a
notification to continue. If one event uses up more than its fair share of CPU
time because it is busy doing a long calculation, every single other event that
is waiting will never get notified.&lt;&#x2F;p&gt;
&lt;p&gt;Now, as previously discussed ZeroMQ is edge triggered, so embedding it into an
event loop that is level triggered doesn&#x27;t do us much good, because we will miss
certain ZeroMQ notifications.&lt;&#x2F;p&gt;
&lt;p&gt;One way to solve this problem is by looping over ZeroMQ&#x27;s event system until we
get back a notification that it no longer has anything else for us to process,
that would look something like this&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-20130420zeromqedge-1&quot;&gt;&lt;a href=&quot;#fn-20130420zeromqedge&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;size_t&lt;&#x2F;span&gt;&lt;span&gt; zevents_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(zevents);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;zmq_socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;do&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; We can read from the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        break&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Check to see if there is more to read ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    zmq_socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; while&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLOUT) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; We can write to the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; If neither of the above is true, then it was a false positive&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However if we are receiving information from ZeroMQ remote endpoints faster
than we can process them, we end up being stuck in that &lt;code&gt;do&lt;&#x2F;code&gt; ... &lt;code&gt;while&lt;&#x2F;code&gt; loop
forever. If we have other events we want to process, that isn&#x27;t entirely fair
since they will never ever get called again. Especially in a server application
where it may be servicing thousands of clients this is simply not acceptable.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;libev&quot;&gt;libev&lt;&#x2F;h2&gt;
&lt;p&gt;libev provides various different event notifications, to be able to get around
edge triggered notifications, and still provide fair round-robin for all events
we are going to have to build on top of multiple different events.&lt;&#x2F;p&gt;
&lt;p&gt;The events used will be:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pod.tst.eu&#x2F;http:&#x2F;&#x2F;cvs.schmorp.de&#x2F;libev&#x2F;ev.pod#code_ev_io_code_is_this_file_descrip&quot;&gt;&lt;code&gt;ev::io&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;: This one is pretty self explanatory, this is for getting notified
about input output changes. This is the one we are going to use on the
&lt;code&gt;ZMQ_FD&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pod.tst.eu&#x2F;http:&#x2F;&#x2F;cvs.schmorp.de&#x2F;libev&#x2F;ev.pod#code_ev_prepare_code_and_code_ev_che&quot;&gt;&lt;code&gt;ev::prepare&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pod.tst.eu&#x2F;http:&#x2F;&#x2F;cvs.schmorp.de&#x2F;libev&#x2F;ev.pod#code_ev_prepare_code_and_code_ev_che&quot;&gt;&lt;code&gt;ev::check&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;: These two are generally used together, they
can be used to change the event loop and or make modifications on the fly to
events that have been registered with the event loop.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pod.tst.eu&#x2F;http:&#x2F;&#x2F;cvs.schmorp.de&#x2F;libev&#x2F;ev.pod#code_ev_idle_code_when_you_ve_got_no&quot;&gt;&lt;code&gt;ev::idle&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;: This is an event that gets fired whenever the event loop has
nothing else to do, so no other events fired, this will fire.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;plan-of-attack&quot;&gt;Plan of attack&lt;&#x2F;h2&gt;
&lt;p&gt;Since the &lt;code&gt;prepare&lt;&#x2F;code&gt; and &lt;code&gt;check&lt;&#x2F;code&gt; run before and after the loop, we are going to
be using those to do most of the work. We use an &lt;code&gt;io&lt;&#x2F;code&gt; so that we can turn off
the &lt;code&gt;idle&lt;&#x2F;code&gt; when we can actually wait for a result from ZeroMQ&#x27;s file
descriptor, otherwise we use &lt;code&gt;idle&lt;&#x2F;code&gt; so that we will always get called once
every loop.&lt;&#x2F;p&gt;
&lt;p&gt;In the &lt;code&gt;prepare&lt;&#x2F;code&gt; watcher callback we do the following:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Check to see what events ZeroMQ has for us, and check what events the user
has requested.&lt;&#x2F;li&gt;
&lt;li&gt;If the ZeroMQ has an event for us that we want, and the user has requested
that event, we start the idle watcher.&lt;&#x2F;li&gt;
&lt;li&gt;If ZeroMQ has no events, we start the io watcher.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;In the &lt;code&gt;check&lt;&#x2F;code&gt; watcher callback we do the following:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Stop both the &lt;code&gt;io&lt;&#x2F;code&gt; and &lt;code&gt;idle&lt;&#x2F;code&gt; watchers, they were only there to make sure
that our &lt;code&gt;check&lt;&#x2F;code&gt; watcher was called.&lt;&#x2F;li&gt;
&lt;li&gt;See what event ZeroMQ has for us, and check that against what the user
wants. Depending on the event, call user defined function write() or user
defined function read().&lt;&#x2F;li&gt;
&lt;li&gt;If this was a spurious wake-up on the part of ZeroMQ we simply ignore it
and let libev go on to other events.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;We could make all of this work by simply using the &lt;code&gt;prepare&lt;&#x2F;code&gt;, &lt;code&gt;check&lt;&#x2F;code&gt; and
&lt;code&gt;idle&lt;&#x2F;code&gt; watchers, but that would mean libev would be busy-waiting for something
to happen on the ZeroMQ socket. The &lt;code&gt;io&lt;&#x2F;code&gt; watcher is required simply so in times
of nothing happening libev in its library can call into the kernels event
handling mechanism and go to sleep. We can&#x27;t use just the &lt;code&gt;io&lt;&#x2F;code&gt; watcher due to
the edge-triggered notification, because we&#x27;d miss all kinds of ZeroMQ
messages. So all four watchers are required, and play crucial parts in making
this work.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;let-s-get-down-to-code&quot;&gt;Let&#x27;s get down to code&lt;&#x2F;h2&gt;
&lt;p&gt;Below you will find example code, it is not complete. Do note that I am using
some C++11isms, error checking code may not be complete&#x2F;correct and in general
I don&#x27;t suggest you copy and paste this without reading and understanding what
it does.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;zmq_event&lt;&#x2F;code&gt; class is meant to be used as a base class, inherit from it, and
create the &lt;code&gt;write()&lt;&#x2F;code&gt; and &lt;code&gt;read()&lt;&#x2F;code&gt; functions. These functions will be called
when you are able to read from the ZeroMQ socket, or when you are able to write
to the ZeroMQ socket. You are guaranteed to be able to read one whole ZeroMQ
message, so if it is a multi-part message, do make sure to loop on
&lt;code&gt;ZMQ_SNDMORE&lt;&#x2F;code&gt; as required.&lt;&#x2F;p&gt;
&lt;p&gt;Upon instantiation it will automatically start being notified about events, we
start off with &lt;code&gt;ev::READ&lt;&#x2F;code&gt;. When your sub-class wants to write to ZeroMQ it
should put the messages to be written into a list somewhere, and set
&lt;code&gt;ev::READ | ev::WRITE&lt;&#x2F;code&gt; on &lt;code&gt;watcher_io&lt;&#x2F;code&gt;, by calling
&lt;code&gt;watcher_io.set(socket_fd, ev::READ | ev::WRITE)&lt;&#x2F;code&gt;. &lt;code&gt;write()&lt;&#x2F;code&gt; will then be
called, write a single message to ZeroMQ, and if necessary when finished
writing, unset &lt;code&gt;ev::WRITE&lt;&#x2F;code&gt; using &lt;code&gt;watcher_io.set(socket_fd, ev::READ)&lt;&#x2F;code&gt;. If you
are not finished writing, after writing that singular message you may return
and &lt;code&gt;write()&lt;&#x2F;code&gt; will be called again the next loop iteration. This way if you
have a lot of data to write you don&#x27;t starve the other events from receiving
their notifications.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;zmq-event-h&quot;&gt;&lt;code&gt;zmq_event.h&lt;&#x2F;code&gt;&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;ev++.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;zmq.hpp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span&gt; zmq_event {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    public:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        zmq_event&lt;&#x2F;span&gt;&lt;span&gt;(zmq::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;context_t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; context&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; type&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; const&lt;&#x2F;span&gt;&lt;span&gt; std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; connect&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        virtual&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; ~zmq_event&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    protected:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; This gets fired before the event loop, to prepare&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; before&lt;&#x2F;span&gt;&lt;span&gt;(ev::prepare&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; prep&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; revents&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; This is fired after the event loop, but before any other type of events&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; after&lt;&#x2F;span&gt;&lt;span&gt;(ev::check&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; check&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; revents&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; We need to have a no-op function available for those events that we&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; want to add to the list, but should never fire an actual event&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        template&lt;&#x2F;span&gt;&lt;span&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;typename&lt;&#x2F;span&gt;&lt;span&gt; T&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            inline&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; noop&lt;&#x2F;span&gt;&lt;span&gt;(T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; w&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; revents&lt;&#x2F;span&gt;&lt;span&gt;) {};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; Function we are going to call to write to the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        virtual&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; write&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; Function we are going to call to read from the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        virtual&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; read&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; Some helper function, one to start notifications&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; start_notify&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; And one to stop notifications.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; stop_notify&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; Our event types&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ev::io      watcher_io;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ev::prepare watcher_prepare;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ev::check   watcher_check;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ev::idle    watcher_idle;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; Our ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        zmq::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;socket_t&lt;&#x2F;span&gt;&lt;span&gt; socket;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt;           socket_fd &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;= -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;zmq-event-cc&quot;&gt;&lt;code&gt;zmq_event.cc&lt;&#x2F;code&gt;&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;stdexcept&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;zmq_event.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zmq_event::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zmq_event&lt;&#x2F;span&gt;&lt;span&gt;(zmq::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;context_t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; context,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; type,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; const&lt;&#x2F;span&gt;&lt;span&gt; std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; connect) :&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; socket&lt;&#x2F;span&gt;&lt;span&gt;(context, type) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Get the file descriptor for the socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    size_t&lt;&#x2F;span&gt;&lt;span&gt; fd_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(_socket_fd);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_FD,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;socket_fd,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;fd_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Actually connect to the ZeroMQ endpoint, could replace this with a bind as well ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;bind&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;connect&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;c_str&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Set up all of our watchers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Have our IO watcher check for READ on the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;set&lt;&#x2F;span&gt;&lt;span&gt;(socket_fd, ev::READ);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; This watcher has a no-op callback&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;set&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event::noop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;this&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Set up our prepare watcher to call the before() function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_prepare&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;set&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event::before&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;this&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Set up the check watcher to call the after() function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_check&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;set&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event::after&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;this&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Set up our idle watcher, once again a no-op&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_idle&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;set&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zmq_event::noop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;this&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Tell libev to start notifying us!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    start_notify&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zmq_event::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zmq_event&lt;&#x2F;span&gt;&lt;span&gt;() {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zmq_event::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;before&lt;&#x2F;span&gt;&lt;span&gt;(ev::prepare&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; revents) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (EV_ERROR &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; revents) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        throw&lt;&#x2F;span&gt;&lt;span&gt; std::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;runtime_error&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;libev error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Get any events that may be waiting&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    uint32_t&lt;&#x2F;span&gt;&lt;span&gt; zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    size_t&lt;&#x2F;span&gt;&lt;span&gt; zevents_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(zevents);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Lucky for us, getting the events available doesn&amp;#39;t invalidate the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; events, so that calling this in `before()` and in `after()` will&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; give us the same results.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Check what events exists, and check it against what event we want. We&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; &amp;quot;abuse&amp;quot; our watcher_io.events for this information.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ((zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLOUT)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;events&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ev::WRITE)) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        watcher_idle&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ((zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;events&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ev::READ)) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        watcher_idle&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; No events ready to be processed, we&amp;#39;ll just go watch some io&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zmq_event::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;after&lt;&#x2F;span&gt;&lt;span&gt;(ev::check&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; revents) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (EV_ERROR &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; revents) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        throw&lt;&#x2F;span&gt;&lt;span&gt; std::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;runtime_error&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;libev error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Stop both the idle and the io watcher, no point in calling the no-op callback&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; One of them will be reactived by before() on the next loop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_idle&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;stop&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;stop&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Get the events&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    uint32_t&lt;&#x2F;span&gt;&lt;span&gt; zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    size_t&lt;&#x2F;span&gt;&lt;span&gt; zevents_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(zevents);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Check the events and call the users read&#x2F;write function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ((zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;events&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ev::READ)) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;        this&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;read&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ((zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLOUT)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;watcher_io&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BAEBE2;&quot;&gt;events&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ev::WRITE)) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;        this&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;write&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zmq_event::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start_notify&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_check&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_prepare&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zmq_event::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;stop_notify&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_check&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;stop&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    watcher_prepare&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;stop&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;other-event-loops&quot;&gt;Other event loops&lt;&#x2F;h2&gt;
&lt;p&gt;libev is but just one of many event loops that exist out there, hopefully
this shows how it is possible to embed ZeroMQ into an event loop, thereby
making it easier to embed ZeroMQ into any other event loops.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-20130420zeromqedge&quot;&gt;
&lt;p&gt;This snippet was from my older article regarding
&lt;a href=&quot;&#x2F;2012&#x2F;zeromq-edge-triggered&#x2F;&quot;&gt;ZeroMQ edge triggered notifications&lt;&#x2F;a&gt;. I would highly suggest reading that
article for more information and even more background on what is going on. &lt;a href=&quot;#fr-20130420zeromqedge-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>ZeroMQ - Edge Triggered Notification</title>
        <published>2012-09-10T19:01:50+00:00</published>
        <updated>2012-09-10T19:01:50+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2012/zeromq-edge-triggered/"/>
        <id>https://funcptr.net/2012/zeromq-edge-triggered/</id>
        
        <content type="html" xml:base="https://funcptr.net/2012/zeromq-edge-triggered/">&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.zeromq.org&quot;&gt;ZeroMQ&lt;&#x2F;a&gt; is an absolutely fantastic communications library that has allowed
me to very easily create networks&#x2F;connections between multiple different
applications to communicate in an extremely fast yet directed manner and allow
scaling of the connected entities with almost no second thought.&lt;&#x2F;p&gt;
&lt;p&gt;I have used ZeroMQ within Python and C++, and it has been fantastic leaving
that part of the communication layer to a library rather than writing something
similar myself. However, embedding ZeroMQ into an another event loop has proven
to have some quirks. They are documented in the API, but not so much by other
users&#x2F;examples found around the web, and caught me by surprise.&lt;&#x2F;p&gt;
&lt;p&gt;This post mainly goes over the issue, the difference between edge and level
triggered and how ZeroMQ works. I am hoping to spend some time documenting how
to embed ZeroMQ correctly inside &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;software.schmorp.de&#x2F;pkg&#x2F;libev.html&quot;&gt;libev&lt;&#x2F;a&gt; at a later date.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-quirk&quot;&gt;The quirk&lt;&#x2F;h2&gt;
&lt;p&gt;ZeroMQ allows you to get an underlying file descriptor (&lt;code&gt;ZMQ_FD&lt;&#x2F;code&gt;) for a ZeroMQ
socket using &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;api.zeromq.org&#x2F;2-2:zmq-getsockopt#toc21&quot;&gt;&lt;code&gt;getsockopt()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, this is not the actual ZeroMQ file descriptor
but a stand-in:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; fd &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;size_t&lt;&#x2F;span&gt;&lt;span&gt; fd_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(fd);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;zmq_socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_FD,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;fd,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;fd_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This file descriptor can then be passed on to &lt;code&gt;poll()&lt;&#x2F;code&gt;, &lt;code&gt;select()&lt;&#x2F;code&gt;, &lt;code&gt;kqueue()&lt;&#x2F;code&gt;
or whatever your event notification library of choice may be, the idea being
that if the file descriptor is notified to be available for reading then you
check the sockets &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;api.zeromq.org&#x2F;2-2:zmq-getsockopt#toc22&quot;&gt;&lt;code&gt;ZMQ_EVENTS&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and find out if you are allowed to read or
write to the ZeroMQ socket, or even possibly neither (false positive). The same
file descriptor is also used internally within the ZeroMQ library for
notification and thus we may receive an event notification that we can&#x27;t do
anything with.&lt;&#x2F;p&gt;
&lt;p&gt;As stated in the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;api.zeromq.org&#x2F;2-2:zmq-getsockopt#toc21&quot;&gt;ZeroMQ API guide for &lt;code&gt;getsockopt()&lt;&#x2F;code&gt; under &lt;code&gt;ZMQ_FD&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;the ØMQ library shall signal any pending events on the socket in an
&lt;em&gt;edge-triggered&lt;&#x2F;em&gt; fashion by making the file descriptor become ready for
reading.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;and further it states:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The ability to read from the returned file descriptor does not necessarily
indicate that messages are available to be read from, or can be written to,
the underlying socket; applications must retrieve the actual event state with
a subsequent retrieval of the &lt;code&gt;ZMQ_EVENTS&lt;&#x2F;code&gt; option.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;So far so good, so after we return from our event notification on the file
descriptor we simply ask ZeroMQ whether or not we can read or write (or
possibly both):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;size_t&lt;&#x2F;span&gt;&lt;span&gt; zevents_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(zevents);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;zmq_socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; We can read from the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLOUT) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; We can write to the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; If neither of the above is true, then it was a false positive&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So now you are happily reading from ZeroMQ and using the data as you wish,
except you start to notice that sometimes it can take a little while for data
to show up, or that if the end-point you are connected to on ZeroMQ sends a lot
of data it is not delivered in a timely fashion. This is where the
documentation for edge triggered comes into play, and that is something that is
different about ZeroMQ compared to for example BSD sockets.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;edge-triggered-versus-level-triggered&quot;&gt;Edge triggered versus level triggered&lt;&#x2F;h2&gt;
&lt;p&gt;Edge and level triggered refer to what kind of signal a device will output in
an attempt to gain the attention of another device. Edge and level triggered
have their history in electronics and hardware, where they play a very crucial
role.&lt;&#x2F;p&gt;
&lt;p&gt;For both level and edge triggered assume the data is represented by this simple string:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;00000000000111111111111111111111100000000011111111111000000000&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The zeroes (0) are where no data is available, and the ones (1) are where data
is available for processing.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;level-triggered&quot;&gt;Level triggered&lt;&#x2F;h3&gt;
&lt;p&gt;Level triggered devices when they require attention, and until they no longer
require attention will signal with a high voltage (going back to early
electronics), and when they no longer require attention signal with a low
voltage.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Data:  00000000001111111111111111111111000000000011111111111000000000&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Block:      A               B              C         D&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+ 5v              ____________________           _________&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -    __________|                    |_________|         |__________&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  0v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;State: 0          1                    0          1        0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;At this point, once the signal turns to 1 in block B we can start processing
data, and until we are done processing data the signal will stay 1. Once we are
done processing the device will signal that we are done by setting the state to
0 in block C, and the process can repeat itself with block D.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;edge-triggered&quot;&gt;Edge triggered&lt;&#x2F;h3&gt;
&lt;p&gt;Edge triggered devices when they require attention will simply turn on the
signal for a short period of time and then turn it back off until all of the
requireding processing is complete at which point they will once again signal
that they need processing.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Data:  00000000001111111111111111111111100000000011111111111000000000&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Block:      A     B              C                 D&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+ 5v              __                              __&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -    __________|  |____________________________|  |________________&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  0v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;State: 0          1              0                1        0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In this case when the trigger arrives you have to process all of the data
available. When block B arrives and we get 1 as our signal, we have to process
all of the data, we won&#x27;t know when we are done other than some other
notification scheme by the device. (Such as a special message that says we are
done). Then when we are done we can go back to listening to waiting for a
trigger.&lt;&#x2F;p&gt;
&lt;p&gt;If however in the time that we are processing the data from the trigger at B
receive more data to process we won&#x27;t get notified because we weren&#x27;t
officially done processing data from the device, and thus the device will not
notify us of the new data again until we have processed all of the data.&lt;&#x2F;p&gt;
&lt;p&gt;There are some devices that as soon as you start processing their data, you
re-enable the trigger, so if you receive new data while still processing the
old you will get a new notification.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;zeromq-uses-edge-triggered&quot;&gt;ZeroMQ uses edge triggered&lt;&#x2F;h2&gt;
&lt;p&gt;When multiple message arrive for the ZeroMQ socket, one notification is sent.
You check to see if the &lt;code&gt;ZMQ_EVENTS&lt;&#x2F;code&gt; actually contains &lt;code&gt;ZMQ_POLLIN&lt;&#x2F;code&gt; and then
read a single message from ZeroMQ. Content that you have processed the data
ZeroMQ has for you, you add the file descriptor back to the event notification
library and wait. However, you know you sent two messages, but all you got was
one. The next time you send data to the socket, it returns the second message,
and you have now send three but the third doesn&#x27;t seem to arrive.&lt;&#x2F;p&gt;
&lt;p&gt;This is where the edge triggered comes in. ZeroMQ only notifies you once, and
after it has notified you it won&#x27;t notify you again until it receives new
messages, &lt;em&gt;EVEN&lt;&#x2F;em&gt; if you have messages waiting for you. In BSD sockets when you
&lt;code&gt;recv()&lt;&#x2F;code&gt; data from the socket, if it is not all of the data it will simply tell
you, and until all of the data has been read that the socket has to offer it is
going to tell you (level triggered).&lt;&#x2F;p&gt;
&lt;p&gt;This means that when you get a notification from ZeroMQ you have to use a loop
to process all of the messages that are coming your way:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;size_t&lt;&#x2F;span&gt;&lt;span&gt; zevents_len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(zevents);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;zmq_socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;do&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        &#x2F;&#x2F; We can read from the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        break&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Check to see if there is more to read ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;    zmq_socket&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;getsockopt&lt;&#x2F;span&gt;&lt;span&gt;(ZMQ_EVENTS,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;zevents_len);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; while&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLIN);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (zevents &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; ZMQ_POLLOUT) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; We can write to the ZeroMQ socket&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; If neither of the above is true, then it was a false positive&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The same is true if you need to send multiple messages, you will need to check
&lt;code&gt;ZMQ_EVENTS&lt;&#x2F;code&gt; for &lt;code&gt;ZMQ_POLLOUT&lt;&#x2F;code&gt; and send messages so long as that holds true, as
soon as it is no longer true you will need to wait until you get triggered
again by using the file descriptor in your event notification library.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;embedding-or-co-existing-with-another-event-loop&quot;&gt;Embedding or co-existing with another event loop&lt;&#x2F;h2&gt;
&lt;p&gt;Embedding ZeroMQ into a different event loop becomes more difficult when you
realise that it is edge triggered versus level triggered. If you want to allow
fair processing of data between events it becomes harder to accomplish with
ZeroMQ because you are required to process all of the data before going back to
your event loop or requires the setting up of different types of events
depending on the state that the ZeroMQ socket is in to make sure you process
all of the data and don&#x27;t forget any.&lt;&#x2F;p&gt;
&lt;p&gt;Edge triggered for the ZeroMQ file descriptor was a design decision which
unfortunately made the use of ZeroMQ sockets more difficult and different from
BSD sockets which makes it harder for application programmers to do the right
thing. There are plenty of questions on the internet regarding the proper usage
of &lt;code&gt;ZMQ_FD&lt;&#x2F;code&gt; with various different event notification schemes&#x2F;implementations.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>IPv6 -- getaddrinfo() and bind() ordering with V6ONLY</title>
        <published>2012-08-07T22:39:56+00:00</published>
        <updated>2012-08-07T22:39:56+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2012/ipv6-and-getaddrinfo/"/>
        <id>https://funcptr.net/2012/ipv6-and-getaddrinfo/</id>
        
        <content type="html" xml:base="https://funcptr.net/2012/ipv6-and-getaddrinfo/">&lt;p&gt;Recently I ran into an issue that took me a while to sort out, and it is
regarding inconsistent behaviour on various OS&#x27;s with regards to IPv6 sockets
(&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;sys_socket.h.html&quot;&gt;&lt;code&gt;AF_INET6&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-20120807afvspf-1&quot;&gt;&lt;a href=&quot;#fn-20120807afvspf&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;) and calling &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=bind&amp;amp;apropos=0&amp;amp;sektion=2&amp;amp;manpath=FreeBSD+9.0-RELEASE&amp;amp;arch=default&amp;amp;format=html&quot;&gt;&lt;code&gt;bind(2)&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; after getting the
results back from &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=getaddrinfo&amp;amp;apropos=0&amp;amp;sektion=3&amp;amp;manpath=FreeBSD+9.0-RELEASE&amp;amp;arch=default&amp;amp;format=html&quot;&gt;&lt;code&gt;getaddrinfo(3)&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;A call to &lt;code&gt;getaddrinfo()&lt;&#x2F;code&gt; with the hints set to &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;sys_socket.h.html&quot;&gt;&lt;code&gt;AF_UNSPEC&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; in &lt;code&gt;ai_family&lt;&#x2F;code&gt;
and &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=getaddrinfo&amp;amp;apropos=0&amp;amp;sektion=3&amp;amp;manpath=FreeBSD+9.0-RELEASE&amp;amp;arch=default&amp;amp;format=html&quot;&gt;&lt;code&gt;AI_PASSIVE&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; in &lt;code&gt;ai_flags&lt;&#x2F;code&gt; will return to us 1 or more results that we
can &lt;code&gt;bind()&lt;&#x2F;code&gt; to. Sample code for that looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; addrinfo hints,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;addrlist;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;memset&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;hints&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(hints));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; Ask for TCP&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hints.ai_socktype &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; SOCK_STREAM;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; Any family works for us ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hints.ai_family &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; AF_UNSPEC;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; Set some hints&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hints.ai_flags &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AI_PASSIVE    &lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; &#x2F;&#x2F; We want to use this with bind&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AI_ADDRCONFIG;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;  &#x2F;&#x2F; Only return IPv4 or IPv6 if they are configured&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; rv;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ((rv &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; getaddrinfo&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;7020&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;hints&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;addrlist&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    fprintf&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(stderr,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;getaddrinfo: &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;%s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; gai_strerror&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(rv))&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; Use the list in *addrlist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; (addr &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; addrlist; addr &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;!=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;; addr &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; addr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;ai_next) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; use *addr as appropriate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; Clean up the memory from getaddrinfo()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;freeaddrinfo&lt;&#x2F;span&gt;&lt;span&gt;(addrlist);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;On Linux there are two entries returned when the host it is run on has both
IPv4 and IPv6 enabled. An &lt;code&gt;AF_INET&lt;&#x2F;code&gt; which was followed by an &lt;code&gt;AF_INET6&lt;&#x2F;code&gt;. Now,
it is not said that you are required to use all of the results that are
returned, but if you want to listen on all address families it is off course
suggested.&lt;&#x2F;p&gt;
&lt;p&gt;Following the steps below for each of the returned results should result in
having 1 or more different sockets that are bound to a single port.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create the socket()&lt;&#x2F;li&gt;
&lt;li&gt;Set any socket options you want (&lt;code&gt;SO_REUSEADDR&lt;&#x2F;code&gt; for example)&lt;&#x2F;li&gt;
&lt;li&gt;Then bind() the socket&lt;&#x2F;li&gt;
&lt;li&gt;After that call listen() (followed off course by accept() on the socket)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Only for some unknown reason (and &lt;code&gt;errno&lt;&#x2F;code&gt; is no help) &lt;code&gt;bind()&lt;&#x2F;code&gt; fails when you
get to the &lt;code&gt;AF_INET6&lt;&#x2F;code&gt;, which was returned second. Searching online as to why
the bind would fail doesn&#x27;t give you any good results and the thing that is
even worse is that if you run the same code on another platform such as
&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&quot;&gt;FreeBSD&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;openindiana.org&quot;&gt;OpenIndiana&lt;&#x2F;a&gt; or &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20120808044613&#x2F;http:&#x2F;&#x2F;www.apple.com&#x2F;osx&#x2F;&quot;&gt;Mac OS X&lt;&#x2F;a&gt; no such failure exists. However
I started suspecting something was up when I started looking at the output from
&lt;code&gt;netstat -lan | grep 7020&lt;&#x2F;code&gt; on Mac OS X. Where 7020 is the port I passed into
&lt;code&gt;getaddrinfo()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tcp46      0      0  *.7020                 *.*  LISTEN     &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tcp4       0      0  *.7020                 *.*  LISTEN &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Wait a minute ... one of the sockets is on both IPv4 and on IPv6. Some more
time spent searching the internet I came across &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;rfc3493#page-22&quot;&gt;RFC 3493 section 5.3&lt;&#x2F;a&gt;,
which is titled &quot;&lt;code&gt;IPV6_V6ONLY&lt;&#x2F;code&gt; option for &lt;code&gt;AF_INET6&lt;&#x2F;code&gt; Sockets&quot;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;As stated in section &amp;lt;3.7 Compatibility with IPv4 Nodes&amp;gt;, &lt;code&gt;AF_INET6&lt;&#x2F;code&gt; sockets
may be used for both IPv4 and IPv6 communications.  Some applications may
want to restrict their use of an &lt;code&gt;AF_INET6&lt;&#x2F;code&gt; socket to IPv6 communications
only.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This was going down the right route, so I changed my code so that in the steps
listed above in number 2 I added the following code if the socket type is
&lt;code&gt;AF_INET6&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;setsockopt&lt;&#x2F;span&gt;&lt;span&gt;(sockfd, IPPROTO_IPV6, IPV6_V6ONLY,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;yes&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    close&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(sockfd)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    fprintf&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(stderr,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;setsockopt: &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;%s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; IPV6_V6ONLY&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; strerror&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(errno))&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    continue&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The RFC 3493 section 5.3 also states that this option should be turned off by
default, which means that all IPv6 sockets can also communicate over IPv4. Thus
technically setting the option manually in code the best way to fix the issue.
FreeBSD has had this feature turned on (as in IPv6 sockets can only communicate
with IPv6 and NOT IPv4) since 5.x.&lt;&#x2F;p&gt;
&lt;p&gt;The biggest issue is that the remaining operating systems (OS X and
OpenIndiana) don&#x27;t have the same behaviour as Linux which makes troubleshooting
this issue more difficult than it should be. The issue is that the RFC doesn&#x27;t
specify what exactly the operating should do when it encounters a request to
bind to the same port on IPv4 and IPv6. The only place where I have found this
documented is in &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.amazon.com&#x2F;Network-Programming-Jun-ichiro-itojun-Hagino&#x2F;dp&#x2F;1555583180&quot;&gt;&quot;IPv6 Network Programming&quot;&lt;&#x2F;a&gt; under &quot;Tips in IPv6
Programming&quot; chapter 4, section 4, appropriately titled &quot;bind(2) Ordering and
Conflicts&quot;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If you get a &lt;code&gt;bind()&lt;&#x2F;code&gt; error when attempting to bind to an &lt;code&gt;AF_INET6&lt;&#x2F;code&gt; socket
please make sure that you set the socket option &lt;code&gt;IPV6_V6ONLY&lt;&#x2F;code&gt; on the &lt;code&gt;AF_INET6&lt;&#x2F;code&gt;
socket. The default as required by RFC 3493 is to have that option be off. The
default is wrong, and the RFC should have been more specific regarding what the
right behaviour is when attempting to bind on an &lt;code&gt;AF_INET6&lt;&#x2F;code&gt; socket when already
bound on an &lt;code&gt;AF_INET&lt;&#x2F;code&gt; while &lt;code&gt;IPV6_V6ONLY&lt;&#x2F;code&gt; is set to false.&lt;&#x2F;p&gt;
&lt;p&gt;The full code that I used for testing, along with a little bit more information
is available as a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;3231892&quot;&gt;gist on github&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-20120807afvspf&quot;&gt;
&lt;p&gt;The old BSD style &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=socket&amp;amp;apropos=0&amp;amp;sektion=2&amp;amp;manpath=FreeBSD+9.0-RELEASE&amp;amp;arch=default&amp;amp;format=html&quot;&gt;&lt;code&gt;socket()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; called for defines
starting with &lt;code&gt;PF_&lt;&#x2F;code&gt; such as &lt;code&gt;PF_INET&lt;&#x2F;code&gt; and &lt;code&gt;PF_INET6&lt;&#x2F;code&gt; with the &lt;code&gt;PF&lt;&#x2F;code&gt; standing for
protocol family. POSIX starts them with &lt;code&gt;AF_&lt;&#x2F;code&gt;, and calls them an address
family. On almost every operating system &lt;code&gt;PF_INET&lt;&#x2F;code&gt; is the same as &lt;code&gt;AF_INET&lt;&#x2F;code&gt;. If
the define doesn&#x27;t exist you can always create it. &lt;a href=&quot;#fr-20120807afvspf-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>FreeBSD 8.2 to 9.0 update with ZFS on root (mirror)</title>
        <published>2012-04-24T18:36:20+00:00</published>
        <updated>2012-04-24T18:36:20+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2012/freebsd-8-2-to-9-0-update-with-zfs-on-root/"/>
        <id>https://funcptr.net/2012/freebsd-8-2-to-9-0-update-with-zfs-on-root/</id>
        
        <content type="html" xml:base="https://funcptr.net/2012/freebsd-8-2-to-9-0-update-with-zfs-on-root/">&lt;p&gt;Upgrading from one version of FreeBSD to another has become much simpler with
&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.daemonology.net&#x2F;freebsd-update&#x2F;&quot;&gt;&lt;code&gt;freebsd-update&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; than before, a full rebuild of the FreeBSD kernel&#x2F;world
source used to be required (other upgrade paths existed but were not widely
touted). &lt;code&gt;freebsd-update&lt;&#x2F;code&gt; works extremely well when using UFS as your file
system, there are however some gotcha&#x27;s that one needs to look out for when
using FreeBSD Root on ZFS. Two machines needed upgrading, both are running with
a ZFS root mirror on FreeBSD 8.2-RELEASE. I had followed the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;wiki.freebsd.org&#x2F;RootOnZFS&#x2F;GPTZFSBoot&#x2F;Mirror&quot;&gt;FreeBSD Root on
ZFS (mirror)&lt;&#x2F;a&gt; wiki article and everything has been running smoothly ever
since.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  pool: zroot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; state: ONLINE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; scrub: scrub completed after 0h35m with 0 errors on Mon Mar  5 10:58:19 2012&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;config:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    NAME           STATE     READ WRITE CKSUM&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    zroot          ONLINE       0     0     0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      mirror       ONLINE       0     0     0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gpt&#x2F;disk0  ONLINE       0     0     0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gpt&#x2F;disk1  ONLINE       0     0     0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;errors: No known data errors&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Wanting to take advantage of some of the advancements made in &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;releases&#x2F;9.0R&#x2F;announce.html&quot;&gt;FreeBSD
9.0-RELEASE&lt;&#x2F;a&gt; such as the updated ZFS, a bug that was fixed that stopped
jails from owning a ZFS file system, improved dtrace, and better IPv6 support
required that the plunge be taken and an upgrade was in order.  There were a
couple reports of people having done source upgrades and then having issues
booting their system, but I found one &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;lists.freebsd.org&#x2F;pipermail&#x2F;freebsd-questions&#x2F;2012-January&#x2F;237308.html&quot;&gt;mailling list post&lt;&#x2F;a&gt; that suggested
that everything went well using &lt;code&gt;freebsd-update&lt;&#x2F;code&gt;, so that is the route I went
with.&lt;&#x2F;p&gt;
&lt;p&gt;I read through the entirety of the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.FreeBSD.org&#x2F;releases&#x2F;9.0R&#x2F;relnotes-detailed.html#UPGRADE&quot;&gt;FreeBSD 9.0-ERLEASE Release Notes&lt;&#x2F;a&gt;
before moving forward to make sure I didn&#x27;t miss any important changes that
would cause my system to not restart correctly or would require changing system
configuration files before attempting the upgrade. I would advise you to do the
same.&lt;&#x2F;p&gt;
&lt;p&gt;I ran &lt;code&gt;freebsd-update -r 9.0-RELEASE upgrade&lt;&#x2F;code&gt; and after accepting the list of
components that were installed, I got an error saying:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# freebsd-update -r 9.0-RELEASE upgrade&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Looking up update.FreeBSD.org mirrors... 4 mirrors found.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Fetching metadata signature for 8.2-RELEASE from update2.freebsd.org... done.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Fetching metadata index... done.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Inspecting system... done.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;The following components of FreeBSD seem to be installed:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;kernel&#x2F;generic src&#x2F;base src&#x2F;bin src&#x2F;cddl src&#x2F;contrib src&#x2F;crypto src&#x2F;etc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;src&#x2F;games src&#x2F;gnu src&#x2F;include src&#x2F;krb5 src&#x2F;lib src&#x2F;libexec src&#x2F;release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;src&#x2F;rescue src&#x2F;sbin src&#x2F;secure src&#x2F;share src&#x2F;sys src&#x2F;tools src&#x2F;ubin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;src&#x2F;usbin world&#x2F;base world&#x2F;catpages world&#x2F;dict world&#x2F;doc world&#x2F;games&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;world&#x2F;info world&#x2F;lib32 world&#x2F;manpages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;The following components of FreeBSD do not seem to be installed:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;world&#x2F;proflibs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Does this look reasonable (y&#x2F;n)? y&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Fetching metadata signature for 9.0-RELEASE from update2.freebsd.org... done.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Fetching metadata index... done.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;The update metadata is correctly signed, but&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;failed an integrity check.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Cowardly refusing to proceed any further.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Specifically the line stating &quot;Cowardly refusing to proceed further&quot;, a quick
&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;google.com&#x2F;&quot;&gt;Google&lt;&#x2F;a&gt; later I found the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;lists.freebsd.org&#x2F;pipermail&#x2F;freebsd-stable&#x2F;2011-October&#x2F;064321.html&quot;&gt;9.0-RC1 mailling list post&lt;&#x2F;a&gt; that suggested
the following one line fix:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;sed&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -e&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;s&#x2F;=_&#x2F;=%@_&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;sbin&#x2F;freebsd-update&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After that quick fix, a re-run of &lt;code&gt;freebsd-update&lt;&#x2F;code&gt; functioned without issues
and finished, showing me what it would change, asking me if it seemed
acceptable and telling me what it was going to remove and what was going to be
installed.&lt;&#x2F;p&gt;
&lt;p&gt;Next we run &lt;code&gt;freebsd-update&lt;&#x2F;code&gt; for the first time in this three step process:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;freebsd-update&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; install&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Don&#x27;t restart yet (although it tells you to)! We need to go back and make sure
we update the boot records first.&lt;&#x2F;p&gt;
&lt;p&gt;Going back to the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;lists.freebsd.org&#x2F;pipermail&#x2F;freebsd-questions&#x2F;2012-January&#x2F;237308.html&quot;&gt;mailling list post made by Magnus Strahlert&lt;&#x2F;a&gt;, I made note
of the following:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Had to upgrade the gpt bootcode as instructed when upgrading the zpool for
the system to boot.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This is the only comment that worried me, and nowhere in the email thread does
the poster describe what commands he ran. In any case I figure he meant
re-running the boot code commands from the FreeBSD Root on ZFS wiki article:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;gpart&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; bootcode&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;boot&#x2F;pmbr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;boot&#x2F;gptzfsboot&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; da0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;gpart&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; bootcode&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;boot&#x2F;pmbr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;boot&#x2F;gptzfsboot&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; da1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After running these commands, it told me that it had updated the boot code and then I ran:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;shutdown&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -r&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; now&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After the machine came back online (it is in those moments when you have a
small heartattack when the machine doesn&#x27;t come up as fast as you had expected
...) you log back in and run:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;freebsd-update&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; install&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will install all of the updated binaries that came with FreeBSD 9.0, at
this point FreeBSD update will tell you to upgrade all installed software and
ports, and then run &lt;code&gt;freebsd-update&lt;&#x2F;code&gt; one more time to remove all unnecessary
shared libraries. If you want to have certain software continue functioning,
yet you want &lt;code&gt;freebsd-update&lt;&#x2F;code&gt; to remove any other remaining old 8.x files, you
can install &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freshports.org&#x2F;misc&#x2F;compat8x&#x2F;&quot;&gt;&lt;code&gt;misc&#x2F;compat8x&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; from the ports tree. This is the suggested
route to go if you want to keep the 8.x libraries around for compatibility
reasons.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;ports&#x2F;misc&#x2F;compat8x&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;make&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; install clean&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# or&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# portmaster misc&#x2F;compat8x&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I use &lt;code&gt;portmaster&lt;&#x2F;code&gt; and the following command will simply rebuild every port
installed on the system:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;portmaster&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -aPf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;code&gt;-P&lt;&#x2F;code&gt; to &lt;code&gt;portmaster&lt;&#x2F;code&gt; means look for package and if available use it,
otherwise build from port.&lt;&#x2F;p&gt;
&lt;p&gt;Run &lt;code&gt;freebsd-update&lt;&#x2F;code&gt; one last time:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;freebsd-update&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; install&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Since we are running ZFS we will most likely also want to upgrade our pool to
the latest version of ZFS to take advantage of any new goodies (such as
deduplication!), upgrading a zpool is easy:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zpool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; upgrade zroot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That upgrades to the latest pool version, now we will want to upgrade our
existing file systems to the latest version of ZFS, do note that this will make
them incompatible with older file system verisons (so if you use zfs send for
backups, your other endpoint will need to be of the same ZFS version)&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zfs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; upgrade&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # List all ZFS file systems that need to be upgraded&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zfs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; upgrade&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # Upgrade all file systems&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After this one last reboot to make sure that all the processes come back online
using the newer libraries and that you didn&#x27;t accidentally miss something.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;shutdown&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -r&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; now&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;At this point the system has been upgraded from FreeBSD 8.0-RELEASE to FreeBSD
9.0-RELEASE and has all of the latest updates and enhancements.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>OpenSSL as a Filter (or non-blocking OpenSSL)</title>
        <published>2012-04-08T16:50:14+00:00</published>
        <updated>2012-04-08T16:50:14+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2012/openssl-as-a-filter/"/>
        <id>https://funcptr.net/2012/openssl-as-a-filter/</id>
        
        <content type="html" xml:base="https://funcptr.net/2012/openssl-as-a-filter/">&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;openssl.org&#x2F;&quot;&gt;OpenSSL&lt;&#x2F;a&gt; as a library at first glance is complicated, and then you realise
that a lot of the &lt;a rel=&quot;external&quot; title=&quot;ssl(3) documentation&quot; href=&quot;http:&#x2F;&#x2F;openssl.org&#x2F;docs&#x2F;ssl&#x2F;ssl.html&quot;&gt;documentation&lt;&#x2F;a&gt; seems to be incomplete or missing.
Generally the individual man pages for the various functions are not bad, and
they will give you relevant information to help you along, but it can be hard
to find.&lt;&#x2F;p&gt;
&lt;p&gt;The idea is to write a filter in such a way that OpenSSL can easily be disabled
or removed. We don&#x27;t want to rely on OpenSSL specific functionality in our
code, for instance in the future we may want to change to using &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;botan.randombit.net&#x2F;&quot;&gt;Botan&lt;&#x2F;a&gt; or
another SSL&#x2F;TLS library without having to change a lot of core functionality.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;possible-methods&quot;&gt;Possible methods&lt;&#x2F;h2&gt;
&lt;p&gt;There are various ways of doing non-blocking OpenSSL, the main one is to simply
set the underlying socket to non-blocking and pass it into OpenSSL, at that
point the functions &lt;code&gt;SSL_write()&lt;&#x2F;code&gt; and &lt;code&gt;SSL_read()&lt;&#x2F;code&gt; will enter various error
states that can be read by &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.openssl.org&#x2F;docs&#x2F;ssl&#x2F;SSL_get_error.html&quot;&gt;&lt;code&gt;SSL_get_error()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, more specifically the
function will return either &lt;code&gt;SSL_ERROR_WANT_READ&lt;&#x2F;code&gt; or &lt;code&gt;SSL_ERROR_WANT_WRITE&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The other method, the one used below, was described by &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;lists.schmorp.de&#x2F;pipermail&#x2F;libev&#x2F;2008q2&#x2F;000325.html&quot;&gt;Marc Lehmann in a post
to the libev mailling list&lt;&#x2F;a&gt; and uses &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.openssl.org&#x2F;docs&#x2F;crypto&#x2F;bio.html&quot;&gt;memory BIO&lt;&#x2F;a&gt; objects. Specifically
he linked to some Perl sample code; the OpenSSL &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;ue.tst.eu&#x2F;f7383715351b4427b6b9db660b6289f8.txt&quot;&gt;setup&lt;&#x2F;a&gt;, and the function
called for new incoming data&#x2F;data to be written: &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;ue.tst.eu&#x2F;2f4cfee5166db411bd85a40e06de6dbf.txt&quot;&gt;dotls function&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The code is very new and might still be buggy, but it outlines the
principles: use a memory stream, which will avoid all issues with blocking in
openssl&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;It shows the idea pretty clearly but unless you know Perl it can be really
confusing as to what is going on.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-ssl-filter-implementation&quot;&gt;The SSL Filter implementation&lt;&#x2F;h2&gt;
&lt;p&gt;The &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.openssl.org&#x2F;docs&#x2F;ssl&#x2F;SSL_CTX_new.html&quot;&gt;&lt;code&gt;SSL_CTX&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; that is passed in contains all of the initialisation that is
done for OpenSSL in general, which is not shown here. The &lt;code&gt;SSLFilter&lt;&#x2F;code&gt; is
created for each time you want to have a socket start doing SSL.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; openssl_filter.h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span&gt; SSLFilter {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    public:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        SSLFilter&lt;&#x2F;span&gt;&lt;span&gt;(SSL_CTX&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; ctxt&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                  std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; nread&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                  std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; nwrite&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                  std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; aread&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                  std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; awrite&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        virtual&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; ~SSLFilter&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; update&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    private:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; continue_ssl_&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; function_return&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        SSL &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; ssl;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        BIO &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; rbio;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        BIO &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; wbio;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; nread;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; nwrite;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; aread;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; awrite;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The class contains mainly various different bits of state, when you create the
filter you pass in a pointer to four different strings, they are used as
follows:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;nread&lt;&#x2F;code&gt;: This contains data to be processed by the filter, from the network&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;nwrite&lt;&#x2F;code&gt;: This contains data that has been processed by the filter, and has
to be sent to the network&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;aread&lt;&#x2F;code&gt;: This contains data that has been processed by the filter, and is
ready to be processed by the application&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;awrite&lt;&#x2F;code&gt;: This contains data that the application wants to send out to the
network and is ready for processing by the filter.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The other private variables contain various different pieces of state and are
created by the filters constructors.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ssl&lt;&#x2F;code&gt;: Contains the state for the current SSL connection.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;rbio&lt;&#x2F;code&gt;: Contains the data that the SSL functions will read from, data put in
here is copied from &lt;code&gt;nread&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;wbio&lt;&#x2F;code&gt;: Contains the data that the SSL functions will write to, data from
this BIO is copied to &lt;code&gt;nwrite&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The implementation is the really interesting part.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;&#x2F;&#x2F; openssl_filter.cc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;stdexcept&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  5&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;openssl_filter.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  6&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  7&lt;&#x2F;span&gt;&lt;span&gt;SSLFilter::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;SSLFilter&lt;&#x2F;span&gt;&lt;span&gt;(SSL_CTX&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; ctxt, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  8&lt;&#x2F;span&gt;&lt;span&gt;                     std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; nread, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  9&lt;&#x2F;span&gt;&lt;span&gt;                     std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; nwrite,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;                     std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; aread,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 11&lt;&#x2F;span&gt;&lt;span&gt;                     std::string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; awrite)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 12&lt;&#x2F;span&gt;&lt;span&gt;                      :&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 13&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;                     nread&lt;&#x2F;span&gt;&lt;span&gt;(nread), &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 14&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;                     nwrite&lt;&#x2F;span&gt;&lt;span&gt;(nwrite), &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 15&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;                     aread&lt;&#x2F;span&gt;&lt;span&gt;(aread), &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;                     awrite&lt;&#x2F;span&gt;&lt;span&gt;(awrite) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 17&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 18&lt;&#x2F;span&gt;&lt;span&gt;    rbio &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; BIO_new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;BIO_s_mem&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 19&lt;&#x2F;span&gt;&lt;span&gt;    wbio &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; BIO_new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;BIO_s_mem&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 20&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 21&lt;&#x2F;span&gt;&lt;span&gt;    ssl &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; SSL_new&lt;&#x2F;span&gt;&lt;span&gt;(ctxt);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 22&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 23&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    SSL_set_accept_state&lt;&#x2F;span&gt;&lt;span&gt;(ssl);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 24&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    SSL_set_bio&lt;&#x2F;span&gt;&lt;span&gt;(ssl, rbio, wbio);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 25&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 26&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 27&lt;&#x2F;span&gt;&lt;span&gt;SSLFilter::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;SSLFilter&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 28&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;    SSL_free&lt;&#x2F;span&gt;&lt;span&gt;(_ssl);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 29&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 30&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 31&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span&gt; SSLFilter::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(Filter::FilterDirection) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; If we have data from the network to process, put it the memory BIO for OpenSSL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 33&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;nread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;empty&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; written &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; BIO_write&lt;&#x2F;span&gt;&lt;span&gt;(rbio,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; nread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;c_str&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; nread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;length&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 35&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (written &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; nread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;erase&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, written);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 36&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 37&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 38&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; If the application wants to write data out to the network, process it with SSL_write&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 39&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;awrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;empty&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 40&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; written &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; SSL_write&lt;&#x2F;span&gt;&lt;span&gt;(ssl,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; awrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;c_str&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; awrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;length&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 41&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;continue_ssl_&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 43&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            throw&lt;&#x2F;span&gt;&lt;span&gt; std::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;runtime_error&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;An SSL error occured.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 44&lt;&#x2F;span&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 45&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 46&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (written &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; awrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;erase&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, written);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 47&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 48&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 49&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Read data for the application from the encrypted connection and place it in the string for the app to read&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 50&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 51&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        char *&lt;&#x2F;span&gt;&lt;span&gt;readto &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; char&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1024&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 52&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; read &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; SSL_read&lt;&#x2F;span&gt;&lt;span&gt;(ssl, readto,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1024&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 53&lt;&#x2F;span&gt;&lt;span&gt;       &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 54&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;continue_ssl_&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 55&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;            delete&lt;&#x2F;span&gt;&lt;span&gt; readto;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 56&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            throw&lt;&#x2F;span&gt;&lt;span&gt; std::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;runtime_error&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;An SSL error occured.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 57&lt;&#x2F;span&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 58&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 59&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (read &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 60&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;            size_t&lt;&#x2F;span&gt;&lt;span&gt; cur_size &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; aread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;length&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 61&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;            aread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;resize&lt;&#x2F;span&gt;&lt;span&gt;(cur_size &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; read);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 62&lt;&#x2F;span&gt;&lt;span&gt;            std::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;copy&lt;&#x2F;span&gt;&lt;span&gt;(readto, readto &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; read,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; aread&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;begin&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; cur_size);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 63&lt;&#x2F;span&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 65&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;        delete&lt;&#x2F;span&gt;&lt;span&gt; readto;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 66&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 67&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;static_cast&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;size_t&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;(read)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1024&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; written &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; break&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 68&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 69&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 70&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;    &#x2F;&#x2F; Read any data to be written to the network from the memory BIO and copy it to nwrite&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 71&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 72&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        char *&lt;&#x2F;span&gt;&lt;span&gt;readto &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; char&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1024&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 73&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; read &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; BIO_read&lt;&#x2F;span&gt;&lt;span&gt;(wbio, readto,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1024&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 74&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 75&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (read &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 76&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;            size_t&lt;&#x2F;span&gt;&lt;span&gt; cur_size &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; nwrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;length&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 77&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;            nwrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;resize&lt;&#x2F;span&gt;&lt;span&gt;(cur_size &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; read);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 78&lt;&#x2F;span&gt;&lt;span&gt;            std::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;copy&lt;&#x2F;span&gt;&lt;span&gt;(readto, readto &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; read,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; nwrite&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;begin&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; cur_size);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 79&lt;&#x2F;span&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 80&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 81&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;        delete&lt;&#x2F;span&gt;&lt;span&gt; readto;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 82&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 83&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;static_cast&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;lt;size_t&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;(read)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1024&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; read &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; break&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 84&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 85&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 86&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 87&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;bool&lt;&#x2F;span&gt;&lt;span&gt; SSLFilter::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;continue_ssl_&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; function_return&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 88&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    int&lt;&#x2F;span&gt;&lt;span&gt; err &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; SSL_get_error&lt;&#x2F;span&gt;&lt;span&gt;(ssl, function_return);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 89&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 90&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (err &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; SSL_ERROR_NONE &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; err &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; SSL_ERROR_WANT_READ) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 91&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 92&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 93&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 94&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (err &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; SSL_ERROR_SYSCALL) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 95&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        ERR_print_errors_fp&lt;&#x2F;span&gt;&lt;span&gt;(stderr);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 96&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        perror&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;syscall error: &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 97&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 98&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 99&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (err &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; SSL_ERROR_SSL) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;101&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        ERR_print_errors_fp&lt;&#x2F;span&gt;&lt;span&gt;(stderr);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;102&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;103&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;104&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;105&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;explanation-of-the-ssl-filter-class&quot;&gt;Explanation of the SSL Filter class&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;Line 7 - 25&lt;&#x2F;strong&gt;, we create the two memory BIO&#x27;s and then call &lt;code&gt;SSL_new()&lt;&#x2F;code&gt; using
the passed in &lt;code&gt;SSL_CTX&lt;&#x2F;code&gt;, set the accept set for SSL and then we hook up the two
BIO objects to the &lt;code&gt;ssl&lt;&#x2F;code&gt; object.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Line 27 - 29&lt;&#x2F;strong&gt;, All we do in the destructor is &lt;code&gt;SSL_free()&lt;&#x2F;code&gt; the SSL state,
which automatically takes care of freeing the two memory BIOs that were given
to it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Line 33 - 36&lt;&#x2F;strong&gt;, if &lt;code&gt;nread&lt;&#x2F;code&gt; is not empty we copy the data into &lt;code&gt;rbio&lt;&#x2F;code&gt;. &lt;code&gt;rbio&lt;&#x2F;code&gt;
is used by the SSL functions to read from (as if it were reading from a
socket). We read into the memory BIO as much as possible, technically this
should be everything, but it is possible it won&#x27;t read everything due to memory
constraints, next time &lt;code&gt;SSLFilter::update()&lt;&#x2F;code&gt; is called it will get emptied as
much as possible again.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Line 39 - 47&lt;&#x2F;strong&gt;, we see if there is anything that the app wants to write out
to the remote client, if there is we call &lt;code&gt;SSL_write()&lt;&#x2F;code&gt;. After the call to
&lt;code&gt;SSL_write()&lt;&#x2F;code&gt; we call &lt;code&gt;continue_ssl_()&lt;&#x2F;code&gt; to see if we can safely continue using
SSL.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Line 50 - 68&lt;&#x2F;strong&gt;, this is where try to read as much data from &lt;code&gt;SSL_read()&lt;&#x2F;code&gt; as
we can and place it in &lt;code&gt;aread&lt;&#x2F;code&gt;. This is data that has been decrypted by OpenSSL
and can be used by the application. After the call to &lt;code&gt;SSL_read()&lt;&#x2F;code&gt; we call
&lt;code&gt;continue_ssl_()&lt;&#x2F;code&gt; to see if we can safely continue using SSL.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Line 71 - 84&lt;&#x2F;strong&gt;, if OpenSSL has to write something to the network, either
directly due to something the app did (by filling &lt;code&gt;awrite&lt;&#x2F;code&gt;) or because of
something the remote client sent, it will place it in its memory buffer
(&lt;code&gt;wbio&lt;&#x2F;code&gt;), what we do here is drain that memory buffer and fill &lt;code&gt;nwrite&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Line 87 - 105&lt;&#x2F;strong&gt;, the &lt;code&gt;continue_ssl_()&lt;&#x2F;code&gt; function gets the SSL errors using
&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.openssl.org&#x2F;docs&#x2F;ssl&#x2F;SSL_get_error.html&quot;&gt;&lt;code&gt;SSL_get_error&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and checks that either it is &lt;code&gt;SSL_ERROR_NONE&lt;&#x2F;code&gt; or
&lt;code&gt;SSL_ERROR_WANT_READ&lt;&#x2F;code&gt; both of which are acceptable errors, any other errors and
we check to see if it is an error due to a system call or due to an SSL error,
we print out the errors to standard error and return false. At that point the
calling code is free to go about its business as it pleases (most likely
throwing an error).&lt;&#x2F;p&gt;
&lt;h4 id=&quot;notes-regarding-this-sample-code&quot;&gt;Notes regarding this sample code ...&lt;&#x2F;h4&gt;
&lt;p&gt;The only thing missing in this example code is checking to see if the SSL
connection has gone into an &lt;code&gt;SSL_shutdown()&lt;&#x2F;code&gt; mode. This should be added so that
you cleanly shut down an SSL connection, but it is not absolutely required,
especially since it seems to be shaky as to whether or not it will work,
especially if you are using SSLv3 or SSLv2.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;how-to-use-the-ssl-filter&quot;&gt;How to use the SSL Filter&lt;&#x2F;h3&gt;
&lt;p&gt;Here are the steps to using this filter:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;At program startup set up the &lt;code&gt;SSL_CTX&lt;&#x2F;code&gt; structure as required, so that it
be used in the &lt;code&gt;SSLFilter&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Set up socket&#x2F;event loop and accept() new socket.&lt;&#x2F;li&gt;
&lt;li&gt;Create four new &lt;code&gt;std::string&lt;&#x2F;code&gt;&#x27;s and create a new SSLFilter, pass in the
&lt;code&gt;SSL_CTX&lt;&#x2F;code&gt; you created, and the four buffers.&lt;&#x2F;li&gt;
&lt;li&gt;Add the new socket to the event loop to wait for reading.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Now upon receiving a read ready status from the event loop, the following should be done:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Read data into &lt;code&gt;nread&lt;&#x2F;code&gt; buffer.&lt;&#x2F;li&gt;
&lt;li&gt;call &lt;code&gt;SSLFilter::update()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;See if &lt;code&gt;aread&lt;&#x2F;code&gt; is not empty, process the data as you please&lt;&#x2F;li&gt;
&lt;li&gt;Write data to &lt;code&gt;awrite&lt;&#x2F;code&gt; as needed, if data is written to &lt;code&gt;awrite&lt;&#x2F;code&gt;, call
&lt;code&gt;SSLFilter::update(WRITE)&lt;&#x2F;code&gt; to process the data&lt;&#x2F;li&gt;
&lt;li&gt;See if &lt;code&gt;nwrite&lt;&#x2F;code&gt; is not empty, if so add socket to event loop for write
readiness.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Once you receive a write ready status from the event loop, you should do the following:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Write data in &lt;code&gt;nwrite&lt;&#x2F;code&gt; to the socket.&lt;&#x2F;li&gt;
&lt;li&gt;If &lt;code&gt;nwrite&lt;&#x2F;code&gt; is empty, remove the socket from the event loop for writing (so
that you don&#x27;t have the event loop notifying you of the ability to write,
even-though you have nothing to write).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Now it becomes simple to add OpenSSL to any open socket, in a way that is easy
to refactor later and or disable depending on parameters passed in as arguments
to the program. If you set &lt;code&gt;nread&lt;&#x2F;code&gt; to the same string as &lt;code&gt;aread&lt;&#x2F;code&gt; and &lt;code&gt;nwrite&lt;&#x2F;code&gt;
to &lt;code&gt;awrite&lt;&#x2F;code&gt; and don&#x27;t create an SSLFilter you have bypassed the filter...&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Converting KVM virtual machines to VirtualBox</title>
        <published>2012-04-01T01:03:32+00:00</published>
        <updated>2012-04-01T01:03:32+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2012/converting-kvm-to-virtualbox/"/>
        <id>https://funcptr.net/2012/converting-kvm-to-virtualbox/</id>
        
        <content type="html" xml:base="https://funcptr.net/2012/converting-kvm-to-virtualbox/">&lt;p&gt;Recently the requirement came up to take a &lt;a rel=&quot;external&quot; title=&quot;Kernel Virtual Machine&quot; href=&quot;http:&#x2F;&#x2F;www.linux-kvm.org&#x2F;&quot;&gt;KVM&lt;&#x2F;a&gt; based virtual machine and
move it over to a &lt;a rel=&quot;external&quot; title=&quot;Oracle VirtualBox&quot; href=&quot;https:&#x2F;&#x2F;www.virtualbox.org&#x2F;&quot;&gt;VirtualBox&lt;&#x2F;a&gt; image. Which turned out to be a fairly simple
endeavour, and was fairly painless. The longest part was transferring over the
40 GB image from one machine to the other where the conversion could take
place. The machine the image was coming from was only on a 100 Mbit&#x2F;sec
connection so that took a good hour.&lt;&#x2F;p&gt;
&lt;p&gt;Converting from KVM to VirtualBox for a FreeBSD image was pretty
simple, the &lt;code&gt;VBoxManage&lt;&#x2F;code&gt; command has a &lt;code&gt;convertdd&lt;&#x2F;code&gt; command that allows you to
convert from raw disk &lt;code&gt;.img&lt;&#x2F;code&gt; format to &lt;code&gt;.vdi&lt;&#x2F;code&gt; format.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;VBoxManage convertdd KVM-image.img VB-image.vdi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After this, unfortunately, there is no way to to automatically convert over the
settings that the virtual machine had, such as the network cards, the memory
allocations and hard drive settings. You will have to go to VirtualBox and
create a new virtual machine and replicate all of the settings. Once that is
done make sure to select the same type of disk controller (SATA or IDE) so that
the drive will hopefully be assigned the same name in the device tree so that
you don&#x27;t need to alter your &lt;code&gt;&#x2F;etc&#x2F;fstab&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Hopefully everything boots without any issues. If not try creating a new
virtual machine, attach the converted image as a secondary drive and see if you
can mount the converted image within your new install. If so maybe transferring
the data using &lt;code&gt;rsync&lt;&#x2F;code&gt; or &lt;code&gt;dump&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;restore&lt;&#x2F;code&gt; would be an option.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Generating stylesheets for pygments</title>
        <published>2011-11-27T00:00:00+00:00</published>
        <updated>2021-02-15T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2011/pygments-stylesheets/"/>
        <id>https://funcptr.net/2011/pygments-stylesheets/</id>
        
        <content type="html" xml:base="https://funcptr.net/2011/pygments-stylesheets/">&lt;p&gt;Update: this blog is no longer using the same technology for deployment as
before, the below information is available for historical reasons.&lt;&#x2F;p&gt;
&lt;hr&gt;
&lt;p&gt;For this blog I am using &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;freewisdom.org&#x2F;projects&#x2F;python-markdown&#x2F;&quot;&gt;Python markdown&lt;&#x2F;a&gt; with the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pygments.org&#x2F;&quot;&gt;Pygments&lt;&#x2F;a&gt; plugin
that is available. Pygments does all of the code highlighting and outputs the
required &lt;code&gt;span&lt;&#x2F;code&gt; tags and inputs them within the page.&lt;&#x2F;p&gt;
&lt;p&gt;If you were to look at the &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;&#x2F;pre&amp;gt;&amp;lt;&#x2F;div&amp;gt;&lt;&#x2F;code&gt; block that is generated
you&#x27;d see something like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;div class=&amp;quot;codehilite&amp;quot;&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;span class=&amp;quot;k&amp;quot;&amp;gt;def&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;nf&amp;quot;&amp;gt;function&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;p&amp;quot;&amp;gt;(&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;n&amp;quot;&amp;gt;var&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;o&amp;quot;&amp;gt;=&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;bp&amp;quot;&amp;gt;None&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;p&amp;quot;&amp;gt;):&amp;lt;&#x2F;span&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;span class=&amp;quot;k&amp;quot;&amp;gt;if&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;n&amp;quot;&amp;gt;var&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;ow&amp;quot;&amp;gt;is&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;ow&amp;quot;&amp;gt;not&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;bp&amp;quot;&amp;gt;None&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;p&amp;quot;&amp;gt;:&amp;lt;&#x2F;span&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;span class=&amp;quot;k&amp;quot;&amp;gt;print&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;n&amp;quot;&amp;gt;var&amp;lt;&#x2F;span&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;pre&amp;gt;&amp;lt;&#x2F;div&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;which is generated from the following snippet of code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;var=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; var&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is not&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        print&lt;&#x2F;span&gt;&lt;span&gt; var&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As you see the top css &lt;code&gt;class&lt;&#x2F;code&gt; is &lt;code&gt;codehilite&lt;&#x2F;code&gt;, and then underneath that there
are a bunch of other classes such as &lt;code&gt;k&lt;&#x2F;code&gt;, &lt;code&gt;n&lt;&#x2F;code&gt;, &lt;code&gt;o&lt;&#x2F;code&gt;, and so forth. Those are all
classes that can be styled. Now one could write such a stylesheet by hand or we
can simply use one of the stylesheets that Pygments ships with.&lt;&#x2F;p&gt;
&lt;p&gt;The documentation for Pygments tells you how to get &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pygments.org&#x2F;docs&#x2F;styles&#x2F;#builtin-styles&quot;&gt;built-in styles&lt;&#x2F;a&gt;, which
is as simple as:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; from&lt;&#x2F;span&gt;&lt;span&gt; pygments.styles&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; get_all_styles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; styles&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; list&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;get_all_styles&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; styles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;monokai&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;manni&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;perldoc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;borland&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;colorful&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;]&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;These are all the styles that are available to you the user, now how do we get
the style into an actual &lt;code&gt;.css&lt;&#x2F;code&gt; file that we can link to in our sites HTML
file? We use the &lt;code&gt;pygmentize&lt;&#x2F;code&gt; command line tool:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;pygmentize&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; html&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; trac&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .codehilite&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; pygments.css&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Feel free to replace &lt;code&gt;trac&lt;&#x2F;code&gt; with any of the styles you have installed on your
system. &lt;code&gt;-f&lt;&#x2F;code&gt; tells it what formatter to use, since we want it to output the css
we ask it to use the HTML formatter, &lt;code&gt;-S&lt;&#x2F;code&gt; tells &lt;code&gt;pygmentize&lt;&#x2F;code&gt; what style to
use, and &lt;code&gt;-a&lt;&#x2F;code&gt; prepends the &lt;code&gt;.codehilite&lt;&#x2F;code&gt; class before every rule (this way we
don&#x27;t pollute the whole CSS namespace with all the aforementioned class&#x27;s such
as &lt;code&gt;k&lt;&#x2F;code&gt;, &lt;code&gt;o&lt;&#x2F;code&gt;, &lt;code&gt;ow&lt;&#x2F;code&gt; and others).&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NAT with PF on an interface with multiple IP addresses</title>
        <published>2011-09-08T02:40:00+00:00</published>
        <updated>2011-09-08T02:40:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2011/nat-with-pf-on-an-interface/"/>
        <id>https://funcptr.net/2011/nat-with-pf-on-an-interface/</id>
        
        <content type="html" xml:base="https://funcptr.net/2011/nat-with-pf-on-an-interface/">&lt;p&gt;If you want to do NAT for your currently running jail instances on FreeBSD so
that they can have outgoing connections you could try the following &lt;code&gt;pf.conf&lt;&#x2F;code&gt;
to set up NAT on the interface that the jails have their IP addresses on.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ext_if=&amp;quot;em0&amp;quot;    # The network card your default gateway is on&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;jail_if=&amp;quot;lo1&amp;quot;   # The interface that your jails have IP addresses on&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Set some options&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set optimization aggressive&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set block-policy drop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set skip on lo&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# NAT on the external interface when coming from the jail interface&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nat on $ext_if from $jail_if:network:0 to any -&amp;gt; ($ext_if)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# We just pass everything&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pass quick all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;What I have done is create IP addresses within the private network range
(&lt;code&gt;10&#x2F;8&lt;&#x2F;code&gt;, &lt;code&gt;172.16&#x2F;12&lt;&#x2F;code&gt;, &lt;code&gt;192.168&#x2F;16&lt;&#x2F;code&gt;) on the &lt;code&gt;lo1&lt;&#x2F;code&gt; interface. These can&#x27;t be in
the &lt;code&gt;127&#x2F;8&lt;&#x2F;code&gt; range because those addresses can&#x27;t be NAT&#x27;ed (not sure if this is
a limitation in pf or if this is a FreeBSD limitation), which is a shame
because using &lt;code&gt;127.1.0.1&#x2F;24&lt;&#x2F;code&gt; would be pretty awesome in my opinion.&lt;&#x2F;p&gt;
&lt;p&gt;What I did find though is that the above will not work correctly if your main
network card (the one your default gateway is on, in the example &lt;code&gt;em0&lt;&#x2F;code&gt;)
contains multiple IP addresses. At that point the syntax &lt;code&gt;($ext_if)&lt;&#x2F;code&gt; does not
function correctly and will cause packet loss&#x2F;drop. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-2011-09-08freebsdversion-1&quot;&gt;&lt;a href=&quot;#fn-2011-09-08freebsdversion&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So instead of using the syntax above we simply replace &lt;code&gt;($ext_if)&lt;&#x2F;code&gt; with the
actual IP address of the interface. This takes care of the issue and will let
your jails have proper internet access without issues.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ext_if=&amp;quot;em0&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;jail_if=&amp;quot;lo1&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set optimization aggressive&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set block-policy drop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set skip on lo&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nat on $ext_if from $jail_if:network:0 to any -&amp;gt; 192.168.1.2 # Your IP! &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pass quick all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The other way you can solve this problem off course is to provide your jails
with IP addresses within the same range that go to your default gateway thereby
solving the problem of needing to NAT in the first place.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-2011-09-08freebsdversion&quot;&gt;
&lt;p&gt;Do note that I am using FreeBSD 8.2, so this may
be fixed in the new FreeBSD 9 that is due to be released soon. &lt;a href=&quot;#fr-2011-09-08freebsdversion-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>FreeBSD running within KVM: Serial Console</title>
        <published>2011-08-21T18:53:52+00:00</published>
        <updated>2011-08-21T18:53:52+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2011/freebsd-running-within-kvm-serial-console/"/>
        <id>https://funcptr.net/2011/freebsd-running-within-kvm-serial-console/</id>
        
        <content type="html" xml:base="https://funcptr.net/2011/freebsd-running-within-kvm-serial-console/">&lt;p&gt;Instead of using virtualisation technology such as VMWare of VirtualBox I
decided to give the new &lt;a rel=&quot;external&quot; title=&quot;Kernel based Virtual Machine&quot; href=&quot;http:&#x2F;&#x2F;www.linux-kvm.org&#x2F;page&#x2F;Main_Page&quot;&gt;KVM&lt;&#x2F;a&gt; technology that is included with Linux. It is
fast, and has been extremely reliable. However I wanted to be able to access
the console on the guest FreeBSD instances.&lt;&#x2F;p&gt;
&lt;p&gt;I used virt-manager, a graphical tool, to set up everything, including creating
the virtual machine, I didn&#x27;t want to have to deal with XML configuration files
and whatnot. After installing FreeBSD there are a few changes I made to get a
virtual console working, this allows &lt;code&gt;virsh console &amp;lt;domain&amp;gt;&lt;&#x2F;code&gt; to function
as expected.&lt;&#x2F;p&gt;
&lt;p&gt;First we add a new file to the root file system (which should be the first
slice on the drive):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;-Dh&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;boot.config&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=boot.config&amp;amp;sektion=5&quot;&gt;man 5 boot.config&lt;&#x2F;a&gt; for more information. Basically -D says that FreeBSD
should boot with a dual console configuration (built-in over VGA) and serial
console, and -h says to force the serial console to on.&lt;&#x2F;p&gt;
&lt;p&gt;If you were to reboot now and use the virsh command:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;virsh&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; console FreeBSD&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;you would see the system go through the boot process and show output starting
from when the boot block gains control, at this point however you still have no
way to login to this new console since we never specified that we wanted any
ttys on the serial console, for that we need to edit &#x2F;etc&#x2F;ttys.&lt;&#x2F;p&gt;
&lt;p&gt;We are looking for the ttyu0 entry, we want to make sure to change dialup to
vt100, and off to on, so that it should look like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ttyu0   &amp;quot;&#x2F;usr&#x2F;libexec&#x2F;getty std.9600&amp;quot;   vt100   on secure&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now when we reboot once more we will get the usual login display that we have
come to expect of console on FreeBSD, and we can login over the serial console.
This way we don&#x27;t have to open up the virtual machine manager to get a console,
and can continue to do almost everything from a terminal window.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL setup for external connections</title>
        <published>2011-08-16T17:48:54+00:00</published>
        <updated>2011-08-16T17:48:54+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2011/postgresql-setup-for-external-connections/"/>
        <id>https://funcptr.net/2011/postgresql-setup-for-external-connections/</id>
        
        <content type="html" xml:base="https://funcptr.net/2011/postgresql-setup-for-external-connections/">&lt;p&gt;PostgreSQL is a fantastic open-source RDBMS which is extremely powerful, once
installed on FreeBSD getting it set up is pretty simple. We do want to change
some of the defaults though. By default the system will be set up to trust any
user using the local socket to connect as any user to any database.&lt;&#x2F;p&gt;
&lt;p&gt;By setting up the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;8.2&#x2F;static&#x2F;app-initdb.html&quot;&gt;&lt;code&gt;initdb&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; flags we can change how PostgreSQL generates
the default configuration files. Adding &lt;code&gt;-A md5&lt;&#x2F;code&gt; tells it to use the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;8.2&#x2F;static&#x2F;auth-methods.html#AUTH-PASSWORD&quot;&gt;md5
authentication mechanism&lt;&#x2F;a&gt;, which requires that passwords sent over the wire
are md5 hashed.&lt;&#x2F;p&gt;
&lt;p&gt;Add the following to &lt;a rel=&quot;external&quot; title=&quot;man 5 rc.conf&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=rc.conf&amp;amp;sektion=5&quot;&gt;&lt;code&gt;&#x2F;etc&#x2F;rc.conf&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; for the initdb flags, and enable
PostgreSQL as a service:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;postgresql_initdb_flags=&amp;quot;-D &#x2F;usr&#x2F;local&#x2F;pgsql&#x2F;data -W -A md5&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;postgresql_enable=&amp;quot;YES&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And then run:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;rc.d&#x2F;postgresql&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; initdb&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will initialise and create the configuration as well as setting up some of
the default tables. You will want to navigate to the folder specified in the
&lt;code&gt;initdb_flags&lt;&#x2F;code&gt; above:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;pgsql&#x2F;data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;this is where you will find the files that we are going to modify next to get
PostgreSQL set up to listen to connections coming in on a private network
(&lt;code&gt;192.168.1.1&#x2F;24&lt;&#x2F;code&gt;) and where we allow connections coming in from servers on
that network. This is strictly for setting up PostgreSQL in a situation where
you have multiple servers accessing it as a client on a private network.&lt;&#x2F;p&gt;
&lt;p&gt;After this we need to modify a few files to get it to listen to TCP&#x2F;IPv4
connections, first we start with &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;8.2&#x2F;static&#x2F;runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS&quot;&gt;&lt;code&gt;postgresql.conf&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and add:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;listen_addresses&lt;&#x2F;span&gt;&lt;span&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;127.0.0.1,192.168.1.1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then in &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;8.2&#x2F;static&#x2F;auth-pg-hba-conf.html&quot;&gt;&lt;code&gt;pg_hba.conf&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; we add a new line:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;host	all		all		192.168.1.1&#x2F;24		md5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This allows anyone in the 192.168.1.1&#x2F;24 range to connect to our PostgreSQL
instance and to use the databases. This is exactly what we want to allow, now
we start PostgreSQL using the rc script:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;usr&#x2F;local&#x2F;etc&#x2F;rc.d&#x2F;postgresql&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; start&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Setting up jails with multiple IPs and providing it with internet access</title>
        <published>2011-08-15T15:40:04+00:00</published>
        <updated>2011-08-15T15:40:04+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2011/setting-up-jails-with-multiple-ips-and-providing-it-with-internet-access/"/>
        <id>https://funcptr.net/2011/setting-up-jails-with-multiple-ips-and-providing-it-with-internet-access/</id>
        
        <content type="html" xml:base="https://funcptr.net/2011/setting-up-jails-with-multiple-ips-and-providing-it-with-internet-access/">&lt;p&gt;I have multiple VMs up and running and generally I have an internal to the
VMs only network set up, in the current project I am working on I have
three completely different networks set up.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;DHCP assigned network that routes to the outside network on the host (192.168.0.1&#x2F;24)&lt;&#x2F;li&gt;
&lt;li&gt;An internal to the VM&#x27;s network interface (10.99.12.1&#x2F;24)&lt;&#x2F;li&gt;
&lt;li&gt;A network that is tied to the host&#x27;s wireless network (setup to be an AP) (10.99.11.1&#x2F;24)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;So within my FreeBSD VM I have the following: &lt;code&gt;em0&lt;&#x2F;code&gt;, &lt;code&gt;em1&lt;&#x2F;code&gt;, &lt;code&gt;em2&lt;&#x2F;code&gt; as
&quot;network cards&quot;. In my FreeBSD VM, I am creating two jails that are going
to contain different pieces of server software. The jails need IP&#x27;s in
the following ranges, 10.99.12.1&#x2F;24 (to connect to another VM),
10.99.11.1&#x2F;24 (Wifi network) and then it needs to have an IP address that
is considered &quot;local&quot; and we can NAT on, so in addition to the above
networks we also needed to add another network. The easiest way to create
new interface with IP addresses is using a bridge. They can be assigned
IP addresses, which is all we need.&lt;&#x2F;p&gt;
&lt;p&gt;At this point inside of a jail it kinda looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;em0: flags=8843&amp;lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&amp;gt; metric 0 mtu 1500&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    options=209b&amp;lt;RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ether 52:54:00:6b:6a:49&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    media: Ethernet autoselect (1000baseT &amp;lt;full-duplex&amp;gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status: active&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;em1: flags=8843&amp;lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&amp;gt; metric 0 mtu 1500&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    options=209b&amp;lt;RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ether 52:54:00:2f:a5:55&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    inet 10.99.12.4 netmask 0xffffffff broadcast 10.99.12.4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    media: Ethernet autoselect (1000baseT &amp;lt;full-duplex&amp;gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status: active&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;em2: flags=8843&amp;lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&amp;gt; metric 0 mtu 1500&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    options=209b&amp;lt;RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ether 52:54:00:bb:b6:43&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    inet 10.99.11.14 netmask 0xffffffff broadcast 10.99.11.14&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    media: Ethernet autoselect (1000baseT &amp;lt;full-duplex&amp;gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status: active&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lo0: flags=8049&amp;lt;UP,LOOPBACK,RUNNING,MULTICAST&amp;gt; metric 0 mtu 16384&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    options=3&amp;lt;RXCSUM,TXCSUM&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bridge0: flags=8843&amp;lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&amp;gt; metric 0 mtu 1500&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ether da:de:63:c9:55:6c&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    inet 10.0.1.4 netmask 0xffffffff broadcast 10.0.1.4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;em0&lt;&#x2F;code&gt; doesn&#x27;t have an address since that is our DHCP address, &lt;code&gt;em1&lt;&#x2F;code&gt;,
&lt;code&gt;em2&lt;&#x2F;code&gt; and &lt;code&gt;bridge0&lt;&#x2F;code&gt; all have IP addresses, in the jail configuration the
&lt;code&gt;bridge0&lt;&#x2F;code&gt; IP address is listed first, and thus when something binds or
sends it sends from that IP address. The thing is that at this point the
jail does not have internet access.&lt;&#x2F;p&gt;
&lt;p&gt;Jails inherit the routing table from their host environment (yes, you
can compile in more routing tables ... but I don&#x27;t want to modify stock),
any traffic that goes to the outside is going to go out over the default
route, thing is you&#x27;d expect that traffic to show up on &lt;code&gt;bridge0&lt;&#x2F;code&gt; where
the IP address exists, instead using &lt;code&gt;tcpdump&lt;&#x2F;code&gt; you see it show up on
&lt;code&gt;em0&lt;&#x2F;code&gt;, which is where the default route is. I would have expected having
to do NAT on the bridge, not just the external interface.&lt;&#x2F;p&gt;
&lt;p&gt;Here is the &lt;code&gt;pf&lt;&#x2F;code&gt; configuration.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ext_if=&amp;quot;em0&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;jail_if=&amp;quot;bridge0&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set optimization aggressive&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set block-policy drop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;set skip on lo&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nat on $ext_if from $jail_if:network:0 to any -&amp;gt; ($ext_if)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pass quick all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And we&#x27;ve got internet within our jail.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Apache mod_fastcgi and PHP with PHP-FPM</title>
        <published>2010-11-14T23:37:27+00:00</published>
        <updated>2010-11-14T23:37:27+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2010/apache-mod-fastcgi-and-php-with-php-fpm/"/>
        <id>https://funcptr.net/2010/apache-mod-fastcgi-and-php-with-php-fpm/</id>
        
        <content type="html" xml:base="https://funcptr.net/2010/apache-mod-fastcgi-and-php-with-php-fpm/">&lt;p&gt;Recently I did a server migration from an older server to a newer server and in
an attempt to help stability I wanted to see if there was a better way to do
PHP FastCGI. In my research I came across running PHP using the FastCGI server
that spins up a PHP on a TCP&#x2F;IP port and allows the web server to connect to
it. However this doesn&#x27;t help with spawning or keeping track of instances or
error recovery.&lt;&#x2F;p&gt;
&lt;p&gt;This is where &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;php-fpm.org&#x2F;&quot;&gt;PHP-FPM&lt;&#x2F;a&gt; comes in handy. It does all of the hard work for us,
it spawns the processes and has a bunch of really awesome features that help
run PHP as various different users as required with different PHP ini files and
memory limits. PHP-FPM&#x27;s defaults, at least from a ports install, are extremely
sane and I don&#x27;t really suggest changing them. After setting up PHP FPM I had
to set up Apache.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; doesn&#x27;t allow for remote connections, and as such I was unable to use
it for what I needed it for. &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; provides the
&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20101111193738&#x2F;http:&#x2F;&#x2F;www.fastcgi.com&#x2F;mod_fastcgi&#x2F;docs&#x2F;mod_fastcgi.html#FastCgiExternalServer&quot;&gt;FastCGIExternalServer&lt;&#x2F;a&gt; configuration key, which is exactly what I needed.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;The FastCgiExternalServer directive defines filename as an external
FastCGI application. If filename does not begin with a slash (&lt;code&gt;&#x2F;&lt;&#x2F;code&gt;) then it is
assumed to be relative to the &lt;code&gt;ServerRoot&lt;&#x2F;code&gt;. The filename does not have to exist
in the local filesystem. URIs that Apache resolves to this filename will be
handled by this external FastCGI application.&quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;What this documentation does not state is that the path up to the last part of
it has to exist in the local file system. So in my first couple of attempts I
pointed it at &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi&#x2F;php5.fcgi&lt;&#x2F;code&gt; without having an actual fastcgi
directory located in &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;www&#x2F;&lt;&#x2F;code&gt;. There are a lot of examples that require
creating a new &lt;code&gt;FastCGIExternalServer&lt;&#x2F;code&gt; for each and every &lt;code&gt;VirtualHost&lt;&#x2F;code&gt; this is
unacceptable to me, the reason they require it is because they set the
&lt;code&gt;FastCGIExternalServer&lt;&#x2F;code&gt; path to the folder where they are going to be serving
files from.&lt;&#x2F;p&gt;
&lt;p&gt;In the end I found that after creating the &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi&lt;&#x2F;code&gt; directory
(and reading the &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; source code) that all it does is make Apache
believe a file exists in a certain directory, much like &lt;code&gt;Alias&lt;&#x2F;code&gt;, except &lt;code&gt;Alias&lt;&#x2F;code&gt;
allows full paths to be aliased, not so here.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;AddType&lt;&#x2F;code&gt; and &lt;code&gt;Action&lt;&#x2F;code&gt; add custom types and what the action should be when
such a type is encountered. In this case the action is to redirect the request
to &lt;code&gt;&#x2F;php5.fcgi&lt;&#x2F;code&gt; which will handle the rest of the request. This does not require
another FastCGI section per &lt;code&gt;VirtualHost&lt;&#x2F;code&gt; as each PHP request will just get
shuttled to the php handler.&lt;&#x2F;p&gt;
&lt;p&gt;Do take note that I have specifically disallowed Apache to serve anything from
the &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi&#x2F;&lt;&#x2F;code&gt; folder, except for a single file &lt;code&gt;php5.fcgi&lt;&#x2F;code&gt;
which is our &lt;code&gt;FastCGIExternalServer&lt;&#x2F;code&gt; file.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;IfModule mod_fastcgi.c&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Alias &#x2F;php5.fcgi &#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi&#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FastCGIExternalServer &#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi&#x2F;php5.fcgi -flush -host 127.0.0.1:9000&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddType application&#x2F;x-httpd-fastphp5 .php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Action application&#x2F;x-httpd-fastphp5 &#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;Directory &amp;quot;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi&#x2F;&amp;quot;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        Order deny,allow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        Deny from all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &amp;lt;Files &amp;quot;php5.fcgi&amp;quot;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            Order allow,deny&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            Allow from all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &amp;lt;&#x2F;Files&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;&#x2F;Directory&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;IfModule&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note that even-though in my &lt;a href=&quot;&#x2F;2009&#x2F;moving-from-mod-fastcgi-to-mod-fcgid&#x2F;&quot;&gt;last post&lt;&#x2F;a&gt; concerning &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; I as moving
away from it, I am now doing the opposite, instead of &lt;a href=&quot;&#x2F;2009&#x2F;moving-from-mod-fastcgi-to-mod-fcgid&#x2F;&quot;&gt;moving from
&lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; to &lt;code&gt;mod_fcgid&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; I&#x27;m back to &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt;, only because
&lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; doesn&#x27;t offer the same functionality.&lt;&#x2F;p&gt;
&lt;p&gt;So far this has provided far more stability, along with PHP-FPM doing all of
the process management I can now use a single PHP instance that is running on a
single port for the various web servers I am testing. At the moment I have both
Lighttpd and Apache using the same PHP-FPM instance. It is faster, less
memory is wasted and PHP-FPM is much better at process management than
&lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; or &lt;code&gt;mod_fcgid&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Magic Properties on Google AppEngine</title>
        <published>2010-03-24T02:15:33+00:00</published>
        <updated>2010-03-24T02:15:33+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2010/magic-properties-on-google-appengine/"/>
        <id>https://funcptr.net/2010/magic-properties-on-google-appengine/</id>
        
        <content type="html" xml:base="https://funcptr.net/2010/magic-properties-on-google-appengine/">&lt;p&gt;Update to my previous &lt;a href=&quot;&#x2F;2010&#x2F;auto-updating-properties-in-google-appengine-models&#x2F;&quot;&gt;Google AppEngine auto-updating properties post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In my last post I was talking about:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;[...] however there is still an issue, for now the MagicProperty is only
updated the first time the property it affects is set&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I fixed that issue, it has a local cache that is added to the model, so if the
value does change, the cache would no longer be valid and the value is
recreated, otherwise the already computed value is returned. There was however
another issue I had to deal with, and that was the fact that the cache was not
being written to the datastore, this meant that upon getting the data back from
the datastore we recomputed it anyway. Now the programmer has to do some extra
work, they have to add a cache unindexed property to the model, and pass it
into the &lt;code&gt;MagicProperty&lt;&#x2F;code&gt; to be used as the caching variable. Within the
&lt;code&gt;save()&lt;&#x2F;code&gt; they have to prime the cache by setting a temporary variable equal to
the to be computed variable just in case the cache variables have not been
primed, this has not yet been documented other than in my SVN history.&lt;&#x2F;p&gt;
&lt;p&gt;We still don&#x27;t allow setting of the magic property, however upon returning from
the datastore it calls &lt;code&gt;make_value_from_datastore&lt;&#x2F;code&gt;, which returns a
&lt;code&gt;_MagicDatastore&lt;&#x2F;code&gt;, as long as we set with an instance of &lt;code&gt;_MagicDatastore&lt;&#x2F;code&gt; it will
allow it to go through, so we can get the value from the datastore without
having to recompute the value.&lt;&#x2F;p&gt;
&lt;p&gt;Read the code for an example on how to use this.&lt;&#x2F;p&gt;
&lt;p&gt;Code is added below, feel free to use it as you wish under the license that is
attached.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;###&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # Copyright (c) 2010 Delta Regeer;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # Permission to use, copy, modify, and distribute this software for any&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  5&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # purpose with or without fee is hereby granted, provided that the above&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  6&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # copyright notice and this permission notice appear in all copies.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot; AND THE AUTHOR DISCLAIMS ALL WARRANTIES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;  9&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 11&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 12&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 13&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 14&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 15&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;###&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 17&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 18&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; logging&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 19&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; hashlib&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 20&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt; google.appengine.ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; db&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 21&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 22&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 23&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; MagicProperty&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;prop&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; magic_func=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; cache_prop=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; pass_instance=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;False&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *args&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **kw&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 24&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; magic_func:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 25&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # No pants required.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 26&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt; _MagicProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; cache_prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; pass_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;kw&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 27&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 28&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # We are putting some pants on the function.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 29&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; pants&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt; _MagicProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; cache_prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; pass_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;kw&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 31&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; pants&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 32&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 33&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFCB8B;&quot;&gt; _MagicDatastore&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;This is an internal class for _MagicProperty.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 35&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 36&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; val&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 37&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; val&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 38&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 39&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; retval&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 40&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 41&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFCB8B;&quot;&gt; _MagicProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;Property&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 43&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;MagicProperty which will modify output based on a function that it is given.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 44&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 45&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    This has several ways in which it may be called:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 46&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 47&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    In this example we create the model, no caching is done, so any data that is returned from the datastore&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 48&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    will be erased the first time that the MagicProperty is accessed and recomputed.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 49&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 50&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        class MagicTest(db.Model):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 51&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            title = db.StringProperty(required=True)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 52&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            chars = utils.MagicProperty(title, len, required=True)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 53&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 54&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        mytest = MagicTest(title=&amp;quot;It was for the good of the school!&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 55&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 56&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytest.title&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 57&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        It was for the good of the school!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 58&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytest.chars&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 59&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        34&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 60&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 61&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        mytest = MagicTest.all().get()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 62&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 63&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytest.title&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        Hello&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 65&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytest.chars		&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 66&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        5	# Do note, this is recalculated the first time it is called, as long as title does not change it won&amp;#39;t be recomputed.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 67&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 68&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    In this example we create the model, and we also create a caching property so that even when we get values back &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 69&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    from the datastore we use the cached computed value rather than running the function again. Do note that this requires overriding put()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 70&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    to prime the cache as there is currently no way to specify that certain properties should be &amp;quot;saved&amp;quot; before others.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 71&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 72&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        class MagicTesting(db.Model):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 73&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            title = db.StringProperty(required=True)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 74&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            cache = db.UnindexedProperty()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 75&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            chars = utils.MagicProperty(title, len, cache_prop=cache, required=True)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 76&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 77&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            def put(self, *args, **kw):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 78&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;                prime_cache = self.chars&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 79&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;                super(MagicTesting).put(*args, **kw)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 81&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        mytesting = MagicTesting(title=&amp;quot;Get the pocket knife out of my boot.&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 82&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 83&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytesting.title&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 84&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        Get the pocket knife out of my boot.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 85&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytesting.chars&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 86&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        36&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 87&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 88&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        mytesting = MagicTest.all().get()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 89&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 90&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytesting.title&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 91&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        How are you?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 92&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        &amp;gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;print mytesting.chars	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 93&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        12	# This is not recomputed so long as the title has not changed, however it uses more datastore space to store a hash.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 94&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 95&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 96&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    Inspired by: &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 97&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    http:&#x2F;&#x2F;appengine-cookbook.appspot.com&#x2F;recipe&#x2F;custom-model-properties-are-cute&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 98&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    http:&#x2F;&#x2F;code.google.com&#x2F;appengine&#x2F;articles&#x2F;extending_models.html&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt; 99&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    http:&#x2F;&#x2F;googleappengine.blogspot.com&#x2F;2009&#x2F;07&#x2F;writing-custom-property-classes.html&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;101&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;102&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; prop&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; magic_func&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; cache_prop&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; pass_instance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *args&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **kw&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;103&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;104&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        Extra parameters you can give this initializer.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;105&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;106&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            prop		= Property to be acted upon&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;107&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            magic_func	= The function to be called when the property is accessed&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;108&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;            cache_prop	= The property that can hold our cache, I suggest it is an db.UnindexedProperty() since it just stores sha1 hashes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;109&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;110&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        super&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;_MagicProperty&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;kw&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;111&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; magic_func&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;112&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.magic_prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; prop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;113&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.magic_cache&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; cache_prop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;114&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.magic_pass&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; pass_instance&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;115&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;116&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; get_cache_val&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; model_instance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;117&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.magic_cache&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is not&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;118&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.magic_cache.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;__get__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;119&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; getattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;orig&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;120&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;121&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; set_cache_val&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; model_instance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; val&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;122&lt;&#x2F;span&gt;&lt;span&gt;        val&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; hashlib.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;sha1&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;val&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;hexdigest&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;123&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;124&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.magic_cache&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is not&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;125&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;            self&lt;&#x2F;span&gt;&lt;span&gt;.magic_cache.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;__set__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; val&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;126&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        setattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;orig&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; val&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;127&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;128&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; attr_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;129&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # In google.appengine.ex.db there is an explicit warning not to use this method, so we test for it first.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;130&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;._attr_name:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;131&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;_attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;132&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;133&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;134&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;135&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __get__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; model_instance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;136&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;137&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;138&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;139&lt;&#x2F;span&gt;&lt;span&gt;        cur&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.magic_prop.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;__get__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;140&lt;&#x2F;span&gt;&lt;span&gt;        cur&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; cur.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;encode&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;utf-8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)		&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;141&lt;&#x2F;span&gt;&lt;span&gt;        last&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;get_cache_val&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;142&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; last&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; hashlib.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;sha1&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;cur&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;hexdigest&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;143&lt;&#x2F;span&gt;&lt;span&gt;            logging.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;info&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Cache hit: &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;%s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; %&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; (cur)&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;144&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; getattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;145&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;146&lt;&#x2F;span&gt;&lt;span&gt;        logging.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;info&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Cache miss: &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;%s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; %&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; (cur)&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;147&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;148&lt;&#x2F;span&gt;&lt;span&gt;        magic_done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; = u&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;149&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.magic_pass:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;150&lt;&#x2F;span&gt;&lt;span&gt;            magic_done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;magic_func&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; cur&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;151&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;152&lt;&#x2F;span&gt;&lt;span&gt;            magic_done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;magic_func&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;cur&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;153&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;154&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # Set the attribute in the model&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;155&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        setattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; magic_done&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;156&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;set_cache_val&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; cur&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;157&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;158&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; magic_done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;159&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;160&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;161&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __set__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; model_instance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;162&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; isinstance&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; _MagicDatastore&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;163&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;            setattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; value.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;retval&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;164&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;165&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            raise&lt;&#x2F;span&gt;&lt;span&gt; db.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;DerivedPropertyError&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;MagicProperty is magic. Magic may not be modified.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;166&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;167&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; make_value_from_datastore&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #4B6479;&quot;&gt;168&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt; _MagicDatastore&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;value&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Auto-updating Properties in Google AppEngine Models</title>
        <published>2010-02-21T04:03:42+00:00</published>
        <updated>2010-03-24T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2010/auto-updating-properties-in-google-appengine-models/"/>
        <id>https://funcptr.net/2010/auto-updating-properties-in-google-appengine-models/</id>
        
        <content type="html" xml:base="https://funcptr.net/2010/auto-updating-properties-in-google-appengine-models/">&lt;p&gt;EDIT: I have an updated version of this code available in a newer post, please
go to &lt;a href=&quot;&#x2F;2010&#x2F;magic-properties-on-google-appengine&#x2F;&quot;&gt;Magic Properties on Google AppEngine&lt;&#x2F;a&gt; for the updated information.
For the generic information that has not changed, and the idea behind the code
please continue below.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;In Google AppEngine a model may contain many different properties, from this
model you can generate a form using djangoforms. This is all good and well
until you have a required property on a model that needs to have part of it be
calculated based upon something the user types in. For example, a blog entry
generally has a &quot;slug&quot; which is generated from the title, now in Google
AppEngine&#x27;s models, if a property is required it has to be set at object
creation time.&lt;&#x2F;p&gt;
&lt;p&gt;Djangoforms has a &lt;code&gt;form.save(committed=False)&lt;&#x2F;code&gt; that allows one to get back an
unsaved &lt;code&gt;Model&lt;&#x2F;code&gt;, however since slug is not in the form (since it is auto
generated) it cannot be set at model creation time. Even adding a hidden field
to the form with the name of the property is not going to satisfy the model
since a value of &lt;code&gt;None&lt;&#x2F;code&gt; is considered to be empty, which means it does not meet
the &lt;code&gt;required=True&lt;&#x2F;code&gt; status.&lt;&#x2F;p&gt;
&lt;p&gt;After trying a multitude of different options I ran across an &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;code.google.com&#x2F;appengine&#x2F;articles&#x2F;extending_models.html&quot;&gt;article about
extending models&lt;&#x2F;a&gt; that specifically talked about adding custom properties
that were saved into the DB, and could be searched on, this got me digging and
I found &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;googleappengine.blogspot.com&#x2F;2009&#x2F;07&#x2F;writing-custom-property-classes.html&quot;&gt;a blog post on the Google AppEngine blogspot&lt;&#x2F;a&gt; about the exact same
thing, using yet again a different example. The one that got me on the right
track was the following post by &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20090517114229&#x2F;http:&#x2F;&#x2F;appengine-cookbook.appspot.com&#x2F;recipe&#x2F;custom-model-properties-are-cute&#x2F;&quot;&gt;Rodrigo Moraes on his custom model
properties&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I came up with the following fairly quickly after also taking a look at
&lt;code&gt;googleappengine.ext.db&lt;&#x2F;code&gt; within the Google AppEngine framework, however there is
still an issue, for now the &lt;code&gt;MagicProperty&lt;&#x2F;code&gt; is only updated the first time the
property it affects is set. I am not yet sure how to work around that, I will
have to do some more digging, maybe there is a way to get notified if another
property gets modified or updated.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; logging&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt; google.appengine.ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; db&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; MagicProperty&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;prop&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; magic_func=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *args&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **kw&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; magic_func:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # No pants required.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt; _MagicProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;kw&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # We are putting some pants on the function.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; pants&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt; _MagicProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;kw&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; pants&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFCB8B;&quot;&gt; _MagicProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;Property&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;MagicProperty which will modify output based on a function that it is given.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    Inspired by: &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    http:&#x2F;&#x2F;appengine-cookbook.appspot.com&#x2F;recipe&#x2F;custom-model-properties-are-cute&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    http:&#x2F;&#x2F;code.google.com&#x2F;appengine&#x2F;articles&#x2F;extending_models.html&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    http:&#x2F;&#x2F;googleappengine.blogspot.com&#x2F;2009&#x2F;07&#x2F;writing-custom-property-classes.html&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __init__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; prop&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; magic_func&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *args&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **kw&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        super&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;_MagicProperty&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; **&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;kw&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.magic_func&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; magic_func&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span&gt;.magic_prop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; prop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; attr_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # In google.appengine.ex.db there is an explicit warning not to use this method, so we test for it first.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;._attr_name:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;_attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __get__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; model_instance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        #&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; TODO&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;: If the property that this one is functioning on is changed, we need a way to know that so that we recalculate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;        # Original __get__ in google.appengine.ext.db has getattr to retrieve the value from the model instance&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        magic_done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; getattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; magic_done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            magic_done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;magic_func&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.magic_prop.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;__get__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; class_instance&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;            # Set the attribute in the model&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;            setattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;model_instance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8EACE3;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;_attr_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; magic_done&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; magic_done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; __set__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; *args&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        raise&lt;&#x2F;span&gt;&lt;span&gt; db.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;DerivedPropertyError&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;MagicProperty is magic. Magic may not be modified.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The approach that the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20100208035715&#x2F;http:&#x2F;&#x2F;code.google.com&#x2F;appengine&#x2F;docs&#x2F;python&#x2F;datastore&#x2F;typesandpropertyclasses.html#DateTimeProperty&quot;&gt;DateTimeProperty&lt;&#x2F;a&gt; takes is one that I can&#x27;t use
because my class is dependant upon an external property, not whether or not a
value was set when the object was instantiated.&lt;&#x2F;p&gt;
&lt;p&gt;Google AppEngine is posing some rather interesting challenges. Although, for
slugs it may not be entirely bad that it can only be set once, as that means
title changes on the article won&#x27;t cause the slug to change possibly breaking
old links. This definitely requires more research and more thinking.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Property class on AppEngine does not support a tuple for choices</title>
        <published>2010-02-15T04:56:59+00:00</published>
        <updated>2010-02-15T04:56:59+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2010/property-class-on-google-appengine-not-supporting-a-tuple-of-choices/"/>
        <id>https://funcptr.net/2010/property-class-on-google-appengine-not-supporting-a-tuple-of-choices/</id>
        
        <content type="html" xml:base="https://funcptr.net/2010/property-class-on-google-appengine-not-supporting-a-tuple-of-choices/">&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;code.google.com&#x2F;appengine&#x2F;&quot;&gt;Google AppEngine&lt;&#x2F;a&gt; does not allow one to set the choices field of a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20100212221437&#x2F;http:&#x2F;&#x2F;code.google.com&#x2F;appengine&#x2F;docs&#x2F;python&#x2F;datastore&#x2F;propertyclass.html#Property&quot;&gt;model
property&lt;&#x2F;a&gt;&lt;&#x2F;a&gt; to a tuple; this workaround will have have a form give the
user the choices with the user friendly items but have the backend store the
non-user friendly version.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# Set up our non-user friendly and user friendly choices&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;REDIRECT_CHOICES&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;301&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;301 - Permanent Redirect&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;302&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;302 - Temporary Redirect&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;403&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;403 - Access Denied&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;404&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;404 - File Not Found&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;500&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;500 - Internal Server Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# Sample model that has the required Property with the choices set to the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# non-user friendly values&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFCB8B;&quot;&gt; Shorturl&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;Model&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    uripath&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; db.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;StringProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;verbose_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt; required&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;True&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    httpcode&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; db.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;IntegerProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        verbose_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;HTTP code&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        required&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;True&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;301&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        choices&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;x&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; REDIRECT_CHOICES&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    location&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; db.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;StringProperty&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;verbose_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Location&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# This is our djangoform that has the choices set as required so that the user&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# gets the user friendly version and not just simply the numbers.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFCB8B;&quot;&gt; ShorturlForm&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;djangoforms&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;ModelForm&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    httpcode&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; forms.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;IntegerField&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        widget&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;forms.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;Select&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;choices&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;REDIRECT_CHOICES&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        required&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;True&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D7DBE0;&quot;&gt;        label&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;HTTP code&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;    class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFCB8B;&quot;&gt; Meta&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; Shorturl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Given the above tuple it will set the choices in the model for Google AppEngine
and pass it to the field on the Django form allowing user friendly output. This
will allow the user to pick the right redirect choice without having to know
that various different redirect codes or have to look them up.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Moving from mod_fastcgi to mod_fcgid</title>
        <published>2009-08-25T23:22:03+00:00</published>
        <updated>2010-11-14T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2009/moving-from-mod-fastcgi-to-mod-fcgid/"/>
        <id>https://funcptr.net/2009/moving-from-mod-fastcgi-to-mod-fcgid/</id>
        
        <content type="html" xml:base="https://funcptr.net/2009/moving-from-mod-fastcgi-to-mod-fcgid/">&lt;p&gt;Update: I&#x27;ve since moved to a PHP-FPM with &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; based setup which works
much better than &lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; could ever dream of, taking process management away
from Apache and putting it where it actually makes sense has improved server
load and improved website speed. See my new &lt;a href=&quot;&#x2F;2010&#x2F;apache-mod-fastcgi-and-php-with-php-fpm&#x2F;&quot;&gt;PHP-FPM with mod_fastcgi
post&lt;&#x2F;a&gt; for more information.&lt;&#x2F;p&gt;
&lt;p&gt;--&lt;&#x2F;p&gt;
&lt;p&gt;Errors, all they cause is trouble. The dreaded 500 error showed up when
visiting my favourite tech website, the one I am the administrator for. This
time I had enough, there was going to be no more playing around with PHP
settings, attempting to figure out why PHP was suddenly dying and or why
&lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; refused to retry a select() when it failed due to a system
signal.&lt;&#x2F;p&gt;
&lt;p&gt;The server in question runs Apache in MPM worker mode since a threaded Apache
is going to be faster than a pre-fork, besides this server does not have as
much memory so it seemed to be better to have multiple threads rather than
multiple processes, each of which would have their own memory segment. There
however is the issue that this server also needs to run PHP, the accepted
method to do so is to use &lt;code&gt;mod_php&lt;&#x2F;code&gt; along with Apache; however PHP is not thread
safe.&lt;&#x2F;p&gt;
&lt;p&gt;The alternative is FastCGI, basically it spawns PHP processes as a separate
stand-alone process, with their own memory space, much like Apache pre-fork,
however now when one process grows to big, or when a process is no longer
needed it can be cleaned up, keeping memory to a minimum. Also, FastCGI is
perfectly thread safe, this means that with Apache running in MPM worker mode
we could now still run our PHP scripts even when they were not thread safe.&lt;&#x2F;p&gt;
&lt;p&gt;Setting up &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; is not that hard, it takes some httpd.conf
configuration values, and off course the loadmodule is assumed here:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Set up mod_fastcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;IfModule `mod_fastcgi`.c&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FastCgiIpcDir &#x2F;var&#x2F;tmp&#x2F;fcgi-ipc&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FastCgiConfig -autoUpdate -singleThreshold 100 -killInterval 300 -idle-timeout 240 -pass-header HTTP_AUTHORIZATION&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddHandler  fastcgi-script              .fcgi .fcg .fpl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Action      application&#x2F;x-httpd-php5    &#x2F;fastcgi-bin&#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddType     application&#x2F;x-httpd-php5    .php .php5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;IfModule&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Set up the script alias, basically anything in this directory gets executed as a fastcgi script&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ScriptAlias &#x2F;fastcgi-bin&#x2F; &amp;quot;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;Location &#x2F;fastcgi-bin&#x2F;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Options ExecCGI &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    SetHandler fastcgi-script&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Order allow,deny&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Allow from all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;Location&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Because of errors that &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; was throwing out at me, I figured
&lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; is worth a try. However all of the configurations I found required
me to add an FCGIWrapper line into each of my VirtualHost blocks, which was an
immediate no-no since there is well over 100 of those on the server, and I&#x27;d
rather spend my time doing other things.&lt;&#x2F;p&gt;
&lt;p&gt;With some trial and error, and some Googling I put the following together for
&lt;code&gt;mod_fcgid&lt;&#x2F;code&gt;, tested it out, and once it worked perfectly set Apache off running
with the following configuration:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Set up mod_fcgid&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;IfModule `mod_fcgid`.c&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddHandler  fcgid-script                 .fcgi .fcg .fpl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    IPCCommTimeout 60&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    SocketPath  &#x2F;var&#x2F;tmp&#x2F;fcgi-ipc&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Action      application&#x2F;x-httpd-php5    &#x2F;fastcgi-bin&#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddType     application&#x2F;x-httpd-php5    .php .php5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;IfModule&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# Set up the script alias, basically anything in this directory gets executed as a fastcgi script&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ScriptAlias &#x2F;fastcgi-bin&#x2F; &amp;quot;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;Location &#x2F;fastcgi-bin&#x2F;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Options ExecCGI &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    SetHandler fcgid-script&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Order allow,deny&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Allow from all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;Location&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Notice how similar they both are, that was the whole goal. &lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; was
supposed to be a drop in replacement, and thankfully it was. PHP was served as
it once was, with a twist.&lt;&#x2F;p&gt;
&lt;p&gt;The php5.fcgi script is as follows for those of you trying to set this up as
well:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# To use your own php.ini, comment the next line and uncomment the following one&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#PHPRC=&amp;quot;&#x2F;usr&#x2F;local&#x2F;etc&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#export PHPRC&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;PHP_FCGI_CHILDREN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;export&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; PHP_FCGI_CHILDREN&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;exec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;bin&#x2F;php-cgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Some things that that intrigued me is that my php processes seemed to be capped
now. Where &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; would spawn processes but never remove them or kill
them when they were no longer needed, &lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; keeps the running php
processes to a sane limit instantly starting new processes when required to
handle the requests coming in. This means that the server now has more free
memory for MySQL, or file caches which has helped speed up other types of
transfers as well. Even with the relatively short time that &lt;code&gt;mod_fcgid&lt;&#x2F;code&gt; has
been in place it has been faster, more reliable and more sane than
&lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt;. Whichever one you pick, make sure to benchmark your server and
check your error logs to solve common issues, the issue may not be what FastCGI
module you picked but rather PHP itself that is causing the errors!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Hosting NFS shares from a Zone</title>
        <published>2009-02-21T00:10:26+00:00</published>
        <updated>2009-02-21T00:10:26+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2009/hosting-nfs-shares-from-a-zone/"/>
        <id>https://funcptr.net/2009/hosting-nfs-shares-from-a-zone/</id>
        
        <content type="html" xml:base="https://funcptr.net/2009/hosting-nfs-shares-from-a-zone/">&lt;p&gt;I am currently trying to get my web development environment all set up.
While I like using vi, I really do prefer TextMate on my Mac OS X to do
the real heavy lifting and all of the editing.&lt;&#x2F;p&gt;
&lt;p&gt;As I was working on getting my homedir on my zone to be shared over NFS I
was getting errors that NFS was not a valid protocol from &lt;code&gt;sharemgr&lt;&#x2F;code&gt;, the
program that is used to add new shares to the system.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# sharemgr create -P nfs homedir  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Invalid protocol specified: nfs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A little bit of Googling brought me to a mailing list message saying that
some server packages may be missing. This is entirely possible since my
Zone was created with a minimal set of packages, so I log into the global
host where NFS sharing does work and run the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@Keyhole.network.lan:~# pkg list | grep nfs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SUNWnfsc                                      0.5.11-0.101    installed  ----&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SUNWnfsckr                                    0.5.11-0.101    installed  ----&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SUNWnfss                                      0.5.11-0.101    installed  ----&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SUNWnfsskr                                    0.5.11-0.101    installed  ----&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Ah, so those are probably not installed in the zone, quick &lt;code&gt;pkg install&lt;&#x2F;code&gt;
later:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# pkg install SUNWnfsc SUNWnfsckr SUNWnfss SUNWnfsskr&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DOWNLOAD                                    PKGS       FILES     XFER (MB)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Completed                                    3&#x2F;3       17&#x2F;17     0.28&#x2F;0.28 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PHASE                                        ACTIONS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Install Phase                                  55&#x2F;55 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PHASE                                          ITEMS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Reading Existing Index                           9&#x2F;9 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Indexing Packages                                3&#x2F;3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, lets re-run the &lt;code&gt;sharemgr&lt;&#x2F;code&gt; command again and see if this time we do
indeed get our group created:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# sharemgr create -P nfs homedir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# sharemgr show -vp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;default nfs=()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;zfs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;homedir nfs=()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Yes, there we go. Now I can add a share to that group. Until more errors
start showing up:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# sharemgr add-share -s &#x2F;export&#x2F;home&#x2F;xistence&#x2F; homedir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;NFS: Cannot share remote filesystem: &#x2F;export&#x2F;home&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;NFS: Service needs to be enabled by a privileged user&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Failed to enable share for &amp;quot;nfs&amp;quot;: system error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This time Google does not help out, instead it gives me the option to
search without quotes around the search terms which gives me absolutely
nothing.&lt;&#x2F;p&gt;
&lt;p&gt;Well, lets see if the services are running in the first place:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# svcs -a | grep nfs    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;disabled       22:19:04 svc:&#x2F;network&#x2F;nfs&#x2F;client:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;disabled       22:24:26 svc:&#x2F;network&#x2F;nfs&#x2F;server:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;online         22:24:20 svc:&#x2F;network&#x2F;nfs&#x2F;rquota:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;online         22:24:20 svc:&#x2F;network&#x2F;nfs&#x2F;status:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;online         22:24:20 svc:&#x2F;network&#x2F;nfs&#x2F;mapid:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;online         22:24:20 svc:&#x2F;network&#x2F;nfs&#x2F;cbd:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;online         22:24:21 svc:&#x2F;network&#x2F;nfs&#x2F;nlockmgr:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Nope, for some reason the nfs server keeps being disabled even though I
did enable it using &lt;code&gt;svcadmin&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Okay, lets take a look with &lt;code&gt;svcs&lt;&#x2F;code&gt; what is going on:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:&#x2F;# svcs -l nfs&#x2F;server&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fmri         svc:&#x2F;network&#x2F;nfs&#x2F;server:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;name         NFS server&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;enabled      false (temporary)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;state        disabled&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;next_state   none&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;state_time   Fri Feb 20 22:25:26 2009&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;logfile      &#x2F;var&#x2F;svc&#x2F;log&#x2F;network-nfs-server:default.log&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;restarter    svc:&#x2F;system&#x2F;svc&#x2F;restarter:default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;contract_id  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   require_any&#x2F;error svc:&#x2F;milestone&#x2F;network (online)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   require_all&#x2F;error svc:&#x2F;network&#x2F;nfs&#x2F;nlockmgr (online)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   optional_all&#x2F;error svc:&#x2F;network&#x2F;nfs&#x2F;mapid (online)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   require_all&#x2F;restart svc:&#x2F;network&#x2F;rpc&#x2F;bind (online)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   optional_all&#x2F;none svc:&#x2F;network&#x2F;rpc&#x2F;keyserv (disabled)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   optional_all&#x2F;none svc:&#x2F;network&#x2F;rpc&#x2F;gss (absent)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   optional_all&#x2F;none svc:&#x2F;network&#x2F;shares&#x2F;group (multiple)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dependency   require_all&#x2F;error svc:&#x2F;system&#x2F;filesystem&#x2F;local (online)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Ah, it has a log file, lets see what that log file says:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:&#x2F;# cat &#x2F;var&#x2F;svc&#x2F;log&#x2F;network-nfs-server\:default.log &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[ Feb 20 22:11:07 Disabled. ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[ Feb 20 22:11:07 Rereading configuration. ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[ Feb 20 22:18:43 Enabled. ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[ Feb 20 22:19:04 Enabled. ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[ Feb 20 22:24:21 Executing start method (&amp;quot;&#x2F;lib&#x2F;svc&#x2F;method&#x2F;nfs-server start&amp;quot;). ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;The NFS server is not supported in a local zone&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Eh? What? That seems weird, but it is of course plausible. Zones are new
to Solaris and thus not everything may be virtualised yet. Taking that
query to google brings me to a web page asking the same question I am
asking: Local zone as NFS server. Taking a look it brings me to a bug
report and ultimately to: Bug ID 4964859 RFE: Zones should be able to be
NFS servers. Well, I guess that ends that little stunt. I will be sharing
it from the global zone. While this is acceptable to me, I do not believe
that it is acceptable to most other people using Zones, and while it is
unfortunate but it does not look like there is a whole lot of activity on
the bug, as apparently there are no resources available.&lt;&#x2F;p&gt;
&lt;p&gt;I ended up doing the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sharemgr create -P nfs webdev-homedir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then I followed that up with some servers that should be allowed access,
and others that should not:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sharemgr set -P nfs -S sys -p &amp;#39;rw=10.10.10.226 none=*&amp;#39; webdev-homedir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And then finally I added the share I wanted to share all along:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sharemgr add-share -r &amp;quot;homedir&amp;quot; -d &amp;quot;xistence home dir&amp;quot; -s &#x2F;storage&#x2F;zones&#x2F;dev-web&#x2F;root&#x2F;export&#x2F;home&#x2F;xistence webdev-homedir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This creates a long NFS share to type in, since the full path now becomes:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nfs:&#x2F;&#x2F;keyhole&#x2F;storage&#x2F;zones&#x2F;dev-web&#x2F;root&#x2F;export&#x2F;home&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Which is not that big of a problem for me, especially since I just save
it in my favourites in Mac OS X and everything is peachy. It works like a
charm.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Upgrading an OpenSolaris ipkg zone</title>
        <published>2009-01-18T00:10:02+00:00</published>
        <updated>2009-01-18T00:10:02+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2009/so-you-want-to-upgrade-your-zone/"/>
        <id>https://funcptr.net/2009/so-you-want-to-upgrade-your-zone/</id>
        
        <content type="html" xml:base="https://funcptr.net/2009/so-you-want-to-upgrade-your-zone/">&lt;p&gt;Recently I was working on my OpenSolaris machine (file server, ZFS rocks, will
write more on that later), and I have one non-global zone, one that use for web
development, which is aptly called dev-web.&lt;&#x2F;p&gt;
&lt;p&gt;So the following shows up when I run zoneadm:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# zoneadm list -iv&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ID NAME             STATUS     PATH                           BRAND    IP    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   0 global           running    &#x2F;                              native   shared&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   4 dev-web          running    &#x2F;storage&#x2F;zones&#x2F;dev-web         ipkg     shared&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The thing is, I had upgraded the global zone with the latest update available for the version (&lt;code&gt;snv_101b&lt;&#x2F;code&gt;):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;pkg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; image-update&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This had not upgraded my one none-global zone. And running &lt;code&gt;pkg image-update&lt;&#x2F;code&gt;
from within the zone itself is not possible, because you can&#x27;t do an upgrade on
a &quot;live&quot; system, mainly because the &lt;code&gt;image-update&lt;&#x2F;code&gt; wants to create a new bootable
environment, something that was already created when I upgraded the global
zone. So what we have to do is mount the non-global zone to &lt;code&gt;&#x2F;mnt&lt;&#x2F;code&gt; and tell &lt;code&gt;pkg&lt;&#x2F;code&gt;
with &lt;code&gt;-R&lt;&#x2F;code&gt; where to find it and upgrade it anyway!&lt;&#x2F;p&gt;
&lt;p&gt;First we are going to halt the current zone, important is running on the test
system, I just used:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zoneadm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; dev-web halt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However, the better way is to off course use the shutdown command:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zlogin&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; dev-web shutdown&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and then for good measure a halt!&lt;&#x2F;p&gt;
&lt;p&gt;Next up, looking at what we are going to be mounting.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# zfs list&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;NAME                               USED  AVAIL  REFER  MOUNTPOINT&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool                             11.9G  42.7G    75K  &#x2F;rpool&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;ROOT                        2.93G  42.7G    18K  legacy&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;ROOT&#x2F;opensolaris            7.34M  42.7G  2.74G  &#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;ROOT&#x2F;opensolaris-1          2.92G  42.7G  2.74G  &#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;dump                        1.87G  42.7G  1.87G  -&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;export                      5.27G  42.7G    19K  &#x2F;export&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;export&#x2F;home                 5.27G  42.7G    21K  &#x2F;export&#x2F;home&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;export&#x2F;home&#x2F;guest           5.24G  14.8G  5.24G  &#x2F;export&#x2F;home&#x2F;guest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;export&#x2F;home&#x2F;xistence        37.0M  42.7G  37.0M  &#x2F;export&#x2F;home&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rpool&#x2F;swap                        1.87G  43.0G  1.51G  -&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage                            493G  3.08T  35.1K  &#x2F;storage&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;media                      398G  3.08T   398G  &#x2F;storage&#x2F;media&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;virtualbox                2.10G  3.08T  2.10G  &#x2F;storage&#x2F;virtualbox&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;xistence                  91.7G  3.08T  91.7G  &#x2F;storage&#x2F;xistence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;zones                      957M  99.1G  30.4K  &#x2F;storage&#x2F;zones&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;zones&#x2F;dev-web              957M  19.1G  32.0K  &#x2F;storage&#x2F;zones&#x2F;dev-web&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;zones&#x2F;dev-web&#x2F;ROOT         957M  19.1G  28.8K  legacy&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;zones&#x2F;dev-web&#x2F;ROOT&#x2F;zbe    1.60M  19.1G   936M  legacy&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;storage&#x2F;zones&#x2F;dev-web&#x2F;ROOT&#x2F;zbe-1   955M  19.1G   935M  legacy&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When &lt;code&gt;pkg image-update&lt;&#x2F;code&gt; was run on the global zone it created a new bootable
environment named opensolaris-1, the cool thing is, that &lt;code&gt;beadm&lt;&#x2F;code&gt; at the same time
will also create a new bootable environment for your zones. That way you can
upgrade your zones afterwards, and if stuff does not work, you can revert the
ENTIRE machine back to the previous state (ZFS is cool like that), thereby also
making sure that your zones are reverted so that there are no
incompatibilities.&lt;&#x2F;p&gt;
&lt;p&gt;So what we are looking for in this case is a zbe-1, this is the new root for
the zone that we need to update, so we now need to mount it.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -F&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; zfs storage&#x2F;zones&#x2F;dev-web&#x2F;ROOT&#x2F;zbe-1 &#x2F;mnt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note, that there is no &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; in front of storage, this is because we are specifying
a pool name, since there is no &quot;real&quot; path that is defined as
&lt;code&gt;&#x2F;storage&#x2F;zones&#x2F;dev-web&#x2F;ROOT&#x2F;zbe-1&lt;&#x2F;code&gt;. Now that it is mounted, we are able to pass
the -R flag to pkg, to get it to update our zone:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# pkg -R &#x2F;mnt image-update -v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Creating Plan &#x2F; Before evaluation:     &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;UNEVALUATED:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;+pkg:&#x2F;entire@0.5.11,5.11-0.101:20081204T010954Z&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;After evaluation:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;pkg:&#x2F;entire@0.5.11,5.11-0.101:20081119T235706Z -&amp;gt; pkg:&#x2F;entire@0.5.11,5.11-0.101:20081204T010954Z&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Actuators:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PHASE                                        ACTIONS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Update Phase                                     1&#x2F;1 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PHASE                                          ITEMS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Reading Existing Index                           9&#x2F;9 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Indexing Packages                                1&#x2F;1 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;---------------------------------------------------------------------------&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;NOTE: Please review release notes posted at:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   http:&#x2F;&#x2F;opensolaris.org&#x2F;os&#x2F;project&#x2F;indiana&#x2F;resources&#x2F;relnotes&#x2F;200811&#x2F;x86&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;---------------------------------------------------------------------------&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Voilá, and the deed is done. The last command is to off course unmount the
zone, that we can then issue a zoneadm boot command to start it back up:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;umount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;mnt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;zoneadm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; dev-web boot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And then on the zone after we log into it (over SSH in my case):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xistence@webdev.network.lan:~# pkg list -u&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;No installed packages have available updates&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Which is exactly what we wanted! Your zone is now upgraded with the latest
version available from the global zone.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Using DJB&#x27;s daemontools and netcat to bounce a request around</title>
        <published>2008-11-29T17:56:05+00:00</published>
        <updated>2008-11-29T17:56:05+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2008/using-djb-s-daemontools-and-netcat-to-bounce-an-incoming-request-around-the-world/"/>
        <id>https://funcptr.net/2008/using-djb-s-daemontools-and-netcat-to-bounce-an-incoming-request-around-the-world/</id>
        
        <content type="html" xml:base="https://funcptr.net/2008/using-djb-s-daemontools-and-netcat-to-bounce-an-incoming-request-around-the-world/">&lt;p&gt;Lately I have been moving the data from one server to another server, located
halfway across the globe, and I needed some way to forward all incoming
requests from the old server to the new server. This had to be done so that DNS
could take its time to update while everything was now already being served
from the new location.&lt;&#x2F;p&gt;
&lt;p&gt;What I ended up doing was using daemontools along with netcat to pipe the
request around the world. Here are the steps I took in doing so:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mkdir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;redirect&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;redirect&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mkdir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; smtp smtp&#x2F;env&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; smtp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Put the following in a file named run:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;exec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; 2&amp;gt;&amp;amp;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;envdir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .&#x2F;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sh&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    case &amp;quot;$REMOTENAME&amp;quot; in h) H=;; p) H=p;; *) H=H;; esac&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    case &amp;quot;$REMOTEINFO&amp;quot; in r) R=;; [0-9]*) R=&amp;quot;t$REMOTEINFO&amp;quot;;; *) R=R;; esac&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    exec \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;    &#x2F;usr&#x2F;local&#x2F;bin&#x2F;tcpserver \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        -vDU&amp;quot;$H$R&amp;quot; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        ${LOCALNAME+&amp;quot;-l$LOCALNAME&amp;quot;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        ${BACKLOG+&amp;quot;-b$BACKLOG&amp;quot;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        ${CONCURRENCY+&amp;quot;-c$CONCURRENCY&amp;quot;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        -- &amp;quot;${IP-0}&amp;quot; &amp;quot;${PORT}&amp;quot; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;        &#x2F;usr&#x2F;bin&#x2F;nc &amp;quot;${REMOTEHOST}&amp;quot; &amp;quot;${REMOTEPORT}&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Make it executable: &lt;code&gt;chmod +x run&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Then we need to set up a few environment variables:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; env&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;example.net&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; REMOTEHOST&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;25&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; REMOTEPORT&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;25&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; PORT&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;hostname&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; LOCALNAME&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;200&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; CONCURRENCY&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I made &lt;code&gt;REMOTEPORT&lt;&#x2F;code&gt; and &lt;code&gt;PORT&lt;&#x2F;code&gt; be separate on purpose, in one case I now had more
IP&#x27;s than before, so instead of having SSL running on a separate port it was
running on the default port, and I needed a clean way to forward that.&lt;&#x2F;p&gt;
&lt;p&gt;Now just add it to your services folder as a symlink and it will automatically
be started, from there it will do it&#x27;s job! I also suggest adding some simple
logging, or discarding all off the output from tcpserver.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>addnumbers.asm updated</title>
        <published>2008-02-03T09:59:04+00:00</published>
        <updated>2008-02-03T09:59:04+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2008/addnumbers-asm-updated/"/>
        <id>https://funcptr.net/2008/addnumbers-asm-updated/</id>
        
        <content type="html" xml:base="https://funcptr.net/2008/addnumbers-asm-updated/">&lt;p&gt;If you have no clue what I am talking about, check out &lt;a href=&quot;&#x2F;2008&#x2F;introduction-to-intel-assembly&#x2F;&quot;&gt;my previous post&lt;&#x2F;a&gt;.
I have fixed the flaws, and now it will parse the commands it is handed on
the command line, and stick them into an integer. It will now print it to
stdout.&lt;&#x2F;p&gt;
&lt;p&gt;This has been an awesome learning experience for me. Especially with regards
to how to do recursion, how to debug a pure assembly program with gdb and
whatnot.&lt;&#x2F;p&gt;
&lt;p&gt;Here comes the code, as I said before, see my previous thread if you don&#x27;t
know what I am talking about, as well as instructions on how to compile the
program.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; File: addnumbers2.asm&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Delta Regeer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; 2008-01-27&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Function:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	Add numbers together that are provided as arguments to the program in argv[1] and argv[2].&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Known limitations:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	This will hopefully be fixed in the next revision. Floating point numbers will not work.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	Any input that is larger than an integer will cause overflows, and thus will not work.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Define some strings that are going to be used throughout the program&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This string is to let the user know they failed to provide the proper amount of arguments.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;args	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;	&amp;quot;Program &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;addnumbers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; &amp;quot;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0xa&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x9&lt;&#x2F;span&gt;&lt;span&gt;, &amp;quot;addnumbers &amp;lt;number &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; &amp;lt;number &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;quot;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0xa&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x9&lt;&#x2F;span&gt;&lt;span&gt;, &amp;quot;Arguments &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt; are required.&amp;quot;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0xa&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x9&lt;&#x2F;span&gt;&lt;span&gt;, &amp;quot;Anything that will cause addition to overflow an &lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;147&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;483&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;647&lt;&#x2F;span&gt;&lt;span&gt;), will fail! :P&amp;quot;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0xa&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;largs	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;equ&lt;&#x2F;span&gt;&lt;span&gt;	$ - args&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This string contains part of the output that we are going to send to the terminal. The last two&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; bytes will be filled automatically by the program, before it is output to stdout.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;msg	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;	&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;Answer&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; &amp;#39;,	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lmsg	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;equ&lt;&#x2F;span&gt;&lt;span&gt;	$ - msg&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;num1	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;num2	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .bss&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This is where I am going to store the output of my conversion from an integer to a char&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;answer	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;resb&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .text&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;global start				&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Linker defined entry point. Mac OS X this is start. &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;global _start				&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; FreeBSD and others _start.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;_start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; 		; Set up the stack frame&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Get argc, we check if it set to at least 3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Put the base pointer into edx, so we can use that in &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;					; our dereferences coming up&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Add 8. We want to skip ebp and argc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	cmp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Check if we have at least 3 arguments to the program. &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;					; At least two arguments are required, and the 3rd one is &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;					; the name of the program&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jl&lt;&#x2F;span&gt;&lt;span&gt;	exit			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; If the value in ecx is less than 3, jump to exit&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esi&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Set the index to 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;edx&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esi&lt;&#x2F;span&gt;&lt;span&gt; * &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;]	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the pointer to the character array into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push eax onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span&gt;	num1			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the pointer to num1 onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	call&lt;&#x2F;span&gt;&lt;span&gt;	ctoi			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Call my char to int function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Put the stack pointer back to where it was.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	inc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Increase the index&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;edx&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esi&lt;&#x2F;span&gt;&lt;span&gt; * &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;]	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the pointer to the character array into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push eax onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span&gt;	num2			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the pointer to num2 onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	call&lt;&#x2F;span&gt;&lt;span&gt;	ctoi			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Call my char to int function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Put the stack pointer back to where it was.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [num1]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move value stored in num1 into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [num2]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Add num2 to eax, this will now be stored in eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the new calculated number onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	call&lt;&#x2F;span&gt;&lt;span&gt;	itoa			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Convert the integer to a character array&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; lmsg		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the length of the string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span&gt;	msg			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the location of the string in memory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the file descriptor to write to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Clean up the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span&gt;	answer			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push answer onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	call&lt;&#x2F;span&gt;&lt;span&gt;	len			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Get it&amp;#39;s length&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the length onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span&gt;	answer			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the pointer to the character string onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the file descriptor to write to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Clean up the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jmp&lt;&#x2F;span&gt;&lt;span&gt;	done			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Program is done. Jump to done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;exit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This label is jumped to when we want to exit the program and let the user know how&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; to run the program. Like for instance what paramaters to send the program.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; Call sys_write&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; largs		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the length of the string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; args		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the location of the string in memory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the file descriptor to write to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Clean up the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This is the label we jump to when we want to exit the program, we set the exit code&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; to 0.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; Call sys_exit&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the value to return to the operating system&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; We never return to this function, so no need to clean the stack.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;ctoi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; char to i. We actually convert entire character array&amp;#39;s to integers.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; We get two paramaters on the stack. The first one we grab is the pointer to the place to store&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; the number. The second is the pointer to the character array.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the old base pointer onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Create a new base pointer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Store all the original registers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push edx, so that we can overwrite it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	sub&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; We get another storage space on the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esp&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; This is the number we are going to multiply by&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;12&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the pointer to the character array into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the pointer to the character array onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	call&lt;&#x2F;span&gt;&lt;span&gt;	len			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Call the string length versoin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Reclaim the space we lost when we pushed eax onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; This is where we are going to store the numbers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esi&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;12&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; This is the pointer to the character array&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	movzx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;di&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; move with extended zero edi.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edi&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Clean up edi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	ctoi_loop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebx&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the value stored in ebx into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mul&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esp&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move it over a 10s place.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebx&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Move the new number back into ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	movzx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esi&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;edi&lt;&#x2F;span&gt;&lt;span&gt;]	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the character into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	movsx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;al&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; We just want the lower part of the character&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	sub&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Subtract 0x30, ASCII 0 so that it is an actual number&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span&gt;	[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebx&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Add the new number to the old number that has been multiplied by 10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	inc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Increase the counter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	loop&lt;&#x2F;span&gt;&lt;span&gt; ctoi_loop			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Loop into cx is 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Restore all the registers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Make esp the original base pointer again&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Pop the original base pointer into the register&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	ret&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; Return caller&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;itoa&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Recursive function. This is going to convert the integer to the character.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Setup a new stack frame&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Save the registers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; eax is going to contain the integer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; This is our &amp;quot;stop&amp;quot; value as well as our value to divide with&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span&gt;, answer		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Put a pointer to answer into ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push ebx on the field for our &amp;quot;stop&amp;quot; value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	itoa_loop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	cmp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Compare eax, and ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jl&lt;&#x2F;span&gt;&lt;span&gt;	itoa_unroll		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Jump if eax is less than ebx (which is 10)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	xor&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;edx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Clear edx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	div&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Divide by ebx (10)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the remainder onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jmp&lt;&#x2F;span&gt;&lt;span&gt;	itoa_loop		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Jump back to the top of the loop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	itoa_unroll&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;			&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	al&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Add 0x30 to the bottom part of eax to make it an ASCII char&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ecx&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; al&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Move the ASCII char into the memory references by ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	inc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Increment ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Pop the next variable from the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	cmp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Compare if eax is ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jne&lt;&#x2F;span&gt;&lt;span&gt;	itoa_unroll		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; If they are not equal, we jump back to the unroll loop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; else we are done, and we execute the next few commands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ecx&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0xa&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Add a newline character to the end of the character array&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	inc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Increment ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ecx&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Add a null byte to ecx, so that when we pass it to our&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; len function it will properly give us a length&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Restore registers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt;		&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	ret&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Returns the length of a string. The string has to be null terminated. Otherwise this function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; will fail miserably. &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Upon return. edi will contain the length of the string.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Save the previous stack pointer. We restore it on return&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;esp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; We setup a new stack frame&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Save registers we are going to use. edi returns the length of the string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; 	ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span&gt;,  [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;]		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the pointer to eax; we want an offset of one, to jump over the return address&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	edi&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Set the counter to 0. We are going to increment this each loop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	len_loop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Just a quick label to jump to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	movzx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ecx&lt;&#x2F;span&gt;&lt;span&gt; + &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;edi&lt;&#x2F;span&gt;&lt;span&gt;]	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the character to eax.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	movsx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;al&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move al to eax. al is part of eax.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	inc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	di&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Increase di.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	cmp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Compare eax to 0.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jnz&lt;&#x2F;span&gt;&lt;span&gt; 	len_loop		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; If it is not zero, we jump back to len_loop and repeat.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	dec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	di&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Remove one from the count&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Restore registers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Set esp back to what ebp used to be.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Restore the stack frame&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	ret&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; Return to caller&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Introduction to Intel Assembly</title>
        <published>2008-01-27T03:42:44+00:00</published>
        <updated>2008-01-27T03:42:44+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2008/introduction-to-intel-assembly/"/>
        <id>https://funcptr.net/2008/introduction-to-intel-assembly/</id>
        
        <content type="html" xml:base="https://funcptr.net/2008/introduction-to-intel-assembly/">&lt;p&gt;This semester I am taking a class on Intel assembly, because I want more of an
insight into how the computer works, and it will allow me to better reverse
engineer new viruses and spyware. The class is also required if one is a
Software Engineering major, so that means I have to take it.&lt;&#x2F;p&gt;
&lt;p&gt;We had our first assignment. Sum two numbers and then output them to the
screen. We were supposed to write inline assembly using Visual Studio C++,
but if we are to do an assembly class, then we should learn how to write
assembly, not have some parts assembly and other parts the compiler. Sure
it makes it easy as you will get immediate access to the standard C
library, but if you want that, you can just link against it.&lt;&#x2F;p&gt;
&lt;p&gt;The following code examples were written on Mac OS X, and will work on
FreeBSD. Linux uses a different calling convention for its syscalls, and as
such this code will not run on Linux, unless it is modified. Do note, you
need an Intel Mac for this to work. This is Intel assembly.&lt;&#x2F;p&gt;
&lt;p&gt;Compile the code with (Mac OS X):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;nasm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; macho addnumbers.asm&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;ld&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -o&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; addnumbers addnumbers.o&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;or (FreeBSD):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;nasm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; elf addnumbers.asm&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;ld&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -o&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; addnumbers addnumbers.o&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then you can run it with:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;.&#x2F;addnumbers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1 5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As you can see in the comments of the source code, there are still some
limitations, but the rest of the source code should be made readable by the
comments that are provided.&lt;&#x2F;p&gt;
&lt;p&gt;Porting to Linux: Please double check that all the syscall numbers are the
same. There are some differences between Linux and FreeBSD&#x2F;Mac OS X in that
regard.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; File: addnumbers.asm&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Delta Regeer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; 2008-01-27&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Function:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	Add numbers together that are provided as arguments to the program in argv[1] and argv[2].&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Known limitations:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	As of right now, the numbers that are provided may not add up to anything more than 9.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	This will hopefully be fixed in the next revision. Floating point numbers will not work.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Todo:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	Write conversion routine, to convert a string of numbers into a real integer on which&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;;	math may be performed.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Define some strings that are going to be used throughout the program&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This string is to let the user know they failed to provide the proper amount of arguments.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;args	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;	&amp;quot;You failed to provide the proper amount of arguments&amp;quot;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0xa&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;largs	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;equ&lt;&#x2F;span&gt;&lt;span&gt;	$ - args&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; This string contains part of the output that we are going to send to the terminal. The last two&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; bytes will be filled automatically by the program, before it is output to stdout.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;msg	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;db&lt;&#x2F;span&gt;&lt;span&gt;	&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;Answer&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; &amp;#39;,	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lmsg	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;equ&lt;&#x2F;span&gt;&lt;span&gt;	$ - msg&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;section .text&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;global start				&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Linker defined entry point. Mac OS X this is start. FreeBSD and others _start.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;global _start&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;_start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Start the program here.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; We don&amp;#39;t care about argc or argv[0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; 	ecx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Get the first argument or argv[1]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jecxz&lt;&#x2F;span&gt;&lt;span&gt;	exit			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; If there was no argument. Exit. Let the user know why&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Change the number from a character to an actual dword&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dword&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ecx&lt;&#x2F;span&gt;&lt;span&gt;]	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the character into eax so we can manipulate it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	sub&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Remove 0x30 from the character. To make it an actual number, not an ASCII number.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	pop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ecx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; get the second argument or argv[2]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jecxz&lt;&#x2F;span&gt;&lt;span&gt;	exit			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; If there was no second argument. Exit. Let the user know why&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dword&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ecx&lt;&#x2F;span&gt;&lt;span&gt;]	&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Move the character into ebx so we can manipulate it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	sub&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	ebx&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Remove 0x30 from the character. To make it an actual number, not an ASCII number.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;ebx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Add the two numbers together&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;0x30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Make it an ASCII number again&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[msg+lmsg-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Replace the null character in the msg with the answer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span&gt;	[msg+lmsg-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0xa&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; Add an newline character so that when it spits it out it is neatly formatted&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;				&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; Call sys_write&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; lmsg		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the length of the string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span&gt;	msg			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the location of the string in memory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the file descriptor to write to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Advance the stack pointer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	jmp&lt;&#x2F;span&gt;&lt;span&gt;	done			&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Program is done. Jump to done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;exit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; Call sys_write&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; largs		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the length of the string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span&gt; args		&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;; Push the location of the string in memory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the file descriptor to write to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	esp&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;byte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Advance esp past the part we were just at&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				; sys_exit&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;	dword&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0x1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;		; Push the value to return to the operating system&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	mov&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Move the syscall number into eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;	eax&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Push the syscall onto the stack&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;	int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;	0x80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;			; Interrupt 80, go to kernel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;	; We never return to this function, so no need to clean the stack.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>X11 mouse button pressed</title>
        <published>2007-03-16T04:51:34+00:00</published>
        <updated>2007-03-16T04:51:34+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2007/x11-mouse-button-pressed/"/>
        <id>https://funcptr.net/2007/x11-mouse-button-pressed/</id>
        
        <content type="html" xml:base="https://funcptr.net/2007/x11-mouse-button-pressed/">&lt;p&gt;For a Rube Goldberg device I needed a way to know if a mouse button was
pressed on the root window of an X11 screen. Here is the code for it:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;stdio.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;stdlib.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;string.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;unistd.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;X11&#x2F;Xlib.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;X11&#x2F;Xutil.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        Display &lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;dsp &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; XOpenDisplay&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;( NULL )&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;dsp ){&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; screenNumber &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; DefaultScreen&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(dsp)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;        long&lt;&#x2F;span&gt;&lt;span&gt; eventMask &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; StructureNotifyMask;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        XSelectInput&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;( dsp,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; DefaultRootWindow&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(dsp), eventMask )&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        XEvent evt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        eventMask &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; ButtonPressMask&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;ButtonReleaseMask;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;        XSelectInput&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(dsp,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; DefaultRootWindow&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(dsp), eventMask)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; &#x2F;&#x2F; override prev&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;        do&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;                XNextEvent&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;( dsp,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;evt )&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;   &#x2F;&#x2F; calls XFlush()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span&gt; ( (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;evt&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; ButtonRelease)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;evt&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; ButtonPress) )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;                exit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; while&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; );&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Compile:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;gcc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -lX11 -L&#x2F;usr&#x2F;local&#x2F;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; x11.c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -o&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; x11-mousebutton&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Upon a mouse button being pressed it will exit 2, so using that return value
in some script you can execute a command. For example, to open a CD rom
drive so a domino falls over.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>FreeBSD GEOM striping and concatenation</title>
        <published>2006-12-13T06:44:20+00:00</published>
        <updated>2006-12-13T06:44:20+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2006/freebsd-geom-striping-and-concatenation/"/>
        <id>https://funcptr.net/2006/freebsd-geom-striping-and-concatenation/</id>
        
        <content type="html" xml:base="https://funcptr.net/2006/freebsd-geom-striping-and-concatenation/">&lt;p&gt;Some of the hard drives in my FreeBSD box. Just a little back-story:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad0 - 20 GB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad1 - 40 GB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad2 - 100 GB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad3 - 60 GB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;da0 - 8 GB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;da1 - 8 GB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I had already made a &lt;code&gt;gstripe(8)&lt;&#x2F;code&gt; out of the two SCSI drives, &lt;code&gt;da[1|2]&lt;&#x2F;code&gt;,
however I wanted to see if I could do the same with &lt;code&gt;ad[1|2|3]&lt;&#x2F;code&gt;. As I did
not want to resort to gvinum, which is rather heavy, and I was unable to
figure out how it worked. The entire point behind gstripe is that since it
is striped, the writes&#x2F;reads are faster since it writes&#x2F;reads to all the
drives at the same time. So first I tried:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;gstripe&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; label&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; st1 &#x2F;dev&#x2F;ad1 &#x2F;dev&#x2F;ad2 &#x2F;dev&#x2F;ad3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That however complained that it would only use 40 GB&#x27;s on all of the
drives, since the smallest drive in the collection was 40 GB. I then read
up on &lt;code&gt;gconcat(8)&lt;&#x2F;code&gt;, which concatenates all the drives together to look
like one big drive, without the speed improvement of striping. So I
figured, since FreeBSD&#x27;s gstripe is GEOM based, it should not care about
what the underlying data sink is, just that it is a device, so just maybe
this could work:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;gconcat&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; label&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; gb100 &#x2F;dev&#x2F;ad1 &#x2F;dev&#x2F;ad3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So now I had created a 100 GB &quot;hd&quot; at &lt;code&gt;&#x2F;dev&#x2F;concat&#x2F;gb100&lt;&#x2F;code&gt;. I now did what
I was planning to do:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;gstripe&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; label&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; st1 &#x2F;dev&#x2F;ad2 &#x2F;dev&#x2F;concat&#x2F;gb100&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;No problem. I now had 180.48 GB, of which only about 166 GB was usable.
Which is still excellent. As it still came with a speed improvement.
Followed up with the standard advice from &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;www.freebsd.org&#x2F;doc&#x2F;en_US.ISO8859-1&#x2F;books&#x2F;handbook&#x2F;geom-striping.html&quot;&gt;the handbook&lt;&#x2F;a&gt; I did the
following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;bsdlabel&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -wB&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;dev&#x2F;stripe&#x2F;st1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;newfs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -U&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;dev&#x2F;stripe&#x2F;st1a&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;dev&#x2F;stripe&#x2F;st1a &#x2F;mnt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Which got me the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;stripe&#x2F;st1a    180G    5.5G    161G     3%    &#x2F;mnt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Full:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Filesystem          Size    Used   Avail Capacity  Mounted on&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad0s1a         496M     63M    393M    14%    &#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;devfs               1.0K    1.0K      0B   100%    &#x2F;dev&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad0s1e         496M    230K    456M     0%    &#x2F;tmp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad0s1f          15G    2.2G     11G    17%    &#x2F;usr&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;ad0s1d         1.4G    115M    1.2G     9%    &#x2F;var&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;stripe&#x2F;st0a     16G    4.0K     15G     0%    &#x2F;usr&#x2F;scsi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;dev&#x2F;stripe&#x2F;st1a    180G    5.5G    161G     3%    &#x2F;mnt&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Next up I might actually add &lt;code&gt;gdbe(8)&lt;&#x2F;code&gt; or &lt;code&gt;geli(8)&lt;&#x2F;code&gt; even in front of the
stripe, so that I will have an encrypted stripe. Talk about stacking.
Might give gvinum a try sometime.&lt;&#x2F;p&gt;
&lt;p&gt;All working:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;keyhole# gconcat status&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        Name  Status  Components&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;concat&#x2F;gb100      UP  ad1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                      ad3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;keyhole# gstripe status&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      Name  Status  Components&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;stripe&#x2F;st0      UP  da0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    da1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;stripe&#x2F;st1      UP  ad2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    concat&#x2F;gb100&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>FastCGI quick and dirty</title>
        <published>2006-09-13T00:19:31+00:00</published>
        <updated>2006-09-13T00:19:31+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2006/fastcgi-quick-and-dirty/"/>
        <id>https://funcptr.net/2006/fastcgi-quick-and-dirty/</id>
        
        <content type="html" xml:base="https://funcptr.net/2006/fastcgi-quick-and-dirty/">&lt;p&gt;In this quick and dirty guide for FreeBSD I will assume you have already
compiled and installed PHP5 with fcgi mode enabled, which can be checked by
running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;usr&#x2F;local&#x2F;bin&#x2F;php-cgi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I will also assume you have installed &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; from &lt;code&gt;www&#x2F;mod_fastcgi&lt;&#x2F;code&gt;
in the ports.&lt;&#x2F;p&gt;
&lt;p&gt;Create the fast cgi ipc temp dir, make sure you place this somewhere it will
keep existing:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;var&#x2F;tmp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mkdir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;var&#x2F;tmp&#x2F;fcgi-ipc&#x2F;dynamic&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;chmod&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -R&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0777&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;var&#x2F;tmp&#x2F;fcgi-ipc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s create the directory where we are going to place our PHP wrapper, this
config is for server wide using the same FastCGI PHP config. This is on
purpose, since it will allow server wide PHP usage. If you want you could then
split it up into virtualhosts if one required a standalone php running for
that.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mkdir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;chmod&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 755&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Next up we create the very simple wrapper:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;cat&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; EOF&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;# To use your own php.ini, comment the next line and uncomment the following one&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;#PHPRC=&amp;quot;&#x2F;usr&#x2F;local&#x2F;etc&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;export PHPRC&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;PHP_FCGI_CHILDREN=8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;export PHP_FCGI_CHILDREN&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;exec &#x2F;usr&#x2F;local&#x2F;bin&#x2F;php-cgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;EOF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Set &lt;code&gt;PHP_FCGI_CHILDREN&lt;&#x2F;code&gt; to whatever value you want, that is how many processes
it will use. I suggest the standard which is 8, if you make it more, you use
more ram, you make it less Apache will have to wait if all of the PHP
processes are in use.&lt;&#x2F;p&gt;
&lt;p&gt;Next up, make it executable:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;chmod&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; +x &#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Last but not least, edit &lt;code&gt;httpd.conf&lt;&#x2F;code&gt; and make sure to add a comment in front
of the &lt;code&gt;mod_php5&lt;&#x2F;code&gt; line, and uncomment the &lt;code&gt;mod_fastcgi&lt;&#x2F;code&gt; line. Then add this
to the end of your Apache config:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;IfModule mod_fastcgi.c&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FastCgiIpcDir &#x2F;var&#x2F;tmp&#x2F;fcgi-ipc&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    FastCgiConfig  -pass-header HTTP_AUTHORIZATION&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddHandler  fastcgi-script              .fcgi .fcg .fpl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Action      application&#x2F;x-httpd-php5    &#x2F;fastcgi-bin&#x2F;php5.fcgi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AddType     application&#x2F;x-httpd-php5    .php .php5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;IfModule&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ScriptAlias &#x2F;fastcgi-bin&#x2F; &amp;quot;&#x2F;usr&#x2F;local&#x2F;www&#x2F;fastcgi-bin&#x2F;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;Location &#x2F;fastcgi-bin&#x2F;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Options ExecCGI&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    SetHandler fastcgi-script&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Order allow,deny&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Allow from all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;Location&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That&#x27;s it. Restart apache and watch as the first time you access a PHP script
FastCGI will spawn several of them, and they start serving requests. Load
usage may seem higher, that is because unlike Apache the standalone running
PHP&#x27;s handle the jobs as they come in with whatever one is first, Apache will
try to put as much work in one of its preforked modules. As the PHP processes
come and go through FastCGI the memory usage will go up and down. Mine has
an average of about 300 MB, which is very good compared to the 800 MB Apache
with &lt;code&gt;mod_php&lt;&#x2F;code&gt; would rack up.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Backup Script</title>
        <published>2006-09-09T00:33:02+00:00</published>
        <updated>2006-09-09T00:33:02+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2006/backup-script/"/>
        <id>https://funcptr.net/2006/backup-script/</id>
        
        <content type="html" xml:base="https://funcptr.net/2006/backup-script/">&lt;p&gt;I was working on some backup scripts and I decided I might as well generalise
almost all of it (I am sorry about the hard coded paths) so almost anyone can
come grab it and use it on their servers. The shell script is pretty self
explanatory and I am not very good at documenting code, so the script source
itself is your best bet as to why I did something some way. This script is in
production use on several servers I administrate, I hope someone can use it as
well.&lt;&#x2F;p&gt;
&lt;p&gt;Documentation on how to use it:&lt;&#x2F;p&gt;
&lt;p&gt;A backup script which will mount &lt;code&gt;&#x2F;backup&lt;&#x2F;code&gt;, then use rsync to copy files from
&lt;code&gt;&#x2F;usr&#x2F;home&lt;&#x2F;code&gt; to &lt;code&gt;&#x2F;backup&#x2F;yyyy-mm-dd&lt;&#x2F;code&gt;. After it is done, it will remove the
oldest backup, 14 days ago. All paths are hardcoded.&lt;&#x2F;p&gt;
&lt;p&gt;If a file &lt;code&gt;.exclude&lt;&#x2F;code&gt; is in a user&#x27;s homedir, it is looked at, and is used to
exclude certain directories or files from the rsync. For example:&lt;&#x2F;p&gt;
&lt;p&gt;In &lt;code&gt;&#x2F;usr&#x2F;home&#x2F;xistence&#x2F;.exclude&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;public_html&#x2F;iso&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;No trailing slash, this will cause the folder
&lt;code&gt;&#x2F;usr&#x2F;home&#x2F;xistence&#x2F;public_html&#x2F;iso&lt;&#x2F;code&gt; to not be backed up. This might be for
various reasons, but for this example it is because backing up GB sized files
should not be something that is done, only because it takes ages and wastes
valuable space.&lt;&#x2F;p&gt;
&lt;p&gt;Thing to keep in mind is, if you want to backup a 40 GB HD, with 22 GB used,
to keep even a 3 day backup of that would require 3 * 22 GB, or 66 GB of
available space on the backup drive. It is therefore in one&#x27;s best interest
to exclude very large files, and back them up in a different method since
they are most likely not going to change much across revisions.&lt;&#x2F;p&gt;
&lt;p&gt;This script should be set to cron every 30 minutes, as rsync will do one full
backup when the day changes, and then from there on do incremental backups.&lt;&#x2F;p&gt;
&lt;p&gt;Maybe removing the &lt;code&gt;--delete&lt;&#x2F;code&gt; option might help with customers that delete
files and expect them to still be in the backup for that day, this way
however if a file is removed it will still exist in the backup until it is
deleted after 14 days.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;#!&#x2F;usr&#x2F;local&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# This file REQUIRES bash, and can not be run under &#x2F;bin&#x2F;sh!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;###&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # Copyright 2006 Delta Regeer. All rights  reserved.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # Redistribution and use in source and binary forms, with or without&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # modification, are permitted provided that the following conditions&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # are met:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # 1. Redistributions of source code must retain the above copyright&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #    notice, this list of conditions and the following disclaimer.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # 2. Redistributions in binary form must reproduce the above copyright&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #    notice, this list of conditions and the following disclaimer in the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #    documentation and&#x2F;or other materials provided with the distribution.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;#39;&amp;#39; AND&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # SUCH DAMAGE.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # The views and conclusions contained in the software and  documentation are&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # those of the authors and should not be  interpreted as representing official&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; # policies, either expressed  or implied, of bsdPanel project.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt; #&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;###&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; HOMEDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;usr&#x2F;bin&#x2F;find&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -maxdepth&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;^.$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;	if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $HOMEDIR&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;.exclude ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;		echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Exclude found for &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$HOMEDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;		while&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt; read&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; line&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;			if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;${&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;				# They are missing a full path, we will be nice and add it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;				TMPLINE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$HOMEDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;				line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$TMPLINE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;			fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;			echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;	Excluding &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;			echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;tmp&#x2F;exclude.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;$$&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;		done&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $HOMEDIR&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;.exclude&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;	fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; $?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; -ne&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	&#x2F;sbin&#x2F;mount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;	if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; $?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; -ne&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;		logger&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -s -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; user.err&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; backup&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Backup drive could not be mounted! Bailing!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;		&#x2F;sbin&#x2F;umount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;		exit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;	fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;BACKUPDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;&#x2F;backup&#x2F;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;date&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;+%Y-%m-%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;OLDDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;&#x2F;backup&#x2F;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;date&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -v-14d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;+%Y-%m-%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; ! -d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $BACKUPDIR&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	mkdir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $BACKUPDIR&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; $?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; -ne&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	logger&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -s -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; user.err&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; backup&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Could not create backup folder &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$BACKUPDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;. Bailing!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	&#x2F;sbin&#x2F;umount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;	exit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #637777;font-style: italic;&quot;&gt;# We got this far, now we have to run rsync. Rsync is very verbose on purpose&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;usr&#x2F;local&#x2F;bin&#x2F;rsync&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -av --relative --delete&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;usr&#x2F;home&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $BACKUPDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; --exclude-from=&#x2F;tmp&#x2F;exclude.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;$$&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; $?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; -ne&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	logger&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -s -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; user.err&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; backup&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;rsync failed. Do not trust backup (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$BACKUPDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	&#x2F;sbin&#x2F;umount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;	exit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F78C6C;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;font-style: italic;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Backup complete! Deleting oldest backup (14 days ago)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; -d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $OLDDIR&lt;&#x2F;span&gt;&lt;span&gt; ];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; then&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;	rm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -rf&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; $OLDDIR&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;fi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;sbin&#x2F;umount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;backup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;&#x2F;bin&#x2F;rm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; &#x2F;tmp&#x2F;exclude.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;$$&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;logger&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -s -p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; user.notice&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; backup&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;Backup complete at &lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;$BACKUPDIR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
</feed>
