<?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 Daniel Trugman on Medium]]></title>
        <description><![CDATA[Stories by Daniel Trugman on Medium]]></description>
        <link>https://medium.com/@dtrugman?source=rss-77e2dc5a5df6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4UZULZRHWcJAhkStreCcrw.png</url>
            <title>Stories by Daniel Trugman on Medium</title>
            <link>https://medium.com/@dtrugman?source=rss-77e2dc5a5df6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:54:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dtrugman/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[Share your terminal like never before]]></title>
            <link>https://medium.com/d-bits/share-your-terminal-like-never-before-5ee7359a84a8?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ee7359a84a8</guid>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[cli]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 10:50:46 GMT</pubDate>
            <atom:updated>2022-08-29T10:50:46.943Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Hacking the Pentagon? Magically solving production issues? Inventing the craziest customer demos? If you did that via CLI and never had the time to write that Wiki document, this is for you.</em></p><p>Everywhere you go, everyone uses CLI tools to boost up productivity. After all, it is way quicker to write a small script to run an automated process, whether it’s setting up a new company laptop, fetching some data from a DB or generating a report. Those CLI based standard operating procedures are very useful, and are definitely here to stay.</p><p>Let’s take a real life example. An engineering team has an integration tests with a glitch. In some scenarios, a duplicate DB record is created and that prevents the test from passing. One of the team members would log into the database and run an SQL DELETE statement. But, since that wouldn’t happen very often, some members have never done that or don’t even know how to connect to the DB.</p><p>One way would be to write a Wiki page, that will work. But the inherent overhead of writing a guide is not insignificant. Another is to write a script, which is by far the best option, but then again, writing a robust, high-quality script is not a 5-min task.</p><p>Luckily for us, there is another way, one where you can just run through the steps once and share it with the next person. It’s called <a href="https://asciinema.org/"><strong>asciinema</strong></a>. It allows you to record and share your terminal sessions, the simple way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-maemSBxvEj19HhK0IDNQ.png" /></figure><p>Consider for example the following scenario. A user created a <a href="https://github.com/archzfs/archzfs/issues/337#issuecomment-622950175">ticket</a> for an open source project and decides to share the steps with the maintainers. He records himself following the steps and uploads that to the <a href="https://github.com/archzfs/archzfs/issues/337#issuecomment-622950175">comment</a>. Easy, right? But that’s not even the best part. These videos are special. Why? Because <strong>you can actually copy text from the video and paste it into your terminal!</strong> Mind-blowing.</p><p>Installing on a Mac is as easy as running a homebrew or pip command (there are many options available on their <a href="https://asciinema.org/docs/installation">official installation page</a>).</p><p>Recording is even easier, just run asciinema rec &lt;filename&gt; . To finish, hit Ctrl-D or type exit . You can then play the recordings on your laptop or upload them to their website. Find all the usage details on <a href="https://asciinema.org/docs/usage">this page</a>.</p><p>Great seeing you again! Hope you had fun.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ee7359a84a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/share-your-terminal-like-never-before-5ee7359a84a8">Share your terminal like never before</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Calendar power tips]]></title>
            <link>https://medium.com/d-bits/calendar-power-tips-b447c4f39e62?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b447c4f39e62</guid>
            <category><![CDATA[calendar]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[gmail]]></category>
            <category><![CDATA[g-suite]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 12:21:01 GMT</pubDate>
            <atom:updated>2022-08-21T12:23:59.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bxlTDvow6CrRiRjL.jpg" /></figure><p><em>If you’re using Google Calendar, these neat tricks might save you a bunch of time that you can then spend on the important things in life.</em></p><h4>Tip #1: Use keyboard shortcuts</h4><p>If you’re as used to keyboard shortcuts as I am, it won’t take you long to understand how much time you’ve spent mouse-ing your way around. Just press ? to see all the shortcuts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HSQ92vpaVzRKxc5LIqz8ZQ.png" /></figure><h4>Tip #2: Instantly create a new meeting</h4><p><em>That’s probably the trick I like the most!</em> Navigating to <a href="http://cal.new/">cal.new</a> in your browser will automatically redirect you to a ‘create new event’ page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ihyn2ugzI7NUdB7T91xWYw.png" /></figure><p><strong>Liked it? Try </strong><a href="http://doc.new/"><strong>doc.new</strong></a><strong>, </strong><a href="http://sheet.new/"><strong>sheet.new</strong></a><strong>, </strong><a href="http://form.new/"><strong>form.new</strong></a><strong>, </strong><a href="http://slide.new/"><strong>slide.new</strong></a><strong> &amp; </strong><a href="http://site.new/"><strong>site.new</strong></a><strong> as well!</strong></p><h4>Tip #3: Create a new meeting from an email thread</h4><p>Want to discuss an email with all the thread participants? From inside the email thread, click the three dots menu at the top and select ‘Create event’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1fKwO_p1TFhpuyYFKEfSw.png" /></figure><p>The meeting will automatically include all the discussion from the email thread, so it’s easier to prepare for.</p><h4>Tip #4: Email all meeting attendees</h4><p>Were you responsible for taking notes during the meeting? If you are looking for an easy way to share them with all the other participants, just click the small button that does exactly that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ebzWh3EuWI-hCJwCp7fnw.png" /></figure><h4>Tip #5: Generate a daily agenda email</h4><p>If you find it useful to receive a daily agenda email rather than going into the calendar and checkin it yourself, just configure an automatic daily agenda.</p><p>Navigate to <a href="https://google.calendar.com/">google.calendar.com</a> and click the three dots icon next to the calendar of interest, and click ‘Settings and sharing’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSPHHkZBC3OEARZUUGCxvQ.png" /></figure><p>From the left-hand menu, choose ‘Other notifications’ and change the ‘Daily agenda’ from ‘None’ to ‘Email’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BxWeaRJhTnipO90fiYztw.png" /></figure><h4>Tip #6: Change event owner</h4><p>There are many reasons for using this feature. For me, it was a teammate who switched jobs, so they had to re-assign some monthly product meetings to me. In other cases, it might be as simple as letting someone else handle a customer meeting when you aren’t feeling too well. Just click the meeting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bKMn73bxzP94p11vPMWHIg.png" /></figure><p>And from the three-dot menu, choose ‘Change owner’ and elect the destined meeting ruler with your blessing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QAGIhxwW1bUhYh2ABvNpBg.png" /></figure><p>That’s it for today! Hope you enjoyed it and your Google Calendar experience will be more efficient than ever.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b447c4f39e62" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/calendar-power-tips-b447c4f39e62">Google Calendar power tips</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep your MacBook alive & kickin’]]></title>
            <link>https://medium.com/d-bits/keep-your-macbook-alive-kickin-ae203373910a?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae203373910a</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[sleep]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[macbook]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Wed, 10 Aug 2022 16:34:54 GMT</pubDate>
            <atom:updated>2022-08-10T21:44:04.783Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Had enough of your company laptop locking itself while you read the document? Ever trained ML models on your laptop and realized the process was cut short?</em></p><p><strong><em>Instead of wiggling your mouse every few seconds, just install </em></strong><a href="https://apps.apple.com/us/app/owly-prevent-display-sleep/id882812218?mt=12"><strong><em>Owly</em></strong></a><strong><em>!</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPh3PG3Ap3tw4aezL5NgYw.png" /></figure><p><a href="https://apps.apple.com/us/app/owly-prevent-display-sleep/id882812218?mt=12">Owly</a> is a small application for MacOS that you can download through the App Store, and its entire purpose is preventing your monitor from going to sleep.</p><p>The application is super easy, once you install it, you get a small widget in your Mac’s menu bar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QtiP6dkeSmUsz1ojAOmEGw.png" /></figure><p>When you click the icon, you get a straightforward menu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*dwPVR5gwL4fvD-alMlwtsQ.png" /></figure><p>Just choose the amount of time you want the Mac to stay awake, and get your CPU to keep on crunching those neural networks for you while you grab a cuppa.</p><p>Ohh, and it supports the new M1 processors, which is nice.</p><p><strong><em>Disclaimer: I don’t get any royalties from the app, I just enjoy it.</em></strong></p><p>Thanks for reading. Hope you found it useful! See you next week.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae203373910a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/keep-your-macbook-alive-kickin-ae203373910a">Keep your MacBook alive &amp; kickin’</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create your next step-by-step guide in no time]]></title>
            <link>https://medium.com/d-bits/create-your-next-step-by-step-guide-in-no-time-a128e869ac3f?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a128e869ac3f</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[scribe]]></category>
            <category><![CDATA[free]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Sun, 17 Jul 2022 20:57:47 GMT</pubDate>
            <atom:updated>2022-07-18T22:57:56.842Z</atom:updated>
            <content:encoded><![CDATA[<p>Every Software engineer I know creates step-by-step guides for different processes. Either for their own team-members, QA teams, support or customers. Eventually, we all find ourselves writing Wikis, taking snapshots and marking buttons with red rectangles using Preview, Paint, Inkscape or whatever your personal preference is.</p><p>Today, I will share with you a tool called <a href="https://scribehow.com/">Scribe</a> that made my guide creation experience so much easier, and hopefully will make yours too!</p><p>All you need is their <a href="https://chrome.google.com/webstore/detail/scribe-%E2%80%94-documentation-so/okfkdaglfjjjfefdcppliegebpoegaii">Chrome plugin</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*02SsCZHwPqYPtHW2ICc-dw.png" /></figure><p>Then, it is as simple as it can be:</p><ul><li>You click the plugin and press ‘Start recording’</li><li>You do your thing</li><li>You click the plugin and press ‘Stop recording’</li><li>DONE!</li></ul><p>The browser automatically redirects to you to a page where your new guide is waiting for you to (optionally) add some final touch-ups and set it free!</p><p>Check out this totally-random tutorial for finding my top-ranked answer on Stack Overflow. It took me 1 minute(!) to create:</p><h3>Stackoverflow my-top-answer workflow</h3><p><a href="https://scribehow.com/shared/Stackoverflow_my-top-answer_workflow__eUTZN_AYRle-i0hx9VXQ7Q"><strong>Made by Daniel Trugman with Scribe</strong></a></p><p>1. Navigate to <a href="https://stackoverflow.com/">https://stackoverflow.com/</a></p><p>2. Click your profile picture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*YogCcHNc_OItgwK1" /></figure><p>3. Click “Score” under the “Answers” section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*6mcCDHp_enyOyjLy" /></figure><p>4. Click the first entry</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*TpBsXHB-kAiTSCTc" /></figure><p>You can then decide to share your newly created guide via their platform, embed it into multiple other supported platforms, <a href="https://scribehow.com/shared/Embedding_Scribes_into_Gmail_body__RmR_7uv7TfqFVmO0nAYFNQ">send it via Gmail</a> (a functionality introduced by the same plugin), export to PDF, Markdown, HTML or Confluence and more in a matter of seconds. And it looks amazing!</p><p>I hope you found this useful! For more tips and tricks on a regular basis, make sure to subscribe to <a href="https://medium.com/d-bits">D-Bits</a>, my weekly newsletter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a128e869ac3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/create-your-next-step-by-step-guide-in-no-time-a128e869ac3f">Create your next step-by-step guide in no time</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The easy & exciting git collaboration plugin you need]]></title>
            <link>https://medium.com/d-bits/the-easy-exciting-git-collaboration-plugin-you-need-cfbbe986dce5?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfbbe986dce5</guid>
            <category><![CDATA[collaboration]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Sat, 09 Jul 2022 13:21:26 GMT</pubDate>
            <atom:updated>2022-07-09T13:21:26.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*piqodUnyDraMreci.png" /></figure><p><em>Have you ever shared a git repository with other teams? Did someone ever change your code without you knowing? Keep on reading for a life-changing method to effectively enforce healthy coordination between code owners!</em></p><p>There’s a lot of discussion going on about monorepos vs. polyrepos. In case you haven’t heard those concepts before, monorepo means using a single repository where projects coexists next to each other, while polyrepo means using a repository per project. In practice, this is far from a dichotomy, and there’s a wide range of options for teams to choose from.</p><p>I personally never worked in a company where there’s actually a single repository for the entire engineering team. Yet I definitely had my share of collaboration over the same code repository with multiple other teams.</p><p>For example, in my previous job, we had a product that supported Linux, Windows and MacOS. We had four different teams, three platform teams for each of the aforementioned platforms (I was leading the Linux team) and a fourth one that was responsible for cross-platform code. Because we were sharing a lot of code between the teams and the products, we ended up using a single repository for all four teams.</p><p>I cannot overstate the importance of clearly communicating code changes in a shared repository. However, no matter how you try, people are going to push code that will have undesired and unexpected affects without CC’ing you on a CR. Sometimes it’s an honest mistake and other times it’s just because that’s how they manage to deliver their features on time. Even though I truly believe we had a superb work environment, you simply can’t avoid that. Amazon’s founder, Jeff Bezos, used to say:</p><blockquote>“Good intentions never work, you need good mechanisms to make anything happen”, Jeff Bezos</blockquote><p>Lucky for us, there is something that can do just that. The <strong>Code Owners</strong> plugin is a great mechanism to enforce those healthy collaboration practices in your git repository. It was introduced into <a href="https://github.blog/2017-07-06-introducing-code-owners/">Github</a> a few years ago, <a href="https://docs.gitlab.com/ee/user/project/code_owners.html">Gitlab</a> and <a href="https://gerrit.googlesource.com/plugins/code-owners/">Gerrit</a> soon followed suit and 3rd parties developed a similar plugin for <a href="https://github.blog/2017-07-06-introducing-code-owners/">Bitbucket</a>. I guess you’ll find it on pretty much every git platform today.</p><p>The idea is super simple. Just like with .gitignore files, you create a CODEOWNERS file in repository’s root directory (some platforms support additional locations) and use the a trivial format to define rightful owners for specific files or directories. It goes like this:</p><pre># Specific Code Owner[s] for a file<br>.gitlab-ci.yml @linux-dev1 @windows-dev1 @macos-dev1</pre><pre># Specific Code Owner[s] for all cpp files in the linux directory<br>linux/*.cpp @linux-teamlead @linux-dev1 @linux-dev2</pre><pre># Code Owners for a directory<br>windows/ @windows-dev1 @windows-dev2</pre><pre># You can also specify a group as Code Owners for a file<br>windows/config.json @windows-group</pre><p>As you can see, the format allows you to use wildcards and user groups to make code ownership management a simpler task as the company grows.</p><p>You might need to enable the plugin in your relevant CI/CD platform, for example, on GitHub:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nAW-YUMgVpUD2JEw" /></figure><p><strong>And that is it! </strong>Now, every time someone touches any of the owned files, the rightful owner will be automatically added to the CR and has to approve the changes before these are merged into the protected branch.</p><p>Liked the idea? Make sure to share it with others! Want to hear more productivity tricks? Subscribe to D-Bits for more weekly hacks and tips.</p><p>Want to learn more about Monorepos and tools that help improve collaboration and productivity? check out this <a href="https://monorepo.tools/#understanding-monorepos">website</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfbbe986dce5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/the-easy-exciting-git-collaboration-plugin-you-need-cfbbe986dce5">The easy &amp; exciting git collaboration plugin you need</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An amazing email productivity hack]]></title>
            <link>https://medium.com/d-bits/an-amazing-email-productivity-hack-c8b84cf4202e?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8b84cf4202e</guid>
            <category><![CDATA[gmail]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[lifehacks]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Sun, 03 Jul 2022 20:01:35 GMT</pubDate>
            <atom:updated>2022-08-09T23:26:18.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KL9zPO5M-KKi3EcuRU2rbg.png" /></figure><ul><li><em>Do you find yourself subscribing to newsletters?</em></li><li><em>Do you find yourself registering to different websites?</em></li><li><em>Do you find yourself manually arranging emails from different sources into different directories or creating per-site filters to do that for you?</em></li><li><em>Do you find yourself sharing your personal email when would’ve preferred not to?</em></li></ul><p><em>If you answered ‘Yes’ to any of those questions. The following is for you! I will share two tricks that will take your email management to the next level.</em></p><p>Before we start, let’s assume that you currently have a single email address box: <strong>my.personal@gmail.com</strong>.</p><h3>Trick #1: Never share your personal email ever again (Unless you want to…)</h3><p>This trick is a combination of two very neat features. It requires an additional mail box that you feel comfortable sharing. Let’s say we’ve created an extra mail box: <strong>my.public@gmail.com.</strong></p><p>You can now go to your <strong>new public mailbox</strong> and setup the first part — Forwarding. In Gmail, you can do that by going to: <em>Settings &gt; Forwarding and POP/IMAP &gt; Forwarding</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NOsxfZ0Nma4F24JS_cne_A.png" /></figure><p>One you add the forwarding address, you get an email to your personal mailbox to approve that, and that’s it, you never have to look at this email account ever again!</p><p>The second part is to go to your <strong>private mailbox</strong> and enable it to send emails under the new alias (Which is a really cool feature by itself). In Gmail, you can do that by going to: <em>Settings &gt; Accounts and Import &gt; Send mail as</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NR7XgzjxBhdFhKD0tmFpaw.png" /></figure><p>Again, you’ll have to approve that in your public mailbox once you receive the request email, and that’s it.</p><p><strong>Now, you can successfully receive and reply to emails sent to the public address from your personal inbox while retaining full control over the private address!</strong></p><h3>Trick #2: Easily manage different topics</h3><p>Now that we can easily subscribe to newsletters and shady websites using our public address, let’s make sure it’s SUPER easy to manage different topics.</p><p>Let’s say you want to buy a new car, and you’re going to be doing a significant amount of market research, but you don’t want to miss interesting newsletter feeds because of that. How does one go around that? Just use <strong>Plus Addressing (aka Subaddressing)!</strong></p><p>This awesome feature goes overlooked, but it’s actually priceless. The idea is super simple: You can append any +&lt;suffix&gt; to you address and incoming mails still hit the same inbox!</p><p>For example, if someone sends an email to my.public+car@gmail.com , the email will arrive at your inbox just like any other mail!</p><p>Now you can create super simple filters to get those emails skip the inbox and hit a dedicated folder:</p><ul><li>Move my.public+car@gmail.com to a car folder</li><li>Move my.public+newsletter@gmail.com to a newsletter folder</li><li>Etc. (You’re smart, you get the point)</li></ul><p>You can even decide to never see those again and simply send them straight to the trash bin!</p><p>Combined together, those two features take your email experience to a whole new level! And I hope this has the same effect for you as it did for me :)</p><p>Hope to see you again next week!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8b84cf4202e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/an-amazing-email-productivity-hack-c8b84cf4202e">An amazing email productivity hack</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New ways to e-meet]]></title>
            <link>https://medium.com/d-bits/new-ways-to-e-meet-13067d3b6ec1?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/13067d3b6ec1</guid>
            <category><![CDATA[video-conferencing]]></category>
            <category><![CDATA[online-meeting-software]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 17:55:29 GMT</pubDate>
            <atom:updated>2022-06-26T17:55:29.818Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a beginning of a weekly blog, where I will try to present a single, bite-sized idea or tool. The idea is not to write something fancy, but simply share something I’ve learned or discovered during the last week.</p><p>Today I’m going to share two platforms I recently discovered and I found really useful. Throughout the last two years, many of my interpersonal connections have become virtual. COVID was the initial trigger. Close friends became figures on my laptop screen, elder family members were hiding behind a safe network medium and the only ones to get an actual hug from were my wife and pets.</p><p>But that wasn’t the end for me. At the end of 2021 if found myself moving with my wife abroad. Leaving all our friends and family behind. Even though many of them visited us, relationships are built on top of frequent, intimate and high-quality communication. At the beginning, we tried using WhatsApp, but at the time, using a phone app really wasn’t the best experience. Then, we tried using Zoom, a platform we were all accustomed to from our work places, but it turned out most of us didn’t have a paid account through our employers anymore, and meetings were limited to 40 minutes. For some reasons, Google Meet didn’t really work well for us and just now did I realise we didn’t even consider Microsoft Teams. I was constantly looking for better solutions.</p><p>Just this week, when I was cleaning up my Google calendar, I noticed the ‘add plugins’ button and realised I never explored it before. When I clicked it, I found a world of different platforms that integrate with the calendar. Some were tools you were expecting to find in a corporate, and didn’t seem useful to me, but two plugin descriptions hinted that I’ve just found the solutions I was looking for.</p><p>The first one was <a href="http://around.co/">Around.co</a>. By their own words, Around is for:</p><blockquote>“<strong>Video calls loved by extraordinary teams”</strong></blockquote><p>Around supports all the platforms you would expect (Android, IOS, Any web browser, Windows, MacOS &amp; Linux) and is built for the future of hybrid work. Their biggest innovation is being able to support multiple participants connected from the same room, each using their own laptop without any annoying echos, allowing everyone to participate equally in the meeting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*219OTzK3c1Vi5hFZZVPVZw.png" /></figure><p>They also present new display layouts during the meeting. From focus modes, where an entire team can stay in the same meeting all day long and keep on working on their things while being able to reach out to anyone else in a hitch, to game modes that boost team productivity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jM4KDOAasvxQDuQgDNqE0Q.png" /></figure><p>But for me, there was another bottom line that made it very useful. Since many of my online meetings are 1 on 1s, I can use this platform for free without any time limits or restrictions. Especially if I’m collaborating with a peer on some open-source project or meeting a friend to discuss some investment options, this platform proved to be very useful.</p><p>The second one was <a href="https://crewdle.com/">Crewdle</a>, an online video conferencing solution that attempts to be:</p><blockquote>“<strong>The greenest videoconferencing solution in the world”</strong></blockquote><p>This one is relatively similar to the platforms we’re used to, but it definitely pushes a very important agenda, calculating the CO2, Water and Energy we all save every year by meeting and working online rather than commuting to the office.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4cHMB5bBzycsN4OScJLN_A.png" /></figure><p>They UI is very clean, the app is really easy to use and it works directly from your browser, so friends won’t complain about you asking them to install a new application. The experience as a whole is really great and it comes with a great plus: they have a personal plan with up to 30 participants and unlimited duration that is <a href="https://crewdle.com/pricing">FREE FOREVER</a>.</p><p>That’s it for today, I hope you’ll find this as helpful as I did. I already feel less dependent on Zoom and other paid platforms that held me captive. <strong>See you next week.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13067d3b6ec1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/d-bits/new-ways-to-e-meet-13067d3b6ec1">New ways to e-meet</a> was originally published in <a href="https://medium.com/d-bits">D-Bits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parsing the Linux procfs]]></title>
            <link>https://itnext.io/parsing-the-linux-procfs-f7343931d864?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7343931d864</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[parser]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Sun, 21 Feb 2021 20:50:08 GMT</pubDate>
            <atom:updated>2021-02-21T21:17:51.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*su04bPNqlSGyUUQh0SuNFg.png" /></figure><p><a href="https://github.com/dtrugman/pfs"><strong><em>→ Link to the library on Github</em></strong></a></p><p>I’m writing C++ code for Unix environments for almost a decade now.<br>And the funny thing is that in the last five years, while working for three different companies, I had to write a new procfs parsing library every time.<br>All those companies were developing security products monitoring applications running on Linux machines, so using the procfs was inevitable.<br>But over time, necessity became great admiration. I simply grew very fond of the amazing creation called procfs.<br>Having the honor of writing Linux kernel code that exported values using the same mechanisms, I also experienced the other end of things and liked it even more.</p><p>Since I haven’t read many blogs posts from library authors, and it’s been a while since I got to writing, I decided to document the mental process I was going through.<br>Hopefully it will make for an interesting reading or better yet, expose me to readers and ideas I can learn from. This blog post is all about me writing the <a href="https://github.com/dtrugman/pfs"><em>pfs</em> library</a>, the decisions I’ve made and why I made them.</p><h3>Styling</h3><p>I try to be true to myself and admit to the faults I’m aware of. One of those is a “slight” OCD. For example: Looking at a standard-sized screen with 60 lines of code in scope, I can easily loose focus over some misaligned lines.<br>It bugged me when I started coding, it bugs me at work and it will probably always bug me.<br>I believe that a huge part of our ability to percept and understand code relies upon our subconscious’ ability to sync with what it sees and know what to expect.<br>That is why <strong>any coding standard is always better than no standard</strong>.<br>I’ve seen great developers throw away hours trying to read and understand code that was simply formatted differently than what they were used to (No, not the ones that do code reviews with IDA).<br>And for those of you that make fun of that, just remember great developers are usually structure people with very developed logical skills.<br>To make use of those skills, one has to make sure that all the pieces come together nicely.</p><p>All in all, I decided to prevent this issue from ever happening here by simply adding a clang-format configuration with a pre-commit hook. I really hope this project will grow and others would like to participate, and making sure the code is accessible &amp; attractive to others is a huge deal.</p><h3>Naming conventions</h3><p>It was a very long and hard process. I tried at least 3 different styles but then decided to go with (almost) the same convention as the standard library.<br><strong>Pros:</strong></p><ul><li>Familiar and feels native for most C++ developers</li><li>Used by many other widely-used libraries, including: boost, fmt &amp; spdlog</li><li>Conveys the fact it’s a library, as most applications use different styles (Yes, I get the irony in that, but still…)</li></ul><p><strong>Cons:</strong></p><ul><li>Since type names are all lowercase, you sometimes cannot use straightforward names for your variables.</li></ul><p>One deviation I took from the standard library was the chosen style for private enums and constant values.<br>I felt like keeping those lowercase as well makes it really hard to follow parsing code with many constants, so I decided to change those to the C POSIX style of uppercase snake_case.</p><h3>API</h3><p>Personally, I write code using VIM, without any intelligent form of auto-completion. I do that when I write code in C, C++, Bash, Python or any other language I’m well acquainted with. Why am I telling you this? Because for me, <strong>predictable</strong> APIs are the everything.<br>I like the standard library, because all containers behave the same.<br>Yes, I know you can’t emplace_back into an std::set, but that’s an easy constraint to follow if you know your containers.</p><p>That is why I tried to keep the names of the APIs as easy to predict as possible.<br>I asked myself, what do I expect someone to do when trying to dig some piece of information from /procfs? And the answer that came to me was:</p><ul><li>Use an interactive shell to find the file that contains that bit</li><li>Convert the path into a function call: /proc/net/tcp6 will become procfs().get_net().get_tcp6()</li></ul><p>But since all rules are made to be broken, there’s also a (really-tiny) single exception from that rule. Since some APIs are actually wrappers to underlying directories, for example /proc/[pid]/fd, I decided that APIs for directories are going to be in plural form: procfs().get_task([pid]).get_fds().</p><h3>Break-down into sub-APIs (and sub-classes)</h3><p>Having all the methods under a single API simply wasn’t an option.<br>If you haven’t figured it out already, I’m a devout follower of certain code practices. One of those is breaking down code into small units, each with a single responsibility.</p><p>Luckily enough, the procfs is already broken down quite nicely, and following the same structure was the trivial go-to solution.</p><p>All files directly under procfs were mapped to methods of the procfs object. And that object is the only “entry point” in the library. If one wants to interact with a specific task, it can ask the procfs object to get a task object for him. If you wish to get some information from the network namespace of that task, you can ask for the net object.</p><p>The decision to allow creation of task objects only through the procfs object obtains two goals:</p><ol><li>Seamless support for systems where the procfs subsystem is mounted at custom locations — Once you create the root procfs object with the actual path, all the objects created by it are already aware of this “system configuration”, sparing you the headache of always passing the path when initializing additional objects during runtime.</li><li>Allow easier future extensibility. Since all properties can be seamlessly propagated down from the main procfs object into the task objects.</li></ol><h3>Types and return values</h3><p>Since this is a “glorified” parser, and parsers are all about getting the information you want, I decided that return values ought to be as simple to use as possible, and decided to use only enums and structs (rather than classes).<br>I refrained from using accessors (getters or setters) because I didn’t presume to predict all the possible use cases. It felt more natural to just return the raw information and let the caller handle it.</p><p>Next were the variable names inside the structs. I tried to keep the names as close to the ones described in the ultimate guide, proc(5).<br>Wherever there weren’t specific names, I tried to be consistent with the naming conventions of Linux.</p><p>There were some types, such as the ip or cap_mask structs, where I wrapped the raw values and added helper methods. At the time of writing, I didn’t know what potential users of this library might want. I merely assumed useful utilities for certain types, such as the per-capability getter to capability masks (cap_mask), might definitely be a well-received enhancement.</p><p>Another decision I made to preserve simplicity and explicitness was to avoid aliases for standard container types. For example, get_cmdline returns an std::vector&lt;std::string&gt;, and not some cmdline_args type.<br>I found that this explicitness in the API helpful in predicting output format, and thus supportive of my main design goal.</p><h3>Error handling</h3><p>I guess error handling is one of the major pain points in modern C++ writing.<br>The official standpoint, as far as the language moderators are concerned, is to use exceptions to make it cleaner and safer. But, when big organizations as Google formally discourage exceptions in their coding guidelines, the decision is never easy.<br>Truth be told, we have the same anti-exceptions convention at work. In my opinion, both forms can work well, and the most important thing here is to be <strong>consistent</strong>.<br>Since I’m using the standard library, the code is susceptible to exceptions thrown from it, mostly bad_alloc .<br>I didn’t want to wrap all my methods internally and translate allocation issues into ENOMEM, and I also wanted the ability to write RAII code. So instead, I decided to provide a consistent experience, hoping that when users call the library’s APIs, they are sensible enough to handle underlying exceptions as well.</p><h3>What’s next</h3><p>One of the harder decisions I had to make was: “What is the MVP?”</p><p>Every company know that this question is super important when first introducing new products and/or features to the market. If it’s too premature, customers simply won’t use it. If it’s too mature, there’s a high chance you invested a lot of work into extra features no one is going to use.</p><p>If you look at the code I published for v0.1.0 (the first, latest and only version available at this time), I decided to cover 80% of the most-interesting (my subjective view of course) files. And of course, some of those files were parsed to the bit resolution; such as capability masks from /proc/[pid]/status, whereas others are just a single string users can embed into their logs files, such as /proc/cmdline . I decided to see how people react to that before investing more time into it.</p><p>I do however have plenty of ideas in the pipeline, and I can only hope that this project gets some traction and I can put them into play.</p><p>That’s it, I hope this was an easy and interesting read. You can find the source code for this project on <a href="https://github.com/dtrugman/pfs">Github</a>. I’ll be happy to hear you opinions, and even happier to know you are using it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7343931d864" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/parsing-the-linux-procfs-f7343931d864">Parsing the Linux procfs</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inode flags, a hidden Linux gem]]></title>
            <link>https://dtrugman.medium.com/inode-flags-a-hidden-linux-gem-250fe812eccf?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/250fe812eccf</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[information-technology]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 16:06:12 GMT</pubDate>
            <atom:updated>2020-07-16T16:06:12.332Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mF1fS4izOYXjmpBD" /><figcaption>Photo by <a href="https://unsplash.com/@hharvey?utm_source=medium&amp;utm_medium=referral">Hao Zhang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the best aspects of my day to day work is that I get to discover many hidden Linux gems, and this case was no different.</p><p>I was toying around with some ideas when I stumbled upon what seemed to be a relatively insignificant feature, yet another esoteric method some hardcore file-systems developer added when he needed an extra flag to tweak and squeeze some extra mips. I would’ve probably skipped it without looking back and overthinking it, but by now I’ve learned that this is the best way to explore the mysteries of my beloved OS.</p><p>The name inode flags is rather inconspicuous, as most system programmers can think of at least a dozen possible flags related to inodes. These creatures are the backbone for so many standard mechanisms that this name is indistinctive enough to not stand out.</p><p>But, once you start reading the man page about <a href="http://man7.org/linux/man-pages/man2/ioctl_iflags.2.html">ioctl_iflags</a> , the syscall that allows us to manipulate these flags, you discover a heavenly world of opportunities.</p><p>Code-wise, it is quite simple, you need a single call to get the fd of the file that you can then manipulate:</p><pre>int attr;<br>fd = open(&quot;pathname&quot;, ...);<br><br>ioctl(fd, FS_IOC_GETFLAGS, &amp;attr);  /* Read current flags */<br>attr |= FS_NOATIME_FL;              /* Add desired flag */<br>ioctl(fd, FS_IOC_SETFLAGS, &amp;attr);  /* Set updated flags */</pre><p>The interesting part is the flags themselves. There are some that help optimize file-operations, others that manipulate the file operational mode and yes, there are always some exotic flags that even after reading their description twice I still don’t know how it would actually affect the system.</p><p>But, inside this haystack I found two shiny needles that really caught my eye and got my heart rate up, and yeah, I know this sounds nerdy :)</p><ul><li><strong>FS_APPEND_FL</strong>: Mark a file, so that it can be opened only with the O_APPEND<strong> </strong>flag.</li><li><strong>FS_IMMUTABLE_FL</strong>: The file is immutable: no changes are permitted to the file contents or metadata (permissions, timestamps, ownership, link count and so on).</li></ul><p>These features could’ve been rendered completely if not for the next cool fact: <strong>Even if you are the superuser, you CANNOT work around this protection</strong>. Yep, even if you sudo the hell out of a file protected using FL_IMMUTABLE_FL , you will fail miserably:</p><pre>$ echo &quot;test&quot; &gt; test.txt<br>$ sudo ./ioctl_iflags.out test.txt 16 1 # Set FS_IMMUTABLE_FL<br>Set flag 16 for test.txt<br>$ sudo rm test.txt<br>rm: cannot remove &#39;test.txt&#39;: Operation not permitted<br>$ sudo ./ioctl_iflags.out test.txt 16 0 # Clear FS_IMMUTABLE_FL<br>Cleared flag 16 for test.txt<br>$ rm test.txt<br>$ cat test.txt<br>cat: test.txt: No such file or directory</pre><p><em>Note: The </em><em>ioctl_iflags.out application is available to you through my GitHub account, find the link at the next paragraph</em></p><p>I don’t know what ideas are crossing your mind while reading this, but I definitely had at least two or three use-cases that could highly benefit from this. I decided to fiddle with it some more and wrote a small and simple test application I’ve then uploaded to GitHub for everyone to enjoy. Feel free to check it out and let me know if you’ve discovered some more juicy stuff.</p><p>Hope you’ve enjoyed and that you can find good use for this information. If you do, I’d appreciate a clap :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=250fe812eccf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ELF Loaders, Libraries and Executables on Linux]]></title>
            <link>https://dtrugman.medium.com/elf-loaders-libraries-and-executables-on-linux-e5cfce318f94?source=rss-77e2dc5a5df6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5cfce318f94</guid>
            <category><![CDATA[c]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[cplusplus]]></category>
            <dc:creator><![CDATA[Daniel Trugman]]></dc:creator>
            <pubDate>Thu, 20 Jun 2019 19:09:06 GMT</pubDate>
            <atom:updated>2020-01-10T15:56:08.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Cecz1U9MeQRHnVBy" /><figcaption>Photo by <a href="https://unsplash.com/@thepootphotographer?utm_source=medium&amp;utm_medium=referral">Janko Ferlič</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The target of the following stream of ASCII characters is to shed some light on an area that is probably not common knowledge even for experienced system developers: loaders, libraries and executables in the ELF Linux ecosystem.</p><p>First, we’ll try to understand what happens when we run a basic program on our Linux machine. Then we’ll discuss libraries and what they bring to the table. Cover the differences between static and dynamic libraries and executables, and finally dive into the inner-works of the dynamic loader, learning how to control, configure and manipulate it.</p><p>Hopefully, we can cover enough concepts, tools and approaches to ultimately provide you with an efficient tool-set for tackling related issues when managing, deploying or developing applications for Linux systems.</p><p>Here are the subjects we’ll attempt to recount:</p><ul><li>Behind the scenes of “Hello World”</li><li>Executable and Linkable Format (ELF)</li><li>Who the hell needs libraries?!</li><li>Libraries needed by an executable</li><li>Static enumeration of needed libraries</li><li>Dynamic enumeration of needed libraries</li><li>Loader who?</li><li>Use your own loader</li><li>What does the loader load?</li><li>R[UN]PATH</li><li>NODEFLIB</li></ul><h3>Behind the scenes of “Hello World”</h3><p>I want to believe that everybody have seen the following piece of C code at least once in their lives:</p><pre>#include &lt;stdio.h&gt;</pre><pre>void main() {<br>  printf(&quot;Hello World!\n&quot;);<br>}</pre><p>And then we&#39;ve probably compiled and executed it:</p><pre>$ gcc main.c -o myapp         # &lt;--- Compile<br>$ ./myapp                     # &lt;--- Execute<br>Hello World!</pre><p>But, did we really understand what happened there during these two trivial steps we went through? What is this myapp file that got created? How could our program use the printf method without implementing it? And what happened when we executed it?</p><p>We’ll try to address each of these questions in the same order in the following paragraphs.</p><h4>Executable and Linkable Format (ELF)</h4><p>People don’t really realize that, but the ELF file format is a cornerstone for all their magical applications! ELF is a standard file format for executables, libraries, and more.</p><p>Just like in our “Hello World” application; myapp is an ELF file (without even knowing it) and used other modules, such as the dynamic loader (which we’ll talk about later) to execute it.</p><p>By design, the ELF format is flexible, extensible, and cross-platform. It supports different endianness and address sizes so it can be used on any CPU or instruction set architecture. This has promoted its adoption by many different operating systems, and made it the de facto standard for Linux and other Unix-like systems.</p><p>Since the ELF format is a topic on its own, we won’t dwell into that, but if you want some more information, take a look at this <a href="https://refspecs.linuxfoundation.org/elf/elf.pdf">comprehensive ELF standard</a>.</p><h4>Who the hell needs libraries?</h4><p>One of the most important concepts in Software Engineering is code reuse. There are numerous reasons for not writing the same code more than once, or using different instances of the same code snippet.</p><p>This is just like in our “Hello World” application, where we used the printf method without implementing it. Because printing to the screen is required by so many applications out there, it was implemented once, and is now readily available for anyone writing C or C++ applications.</p><p>In order to implement this, libraries were invented. Libraries allow programmers to pack code into reusable modules. Then, every program that requires the same functionality can simply use the already-existing library. There are actually two kinds of libraries:</p><p><strong>Static libraries (.a files):</strong> Libraries that become part of the executable (are actually embedded into it) during linking. Which means that once the executable is ready, it doesn&#39;t require any additional files.</p><p><strong>Dynamic libraries (.so files):</strong> Libraries that are shipped separately from the executable, and are required to be present at <strong>run-time</strong>. We can use these libraries in two different ways, and the difference is mainly whether or not the libraries are present during compile-time:</p><ol><li>The executable links with the library at compile time. The executable can call methods defined in the library as if both shared their code-base. There is no need to explicitly load the library, and the loader handles it auto-magically during runtime. A classic example is any C program that links and uses glibc.</li><li>The executable does NOT link with the library at compile time. Instead, it loads and (possibly) unloads the library during execution-time only. The executable “unravels” and uses the library’s API during run-time using functionality provided by the dynamic loader. This is accomplished using dlopen (See <a href="https://linux.die.net/man/3/dlopen">man</a>(3) page for more information). A classic examples is an application that loads plug-ins during runtime.</li></ol><h4>Libraries needed by an executable</h4><p>Now that we know what libraries are, we’ll define two new terms:</p><ul><li><strong>Static executable</strong>: An executable that doesn&#39;t depend on any libraries.</li><li><strong>Dynamic executable</strong>: An executable that depends on other libraries.</li></ul><p>So, given an executable, how can we tell if it’s dynamic or static? Does it require any additional libraries or not? We can use a simple command called file .</p><p>For example, when we use it on our “Hello World” application, we see that it is dynamically linked (emphasis added), thus requiring dynamic libraries:</p><pre>$ file myapp<br>myapp: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), <strong>dynamically linked</strong>, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f385b7c6c03b6b5c8c416e3c4a2267030ca095aa, not stripped</pre><p><em>&gt; Note: Static executables are ‘statically linked’</em></p><p>But, how is this possible? We haven’t told anyone anything about additional libraries! Why is it dynamically linked?</p><p>Well, it turns out that by default, when we compile a C/C++ application, the compiler is programmed to automatically use the standard libraries: glibc.so for C and additionally libstdc++.so for C++.</p><p>Apart from that, in real life, when we compile an application, we usually tell the linker to add additional libraries using the -l flag. For example, if we’re using a publicly available library like boost, we can tell the compiler to link against that library (i.e. require it during runtime) by passing the -lboost parameter during compilation/linkage.</p><p><em>&gt; Note: Required libraries are specified only by their basename, whereas the lookup directories are defined using additional parameters such as </em><em>-L or system default paths, which we’ll discuss later.</em></p><p>Now that we know our application is a dynamic executable, how can we tell which libraries it requires?</p><h4>Static enumeration of needed libraries</h4><p>There are multiple ways to probe for libraries required by a specific executable. We will use an awesome tool called patchelf. Though its mostly intended to do what its name suggests, patching ELFs, it has a useful option called --print-needed that prints a list of libraries (basenames) required by this executable?</p><p>For example, if we use it on our “Hello World” application, we get the following output:</p><pre>$ patchelf --print-needed myapp<br>libc.so.6</pre><p>We can accomplish the same task by directly examining the ELF dynamic sections. Each needed library is represented by an entry in the .dynamic section, so we can simply print the entire .dynamic section using the readelf -d &lt;path-to-elf&gt; command, and look for the keyword NEEDED:</p><pre>$ readelf -d myapp | grep NEEDED<br>0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]</pre><h4>Dynamic enumeration of needed libraries</h4><p>But, how can we check what library the loader is actually going to load?libc.so.6 can exist at multiple locations, which one are we actually going to use?</p><p>In order to collect additional information, we can use a great script called ldd (List Dynamic Dependencies). This script enumerates all the dynamic libraries required by a specific executable. And, unlike the static enumeration methods, this tool describes the full path(!) of the library we are going to use. For example, the output for our “Hello World” application is:</p><pre>$ ldd myapp<br>linux-vdso.so.1 (0x00007fffed5b3000)<br><strong>libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa412e60000)</strong><br>/lib64/ld-linux-x86-64.so.2 (0x00007fa413600000)</pre><p>As you can see, ldd has a much richer output. Right now, we’ll ignore the first and last line, and focus on the line in bold, that follows the format:</p><pre>&lt;lib-basename&gt; =&gt; &lt;lib-full-path&gt; (lib-load-addr)</pre><p>This time, for each of the needed libraries, we can see the actual instance to be loaded and the load address. For instance, libc.so.6 will be loaded from /lib/x86_64-linux-gnu/libc.so.6 .</p><p>How does ldd collect this information? Well, it basically loads the application (without executing it) and traces the loader’s actions. If we run it using Bash’s trace mode enabled (bash -x $(which ldd) myapp), we’ll see that the entire script evaluates to a single line (I removed all the empty export statements around it to improve readability):</p><pre>LD_TRACE_LOADED_OBJECTS=1 /lib64/ld-linux-x86-64.so.2 myapp</pre><p>At this point, one might ask himself, WTF?! Well, yeah, this is definitely peculiar! What are we trying to do here? What is this weird ld-linux-x86-64.so.2 file? Isn&#39;t it a library (according to its .so.2 extension)?</p><p>Well, I&#39;ve been using the ‘loader’ term intermittently in the last few paragraphs, but this is the first time we have actually seen it in action. This is probably a good time to entertain ourselves with some more interesting facts about it.</p><h4>Loader who?</h4><p>As you could guess by now, the dynamic loader is a single static executable ELF file that goes by a name usually reserved by libraries.</p><p>The weird thing about it, is that it can be run either indirectly, by running some dynamically linked program or shared object, or directly, just like we’ve seen in the ldd example.</p><p><em>&gt; Note: The default loader (on 64-bit machines) can be found at </em><em>/lib64/ld-linux.so.2 and is actually a symbolic link to the real loader file </em><em>/lib/x86_64-linux-gnu/ld-&lt;version&gt;.so.</em></p><h4>Use your own loader</h4><p>Well, must we use the system’s loader? Can you BYOL? On the one hand, this is something every systems programmer wishes to avoid. The different package managers take care of many compatibility issues, and once you step off that train and into the wild, a lot of things can go wrong at every turn you take.</p><p>On the other hand, there is a method of distributing software as an encapsulated bundle that depends on it. When following this convention, applications are compiled against and shipped with a very specific set of libraries (I consider the loader to be one of them), thus creating a package that is (almost) independent of the hosting system. To accomplish this goal, we have to “patch” our executable and tell it to use our own loader.</p><p>To find out which loader an ELF “expects”, we can use the file app (emphasis added):</p><pre>$ file myapp<br>myapp: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, <strong>interpreter /lib64/ld-linux-x86-64.so.2</strong>, for GNU/Linux 3.2.0, BuildID[sha1]=f385b7c6c03b6b5c8c416e3c4a2267030ca095aa, not stripped</pre><p>Whereas to change the loader for a specific ELF, we can use patchelf and specify the interpreter and the elf to patch:</p><pre>$ patchelf --set-interpreter &lt;path-to-interpreter&gt; &lt;path-to-elf&gt;</pre><pre># For example:<br>$ patchelf --set-interpreter &quot;/opt/pkg/lib/ld.so.2&quot; /opt/pkg/app</pre><p>But, when shipping such a specially crafted package, one also has to make sure that loader loads the libraries he shipped with it, and not the ones pre-installed on the target system. To accomplish that, we have to understand how the loader works, and how it decided which libraries to load.</p><h4>What does the loader load?</h4><p>When we load a <strong>static executable, </strong>there is no need for the dynamic loader, because all the required libraries were integrated into the executable during <strong>link-time.</strong></p><p>However, when we load a <strong>dynamic executable</strong>, the system depends on the loader to do the heavy lifting.</p><p>The loader <strong>always</strong> starts by loading:</p><ul><li>All the libraries specified by the environment variable LD_PRELOAD</li><li>All the libraries listed in /etc/ld.so.preload</li></ul><p>Then, it tries to satisfy each direct dependency (library) string specified as NEEDED in the ELF’s .dynamic section.</p><p>If one of these libraries requires an additional library, <strong>not required by the executable</strong>, this library is referred to as an ‘indirect dependency’. And once we finished loading all the direct dependencies, the loader loads the indirect ones.</p><p>For each (direct/indirect) dependency, the loader follows this decision making process:</p><p>First, if the dependency string contains a slash, e.g. /mylib (can occur if one was specified during link time), it is interpreted as a (relative or absolute) pathname and loaded from there and no further lookup is required.</p><p>Otherwise, the loader follows these steps (Each step contains a condition. If that condition is not satisfied, the loader will skip it):</p><p><strong>Step 1: </strong>Using the directories in DT_RPATH</p><ul><li>Condition: DT_RUNPATH attribute does not exist</li><li>Note: DT_RPATH is deprecated</li></ul><p><strong>Step 2: </strong>Using the environment variable LD_LIBRARY_PATH</p><ul><li>Condition: The executable is not being run in secure-execution mode (Formally, when AT_SECURE<strong> </strong>has a nonzero value. Informally, this happens when we set the file’s SUID bit, for example)</li><li>Example: When the SETUID bit is set, and the process’s real and effective UIDs differ, the loader will ignore it</li><li>Note: LD_LIBRARY_PATH can be overridden by executing the dynamic linker directly with the option --library-path , e.g: /lib64/ld-linux-x86–64.so.2 --library-path &quot;/my/libs:/my/other/libs&quot; myapp</li></ul><p><strong>Step 3:</strong> Using the directories in DT_RUNPATH</p><ul><li>Condition: The loader is loading a direct dependency.</li><li>Example: If our binary myapp needs a single library a.so , and a.so requires b.so , when the loader will be looking for b.so (which is not a direct dependency of myapp ), it will skip this step!</li><li>Note: This is different from DT_RPATH, which is always applied.</li></ul><p><strong>Step 4</strong>: From the cache file /etc/ld.so.cache</p><ul><li>Condition: The ELF doesn&#39;t contain the NODEFLIB flag.</li></ul><p><strong>Step 5</strong>: In the default path /lib[64] , and then /usr/lib[64]</p><ul><li>Condition: The ELF doesn&#39;t contain the NODEFLIB flag.</li></ul><p>Do you feel like five different preconditioned steps is enough? Well, lucky for us, that’s it for now. If the loader goes through all five steps and still it cannot find a library, the load process fails, and a similar error message is printed:</p><pre>/bin/myapp: error while loading shared libraries: libncursesw.so.5: cannot open shared object file</pre><p>Now that we know what guides the loader while trying to do its job, let’s take it to the next step, and see how we can advise. To do that, we’ll recap and elaborate on some of the UPPERCASE keywords we&#39;ve just seen.</p><h4>R[UN]PATH</h4><p>Both RPATH and RUNPATH are optional entries in the .dynamic section of ELF executables or shared libraries.</p><p>As we already understand, their goal is to empower the developer and allow him to alter the behavior of the dynamic loader.</p><p>In case you didn&#39;t read the last chapter, or just to sharpen your grasp of these values, let’s recap:</p><ul><li>If RUNPATH isn&#39;t set, the loader looks for <strong>every </strong>library in the directories specified by RPATH .</li><li>If RUNPATH is set, the loader looks for <strong>direct dependency </strong>libraries in the directories specified by RUNPATH.</li><li>RPATH is deprecated, and the use of RUNPATH is encouraged instead</li></ul><p>Having a good understanding of the consequences, we can now start talking about the next phase, how can we manipulate it?</p><p>First, before we start breaking things, we should be able to know what we’re dealing with. Given an ELF file, we can examine R[UN]PATH values using:</p><pre>readelf -d &lt;path-to-elf&gt; | egrep &quot;RPATH|RUNPATH&quot;</pre><p>When RPATH and RUNPATH are not set, there won’t be any output, otherwise, we’ll see the dynamic section entry:</p><pre>$ readelf -d ./example | egrep &quot;RPATH|RUNPATH&quot;<br>0x000000000000001d (RUNPATH) Library runpath: [/my/patched/libs]</pre><p>Now, for the fun part. We can manipulate an ELF in two very different ways:</p><ol><li>Set at compile time. The GNU linker ld supports the -rpath option. All -rpath options are concatenated and added to the final executable (See <a href="https://linux.die.net/man/1/ld">ld(1)</a> for more information).</li><li>Manipulate an existing ELF file using the beloved patchelf :</li></ol><pre># Clearing RPATH &amp; RUNPATH<br>patchelf --remove-rpath &lt;path-to-elf&gt;</pre><pre># Setting RPATH<br>patchelf --force-rpath --set-rpath &lt;desired-rpath&gt; &lt;path-to-elf&gt;</pre><pre># Setting RUNPATH<br>patchelf --set-rpath &lt;desired-rpath&gt; &lt;path-to-elf&gt;</pre><h4>NODEFLIB</h4><p>This next one is a flag that we can find in an optional .dynamic section called FLAGS_1. In a nutshell, it tells the loader to avoid loading libraries from:</p><ul><li>The loader cache file</li><li>Default system locations</li></ul><p><em>&gt; Note: This request holds, even if it means that the load operation will fail.</em></p><p>How can we tell if this flag is set? Well, once more, we print out the dynamic sections of the ELF and look for the NODEFLIB expression:</p><pre>readelf -d &lt;path-to-elf&gt; | grep NODEFLIB</pre><p>And how can we manipulate it? Similarly to R[UN]PATH:</p><ul><li><strong>Option 1: </strong>During compile time, by passing the -z nodefaultlib flag to the GNU linker.</li><li><strong>Option 2:</strong> Manipulate an existing ELF using our revered tool of course: patchelf --no-default-lib &lt;path-to-elf&gt;</li></ul><p>This is the end, and I hope you have enjoyed scrolling down to the bottom of this article :)</p><p>Now seriously, I hope that after reading this, you feel better equipped for fighting those sorts of issues on your system. If you think that this article could have used an additional chapter, please let me know!</p><p>If you feel that you’ve gained some insights from reading this, I would really appreciate it if you clap!</p><h4>Resources:</h4><ul><li><a href="https://en.wikipedia.org/wiki/Executable_and_Linkable_Format">Executable and Linkable Format</a> on Wikipedia</li><li><a href="https://linux.die.net/man/8/ld.so">Dynamic loader manual</a>: Know it all, just like the gods wanted</li><li><a href="https://linux.die.net/man/1/ld">GNU Linker manual</a>: Useful for linker flags like nodefaultlib or rpath</li><li><a href="https://pwnypack.readthedocs.io/en/latest/pwnypack/elf.html">Python pwnypack package documentation</a>: Great reference for ELF types and flags values. For example, supported flags in the FLAGS and FLAGS_1 sections</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5cfce318f94" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>