4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
39 } syslst
[30]; /* no more than 30 systems per job */
47 * grade -> service grade
48 * file -> buffer to return filename must be of size MAXBASENAME+1
53 gename(pre
, sys
, grade
, file
)
54 char pre
, *sys
, grade
, *file
;
58 DEBUG(9, "gename(%c, ", pre
);
59 DEBUG(9, "%s, ", sys
);
60 DEBUG(9, "%c)\n", grade
);
63 DEBUG(9, "null sys -> %s\n", sys
);
66 if (pre
== CMDPRE
|| pre
== XQTPRE
) {
67 (void) sprintf(file
, "%c.%.*s%c%.4x",
68 pre
, SYSNSIZE
, sys
, grade
, syslst
[n
].job
);
70 (void) sprintf(file
, "%c.%.5s%.4x%.3x",
71 pre
, sys
, syslst
[n
].job
& 0xffff,
72 ++syslst
[n
].subjob
& 0xfff);
73 DEBUG(4, "file - %s\n", file
);
83 * get next sequence number
85 * number between 1 and 0xffff
87 * sequence number 0 is reserved for polling
97 char seqlock
[MAXFULLNAME
], seqfile
[MAXFULLNAME
];
99 ASSERT(nsys
< sizeof (syslst
)/ sizeof (syslst
[0]),
100 "SYSLST OVERFLOW", "", sizeof (syslst
));
102 (void) time(&seed
); /* crank up the sequence initializer */
103 srand((unsigned)seed
);
105 (void) sprintf(seqlock
, "%s%s", SEQLOCK
, sys
);
106 BASENAME(seqlock
, '/')[MAXBASENAME
] = '\0';
107 for (i
= 1; i
< SLOCKTRIES
; i
++) {
108 if ( mklock(seqlock
) == SUCCESS
)
113 ASSERT(i
< SLOCKTRIES
, Ct_LOCK
, seqlock
, 0);
115 (void) sprintf(seqfile
, "%s/%s", SEQDIR
, sys
);
116 if ((fp
= fopen(seqfile
, "r")) != NULL
) {
117 /* read sequence number file */
118 if (fscanf(fp
, "%4x", &n
) != 1) {
122 fp
= freopen(seqfile
, "w", fp
);
123 ASSERT(fp
!= NULL
, Ct_OPEN
, seqfile
, errno
);
124 (void) chmod(seqfile
, PUB_FILEMODE
);
126 /* can not read file - create a new one */
127 ASSERT((fp
= fopen(seqfile
, "w")) != NULL
,
128 Ct_CREATE
, seqfile
, errno
);
129 (void) chmod(seqfile
, PUB_FILEMODE
);
134 n
&= 0xffff; /* 4 byte sequence numbers */
135 (void) fprintf(fp
, "%.4x\n", n
);
136 ASSERT(ferror(fp
) == 0, Ct_WRITE
, seqfile
, errno
);
138 ASSERT(ferror(fp
) == 0, Ct_CLOSE
, seqfile
, errno
);
140 DEBUG(6, "%s seq ", sys
); DEBUG(6, "now %x\n", n
);
141 (void) strcpy(syslst
[nsys
].sys
, sys
);
142 syslst
[nsys
].job
= n
;
143 syslst
[nsys
].subjob
= rand() & 0xfff; /* random initial value */
148 * initSeq() exists because it is sometimes important to forget any
149 * cached work files. for example, when processing a bunch of spooled X.
150 * files, we must not re-use any C. files used to send back output.
161 * retseq() is used to get the sequence number of a job
162 * for functions outside of this file.
166 * the sequence number of the job for the system.
175 for (i
= 0; i
< nsys
; i
++)
176 if (EQUALSN(syslst
[i
].sys
, sys
, MAXBASENAME
))
179 return(syslst
[i
].job
);
188 for (i
= 0; i
< nsys
; i
++)
189 if (strncmp(syslst
[i
].sys
, sys
, MAXBASENAME
) == SAME
)