aboutsummaryrefslogtreecommitdiffstats
path: root/www/amphetadesk/files/patch-lib_AmphetaDesk_OS_Linux.pm
blob: 0c5d3c670b762a28d4445f1be07f5a9a50f7b4f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--- lib/AmphetaDesk/OS/Linux.pm.orig    Thu May 23 23:35:38 2002
+++ lib/AmphetaDesk/OS/Linux.pm Tue Oct 11 18:46:17 2005
@@ -15,11 +15,26 @@
 use strict;
 use AmphetaDesk::Settings;
 use AmphetaDesk::Utilities;
+use POSIX ":sys_wait_h";
+use POSIX ":unistd_h";
 require Exporter;
 use vars qw( @ISA @EXPORT );
 @ISA = qw( Exporter );
 @EXPORT = qw( gui_init gui_listen gui_note open_url );
 
+# taken from perlipc man page
+sub sigchild {
+  my $child;
+
+  # If a second child dies while in the signal handler caused by the
+  # first death, we won't get another signal. So must loop here else
+  # we will leave the unreaped child as a zombie. And the next time
+  # two children die we get another zombie. And so on.
+  while (($child = waitpid(-1,WNOHANG)) > 0) {}
+
+  $SIG{CHLD} = \&sigchild;
+}
+
 ###############################################################################
 # gui_init - start the gui and display the window.                            #
 ###############################################################################
@@ -105,8 +120,41 @@
    # construct our url.
    my $url = "http://127.0.0.1:" . get_setting("urls_port") . "/index.html";
 
+   # default browser
+   my $browser;
+
    # we spit out our suggestion just to catch all instances.
    note("If your browser doesn't load, go to <$url>.", 1);
+
+   # what browser?
+   if ($ENV{'BROWSER'}) {
+     $browser = $ENV{'BROWSER'};
+   } else {
+     if (get_setting("user_browser_path")) {
+       $browser = get_setting("user_browser_path");
+     }
+   }
+
+   if ( ($browser) && ( (-x $browser) || (-X $browser) ) ) {
+     note("Your environment states that $browser is your default program.");
+
+     $SIG{CHLD} = \&sigchild;
+
+     if (fork() == 0) {
+       my @args = ("$browser", "$url");
+
+       setsid();
+       close(STDIN);
+       close(STDOUT);
+       close(STDERR);
+
+       exec(@args) == 0
+         or note("The browser <$browser> does not exist. Please select another.");
+
+       exit 1;
+     }
+
+   }
 
    return 1;