aboutsummaryrefslogtreecommitdiffstats
path: root/lcd4linux.c
diff options
context:
space:
mode:
authorreinelt <>2003-08-08 06:58:06 +0000
committerreinelt <>2003-08-08 06:58:06 +0000
commitc5e120b8fe161ad249c4c5b39882d7129cd38761 (patch)
tree58b0d87ec40dc853e52d4d3d15316ee6d48e8267 /lcd4linux.c
parent30c378af7cabefb77a3a0017b3d044521d9f74c4 (diff)
downloadlcd4linux-c5e120b8fe161ad249c4c5b39882d7129cd38761.tar.gz
[lcd4linux @ 2003-08-08 06:58:06 by reinelt]
improved forking
Diffstat (limited to 'lcd4linux.c')
-rw-r--r--lcd4linux.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/lcd4linux.c b/lcd4linux.c
index dee44fd..9a1e64b 100644
--- a/lcd4linux.c
+++ b/lcd4linux.c
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.39 2003/07/24 04:48:09 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.40 2003/08/08 06:58:06 reinelt Exp $
*
* LCD4Linux
*
@@ -20,6 +20,9 @@
*
*
* $Log: lcd4linux.c,v $
+ * Revision 1.40 2003/08/08 06:58:06 reinelt
+ * improved forking
+ *
* Revision 1.39 2003/07/24 04:48:09 reinelt
* 'soft clear' needed for virtual rows
*
@@ -224,6 +227,7 @@ char *output=NULL;
int got_signal=0;
int debugging=0;
int foreground=0;
+int background=0;
int tick, tack;
static void usage(void)
@@ -363,6 +367,26 @@ int main (int argc, char *argv[])
exit(2);
}
+ info ("Version " VERSION " starting");
+ if (!foreground && (my_argv[0]==NULL || my_argv[0][0]!='/')) {
+ info ("invoked without full path; restart may not work!");
+ }
+
+ // set default values
+ cfg_set ("row1", "*** %o %v ***");
+ cfg_set ("row2", "%p CPU %r MB RAM");
+ cfg_set ("row3", "Busy %cu%% $r10cu");
+ cfg_set ("row4", "Load %l1%L$r10l1");
+
+ if (cfg_read (cfg)==-1)
+ exit (1);
+
+ driver=cfg_get("display",NULL);
+ if (driver==NULL || *driver=='\0') {
+ error ("missing 'display' entry in %s!", cfg_file());
+ exit (1);
+ }
+
if (!foreground) {
pid_t i;
int fd;
@@ -377,11 +401,22 @@ int main (int argc, char *argv[])
// ignore nasty signals
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
+
+ // chdir("/")
+ if (chdir("/")!=0) {
+ error ("chdir(\"/\") failed: %s", strerror(errno));
+ exit (1);
+ }
+
+ // we want full control over permissions
+ umask (0);
+
// detach stdin
if (freopen("/dev/null", "r", stdin)==NULL) {
error ("freopen (/dev/null) failed: %s", strerror(errno));
exit (1);
}
+
// detach stdout and stderr
fd=open("/dev/null", O_WRONLY, 0666);
if (fd==-1) {
@@ -393,30 +428,7 @@ int main (int argc, char *argv[])
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
close(fd);
- }
-
- if (foreground) {
- info ("Version " VERSION " starting");
- } else {
- info ("Version " VERSION " starting");
- if (my_argv[0]==NULL || my_argv[0][0]!='/') {
- info ("invoked without full path; restart may not work!");
- }
- }
-
- // set default values
- cfg_set ("row1", "*** %o %v ***");
- cfg_set ("row2", "%p CPU %r MB RAM");
- cfg_set ("row3", "Busy %cu%% $r10cu");
- cfg_set ("row4", "Load %l1%L$r10l1");
-
- if (cfg_read (cfg)==-1)
- exit (1);
-
- driver=cfg_get("display",NULL);
- if (driver==NULL || *driver=='\0') {
- error ("missing 'display' entry in %s!", cfg_file());
- exit (1);
+ background=1;
}
debug ("initializing driver %s", driver);