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
7 +# Debian 1.1.30-5.1 2003/07/20 Andreas Barth <aba@not.so.argh.org>
8 +# Can specify group per commandline.
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
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)
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
22 # Revision 1.56 2002/01/04 17:52:42 gert
23 # pass sendfax exit code as 2nd argument to success/failure program
26 # Revision 1.54 2001/12/16 14:26:25 gert
27 # stop queue handling if a file named 'stop' exists
29 +# Add a -D option to allow for running in the background as a Daemon
30 +# Philip Hands <phil@hands.com>
32 # Revision 1.53 2000/08/06 14:28:37 gert
33 # go from using $fax_spool_out/.last_run to VARRUNDIR/faxqueue_done
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';
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';
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
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";
69 if ( $opt_d ) { $opt_v=1; }
72 mgetty+sendfax by Gert Doering
75 -config file read from '$faxrunq_cf'
76 +config read from '$faxrunq_cf'
85 if ( $opt_u ne '' ) # set user ID to $opt_u
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];
92 if ( !defined($uid) || !defined($gid) )
93 { die "$0: no such user: '$opt_u'\n"; }
95 print "change user ID to '$opt_u' (numeric uid: $uid, gid: $gid)\n"
100 - if ( $> != $uid || $) != $gid )
101 - { die "$0: can't set uid to $uid / gid to $gid: $!\n"; }
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);
115 +if ( $> != $uid || $) != $gid )
116 + { die "$0: can't set uid to $uid / gid to $gid: $!\n"; }
118 if ( $> == 0 ) # root check
120 print STDERR "$0: running with root privileges is not recommended\n";
123 +# fork as a daemon if invoked with -D
126 + die "Cannot fork: $!" unless defined $pid ;
128 + # Child process: become leader of a new session, lose STDIN, log STDOUT/ERR
131 + open(STDIN, "/dev/null") ;
132 + open(STDOUT, ">&LOG") ;
133 + open(STDERR, ">&LOG") ;
135 + exit 0; # parent process
140 # startup... write PID file, make sure no other faxrunqd runs
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
149 $SIG{USR2} = \&signal_handler_USR2; # graceful exit
150 $graceful_exit_requested = 0;
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'";
159 print LOG "\n" . localtime() .": faxrunqd starting, pid=$$\n";
161 $roll_log_file_requested=0;
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'";
168 print LOG localtime() .": -- new log file started --\n";
169 @@ -1639,7 +1685,8 @@
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";
178 # save tty statistics