]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/mgetty/mgetty-1.1.30/12-fax_faxrunqd.in
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / mgetty / mgetty-1.1.30 / 12-fax_faxrunqd.in
1 --- mgetty-1.1.30/fax/faxrunqd.in.orig  2003-09-13 11:04:12.000000000 +0000
2 +++ mgetty-1.1.30-5.1/fax/faxrunqd.in   2003-09-13 11:12:47.000000000 +0000
3 @@ -13,6 +13,9 @@
4  #
5  # Change Log:
6  #
7 +# Debian 1.1.30-5.1 2003/07/20  Andreas Barth <aba@not.so.argh.org>
8 +# Can specify group per commandline.
9 +#
10  # $Log: faxrunqd.in,v $
11  # Revision 1.63  2002/11/23 16:52:18  gert
12  # make messages more clear, print warning if running as root
13 @@ -45,6 +48,11 @@
14  # a "low prio" job for phone number 123 could be attached to a high prio
15  # job to 123, and thus be sent before a high prio job to 456)
16  #
17 +# Debian 1.1.28-4 2002/11/27 18:32:23 Wolfgang Sourdeau <was@debian.org>
18 +# Quit quietly when received signal TERM or HUP since it is expected the
19 +# user knows what is happening already. The quit message is still written
20 +# into the logfile.
21 +#
22  # Revision 1.56  2002/01/04 17:52:42  gert
23  # pass sendfax exit code as 2nd argument to success/failure program
24  #
25 @@ -55,6 +63,9 @@
26  # Revision 1.54  2001/12/16 14:26:25  gert
27  # stop queue handling if a file named 'stop' exists
28  #
29 +# Add a -D option to allow for running in the background as a Daemon
30 +#       Philip Hands <phil@hands.com>
31 +#
32  # Revision 1.53  2000/08/06 14:28:37  gert
33  # go from using $fax_spool_out/.last_run to VARRUNDIR/faxqueue_done
34  #
35 @@ -129,6 +140,8 @@
36  #
37  #
38  require 5.004;
39 +
40 +use Fcntl;
41  use POSIX;
42  use IO::Handle;
43  use Getopt::Std;
44 @@ -143,10 +156,10 @@
45  $mail='@MAILER@';
46  
47  $faxrunq_cf='@CONFDIR@/faxrunq.config';
48 -$fax_acct='@FAX_SPOOL@/acct.log';
49 -$faxrd_log='@FAX_SPOOL@/faxrunqd.log';
50 +$fax_acct='/var/log/mgetty/fax/acct.log';
51 +$faxrd_log='/var/log/mgetty/fax/faxrunqd.log';
52  
53 -$faxrd_pid='@FAX_SPOOL_OUT@/faxrunqd.pid';
54 +$faxrd_pid='/var/run/mgetty-fax/faxrunqd.pid';
55  $last_run='@FAX_SPOOL_OUT@/faxqueue_done';
56  
57  $policy_config='';
58 @@ -189,8 +202,10 @@
59  $opt_V = 0;                                    # print version number
60  $opt_l = '';                                   # ttys to use
61  $opt_u = '';                                   # user id to setuid() to
62 -getopts( 'dvVl:u:' ) || 
63 -    die "Valid options: -d (debug), -v (verbose), -l tty<n>, -u uid, -V (version)\n";
64 +$opt_g = '';                                   # group id to setgid() to
65 +$opt_D = 0;                                    # daemon
66 +getopts( 'DdvVl:u:g:' ) || 
67 +    die "Valid options: -D (daemon), -d (debug), -v (verbose), -l tty<n>, -u uid, -g uid, -V (version)\n";
68  
69  if ( $opt_d ) { $opt_v=1; }
70  
71 @@ -201,32 +216,63 @@
72  mgetty+sendfax by Gert Doering
73  $rcs_id
74  
75 -config file read from '$faxrunq_cf'
76 +config read from '$faxrunq_cf'
77  
78  EOF
79      exit 0;
80  }
81  
82 +$uid=$>;
83 +$gid=$);
84 +
85  if ( $opt_u ne '' )    # set user ID to $opt_u
86  {
87 -    my ( $uid, $gid ) = ( getpwnam( $opt_u ) )[2,3];
88 +    ( $uid, $gid ) = ( ( $opt_u =~ /^[0-9]+$/ )
89 +                           ? getpwuid( $opt_u )
90 +                           : getpwnam( $opt_u ) )[2,3];
91  
92      if ( !defined($uid) || !defined($gid) )
93                 { die "$0: no such user: '$opt_u'\n"; }
94  
95      print "change user ID to '$opt_u' (numeric uid: $uid, gid: $gid)\n"
96                                                                 if $opt_d;
97 -    $( = $) = $gid;
98 -    $< = $> = $uid;
99 -
100 -    if ( $> != $uid || $) != $gid )
101 -               { die "$0: can't set uid to $uid / gid to $gid: $!\n"; }
102  }
103 +
104 +if ( $opt_g ne '' )
105 +    {
106 +       $gid = ( ( $opt_g =~ /^[0-9]+$/ )
107 +                  ? getgrgid( $opt_g )
108 +                  : getgrnam( $opt_g ) )[2];
109 +       die "$0: no such group: '$opt_g'\n" unless defined ($gid);
110 +    }
111 +
112 +$( = $) = $gid;
113 +$< = $> = $uid;
114 +
115 +if ( $> != $uid || $) != $gid )
116 +       { die "$0: can't set uid to $uid / gid to $gid: $!\n"; }
117 +
118  if ( $> == 0 )         # root check
119  {
120      print STDERR "$0: running with root privileges is not recommended\n";
121  }
122  
123 +# fork as a daemon if invoked with -D
124 +if ( $opt_D ) {
125 +  $pid = fork ;
126 +  die "Cannot fork: $!" unless defined $pid ;
127 +  if (0 == $pid) {
128 +    # Child process: become leader of a new session, lose STDIN, log STDOUT/ERR
129 +    POSIX::setsid();
130 +    umask(022);
131 +    open(STDIN, "/dev/null") ;
132 +    open(STDOUT, ">&LOG") ;
133 +    open(STDERR, ">&LOG") ;
134 +  } else {
135 +    exit 0;     # parent process
136 +  }
137 +}
138 +
139  #
140  # startup... write PID file, make sure no other faxrunqd runs
141  #
142 @@ -262,7 +308,7 @@
143  
144  $SIG{USR1} = \&signal_handler_USR1;            # roll log file
145  $roll_log_file_requested = 0;
146 -$roll_level=3;                                 # keep 3 old files around
147 +$roll_level=7;                                 # keep 7 old files around
148  
149  $SIG{USR2} = \&signal_handler_USR2;            # graceful exit
150  $graceful_exit_requested = 0;
151 @@ -355,7 +401,7 @@
152  #
153  # open log file
154  #
155 -open( LOG, ">>$faxrd_log" ) ||
156 +sysopen( LOG, "$faxrd_log", O_CREAT | O_APPEND | O_WRONLY, 0640 ) ||
157             die "can't write log file '$faxrd_log'";
158  LOG->autoflush(1);
159  print LOG "\n" . localtime() .": faxrunqd starting, pid=$$\n";
160 @@ -552,7 +598,7 @@
161         $roll_log_file_requested=0;
162  
163         # start new
164 -       open( LOG, ">$faxrd_log" ) ||
165 +       sysopen( LOG, "$faxrd_log", O_CREAT | O_APPEND | O_WRONLY, 0640 ) ||
166                     die "can't re-open log file '$faxrd_log'";
167         LOG->autoflush(1);
168         print LOG localtime() .": -- new log file started --\n";
169 @@ -1639,7 +1685,8 @@
170  {
171  my $sig = shift;
172  
173 -    print "\nfaxrunqd: signal handler: got signal $sig, goodbye...\n";
174 +    print "\nfaxrunqd: signal handler: got signal $sig, goodbye...\n"
175 +       if ($sig ne 'TERM' && $sig ne 'HUP' && $sig ne 'USR2');
176      print LOG "\nfaxrunqd: signal handler: got signal $sig, goodbye...\n";
177  
178      # save tty statistics