The following code is segfaulting when run, and when tested with 'perl -cw'. I am pretty certain it has something to do with the screwy way I am trying to fork off a child and continue on with the parent, but I haven't enough experience with forking to know what I am doing. If anyone can point out how I SHOULD be spawning off the VPN process, I'd appreciate the education:

#!/usr/bin/perl -s # # bootmenu.pl Copyright(C) 2004 . All Rights Reserved. # # Date Name Description # 07/01/04 Rads Created V0.9. # 07/01/04 Jon Robison Updated to V1.3 # $Id$ use Tk; use Expect; use POSIX 'setsid'; ### Establish rdesktop command path my $rdp_exec; unless ($rdp_exec = `which rdesktop`) { die "Cannot find an RDP executable: $!\n"; } chomp $rdp_exec; ### Establish vpnclient command path my $vpn_command; unless ($vpn_command = `which vpnclient`) { die "Cannot find a VPN client utility: $!\n"; } chomp $vpn_command; my $method = "rdp"; # default method is ssh &create_ui; $BOOTMENU_VER = "1.3"; MainLoop(); sub create_ui { $top= MainWindow->new(); $top->title ("Corporate Home CD Boot Selector Version 1.3"); #----------------------------------------------------------------- # #----------------------------------------------------------------- # my $l1 = $top->Label('-text' => 'Corporate Home CD Boot Startup') +; # $l1->grid('-row' => 0, '-column' => 0, '-sticky' => 'w'); #----------- Radio Button ------------------------ my $l1 = $top->Label( '-text' => 'Method:', # '-relief' => 'groove', # '-width' => 10, # '-height' => 3, ); $l1->grid( '-row' => 2, '-column' => 0, '-columnspan' => 1, '-sticky' => 'w' ); my $l2 = $top->Radiobutton( -variable => \$method, -text => "RDP", -value => "rdp" ); $l2->grid( '-row' => 2, '-column' => 1, '-sticky' => 'w' ); my $l3 = $top->Radiobutton( -variable => \$method, -text => "ICA", -value => "ica" ); $l3->grid( '-row' => 2, '-column' => 2, '-sticky' => 'w' ); my $l4 = $top->Radiobutton( -variable => \$method, -text => "X over SSH", -value => "ssh" ); $l4->grid( '-row' => 2, '-column' => 3, '-sticky' => 'w' ); #----------- Server IP Address------------------------ my $l5 = $top->Label( '-text' => 'Server IP Address:' ); $l5->grid( '-row' => 1, '-column' => 0, '-columnspan' => 1, '-sticky' => 'w' ); $ipaddress = $top->Entry (); $ipaddress->grid( '-row' => 1, '-column' => 1, '-columnspan' => 2, '-sticky' => 'w', ); #-------------- My attempt at a line for Username/password---- my $u1 = $top->Label( -text => 'Corporate CDSID (SSH only)', ); $u1->grid( -row => 4, -column => 0, -columnspan => 1, -sticky => 'w', ); $cdsid = $top->Entry (); $cdsid->grid( -row => 4, -column => 1, -columnspan => 2, -sticky => 'w', ); my $u2 = $top->Label( -text => 'Corporate passwd (SSH only)', ); $u2->grid( -row => 5, -column => 0, -columnspan => 1, -sticky => 'w', ); $Corporatepass = $top->Entry ( -show => '*' ); $Corporatepass->grid( -row => 5, -column => 1, -columnspan => 2, -sticky => 'w', ); ######### Adding in the spot for the SecurID information #### my $u3 = $top->Label( -text=> 'PIN+SecurID', ); $u3->grid( -row=> 6, -column=> 0, -columnspan=> 1, -sticky=>'w', ); $securid = $top->Entry( -show => '*', ); $securid->grid( -row => 6, -column => 1, -columnspan => 2, -sticky => 'w', ); #----------- buttons ------------------------ $pkgButton = $top->Button( -text => 'Connect', -command => \&connect, -foreground => 'Green', ); $pkgButton->grid( '-row' => 7, '-column' => 1, '-columnspan' => 1, '-sticky' => 'w' ); $closeButton = $top->Button( -text => 'Close', -command => \&close, -foreground => 'Red', ); $closeButton->grid( '-row' => 7, '-column' => 2, '-columnspan' => 1, '-sticky' => 'w' ); } ########################################################3## sub close { exit(0); } sub connect { getValues(); my $action; if ($method eq "rdp") { print "Performing rdp\n"; # testing $action = "$rdp_exec -u $cdsid_value -f -g 1024x768 $ipaddress_v +alue"; print "Action line is: $action\n"; } elsif ($method eq "ica") { print "Performing ICA\n"; #testing $action = "/usr/X11R6/bin/icaclient -u $cdsid_value -f -g 1024x7 +68 $ipaddress_value"; } elsif ($method eq "ssh") { print "Performing SSH\n"; $action = "xhost + && /usr/bin/ssh -X -l $cdsid_value -f $ipad +dress_value Xsession"; } else { print "No method was chosen! Please try again\n"; exec "/etc/sysconfig/bootmenu.pl $ipaddress_value $method $cdsid_v +alue"; } ######### Set up the VPN Tunnel ##################### my @vpn_params = ('connect', 'Corporate'); my $vpn = new Expect; $vpn->raw_pty(1); my $vpn_status = spawn_vpn($vpn,$cdsid_value,$securid_value); unless ($vpn_status eq 'started') { die "Failed to start VPN: $!\n +"; } ######### Perform the requested remote contact action ################ +## my $command = Expect->spawn($action) or die "Could not spawn progr +am: $!\n"; $command->log_stdout(0); # prevent program output from being shown + on screen unless ($command->expect(10, "password")) { print "$action failed to execute: $!\n"; exec "/etc/sysconfig/bootmenu.pl"; } print $command "$Corporatepass_value\r"; $command->soft_close(); } #------------------------------------------------------------- sub getValues { $ipaddress_value = $ipaddress->get(); $cdsid_value = $cdsid->get(); # $Corporatepass_value = $Corporatepass->get(); $securid_value = $securid->get(); chomp($ipaddress_value); chomp($cdsid_value); # chomp($Corporatepass_value); chomp($securid_value); } sub become_daemon { die "Can't fork" unless defined (my $child = fork); return 'yes' if $child; ## was exit(0) if $child, but that killed +the parent. setsid(); # become session leader open(STDIN, "</dev/null"); open(STDOUT,">/dev/null"); open(STDERR, ">&STDOUT"); # chdir '/'; # umask(0); # forget file mode creation mask return $$; } sub spawn_vpn { my $self = shift; my $username = shift; my $securid_value = shift; my $started = become_deamon(); #daemonize this bitch return 'started' if ($started eq 'yes'); # return if I am the pare +nt $self->spawn($vpn_command, @vpn_params) or die "Cannot spawn $vpn_ +command: $!\n"; $timeout = 5; $self->expect($timeout, [ qr/username: /i, sub { my $self = shift; $self->send("$username\n"); exp_continue; }], [ qr/password: /i, sub { my $self = shift; $self->send("$password\n");, exp_continue; }], [ qr/\[y\/n\]: /i, sub { my $self = shift; $self->send("y\n");, exp_continue; }], ); }


What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

In reply to Segfaulting of a perl script by tame1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.