{"id":919,"date":"2024-09-19T01:13:31","date_gmt":"2024-09-19T07:13:31","guid":{"rendered":"https:\/\/www.hort.net\/blog\/?p=919"},"modified":"2024-09-19T10:51:34","modified_gmt":"2024-09-19T16:51:34","slug":"saving-core-dumps-from-mod_perl","status":"publish","type":"post","link":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/","title":{"rendered":"Saving core dumps from mod_perl"},"content":{"rendered":"<p>I&#8217;ve had some free time lately and have been spending it working on hort.net. Some of the pages still had design elements from 2000 (tables galore!) that I&#8217;ve been converting to a more responsive layout. The design is still, well, what it is (I&#8217;m not a graphic designer), but the tables and colored pixels stretched to all different sizes are mostly gone. I did uncover other weirdnesses, but more on that later.<\/p>\n<p>The site leverages mod_perl on Rocky 9 heavily and the logs would occasionally say something like<\/p>\n<p><code class=\"preserve-code-formatting\">[Sun Sep 15 05:55:53.652955 2024] [core:notice] [pid 1475:tid 1475] AH00051: child pid 8943 exit signal Segmentation fault (11), possible coredump in \/tmp<\/code><\/p>\n<p>Of course, there weren&#8217;t any core dumps to look at, and I never really saw the logs in time to do anything about it anyhow. Today, I decided to change that.<\/p>\n<p>The first thing to do was allow core dumps in systemd, so I created <strong>\/etc\/systemd\/system\/httpd.service.d\/91-core.conf<\/strong>:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n[Service]\nLimitCORE=infinity\n<\/code><\/pre><br \/>\nThe next step is to allow core dumps in Apache. I created <strong>\/etc\/httpd\/conf.d\/00-core.conf<\/strong>:<br \/>\n<pre><code class=\"preserve-code-formatting\">\nCoreDumpDirectory \/var\/crash\/httpd\n<\/code><\/pre><br \/>\nFinally, I ran<br \/>\n<pre><code class=\"preserve-code-formatting\">\nmkdir \/var\/crash\/httpd\nchown apache.apache \/var\/crash\/httpd\nsystemctl daemon-reload\nsystemctl restart httpd\n<\/code><\/pre><br \/>\nAt this point, any core dumps will go into \/var\/crash\/httpd. And they will keep going until the disk is full if they happen often enough. The other problem is that I would never notice they were there until I ran out of disk space, and at that point I&#8217;d have to delete them anyhow. A plan was needed.<\/p>\n<p>I arbitrarily decided that I only needed the last twenty core dumps, but I also knew that I needed to get a notification any time a core dump was generated. This would give me a sense of frequency, a time stamp outside of the system to use when looking at logs, and an automated cleanup process.<\/p>\n<p>inotify seemed like a great tool for this. It watches for filesystem events in a given directory, so I wrote a script that used it for my earlier plan.<\/p>\n<p>First, I installed inotify-tools:<br \/>\n<pre><code class=\"preserve-code-formatting\">\ndnf -y install inotify-tools\n<\/code><\/pre><br \/>\nThen I created this script in <strong>\/usr\/local\/scripts\/watchforcoredumps<\/strong>:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n#!\/bin\/bash\n\n# the directory to monitor\nWATCH_DIR=&quot;\/var\/crash\/httpd\/&quot;\n# who to notify (this isn&#039;t the real address)\nEMAIL=&quot;devnull@mallorn.com&quot;\n\ninotifywait -m -e create &quot;$WATCH_DIR&quot; | while read path action file; do\nif [[ &quot;$file&quot; == core* ]]; then\n&nbsp;&nbsp; # Send an email notification\n&nbsp;&nbsp; echo &quot;A new core dump was created on `hostname`: $file in $path&quot; | mail -s &quot;Core Dump Notification&quot; &quot;$EMAIL&quot;\n&nbsp;&nbsp; find $WATCH_DIR -type f -maxdepth 1 | sed -e &#039;1,20d&#039; | tr &#039;\\n&#039; &#039;\\0&#039; | xargs -0 rm -f\nfi\ndone\n<\/code><\/pre><\/p>\n<p>And then I ran the script:<br \/>\n<pre><code class=\"preserve-code-formatting\">\nnohup ~root\/watchforcoredumps &gt; \/dev\/null\n<\/code><\/pre><\/p>\n<p>What do you need to change if you&#8217;re running this script on your own site? Change <strong>WATCH_DIR<\/strong> and <strong>EMAIL<\/strong> to what you need for your site. If you want more than twenty files, change the 20 in &#8216;1,20d&#8217; to however many you want to keep. If you want 50, make it &#8216;1,50d&#8217;.<\/p>\n<p>And finally, one last comment about the deletion line.<\/p>\n<p>You don&#8217;t know what filename you&#8217;ll end up with for your core dump, or if you have non-core files (like a file upload site) you don&#8217;t know what characters will be in the filename. What if there&#8217;s a semi-colon in the filename? An exclamation point? Generally speaking you&#8217;re probably safe from ne&#8217;er-do-wells, but the best way to protect against command injections via filenames is to remove the newlines. If there&#8217;s no newline, no command can be run.<\/p>\n<p>So how do you get rid of newlines?<\/p>\n<p>We take the output of our find command that&#8217;s piped into sed and run it through tr:<br \/>\n<pre><code class=\"preserve-code-formatting\">\ntr &#039;\\n&#039; &#039;\\0&#039; | xargs -0 [command]\n<\/code><\/pre><\/p>\n<p>That takes every linefeed and makes it a NULL character. xargs has a -0 argument that uses NULL characters as the end of the string, helping to prevent exploits due to weird character trickery.<\/p>\n<p>Now I&#8217;ve delayed things long enough, and I probably need to start loading up these dumps with gdb. That&#8217;s not going to be nearly as fun&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve had some free time lately and have been spending it working on hort.net. Some of the pages still had design elements from 2000 (tables galore!) that I&#8217;ve been converting to a more responsive layout. The design is still, well, what it is (I&#8217;m not a graphic designer), but the tables and colored pixels stretched [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-919","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Saving core dumps from mod_perl - hort.net blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Saving core dumps from mod_perl - hort.net blog\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve had some free time lately and have been spending it working on hort.net. Some of the pages still had design elements from 2000 (tables galore!) that I&#8217;ve been converting to a more responsive layout. The design is still, well, what it is (I&#8217;m not a graphic designer), but the tables and colored pixels stretched [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/\" \/>\n<meta property=\"og:site_name\" content=\"hort.net blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-19T07:13:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-19T16:51:34+00:00\" \/>\n<meta name=\"author\" content=\"Christopher Lindsey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christopher Lindsey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/\"},\"author\":{\"name\":\"Christopher Lindsey\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/#\\\/schema\\\/person\\\/c5048c118466b10e17155d29454e63de\"},\"headline\":\"Saving core dumps from mod_perl\",\"datePublished\":\"2024-09-19T07:13:31+00:00\",\"dateModified\":\"2024-09-19T16:51:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/\"},\"wordCount\":557,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/\",\"url\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/\",\"name\":\"Saving core dumps from mod_perl - hort.net blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/#website\"},\"datePublished\":\"2024-09-19T07:13:31+00:00\",\"dateModified\":\"2024-09-19T16:51:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/#\\\/schema\\\/person\\\/c5048c118466b10e17155d29454e63de\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/2024\\\/09\\\/19\\\/saving-core-dumps-from-mod_perl\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Saving core dumps from mod_perl\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/\",\"name\":\"hort.net blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/#\\\/schema\\\/person\\\/c5048c118466b10e17155d29454e63de\",\"name\":\"Christopher Lindsey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/07\\\/Christopher-Lindsey_avatar_1437067426-96x96.jpg\",\"url\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/07\\\/Christopher-Lindsey_avatar_1437067426-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/07\\\/Christopher-Lindsey_avatar_1437067426-96x96.jpg\",\"caption\":\"Christopher Lindsey\"},\"url\":\"https:\\\/\\\/www.hort.net\\\/blog\\\/author\\\/chris\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Saving core dumps from mod_perl - hort.net blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/","og_locale":"en_US","og_type":"article","og_title":"Saving core dumps from mod_perl - hort.net blog","og_description":"I&#8217;ve had some free time lately and have been spending it working on hort.net. Some of the pages still had design elements from 2000 (tables galore!) that I&#8217;ve been converting to a more responsive layout. The design is still, well, what it is (I&#8217;m not a graphic designer), but the tables and colored pixels stretched [&hellip;]","og_url":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/","og_site_name":"hort.net blog","article_published_time":"2024-09-19T07:13:31+00:00","article_modified_time":"2024-09-19T16:51:34+00:00","author":"Christopher Lindsey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Christopher Lindsey","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/#article","isPartOf":{"@id":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/"},"author":{"name":"Christopher Lindsey","@id":"https:\/\/www.hort.net\/blog\/#\/schema\/person\/c5048c118466b10e17155d29454e63de"},"headline":"Saving core dumps from mod_perl","datePublished":"2024-09-19T07:13:31+00:00","dateModified":"2024-09-19T16:51:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/"},"wordCount":557,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/","url":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/","name":"Saving core dumps from mod_perl - hort.net blog","isPartOf":{"@id":"https:\/\/www.hort.net\/blog\/#website"},"datePublished":"2024-09-19T07:13:31+00:00","dateModified":"2024-09-19T16:51:34+00:00","author":{"@id":"https:\/\/www.hort.net\/blog\/#\/schema\/person\/c5048c118466b10e17155d29454e63de"},"breadcrumb":{"@id":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hort.net\/blog\/2024\/09\/19\/saving-core-dumps-from-mod_perl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hort.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Saving core dumps from mod_perl"}]},{"@type":"WebSite","@id":"https:\/\/www.hort.net\/blog\/#website","url":"https:\/\/www.hort.net\/blog\/","name":"hort.net blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hort.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.hort.net\/blog\/#\/schema\/person\/c5048c118466b10e17155d29454e63de","name":"Christopher Lindsey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hort.net\/blog\/wp-content\/uploads\/2015\/07\/Christopher-Lindsey_avatar_1437067426-96x96.jpg","url":"https:\/\/www.hort.net\/blog\/wp-content\/uploads\/2015\/07\/Christopher-Lindsey_avatar_1437067426-96x96.jpg","contentUrl":"https:\/\/www.hort.net\/blog\/wp-content\/uploads\/2015\/07\/Christopher-Lindsey_avatar_1437067426-96x96.jpg","caption":"Christopher Lindsey"},"url":"https:\/\/www.hort.net\/blog\/author\/chris\/"}]}},"_links":{"self":[{"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/posts\/919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/comments?post=919"}],"version-history":[{"count":15,"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/posts\/919\/revisions"}],"predecessor-version":[{"id":934,"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/posts\/919\/revisions\/934"}],"wp:attachment":[{"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/media?parent=919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/categories?post=919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hort.net\/blog\/wp-json\/wp\/v2\/tags?post=919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}