{"id":125,"date":"2009-10-25T00:04:23","date_gmt":"2009-10-25T04:04:23","guid":{"rendered":""},"modified":"2011-02-02T00:22:28","modified_gmt":"2011-02-02T05:22:28","slug":"xlock-on-pm-suspend","status":"publish","type":"post","link":"https:\/\/pappp.net\/?p=125","title":{"rendered":"xlock on pm-suspend"},"content":{"rendered":"\n<p> I&#8217;ve always preferred that my machines be locked when they wake up from sleep\/suspend\/hibernate\/etc., and this has been a little bit of a fuss to hand-configure on Linux of late.  The problem is that the <a class=\"externlink\" title=\"Go to http:\/\/pm-utils.freedesktop.org\/wiki\/\" href=\"http:\/\/pm-utils.freedesktop.org\/wiki\/\">pm-utils<\/a> suite that almost all distributions use isn&#8217;t really well suited to triggering a lock, and <a class=\"externlink\" title=\"Go to http:\/\/lists.freedesktop.org\/archives\/pm-utils\/2009-February\/001905.html\" href=\"http:\/\/lists.freedesktop.org\/archives\/pm-utils\/2009-February\/001905.html\">not everyone<\/a> thinks it should be able to.  The Ubuntu solution follows the &#8220;not in pm-suspend&#8221; idea, and predictably adds another (bulky) layer of abstraction, using gnome-power-manager lock the screen and call the suspend scripts separately.  Because I don&#8217;t always call pm-suspend the same way and don&#8217;t want an extra thing running anyway, that isn&#8217;t an option for me. So, a solution to run xlock on every invocation of pm-suspend that ACTUALLY WORKS is to add an <a class=\"externlink\" title=\"Go to http:\/\/www.fredprod.com\/cgi-bin\/man\/man2html?pm-suspend-hybrid+8#lbAG\" href=\"http:\/\/www.fredprod.com\/cgi-bin\/man\/man2html?pm-suspend-hybrid+8#lbAG\">appropriately named<\/a> file in \/etc\/pm\/sleep.d, like the following:<\/p>\n<p><strong>22lock<\/strong><\/p>\n<pre>\n#!\/bin\/bash\nuser=`finger|&nbsp;grep&nbsp;-m1&nbsp;:0&nbsp;|&nbsp;awk&nbsp;'{print&nbsp;$1}'`\ncase&nbsp;$1&nbsp;in\n&nbsp;&nbsp;&nbsp;&nbsp;hibernate)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;su&nbsp;$user&nbsp;-c&nbsp;\"xlock&nbsp;-mode&nbsp;blank&nbsp;-display&nbsp;:0&#038;\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;\n&nbsp;&nbsp;&nbsp;&nbsp;suspend)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;su&nbsp;$user&nbsp;-c&nbsp;\"xlock&nbsp;-mode&nbsp;blank&nbsp;-display&nbsp;:0&#038;\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;\n&nbsp;&nbsp;&nbsp;&nbsp;thaw)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;\n&nbsp;&nbsp;&nbsp;&nbsp;resume)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;\n&nbsp;&nbsp;&nbsp;&nbsp;*)&nbsp;&nbsp;echo&nbsp;\"The&nbsp;xlock-on-sleep&nbsp;script&nbsp;is&nbsp;broken\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;\nesac\n<\/pre>\n<p>Remember to make the file executable (chmod +x).<br \/>\nThe finger\/grep\/awk incantation at the top is a cheap (and not entirely proper) way of grabbing the first user on display :0, which is USUALLY the user logged in on what is USUALLY the local X server; sudoing to an appropriate user (and the explicit &#8220;-display :0&#8221;) is required because the script is run in an environment where the display isn&#8217;t visible and the user is always root.<br \/>\nxlock and it&#8217;s options can be modified or swapped out for your screen-locker of choice.<\/p>\n<p>(Posting as a reminder to myself, and because I didn&#8217;t see a solution when I searched)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve always preferred that my machines be locked when they wake up from sleep\/suspend\/hibernate\/etc., and this has been a little bit of a fuss to hand-configure on Linux of late. The problem is that the pm-utils suite that almost all &hellip; <a href=\"https:\/\/pappp.net\/?p=125\">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":{"footnotes":""},"categories":[4,8,1,12],"tags":[51],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-computers","category-diy","category-general","category-oldblog","tag-linux"],"_links":{"self":[{"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":0,"href":"https:\/\/pappp.net\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"wp:attachment":[{"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pappp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}