Browse Source

patch from Tobias Roth: put pid in lockfile + remove stale lockfile; added special commands and shortcuts info to the man page

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/slim/trunk@94 7c53e7cc-98ea-0310-8f1f-a0b24da60408
sip 18 years ago
parent
commit
5f0d16f2f7
2 changed files with 81 additions and 17 deletions
  1. 35 10
      app.cpp
  2. 46 7
      slim.1

+ 35 - 10
app.cpp

@@ -17,6 +17,8 @@
 #include <cstring>
 #include <cstring>
 #include <cstdio>
 #include <cstdio>
 
 
+#include <iostream>
+#include <fstream>
 #include <sstream>
 #include <sstream>
 #include <vector>
 #include <vector>
 #include <algorithm>
 #include <algorithm>
@@ -723,17 +725,40 @@ void App::setBackground(const string& themedir) {
     XFlush(Dpy);
     XFlush(Dpy);
 }
 }
 
 
-// Lock or die!
+// Check if there is a lockfile and a corresponding process
 void App::GetLock() {
 void App::GetLock() {
-    int fd;
-    fd=open(cfg.getOption("lockfile").c_str(),O_WRONLY | O_CREAT | O_EXCL);
-    if (fd<0 && errno==EEXIST) {
-        cerr << APPNAME << ": It appears there is another instance of the program already running" <<endl
-            << "If not, try to remove the lockfile: " << cfg.getOption("lockfile") <<endl;
-        exit(ERR_EXIT);
-    } else if (fd < 0) {
-        cerr << APPNAME << ": Could not accesss lock file: " << cfg.getOption("lockfile") << endl;
-        exit(ERR_EXIT);
+    std::ifstream lockfile(cfg.getOption("lockfile").c_str());
+    if (!lockfile) {
+        // no lockfile present, create one
+        std::ofstream lockfile(cfg.getOption("lockfile").c_str(), ios_base::out);
+        if (!lockfile) {
+            cerr << APPNAME << ": Could not create lock file: " << cfg.getOption("lockfile").c_str() << std::endl;
+            exit(ERR_EXIT);
+        }
+        lockfile << getpid() << std::endl;
+        lockfile.close();
+    } else {
+        // lockfile present, read pid from it
+        int pid = 0;
+        lockfile >> pid;
+        lockfile.close();
+        if (pid > 0) {
+            // see if process with this pid exists
+            int ret = kill(pid, 0);
+            if (ret == 0 || (ret == -1 && errno == EPERM) ) {
+                cerr << APPNAME << ": Another instance of the program is already running with PID " << pid << std::endl;
+                exit(0);
+            } else {
+                cerr << APPNAME << ": Stale lockfile found, removing it" << std::endl;
+                std::ofstream lockfile(cfg.getOption("lockfile").c_str(), ios_base::out);
+                if (!lockfile) {
+                    cerr << APPNAME << ": Could not create new lock file: " << cfg.getOption("lockfile") << std::endl;
+                    exit(ERR_EXIT);
+                }
+                lockfile << getpid() << std::endl;
+                lockfile.close();
+            }
+        }
     }
     }
 }
 }
 
 

+ 46 - 7
slim.1

@@ -1,5 +1,5 @@
 ." Text automatically generated by txt2man-1.4.7
 ." Text automatically generated by txt2man-1.4.7
-.TH slim 1 "May 15, 2005" "" ""
+.TH slim 1 "January 09, 2006" "" ""
 .SH NAME
 .SH NAME
 \fBslim \fP- Simple LogIn Manager
 \fBslim \fP- Simple LogIn Manager
 \fB
 \fB
@@ -15,29 +15,29 @@ of a graphical session by entring username and password in a login screen.
 .SH OPTIONS
 .SH OPTIONS
 .TP
 .TP
 .B
 .B
--d
+\fB-d\fP
 run as a daemon
 run as a daemon
 .TP
 .TP
 .B
 .B
--p /path/to/theme
+\fB-p\fP /path/to/theme
 display a preview of the theme. An already running X11 session
 display a preview of the theme. An already running X11 session
 is required for theme preview.
 is required for theme preview.
 .TP
 .TP
 .B
 .B
--h
+\fB-h\fP
 display a brief help message
 display a brief help message
 .TP
 .TP
 .B
 .B
--v
+\fB-v\fP
 display version information
 display version information
 .SH EXAMPLES
 .SH EXAMPLES
 .TP
 .TP
 .B
 .B
-\fBslim\fP -d
+\fBslim\fP \fB-d\fP
 run \fBslim\fP in daemon mode
 run \fBslim\fP in daemon mode
 .TP
 .TP
 .B
 .B
-\fBslim\fP -p /usr/share/\fBslim\fP/themes/default
+\fBslim\fP \fB-p\fP /usr/share/\fBslim\fP/themes/default
 preview of the default theme
 preview of the default theme
 .SH STARTING SLIM AT BOOT
 .SH STARTING SLIM AT BOOT
 Please refer to documentation of your Operating System to make \fBslim\fP
 Please refer to documentation of your Operating System to make \fBslim\fP
@@ -45,6 +45,45 @@ automatically startup after the system boots.
 .SH CONFIGURATION
 .SH CONFIGURATION
 Global configuration is stored in the /etc/slim.conf file. See the comments
 Global configuration is stored in the /etc/slim.conf file. See the comments
 inside the file for a detailed explanation of the \fIoptions\fP.
 inside the file for a detailed explanation of the \fIoptions\fP.
+.SH USAGE AND SPECIAL USERNAMES
+When started, \fBslim\fP will show a login panel; enter the username and
+password of the user you want to login as.
+.PP
+Special usernames:
+.TP
+.B
+console
+open a xterm console
+.TP
+.B
+exit
+quit \fBslim\fP
+.TP
+.B
+halt
+shutdown the machine
+.TP
+.B
+reboot
+reboot the machine
+.TP
+.B
+suspend
+power-suspend the machine
+.PP
+See the configuration file for customizing the above commands.
+The 'halt' and 'reboot' commands need the root password, this may
+change in future releases.
+.PP
+Shortcuts:
+.TP
+.B
+F11
+executes a custom command (by default takes a screenshot)  
+.TP
+.B
+F1
+choose session type (see configuration file and xinitrc.sample)
 .SH AUTHORS 
 .SH AUTHORS 
 Simone Rota <sip@varlock.com>
 Simone Rota <sip@varlock.com>
 .PP
 .PP