<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by buffer0x7cd on Medium]]></title>
        <description><![CDATA[Stories by buffer0x7cd on Medium]]></description>
        <link>https://medium.com/@manav503?source=rss-43ff4bf28246------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DtQFxd1qyGphC6Pj.jpg</url>
            <title>Stories by buffer0x7cd on Medium</title>
            <link>https://medium.com/@manav503?source=rss-43ff4bf28246------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 09:07:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manav503/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Strace to perform fault injection in system calls.]]></title>
            <link>https://medium.com/@manav503/using-strace-to-perform-fault-injection-in-system-calls-fcb859940895?source=rss-43ff4bf28246------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcb859940895</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[strace]]></category>
            <category><![CDATA[linux-kernel]]></category>
            <dc:creator><![CDATA[buffer0x7cd]]></dc:creator>
            <pubDate>Mon, 20 Jan 2020 20:33:34 GMT</pubDate>
            <atom:updated>2020-01-21T06:18:27.761Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Strace for performing fault injection in system calls.</h3><p>Gracefully handling failures in system calls is one of the most important parts of writing any low-level system code. While many of the Linux systems calls are well defined and have easy to reproduce failure conditions, some of them still lack an easy way to mimic a failure condition.</p><p>For example, let’s say your application uses the <strong>fork</strong> (Note, In modern Linux systems <strong>fork, </strong>is a wrapper around <strong>clone </strong>system call) system call to create a new process and do some processing in the child process. Now to test that your application handles the <strong>fork</strong> failure properly, you have written an appropriate error handler, but now the question remains how are you going to test this code path?</p><p>lest’s take the below code snippet as an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fad32353e8607e259a386489a2d687a/href">https://medium.com/media/3fad32353e8607e259a386489a2d687a/href</a></iframe><p>As we can see in the above code snippet, we are checking if the call to fork fails and then doing some post-processing in case it fails(albeit a very simple one, where the program prints the fork error message and then exit).</p><p>As we can see in the above code, lines 4 to 7 are only executed if the call to fork fails. One way of achieving this to run a program and create lots of processes so that any further call to <strong>fork </strong>starts failing, but this approach is very destructive and is very expensive to implement. Another alternative is to use the Linux kernel&#39;s <strong>PID </strong>cgroup functionality and put a very low limit on the running process(you can get more details about <strong>PID </strong>cgroup <a href="https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt">here</a>), But the issue with this approach is that we don’t have flexibility where we can specify things like <strong>Make every 4th call to fork fail, etc.</strong> Also, there are a lot of system calls that can’t be controlled with cgroups. examples like <strong>connect, wait, etc.</strong></p><p>One very easy to use tool for these kinds of requirements is Strace. While Strace is a very popular tool to inspect any kind of system calls that are being performed by the process. It also has the ability to inject errors for system calls inside a target process.</p><p>Taking the below code snippet as an example, let’s see how Strace can be used to make a system call fail inside a target process.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f6cc2669bc18791a85869cf74798776/href">https://medium.com/media/4f6cc2669bc18791a85869cf74798776/href</a></iframe><p>Inline 35 to 39, we are creating a child process, printing some information messages and then immediately exiting out.</p><p>On line 42, we are calling wait on the child process, so that the exited child process can be cleared from kernel’s process table.</p><p>Let’s check a normal execution of the above program.</p><pre>&gt; gcc -o fork-example fork-example.c<br>&gt; ./fork-example<br>Waiting for the child to terminate in Parent with PID 2745<br>Running in child process with PID: 2746<br>Child with PID 2746 exited</pre><p>Looks good. now let’s test our <strong>Fork </strong>function and ensure that it’s handling the errors in <strong>fork</strong> system call properly by causing the call to <strong>fork</strong> fail</p><pre>&gt; strace -e trace=clone -e fault=clone:error=EAGAIN ./fork-example</pre><pre>clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fb29819d790) = -1 EAGAIN (Resource temporarily unavailable) (INJECTED)<br><strong>Error, while calling fork</strong><br>: Resource temporarily unavailable<br>+++ exited with 1 +++<br></pre><p>Here, as we can see that the call to fork is failed in the target process and our error handler code got executed successfully. Now let’s breakdown the above Strace command to understand how does the fault injection works.</p><ul><li><strong>- e trace=clone</strong> this instruct Strace to only trace the <strong>clone </strong>system call (Note: on a modern Linux system, <strong>fork </strong>is only a Glibc wrapper function which uses the <strong>Clone</strong> system call to create new processes ( This will be covered in another blog but you can read more about the working of <strong>Fork and Clone </strong><a href="https://eli.thegreenplace.net/2018/launching-linux-threads-and-processes-with-clone/">here</a>.)</li><li><strong>- e fault=clone:error=EAGAIN </strong>This instruct Strace to inject the error in all invocations to <strong>clone</strong> system call and set the error response to <strong>EAGAIN. </strong>Definition of EAGIN from the clone(2) man page</li></ul><pre>EAGAIN Too many processes are already running; see fork(2).</pre><p>One another useful option while performing the fault injection is the <strong>when</strong> directive, which can make the <strong>nth</strong> invocation to a system call fail. for example</p><pre>strace -e trace=wait4 -e inject fault=wait4:when=4:error=EINVAL TARGET_PROCESS</pre><p>This will make every 4th call to <strong>wait</strong> to fail inside the TARGET_PROCESS</p><p>While in most of the example above, the process is invoked through Strace, The above-mentioned technique works for any other long-running process that Strace can be attached to like Nginx, python, or JVM, etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcb859940895" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build docker images inside a Jenkins container.]]></title>
            <link>https://medium.com/@manav503/how-to-build-docker-images-inside-a-jenkins-container-d59944102f30?source=rss-43ff4bf28246------2</link>
            <guid isPermaLink="false">https://medium.com/p/d59944102f30</guid>
            <category><![CDATA[continous-integration]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[continous-deployment]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[buffer0x7cd]]></dc:creator>
            <pubDate>Sun, 22 Apr 2018 17:57:46 GMT</pubDate>
            <atom:updated>2018-04-22T18:07:42.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mCWtnSrtDhL0Gy0xeTgMVw.png" /></figure><p>Every now and then, I come across cases where I need to build docker images inside a Jenkins container, as part of CI/CD process. Although we can run docker inside docker using <a href="https://github.com/jpetazzo/dind"><strong>dind</strong></a>, but it’s not a recommended practice due to various risks of data corruption that comes with it( you can read the details about <strong>dind </strong>in this blog <a href="http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/">post</a>)</p><p>After researching for sometime about this topic, I came across a solution which involves <strong><em>mounting the host machine’s docker socket to the Jenkins container</em></strong>, This way Jenkins can start new sibling containers( note, we are using the word siblings here instead of child containers due to the fact that, newly created container will run along side the Jenkins container rather then running inside Jenkins container).</p><p>We still need to install the docker client binaries inside our Jenkins container so that our container can talk to the mounted docker daemon.</p><h4>Step-1: Build the docker image.</h4><p>This Dockerfile will use a Jenkins container as a base image and then install the docker client , So that it can communicate with the docker daemon.</p><pre>from jenkinsci/jenkins:lts<br> <br>USER root<br>RUN apt-get update -qq \<br>    &amp;&amp; apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common <br>RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -<br>RUN add-apt-repository \<br>   &quot;deb [arch=amd64] https://download.docker.com/linux/debian \<br>   $(lsb_release -cs) \<br>   stable&quot;<br>RUN apt-get update  -qq \<br>    &amp;&amp; apt-get install docker-ce=17.12.1~ce-0~debian -y<br>RUN usermod -aG docker jenkins</pre><p>(you can clone the Dockerfile from this github <a href="https://github.com/Buffer0x7cd/jenkins-docker">repo</a>)</p><p>Build the image with below command</p><p>$ docker image build -t jenkins-docker .</p><p><strong>Note: </strong><em>Change the version of docker inside the Dockerfile based on your own requirements.</em></p><h4>Step-2: Start the container with mounted docker daemon</h4><p>After successfully building the container in step 1 we need to run the container with mounted docker daemon</p><p>$ docker container run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock jenkins-docker</p><p><strong>Note:</strong><em> The docker daemon running on host machine must be compatible with docker client running in Jenkins container. check the version of the host with</em><strong> </strong>docker --version <em>and install the appropriate version of docker client inside the Jenkins container.</em></p><h4>Conclusion:</h4><p>Your Jenkins container now should have a functional docker installation. verify it by running</p><p>docker container ls</p><p>From inside the Jenkins container. The output should have same as running docker container ls from the docker host.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d59944102f30" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>