~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to demo/linux/daemon.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
                                 CncWare
3
3
                           (c) Copyright 2000
4
4
 ---------------------------------------------------------------------------
5
 
  $Id: daemon.pp,v 1.3 2002/09/07 15:06:35 peter Exp $
 
5
  $Id: daemon.pp,v 1.5 2005/04/06 10:47:01 marco Exp $
6
6
  Filename..: daemon.pp
7
7
  Programmer: Ken J. Wright
8
8
  Date......: 03/21/2000
30
30
------------------------------------------------------------------------------
31
31
}
32
32
Program Daemon;
33
 
uses linux;
 
33
uses SysUtils,BaseUnix;
34
34
Var
35
35
   { vars for daemonizing }
36
36
   bHup,
42
42
   aHup : pSigActionRec;
43
43
   ps1  : psigset;
44
44
   sSet : cardinal;
45
 
   pid : longint;
 
45
   pid  : pid_t;
46
46
   secs : longint;
 
47
   zerosigs : sigset_t;
47
48
   hr,mn,sc,sc100 : word;
48
49
 
49
50
{ handle SIGHUP & SIGTERM }
60
61
Begin
61
62
   Assign(fLog,logname);
62
63
   Rewrite(fLog);
63
 
   GetTime(hr,mn,sc,sc100);
64
 
   Writeln(flog,'Log created at ',hr:0,':',mn:0,':',sc:0);
 
64
   Writeln(flog,'Log created at ',formatdatetime('hh:nn:ss',now));
65
65
   Close(fLog);
66
66
End;
67
67
 
68
68
Begin
69
69
   logname := 'daemon.log';
70
70
   secs := 10;
 
71
   fpsigemptyset(zerosigs);
71
72
 
72
73
   { set global daemon booleans }
73
74
   bHup := true; { to open log file }
76
77
   { block all signals except -HUP & -TERM }
77
78
   sSet := $ffffbffe;
78
79
   ps1 := @sSet;
79
 
   sigprocmask(sig_block,ps1,nil);
 
80
   fpsigprocmask(sig_block,ps1,nil);
80
81
 
81
82
   { setup the signal handlers }
82
83
   new(aOld);
83
84
   new(aHup);
84
85
   new(aTerm);
85
 
   aTerm^.handler.sh := @DoSig;
86
 
   aTerm^.sa_mask := 0;
 
86
   aTerm^.sa_handler{.sh} := SigactionHandler(@DoSig);
 
87
 
 
88
   aTerm^.sa_mask := zerosigs;
87
89
   aTerm^.sa_flags := 0;
88
90
   {$ifndef BSD}                {Linux'ism}
89
91
    aTerm^.sa_restorer := nil;
90
92
   {$endif}
91
 
   aHup^.handler.sh := @DoSig;
92
 
   aHup^.sa_mask := 0;
 
93
   aHup^.sa_handler := SigactionHandler(@DoSig);
 
94
   aHup^.sa_mask := zerosigs;
93
95
   aHup^.sa_flags := 0;
94
96
   {$ifndef BSD}                {Linux'ism}
95
97
    aHup^.sa_restorer := nil;
96
98
   {$endif}
97
 
   SigAction(SIGTERM,aTerm,aOld);
98
 
   SigAction(SIGHUP,aHup,aOld);
 
99
   fpSigAction(SIGTERM,aTerm,aOld);
 
100
   fpSigAction(SIGHUP,aHup,aOld);
99
101
 
100
102
   { daemonize }
101
 
   pid := Fork;
 
103
   pid := fpFork;
102
104
   Case pid of
103
105
      0 : Begin { we are in the child }
104
106
         Close(input);  { close standard in }
125
127
      End;
126
128
      {----------------------}
127
129
      { Do your daemon stuff }
128
 
      GetTime(hr,mn,sc,sc100);
129
130
      Append(flog);
130
 
      Writeln(flog,'daemon code activated at ',hr:0,':',mn:0,':',sc:0);
 
131
      Writeln(flog,'daemon code activated at ',formatdatetime('hh:nn:ss',now));
131
132
      Close(fLog);
132
133
      { the following output goes to the bit bucket }
133
134
      Writeln('daemon code activated at ',hr:0,':',mn:0,':',sc:0);
136
137
         BREAK
137
138
      Else
138
139
         { wait a while }
139
 
         Select(0,nil,nil,nil,secs*1000);
 
140
         fpSelect(0,nil,nil,nil,secs*1000);
140
141
   Until bTerm;
141
142
End.
142
143
{
143
144
  $Log: daemon.pp,v $
 
145
  Revision 1.5  2005/04/06 10:47:01  marco
 
146
   * sigactionhandler fix
 
147
 
 
148
  Revision 1.4  2004/06/04 12:37:52  marco
 
149
   * modernized. Now only uses baseunix,sysutils
 
150
 
144
151
  Revision 1.3  2002/09/07 15:06:35  peter
145
152
    * old logs removed and tabs fixed
146
153