{"id":60,"date":"2020-08-25T16:19:30","date_gmt":"2020-08-25T21:19:30","guid":{"rendered":"https:\/\/sourceopen.com\/?p=60"},"modified":"2020-08-25T17:02:14","modified_gmt":"2020-08-25T22:02:14","slug":"build-alpine-2-23-on-openbsd-to-fix-hang-when-sending-mail","status":"publish","type":"post","link":"https:\/\/sourceopen.com\/index.php\/build-alpine-2-23-on-openbsd-to-fix-hang-when-sending-mail\/","title":{"rendered":"Build Alpine 2.23 on OpenBSD to Fix Hang When Sending Mail"},"content":{"rendered":"\n<p>Once again, I love the <a rel=\"noreferrer noopener\" href=\"http:\/\/alpine.x10host.com\/\" target=\"_blank\">Alpine MUA<\/a>. Simple and robust, it just works, and is much faster than a GUI mail client.<\/p>\n\n\n\n<p>During a recent OpenBSD install (6.7)  I ran into a issue where Alpine 2.21 from Ports (alpine-2.21p4) hangs when &#8220;Sending Mail.&#8221; Occasionally, but repeatably if you send a number of messages Alpine will hang when it gets to Sending Mail. I tried the usual fixes&#8230; I checked the &#8220;Sendmail Path&#8221; and the &#8220;SMTP Server (for sending)&#8221; settings in the config and tested that those were working. The code would suggest that Sendmail Path is used first. So if that is not working on your system then you want to remove that setting in the config (it&#8217;s down lower in the config for some reason, rather than up at the top) before setting your SMTP Server.<\/p>\n\n\n\n<p>This was not the issue in my case, and unlikely your issue if you have smtpd configured and running. Sending via sendmail -t and the SMTP server on localhost worked fine most of the time&#8230; But then every few emails (sometimes as few as two, sometimes ten or more) Alpine would hang on Sending Mail and I would have to kill it with a kill -9.<\/p>\n\n\n\n<p>For the curious (<a href=\"#fix\">skip <\/a>this unless you like code), this is the ktrace where it would hang every time. The last line is me killing it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> 53976 alpine   NAMI  \"\/tmp\/pine_p43476\"\n 53976 alpine   RET   lstat -1 errno 2 No such file or directory\n 53976 alpine   CALL  open(0x32ce7654b80,0xa01&lt;O_WRONLY|O_CREAT|O_EXCL>,0600&lt;S_IRUSR|S_IWUSR>)\n 53976 alpine   NAMI  \"\/tmp\/pine_p43476\"\n 53976 alpine   RET   open 6\n 53976 alpine   CALL  close(6)\n 53976 alpine   RET   close 0\n 53976 alpine   CALL  pipe(0x7f7ffffc41b8)\n 53976 alpine   STRU  int &#91;2] { 6, 7 }\n 53976 alpine   RET   pipe 0\n 53976 alpine   CALL  sigaction(SIGCHLD,0x7f7ffffc3d28,0x7f7ffffc3d18)\n 53976 alpine   STRU  struct sigaction { handler=0x32a0e994e70, mask=0&lt;>, flags=0x2&lt;SA_RESTART> }\n 53976 alpine   STRU  struct sigaction { handler=0x32a0e994e70, mask=0&lt;>, flags=0x2&lt;SA_RESTART> }\n 53976 alpine   RET   sigaction 0\n 53976 alpine   CALL  futex(0x32cf9b38690,0x81&lt;FUTEX_WAIT|FUTEX_PRIVATE_FLAG>,2,0,0)\n 53976 alpine   RET   nanosleep 0\n 53976 alpine   CALL  kbind(0x32c364e8868,24,0x400e0443c3a0c61)\n 53976 alpine   RET   kbind 0\n 53976 alpine   CALL  gettimeofday(0x32c364e8660,0)\n 53976 alpine   STRU  struct timeval { 1598335368&lt;\"Aug 25 01:02:48 2020\">.986756 }\n 53976 alpine   RET   gettimeofday 0\n 53976 alpine   CALL  futex(0x32cf9b38618,0x81&lt;FUTEX_WAIT|FUTEX_PRIVATE_FLAG>,2,0,0)\n 53976 alpine   PSIG  SIGKILL SIG_DFL\n<\/code><\/pre>\n\n\n\n<p>A backtrace in gdb showed it was called from _rthread_mutex_timedlock. However, I did not research it further. I am not up on debugging pthread programs, and gdb kept breaking constantly when changing threads.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"fix\">The Fix<\/h3>\n\n\n\n<p>Anyway, I built and installed the latest Alpine 2.23 from the official source. I had to patch it with the patches from the ports collection, as well as with my own highly recommended patch to fix the &#8220;[Folder vulnerable &#8211; directory \/var\/mail must have 1777 protection]&#8221; issue on OpenBSD detailed <a rel=\"noreferrer noopener\" href=\"https:\/\/sourceopen.com\/index.php\/a-journey-with-the-alpine-mail-user-agent-mua-in-openbsd-or-how-to-safely-fix-folder-vulnerable-directory-var-mail-must-have-1777-protection\" target=\"_blank\">here<\/a>. Without the patch on that other page your mailbox may be subject to corruption. <a rel=\"noreferrer noopener\" href=\"https:\/\/sourceopen.com\/index.php\/a-journey-with-the-alpine-mail-user-agent-mua-in-openbsd-or-how-to-safely-fix-folder-vulnerable-directory-var-mail-must-have-1777-protection\" target=\"_blank\">Check it out<\/a>.<\/p>\n\n\n\n<p>First download the <a rel=\"noreferrer noopener\" href=\"http:\/\/alpine.x10host.com\/alpine\/release\/src\/alpine-2.23.tar.xz\" target=\"_blank\">latest source tarball<\/a> from the <a rel=\"noreferrer noopener\" href=\"http:\/\/alpine.x10host.com\/\" target=\"_blank\">official Alpine site<\/a>. I like to do all this in $HOME\/src\/  but you can do this wherever you like. Also grab my <a rel=\"noreferrer noopener\" href=\"https:\/\/sourceopen.com\/alpine-2.23-openbsd-patch\" target=\"_blank\">complete patch<\/a> (<a rel=\"noreferrer noopener\" href=\"https:\/\/sourceopen.com\/alpine-2.23-openbsd-patch.sha256\" target=\"_blank\">SHA256<\/a>) which combines the OpenBSD Ports patches plus my <a rel=\"noreferrer noopener\" href=\"https:\/\/sourceopen.com\/index.php\/a-journey-with-the-alpine-mail-user-agent-mua-in-openbsd-or-how-to-safely-fix-folder-vulnerable-directory-var-mail-must-have-1777-protection\" target=\"_blank\">Folder Vulnerable patch<\/a> in one big patch file. (You might want to check the hash on the Alpine distro with the one posted on the Alpine site.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget http:\/\/alpine.x10host.com\/alpine\/release\/src\/alpine-2.23.tar.xz\nwget https:\/\/sourceopen.com\/alpine-2.23-openbsd-patch\nwget https:\/\/sourceopen.com\/alpine-2.23-openbsd-patch.sha256<\/code><\/pre>\n\n\n\n<p>Note this is an .xz compressed archive for some reason instead of the usual .gzip. So:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unxz alpine-2.23.tar.xz<\/code><\/pre>\n\n\n\n<p>Then expand the tar archive:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar xf alpine-2.23.tar<\/code><\/pre>\n\n\n\n<p>Next we will apply the patch to the source code. <\/p>\n\n\n\n<p><em>A little security note: Please take a look at the patch and make sure there is nothing untoward. I point this out only because applying random patches can possibly be dangerous. Rest assured, I am a nice guy and not trying to do anything bad, but you want to be in the habit of at least looking at the lines in the patch preceded by &#8220;+&#8221; to make sure there is nothing fishy going on. This works perfectly here. YMMV. <\/em><\/p>\n\n\n\n<p>We first check the hash of the patch before applying it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sha256 alpine-2.23-openbsd-patch<\/code><\/pre>\n\n\n\n<p>This should result in output like this (the hash should match <em>exactly<\/em>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHA256 alpine-2.23-openbsd-patch) = e7c6d44678030dd11e6e686da2d8997810408561bf51e461a0914cce6baa2791<\/code><\/pre>\n\n\n\n<p>Next we apply the patch from the directory one above the alpine-2.23 directory. So if you have \/$HOME\/src\/alpine-2.23 then you should still be in the directory you downloaded to \/$HOME\/src\/. This command and this patch will patch all the various files in the alpine-2.23 directory at once!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>patch -p0 &lt; alpine-2.23-openbsd-patch<\/code><\/pre>\n\n\n\n<p>This should result in a bunch of output from patch. Look over this and make sure all the &#8220;hunks&#8221; succeeded.<\/p>\n\n\n\n<p>Next we configure and make, but we <strong>do not install<\/strong>. You could use make to install, but this will install all the other programs you likely don&#8217;t need like pico (use <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nano-editor.org\/\" target=\"_blank\">GNU nano<\/a> instead) and pilot, etc. We will install manually below. It&#8217;s easy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd alpine-2.23\n.\/configure\nmake\n\n# Or you can do them both if you want to walk away while it build with:\n.\/configure &amp;&amp; make<\/code><\/pre>\n\n\n\n<p>This will build everything up, hopefully with no errors. It is possible there are prerequisite packages (dependencies) that need to be built or installed. In this case you might be easiest to first install the package for alpine, letting pkg_add install the dependencies, and then uninstall the alpine package without removing dependencies.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pkg_add alpine\n#(let it install dependencies)\npkg_delete alpine\n#(only deletes alpine by default and not dependencies)<\/code><\/pre>\n\n\n\n<p>After running this go back and run the .\/configure and make again. Probably a good idea to do a make distclean first, in case any of the missing stuff was cached as missing. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make distclean\n.\/configure &amp;&amp; make<\/code><\/pre>\n\n\n\n<p>Now you can manually install just the alpine binary. Make sure you are in the alpine-2.23 directory and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>doas install -o root -g bin -m 0755 -b alpine\/alpine \/usr\/local\/bin\/alpine<\/code><\/pre>\n\n\n\n<p>The -b option will backup any existing alpine to \/usr\/local\/bin\/alpine.old. Be sure to delete this when you are sure you don&#8217;t need it any more. If you get an error about doas not being enabled then su to root and install it without the &#8220;doas&#8221; at the start of the line. (Or enable doas if you prefer. I don&#8217;t care for doas, and don&#8217;t use it.)<\/p>\n\n\n\n<p>Now start up Alpine (just run &#8220;alpine&#8221;) and make sure you are seeing version 2.23 in the top banner. That&#8217;s it! This new update solved my issue of Alpine hanging on Sending Mail in OpenBSD. You should also now not have to worry about the whole <a rel=\"noreferrer noopener\" href=\"https:\/\/sourceopen.com\/index.php\/a-journey-with-the-alpine-mail-user-agent-mua-in-openbsd-or-how-to-safely-fix-folder-vulnerable-directory-var-mail-must-have-1777-protection\" target=\"_blank\">Folder Vulnerable issue<\/a> as well, as this patch is included.<\/p>\n\n\n\n<p>Let me know in the comments how this worked for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once again, I love the Alpine MUA. Simple and robust, it just works, and is much faster than a GUI mail client. During a recent OpenBSD install (6.7) I ran into a issue where Alpine 2.21 from Ports (alpine-2.21p4) hangs &hellip; <a href=\"https:\/\/sourceopen.com\/index.php\/build-alpine-2-23-on-openbsd-to-fix-hang-when-sending-mail\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[36,31,3,4,47,44,28,46,32,2,34,45,33,24],"_links":{"self":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts\/60"}],"collection":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":7,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts\/60\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}