at.c revision b0d023d2a077dec1f7abfd95a9dd81fb8ec2cb10
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2011 Gary Mills 2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A#
define TMPFILE "_at" /* prefix for temporary files */ 2N/A * Mode for creating files in ATDIR. 2N/A * Setuid bit on so that if an owner of a file gives that file 2N/A * away to someone else, the setuid bit will no longer be set. 2N/A * If this happens, atrun will not execute the file 2N/A#
define ROOT 0
/* user-id of super-user */ 2N/A#
define MAXTRYS 100 /* max trys to create at job file */ 2N/A#
define BADQUEUE "queue name must be a single character a-z" 2N/A#
define CANTCD "can't change directory to the at directory" 2N/A#
define CANTCHOWN "can't change the owner of your job to you" 2N/A "usage: at [-c|-k|-s] [-m] [-f file] [-p project] [-q queuename] "\
2N/A " at [-c|-k|-s] [-m] [-f file] [-p project] [-q queuename] "\
2N/A " at -l [-p project] [-q queuename] [at_job_id...]\n"\
2N/A " at -r at_job_id ...\n" 2N/A * Error in getdate(3G) 2N/A/* 1 */ "getdate: The DATEMSK environment variable is not set",
2N/A/* 2 */ "getdate: Error on \"open\" of the template file",
2N/A/* 3 */ "getdate: Error on \"stat\" of the template file",
2N/A/* 4 */ "getdate: The template file is not a regular file",
2N/A/* 5 */ "getdate: An error is encountered while reading the template",
2N/A/* 6 */ "getdate: Malloc(3C) failed",
2N/A/* 7 */ "getdate: There is no line in the template that matches the input",
2N/A/* 8 */ "getdate: Invalid input specification" 2N/Aint mday[
12] = {
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31};
2N/A "project %s (%d)\n"),
2N/A "project %s (%d)\n"),
2N/A if (
when == 0) {
/* figure out what time to run the job */ 2N/A /* guard against buffer overflow */ 2N/A * Fix for 1047182 - we have to let yyparse 2N/A * check bounds on mday[] first, then fixup 2N/A * the leap year case. 2N/A }
else {
/* DATEMSK is set */ if (
when <
now)
/* time has already past */ 10 +
1;
/* 10 for an INT_MAX pid */ /* catch INT, HUP, TERM and QUIT signals */ * Open the input file with the user's permissions. "at: this job may not be executed at the proper time.\n"));
/* fix for 1099183, 1116833 - create file here, avoid race */ * add time structures logically * return time from time structure {
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31};
* We call isleap since leap() adds * 1900 onto any value passed atabort(
"bad date - not a leap year");
* make job file from proto + stdin * If the inputfile is from a tty, then turn on prompting, and * put out a prompt now, instead of waiting for a lot of file * Determine what shell we should use to run the job. If the user * didn't explicitly request that his/her current shell be over- * ridden (shflag or cshflag), then we use the current shell. /* SHELL is NULL or unset, therefore use default */ printf(
": notify by mail: %s\n", (
mflag) ?
"yes" :
"no");
* Check if current user is a member of current project. * This check is done here to avoid setproject() failure * later when the job gets executed. If current user does * not belong to current project, user's default project * will be used instead. This is achieved by not specifying * the project (": project: <project>\n") in the job file. * Put in a line to run the proper shell using the rest of * the file as input. Note that 'exec'ing the shell will * cause sh() to leave a /tmp/sh### file around. (1053807) printf(
"%s << '...the rest of this file is shell input'\n",
shell);
* Must obtain current working directory as the user /* change euid for getcwd */ "can't obtain current working directory");
/* change back afterwards */ * fix for 1113572 - use fputs() so that a * newline isn't appended to the one returned * with fgets(); 1099381 - prompt for input. if (
ttyinput)
/* clean up the final output */ /* remove jobs that are specified */ for (i = 0; i <
argc; i++)
/* list all jobs for a user */ atabort(
"Can not get status of spooling" }
else /* list particular jobs for user */ for (i = 0; i <
argc; i++) {
if (((t =
num(&
ptr)) == 0) || (*
ptr !=
'.')) {
"at: invalid job name %s\n"),
argv[i]);
"at: you don't own %s\n"),
argv[i]);
* open the command file and read the project id line * compare to the project number provided via -p on the command line * return 0 if they match, 1 if they don't match or an error occurs. #
define SKIPCOUNT 3 /* lines to skip to get to project line in file */ * time in the following format (defined by the touch(1) spec): case 12:
/* CCYYMMDDhhmm */ case 10:
/* YYMMDDhhmm */ value = (*p -
'0') *
10 + *(p+
1) -
'0';