Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/bin/rc
2
rfork s
3
 
4
if (! ~ $DEBUG '') flag x +
5
 
6
LPDELAY=60
7
 
8
if (! ~ $#* 2 && ! ~ $#* 3) {
9
	echo 'usage generic local_cmd _remote_cmd [ success_cmd ]' >[1=2]
10
	exit 'argument count'
11
}
12
LOCAL_CMD=$1
13
REMOTE_CMD=$2
14
SUCCESS_CMD=$3
15
 
16
# we don't want to make a LOCK file unless we are at the destination
17
# let the spooler take care of moving it there
18
# this is necessary for clients and servers that share the
19
# same name space
20
if (! ~ $THIS_HOST $DEST_HOST || ! LOCK $LPSPOOL/$LPDEST/LOCK $sysname $pid) exit ''
21
 
22
cd $LPSPOOL
23
 
24
MAXTRY=2
25
PRINTLOG=$LPLOGDIR/$LPDEST^.st
26
 
27
fn schedule{
28
	FILE=`{
29
		@{
30
			rfork n
31
			bind -b $LPLIB/sched /bin
32
			$SCHED $LPDEST
33
		}
34
	}
35
}
36
 
37
while (schedule; ! ~ $#FILE 0) {
38
	SCHEDLINE=`{cat $LPDEST/$FILE(1)^id}
39
	LSLINE=`{ls -l $LPDEST/$FILE(1)}
40
	if (! test -s $LPDEST/.seqno) {
41
		echo 0 > $LPDEST/.seqno
42
	}
43
	if not {
44
		LPSEQNO = `{cat $LPDEST/.seqno | awk '{seqno = $1 + 1; if (seqno > 999) seqno = 0; print seqno}'}
45
		echo $LPSEQNO > $LPDEST/.seqno
46
	}
47
	STARTIME=`{date}
48
	if (! test -s $LPDEST/$FILE(1)) {
49
		echo $SCHEDLINE(2)$SCHEDLINE(4)'	'$SCHEDLINE(3)	$SCHEDLINE(5)' ! '$LSLINE(6) $STARTIME(4) >> $LPLOG
50
		rm -f $LPDEST/$FILE $LPDEST/$FILE^id
51
	}
52
	if not {
53
		if (~ $THIS_HOST $DEST_HOST) {
54
			if (test -f $LPLIB/perm/$LPDEST && grep -s $SCHEDLINE(2) $LPLIB/perm/$LPDEST) {
55
				echo you are not allowed to use printer $LPDEST | mail $SCHEDLINE(2)
56
				rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
57
			}
58
			if not {
59
				> $PRINTLOG
60
				STARTIME=`{date}
61
				eval $LOCAL_CMD
62
				rv=$status
63
				ENDTIME=`{date}
64
				status=$rv
65
				if () {
66
					echo $SCHEDLINE(1)^$SCHEDLINE(3)'	'$SCHEDLINE(2)'	'$SCHEDLINE(4)' + '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)
67
					eval $SUCCESS_CMD
68
					rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
69
				}
70
				if not {
71
					echo $SCHEDLINE(1)^$SCHEDLINE(3)'	'$SCHEDLINE(2)'	'$SCHEDLINE(4)' - '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)' status='$rv
72
					THISTRY=`{echo $SCHEDLINE(4) + 1|hoc}
73
					echo $SCHEDLINE(1) $SCHEDLINE(2) $SCHEDLINE(3) $THISTRY >$LPDEST/$FILE(1)^id
74
					if (test $THISTRY -ge $MAXTRY) {
75
						if (test -d $LPLIB/prob/$LPDEST) {
76
							cp $LPDEST/$FILE(1) $LPLIB/prob/$LPDEST
77
							cp $LPDEST/$FILE(1)^id $LPLIB/prob/$LPDEST
78
							cp $PRINTLOG $LPLIB/prob/$LPDEST/$FILE(1)^log
79
						}
80
						upasname=daemon
81
						mail $SCHEDLINE(2) <<endmail1
82
						rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
83
					}
84
					if not {
85
						touch $LPDEST/$FILE(1)
86
						sleep $LPDELAY
87
					}
88
				}
89
			}
90
		}
91
		if not {
92
# we don't want to be here
93
#			trap '' 13	# temp hack: ignore SIGPIPE
94
			STARTIME=`{date}
95
			eval $REMOTE_CMD 
96
			rv=$status
97
			ENDTIME=`{date}
98
			if (~ $rv '') {
99
				echo $SCHEDLINE(1)^$SCHEDLINE(3)'	'$SCHEDLINE(2)'	'$SCHEDLINE(4)' + '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)
100
				rm -f $LPDEST/$FILE(1) $LPDEST/$FILE(1)^id
101
			}
102
			if not {
103
				echo $SCHEDLINE(1)^$SCHEDLINE(3)'	'$SCHEDLINE(2)'	'$SCHEDLINE(4)' - '$LSLINE(6)' '$STARTIME(4)' '$ENDTIME(4)
104
				echo status $rv from '$REMOTE_CMD'
105
				THISTRY=`{echo $SCHEDLINE(4) + 1|hoc}
106
				echo $SCHEDLINE(1) $SCHEDLINE(2) $SCHEDLINE(3) $THISTRY >$LPDEST/$FILE(1)^id
107
				if (~ $THISTRY $MAXTRY) {
108
					upasname=daemon
109
					mail $SCHEDLINE(2) <<endmail2
110
				}
111
				if not {
112
					touch $LPDEST/$FILE(1)
113
					sleep $LPDELAY
114
 
115
				# this is here to deal with running out of
116
				# Datakit channels or other stupid problems
117
				# backoff connection attempts but not too long
118
					LPDELAY=`{echo $LPDELAY '*' 2|hoc}
119
					if (test $LPDELAY -gt 960)
120
						LPDELAY=60
121
				}
122
			}
123
		}
124
	}
125
}
126
Your job has failed to print on $LPDEST after $MAXTRY attempt(s).
127
If the directory $LPLIB/prob/$LPDEST exists on $DEST_HOST,
128
the file has been put there along with the printer log file.
129
			Your friendly printer daemon
130
endmail1
131
Your job has failed to print on $LPDEST after $MAXTRY attempt(s).
132
There is a problem in sending the job to $DEST_HOST,
133
but I'll keep trying.  Have a nice day.
134
			Your enthusiastic printer daemon
135
endmail2
136
UNLOCK $LPSPOOL/$LPDEST
137
rm $LPSPOOL/$LPDEST >[2]/dev/null