File:  [mozdev] / mozptch / linux_system.pas
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Sun May 30 19:51:15 2004 UTC (15 years, 5 months ago) by oertel
Branches: MAIN
CVS tags: version_30_05_04, HEAD
-Linux support ready for delivery (beta)
-New Variables for EmailAddress, ncoming and outgoing server
-INI-Files debuged
- new bin zip file

unit linux_system;

//http://rick-ross.com/papers/borcon2001/6204.html
//linkill from
// Written for "Kylix Power Solutions" 
// Copyright (c) 2001, Coriolis Group Books


interface
{$IFDEF LINUX}
uses Classes, libc, SysUtils, fork_exec, ProcStuff;
// forward definition

procedure linStart(cmdline : string);
function start(commandline : string) : boolean;
procedure linKill(name : string);
{$ENDIF}

implementation
{$IFDEF LINUX}




//Using the Classes - A Simple OO Shell

//Now that the TForker and TExecuter classes have been created, lets re-write the simple shell example.

procedure linStart(cmdline : string);
var
  cmd     : string;
  f       : TForker;

  procedure ParseArgs(commandline : string; var cmd : string;
                      strlst : TStrings);
  var
    tmp    : string;
    i      : integer;

  begin
    // start with an empty parameter list
    strlst.Clear;

    tmp := commandline;
    i   := Pos(' ',tmp);
    while (i > 0) do
    begin
      // found an argument
      // extract the string from 1 to i-1
      strlst.Add(  Copy(tmp,1,(i-1)) );

      tmp := Copy(tmp,i+1,length(tmp));
      i   := Pos(' ',tmp);
    end;

    if (tmp <> '') then
    begin
      // found an argument
      // extract the string from 1 to len
      strlst.Add( Copy(tmp,1,length(tmp)) );
    end;

    // now get the command from the first argument
    cmd := strlst.Strings[0];

    // and delete the first parameter
    strlst.Delete(0);
  end; // ParseArgs

begin
  // create the forker object
  f := TForker.Create;
  f.Exec := TExecuter.Create;
  f.WaitForChild := true;


  // search for arguments in the string
  ParseArgs(cmdline, cmd, f.Exec.Parameters);
  f.Exec.ProcessName := cmd;
  f.DoFork;
end;

function start(commandline : string) : boolean;
begin
 linStart(commandline);
 start := true;
end;

procedure linKill(name : string);
var
 i : Integer;
 L : TList;
 PRec : PProcInfoRec;
begin
 L := GetProcessListByName(name);
 if L.Count > 0
  then for i := 0 to L.Count - 1 do
   begin
    PRec := L.Items[i];
    with PRec^ do
    (*
     if MessageDlg('Kill Process ',
         'Process ' + IntToStr(i + 1) + ' of ' + IntToStr(L.Count)
          + LF + LF
         + 'Kill this process?' + LF + LF
         + 'Process ID: ' + IntToStr(PID) + LF
         + 'Status: ' + Status + LF
         + 'User name: ' + UName + LF
         + 'Command: ' + CmdName + LF,
         mtConfirmation, [mbYes, mbNo], 0) = mrYes
     then *)
     kill(PID, SIGTERM);
   end; { for }
   //else ShowMessage('No matches found for ' + PROCESSNAME);
 L.Free;
end;

{$ENDIF}
end.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>