{"id":435,"date":"2014-04-15T18:44:52","date_gmt":"2014-04-15T06:44:52","guid":{"rendered":"http:\/\/mdickinson.dyndns.org\/php\/wordpress\/?p=435"},"modified":"2014-04-15T18:44:52","modified_gmt":"2014-04-15T06:44:52","slug":"private-tmp-and-vartmp-directories-under-systemd","status":"publish","type":"post","link":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/?p=435","title":{"rendered":"Private \/tmp and \/var\/tmp directories under systemd"},"content":{"rendered":"<p>Who knew, well I suppose it is in a manual somewhere.<\/p>\n<p>Took me a while to figure out what this was.<br \/>\nThe answer was at <a href=\"http:\/\/stackoverflow.com\/questions\/12206857\/php-cant-read-file-on-var-tmp\">http:\/\/stackoverflow.com\/questions\/12206857\/php-cant-read-file-on-var-tmp<\/a><\/p>\n<p>I have Apache rewite rules that run a bash script from \/cgi-bin\/ and write to a file in \/var\/tmp. A also have a PHP webpage that reads the file in \/var\/tmp, unfortunately under the F20 release of systemd \/var\/tmp is a movable location when it is accessed from under Apache.<\/p>\n<p>Knowing the file name I did a search for it. And found it in unexpected locations, for example<\/p>\n<pre>\/var\/tmp\/systemd-httpd.service-XQe2EnM\/tmp\/blacklist.log\r\n\/var\/tmp\/systemd-httpd.service-XBx5E16\/tmp\/blacklist.log<\/pre>\n<p>Now thats obviously by design.<\/p>\n<p>The file is supposed to be appended to, but it looks like when httpd is restarted by systemd writes\/reads to \/var\/tmp go to a dynamically remapped folder so I am ending up with multiple files in random locations that are being appended to.<\/p>\n<p>An example of the PHP code that reads the file and the bash code that writes the file is below<\/p>\n<pre>\r\n\/* PHP that reads the file *\/\r\n$filename = \"\/var\/tmp\/blacklist.log\";\r\n$databuf = \"\";\r\nif (file_exists($filename)) {\r\n   if (is_readable($filename)) {\r\n      if ($databuf = file_get_contents( $filename )) {\r\n         echo \"&lt;pre&gt;$databuf&lt;\/pre&gt;\";\r\n      }\r\n   }\r\n}\r\n\r\n# bash script code that appends to the file\r\nLOGFILE=\"\/var\/tmp\/blacklist.log\"\r\necho \"Message I want logged\" &gt;&gt; ${LOGFILE}\r\n<\/pre>\n<p>So how to get the damn scripts writing\/reading where they should ?.<br \/>\nAs mentioned in the post I linked to above it is to do with systemd private temp directories.<\/p>\n<pre>vi \/usr\/lib\/systemd\/system\/httpd.service\r\nchange 'PrivateTmp=true' to 'PrivateTmp=false'\r\nsystemctl daemon-reload\r\nsystemctl restart httpd.service<\/pre>\n<p>And that fixes it for httpd\/apache anyway.<\/p>\n<p>However using private temp directories does seem like a good idea from a security perspective, thats why they were introduced in the first place. So I will try to find time to rewrite all my scripts to store semi-permanent data somewhere else&#8230; outside the webserver directories as external scripts that use the file have no need to traverse the webserver directories, so I guess more pain with SELinux lies ahead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Who knew, well I suppose it is in a manual somewhere. Took me a while to figure out what this was. The answer was at http:\/\/stackoverflow.com\/questions\/12206857\/php-cant-read-file-on-var-tmp I have Apache rewite rules that run a bash script from \/cgi-bin\/ and write &hellip; <a href=\"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/?p=435\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-435","post","type-post","status-publish","format-standard","hentry","category-my-nux-thoughts-and-notes"],"_links":{"self":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=435"}],"version-history":[{"count":5,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/435\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/435\/revisions\/440"}],"wp:attachment":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}