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 2005 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"
35 #define USAGE "[-xNUM] [-uNUM]"
40 char jgrade
[2*MAXGRADE
+1];
44 void cleanup(), exuucico();
46 void logent(){} /* to load ulockf.c */
49 main(argc
, argv
, envp
)
54 struct m
*m
, *machine();
55 DIR *spooldir
, *subdir
, *gradedir
;
56 char f
[256], g
[256], fg
[256], subf
[256];
58 char *gradelist
, *gradeptr
[MAXGRADE
+1];
60 char lckname
[MAXFULLNAME
];
61 struct limits limitval
;
68 (void) strcpy(Progname
, "uusched");
69 while ((i
= getopt(argc
, argv
, "u:x:")) != EOF
) {
75 "WARNING: %s: invalid debug level %s ignored, using level 1\n",
81 "WARNING: uusched built with SMALL flag defined -- no debug info available\n");
88 "WARNING: %s: invalid debug level %s ignored, using level 1\n",
94 (void) fprintf(stderr
, "\tusage: %s %s\n",
100 (void) fprintf(stderr
, "\tusage: %s %s\n", Progname
, USAGE
);
104 DEBUG(9, "Progname (%s): STARTED\n", Progname
);
105 if (scanlimit("uusched", &limitval
) == FAIL
) {
106 DEBUG(1, "No limits for uusched in %s\n", LIMITS
);
109 maxnumb
= limitval
.totalmax
;
111 DEBUG(4, "Non-positive limit for uusched in %s\n", LIMITS
);
112 DEBUG(1, "No limits for uusched\n%s", "");
114 DEBUG(4, "Uusched limit %d -- ", maxnumb
);
115 i
= cuantos(S_LOCKPRE
, X_LOCKDIR
);
117 DEBUG(4, "found %d -- cleaning up\n", i
);
120 DEBUG(4, "continuing\n", maxnumb
);
124 if (chdir(SPOOL
) != 0 || (spooldir
= opendir(SPOOL
)) == NULL
)
125 cleanup(101); /* good old code 101 */
126 while (gdirf(spooldir
, f
, SPOOL
) == TRUE
) {
128 ASSERT(subdir
!= NULL
, Ct_OPEN
, f
, errno
);
129 while (gdirf(subdir
, g
, f
) == TRUE
) {
130 (void) sprintf(fg
, "%s/%s", f
, g
);
131 gradedir
= opendir(fg
);
132 ASSERT(gradedir
!= NULL
, Ct_OPEN
, g
, errno
);
133 while (gnamef(gradedir
, subf
) == TRUE
) {
134 if (subf
[1] == '.') {
135 if (subf
[0] == CMDPRE
) {
136 /* Note - we can break now, since we
137 * have found a job grade with at least
140 (void) strncat(machine(f
)->jgrade
, g
, strlen(g
));
150 /* Make sure the overflow entry is null since it may be incorrect */
151 M
[UUSTAT_TBL
].mach
[0] = NULLCHAR
;
153 /* count the number of systems */
154 for (num
=0, m
=M
; m
->mach
[0] != '\0'; m
++, num
++) {
155 DEBUG(5, "machine: %s, ", M
[num
].mach
);
156 DEBUG(5, "job grade list: %s\n", M
[num
].jgrade
);
158 DEBUG(5, "Execute num=%d \n", num
);
161 * create lock file once we have work to do
162 * (but only if there is a job limit)
165 for (i
= 0; i
< maxnumb
; i
++) {
166 (void) sprintf(lckname
, "%s.%d", S_LOCK
, i
);
167 if (mklock(lckname
) == SUCCESS
)
171 DEBUG(4, "found %d -- cleaning up\n", i
);
175 snumber
= (time((time_t *) 0) % num
); /* random num */
176 (void) strcpy(Rmtname
, M
[snumber
].mach
);
177 gradelist
= M
[snumber
].jgrade
;
178 DEBUG(5, "num=%d, ", num
);
179 DEBUG(5, "snumber=%d, ", snumber
);
180 DEBUG(5, "Rmtname=%s, ", Rmtname
);
181 DEBUG(5, "job grade list= %s\n", gradelist
);
183 numgrade
= getargs(gradelist
, gradeptr
, MAXGRADE
);
184 for (i
=0; i
<numgrade
; i
++) {
185 (void) sprintf(lckname
, "%s.%s.%s", LOCKPRE
, Rmtname
, gradeptr
[i
]);
186 if (cklock(lckname
) != FAIL
&& callok(Rmtname
) == 0) {
187 /* no lock file and status time ok */
188 DEBUG(5, "call exuucico(%s)\n", Rmtname
);
193 /* job grade locked - look for the next one */
194 DEBUG(5, "job grade %s locked or inappropriate status\n",
199 M
[snumber
] = M
[num
-1];
215 namelen
= strlen(name
);
216 DEBUG(9, "machine(%s) called\n", name
);
217 for (m
= M
; m
->mach
[0] != '\0'; m
++)
218 /* match on overlap? */
219 if (EQUALSN(name
, m
->mach
, MAXBASENAME
)) {
220 /* check for job grade */
221 if (m
->jgrade
[0] != NULLCHAR
)
222 (void) strncat(m
->jgrade
, " ", 1);
224 /* use longest name */
225 if (namelen
> strlen(m
->mach
))
226 (void) strcpy(m
->mach
, name
);
231 * The table is set up with 2 extra entries
232 * When we go over by one, output error to errors log
233 * When more than one over, just reuse the previous entry
235 if (m
-M
>= UUSTAT_TBL
) {
236 if (m
-M
== UUSTAT_TBL
) {
237 errent("MACHINE TABLE FULL", "", UUSTAT_TBL
,
241 /* use the last entry - overwrite it */
245 (void) strcpy(m
->mach
, name
);
246 m
->jgrade
[0] = NULLCHAR
;
260 (void) sprintf(sopt
, "-s%s", name
);
262 (void) sprintf(uopt
, "-x%.1d", Uopt
);
264 if ((pid
= vfork()) == 0) {
266 (void) execle(UUCICO
, "UUCICO", "-r1", uopt
, sopt
, (char *) 0, Env
);
268 (void) execle(UUCICO
, "UUCICO", "-r1", sopt
, (char *) 0, Env
);
272 while ((ret
= wait(&status
)) != pid
)
273 if (ret
== -1 && errno
!= EINTR
)
276 DEBUG(3, "ret=%ld, ", (ret
== pid
? (long) status
: (long) ret
));