17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5004388ebScasper * Common Development and Distribution License (the "License").
6004388ebScasper * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
210a44ef6dSjacobs
227c478bd9Sstevel@tonic-gate /*
23004388ebScasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27f928ce67Sceastha /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28f928ce67Sceastha /* All Rights Reserved */
29f928ce67Sceastha
307c478bd9Sstevel@tonic-gate #include "limits.h"
317c478bd9Sstevel@tonic-gate #include "ulimit.h"
327c478bd9Sstevel@tonic-gate #include "sys/utsname.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include "lpsched.h"
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #include <sys/stat.h>
377c478bd9Sstevel@tonic-gate #include <sys/time.h> /* to up the max # of fds */
387c478bd9Sstevel@tonic-gate #include <sys/resource.h>
397c478bd9Sstevel@tonic-gate #include <syslog.h>
407c478bd9Sstevel@tonic-gate #include <locale.h>
41004388ebScasper #include <stdio_ext.h>
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate int lock_fd = -1;
457c478bd9Sstevel@tonic-gate int isStartingForms = 0;
467c478bd9Sstevel@tonic-gate int Starting = 0;
477c478bd9Sstevel@tonic-gate int Shutdown = 0;
487c478bd9Sstevel@tonic-gate int DoneChildren = 0;
497c478bd9Sstevel@tonic-gate int Sig_Alrm = 0;
507c478bd9Sstevel@tonic-gate int OpenMax = OPEN_MAX;
517c478bd9Sstevel@tonic-gate int Reserve_Fds = 0;
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate char *Local_System = 0;
547c478bd9Sstevel@tonic-gate char *SHELL = 0;
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate gid_t Lp_Gid;
577c478bd9Sstevel@tonic-gate uid_t Lp_Uid;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate #if defined(DEBUG)
607c478bd9Sstevel@tonic-gate unsigned long debug = 0;
617c478bd9Sstevel@tonic-gate static int signals = 0;
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate extern int errno;
657c478bd9Sstevel@tonic-gate extern void shutdown_messages();
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate int am_in_background = 0;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static void disable_signals();
707c478bd9Sstevel@tonic-gate static void startup();
717c478bd9Sstevel@tonic-gate static void process();
727c478bd9Sstevel@tonic-gate static void ticktock(int);
737c478bd9Sstevel@tonic-gate static void background();
747c478bd9Sstevel@tonic-gate static void usage();
757c478bd9Sstevel@tonic-gate static void Exit();
767c478bd9Sstevel@tonic-gate static void disable_signals();
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /**
797c478bd9Sstevel@tonic-gate ** main()
807c478bd9Sstevel@tonic-gate **/
817c478bd9Sstevel@tonic-gate
82f928ce67Sceastha int
main(int argc,char * argv[])837c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate int c;
867c478bd9Sstevel@tonic-gate extern char *optarg;
877c478bd9Sstevel@tonic-gate extern int optopt;
887c478bd9Sstevel@tonic-gate extern int opterr;
897c478bd9Sstevel@tonic-gate char * cp;
907c478bd9Sstevel@tonic-gate struct rlimit rlim;
917c478bd9Sstevel@tonic-gate int fd_limit = 4096;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
947c478bd9Sstevel@tonic-gate if ((cp = strrchr(argv[0], '/')) == NULL)
957c478bd9Sstevel@tonic-gate cp = argv[0];
967c478bd9Sstevel@tonic-gate else
977c478bd9Sstevel@tonic-gate cp++;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate /* open the syslog() */
1007c478bd9Sstevel@tonic-gate openlog(cp, LOG_PID|LOG_NDELAY|LOG_NOWAIT, LOG_LPR);
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate SHELL = DEFAULT_SHELL;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate opterr = 0;
1050a44ef6dSjacobs while((c = getopt(argc, (char * const *)argv, "dsf:n:r:M:p:")) != EOF)
1067c478bd9Sstevel@tonic-gate switch(c)
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate # if defined (DEBUG)
1097c478bd9Sstevel@tonic-gate case 'd':
1107c478bd9Sstevel@tonic-gate debug = DB_ALL;
1110a44ef6dSjacobs syslog(LOG_DEBUG, "debug = DB_ALL");
1127c478bd9Sstevel@tonic-gate break;
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate case 's':
1157c478bd9Sstevel@tonic-gate signals++;
1167c478bd9Sstevel@tonic-gate break;
1177c478bd9Sstevel@tonic-gate # endif /* DEBUG */
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate case 'f':
1207c478bd9Sstevel@tonic-gate if ((ET_SlowSize = atoi(optarg)) < 1)
1217c478bd9Sstevel@tonic-gate ET_SlowSize = 1;
1220a44ef6dSjacobs syslog(LOG_DEBUG, "-f option is %d", ET_SlowSize);
1237c478bd9Sstevel@tonic-gate break;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate case 'n':
1267c478bd9Sstevel@tonic-gate if ((ET_NotifySize = atoi(optarg)) < 1)
1277c478bd9Sstevel@tonic-gate ET_NotifySize = 1;
1280a44ef6dSjacobs syslog(LOG_DEBUG, "-n option is %d", ET_NotifySize);
1297c478bd9Sstevel@tonic-gate break;
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate case 'r':
1327c478bd9Sstevel@tonic-gate if ((Reserve_Fds = atoi(optarg)) < 0)
1337c478bd9Sstevel@tonic-gate Reserve_Fds = 0;
1340a44ef6dSjacobs syslog(LOG_DEBUG, "-r option is %d", Reserve_Fds);
1357c478bd9Sstevel@tonic-gate break;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate case 'p':
1387c478bd9Sstevel@tonic-gate if ((fd_limit = atoi(optarg)) < 16)
1397c478bd9Sstevel@tonic-gate fd_limit = 4096;
1400a44ef6dSjacobs syslog(LOG_DEBUG, "-p option is %d", fd_limit);
1417c478bd9Sstevel@tonic-gate break;
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate case '?':
1447c478bd9Sstevel@tonic-gate if (optopt == '?') {
1457c478bd9Sstevel@tonic-gate usage ();
1467c478bd9Sstevel@tonic-gate exit (0);
1477c478bd9Sstevel@tonic-gate } else
1487c478bd9Sstevel@tonic-gate fail ("%s: illegal option -- %c\n", argv[0], optopt);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /* reset the fd resource limit */
1527c478bd9Sstevel@tonic-gate rlim.rlim_max = rlim.rlim_cur = fd_limit;
1537c478bd9Sstevel@tonic-gate setrlimit(RLIMIT_NOFILE, &rlim);
1547c478bd9Sstevel@tonic-gate getrlimit(RLIMIT_NOFILE, &rlim);
155004388ebScasper (void) enable_extended_FILE_stdio(-1, -1);
1567c478bd9Sstevel@tonic-gate syslog(LOG_DEBUG, "file descriptor resource limit is %d (~%d printers)",
1577c478bd9Sstevel@tonic-gate rlim.rlim_cur, (rlim.rlim_cur - 12)/ 2);
158*2a8bcb4eSToomas Soome
1597c478bd9Sstevel@tonic-gate lp_alloc_fail_handler = mallocfail;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate startup();
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate process();
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate lpshut(1); /* one last time to clean up */
1667c478bd9Sstevel@tonic-gate /*NOTREACHED*/
167f928ce67Sceastha return (0);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate static void
startup()1717c478bd9Sstevel@tonic-gate startup()
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate struct passwd *p;
1747c478bd9Sstevel@tonic-gate
175*2a8bcb4eSToomas Soome
1767c478bd9Sstevel@tonic-gate Starting = 1;
1777c478bd9Sstevel@tonic-gate getpaths();
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate * There must be a user named "lp".
1817c478bd9Sstevel@tonic-gate */
1827c478bd9Sstevel@tonic-gate if ((p = getpwnam(LPUSER)) == NULL)
1837c478bd9Sstevel@tonic-gate fail ("Can't find the user \"lp\" on this system!\n");
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate Lp_Uid = p->pw_uid;
1867c478bd9Sstevel@tonic-gate Lp_Gid = p->pw_gid;
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate /*
1897c478bd9Sstevel@tonic-gate * Only "root" is allowed to run us.
1907c478bd9Sstevel@tonic-gate */
1917c478bd9Sstevel@tonic-gate if ((getuid() != 0) && (geteuid() != 0))
1927c478bd9Sstevel@tonic-gate fail ("You must be \"root\" to run this program.\n");
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate setuid (0);
1957c478bd9Sstevel@tonic-gate
1965c88ba20Swendyp Local_System = Strdup("localhost");
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate /*
199*2a8bcb4eSToomas Soome * Make sure that all critical directories are present and that
2007c478bd9Sstevel@tonic-gate * symbolic links are correct.
2017c478bd9Sstevel@tonic-gate */
2027c478bd9Sstevel@tonic-gate lpfsck();
203*2a8bcb4eSToomas Soome
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * Try setting the lock file to see if another Spooler is running.
2067c478bd9Sstevel@tonic-gate * We'll release it immediately; this allows us to fork the child
2077c478bd9Sstevel@tonic-gate * that will run in the background. The child will relock the file.
2087c478bd9Sstevel@tonic-gate */
2097c478bd9Sstevel@tonic-gate if ((lock_fd = open_locked(Lp_Schedlock, "a", 0664)) < 0)
2107c478bd9Sstevel@tonic-gate if (errno == EAGAIN)
2117c478bd9Sstevel@tonic-gate fail ("Print services already active.\n");
2127c478bd9Sstevel@tonic-gate else
2137c478bd9Sstevel@tonic-gate fail ("Can't open file \"%s\" (%s).\n", NB(Lp_Schedlock), PERROR);
2147c478bd9Sstevel@tonic-gate close(lock_fd);
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate background();
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate * We are the child process now.
2197c478bd9Sstevel@tonic-gate */
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate if ((lock_fd = open_locked(Lp_Schedlock, "w", 0664)) < 0)
2227c478bd9Sstevel@tonic-gate fail ("Failed to lock the file \"%s\" (%s).\n", NB(Lp_Schedlock), PERROR);
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate Close (0);
2257c478bd9Sstevel@tonic-gate Close (2);
2267c478bd9Sstevel@tonic-gate if (am_in_background)
2277c478bd9Sstevel@tonic-gate Close (1);
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate if ((OpenMax = ulimit(4, 0L)) == -1)
2307c478bd9Sstevel@tonic-gate OpenMax = OPEN_MAX;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate disable_signals();
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate init_messages();
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate init_memory();
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate note ("Print services started.\n");
2397c478bd9Sstevel@tonic-gate Starting = 0;
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate void
lpshut(int immediate)2437c478bd9Sstevel@tonic-gate lpshut(int immediate)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate int i;
2467c478bd9Sstevel@tonic-gate extern MESG * Net_md;
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate * If this is the first time here, stop all running
2517c478bd9Sstevel@tonic-gate * child processes, and shut off the alarm clock so
2527c478bd9Sstevel@tonic-gate * it doesn't bug us.
2537c478bd9Sstevel@tonic-gate */
2547c478bd9Sstevel@tonic-gate if (!Shutdown) {
2557c478bd9Sstevel@tonic-gate mputm (Net_md, S_SHUTDOWN, 1);
2560a44ef6dSjacobs for (i = 0; Exec_Table != NULL && Exec_Table[i] != NULL; i++)
2570a44ef6dSjacobs terminate (Exec_Table[i]);
2587c478bd9Sstevel@tonic-gate alarm (0);
2597c478bd9Sstevel@tonic-gate Shutdown = (immediate? 2 : 1);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate /*
2637c478bd9Sstevel@tonic-gate * If this is an express shutdown, or if all the
2647c478bd9Sstevel@tonic-gate * child processes have been cleaned up, clean up
2657c478bd9Sstevel@tonic-gate * and get out.
2667c478bd9Sstevel@tonic-gate */
2677c478bd9Sstevel@tonic-gate if (Shutdown == 2) {
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate * We don't shut down the message queues until
2717c478bd9Sstevel@tonic-gate * now, to give the children a chance to answer.
2727c478bd9Sstevel@tonic-gate * This means an LP command may have been snuck
2737c478bd9Sstevel@tonic-gate * in while we were waiting for the children to
2747c478bd9Sstevel@tonic-gate * finish, but that's OK because we'll have
2757c478bd9Sstevel@tonic-gate * stored the jobs on disk (that's part of the
2767c478bd9Sstevel@tonic-gate * normal operation, not just during shutdown phase).
2777c478bd9Sstevel@tonic-gate */
2787c478bd9Sstevel@tonic-gate shutdown_messages();
279*2a8bcb4eSToomas Soome
2807c478bd9Sstevel@tonic-gate (void) close(lock_fd);
2817c478bd9Sstevel@tonic-gate (void) Unlink(Lp_Schedlock);
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate note ("Print services stopped.\n");
2847c478bd9Sstevel@tonic-gate exit (0);
2857c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate static void
process()2907c478bd9Sstevel@tonic-gate process()
2917c478bd9Sstevel@tonic-gate {
2920a44ef6dSjacobs FSTATUS *pfs;
2930a44ef6dSjacobs PWSTATUS *ppws;
2940a44ef6dSjacobs int i;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate * Call the "check_..._alert()" routines for each form/print-wheel;
2997c478bd9Sstevel@tonic-gate * we need to do this at this point because these routines
3007c478bd9Sstevel@tonic-gate * short-circuit themselves while we are in startup mode.
3017c478bd9Sstevel@tonic-gate * Calling them now will kick off any necessary alerts.
3027c478bd9Sstevel@tonic-gate */
3037c478bd9Sstevel@tonic-gate isStartingForms = 1;
3040a44ef6dSjacobs for (i = 0; FStatus != NULL && FStatus[i] != NULL; i++)
3050a44ef6dSjacobs check_form_alert (FStatus[i], (_FORM *)0);
3067c478bd9Sstevel@tonic-gate isStartingForms = 0;
3077c478bd9Sstevel@tonic-gate
3080a44ef6dSjacobs for (i = 0; PWStatus != NULL && PWStatus[i] != NULL; i++)
3090a44ef6dSjacobs check_pwheel_alert (PWStatus[i], (PWHEEL *)0);
310*2a8bcb4eSToomas Soome
3117c478bd9Sstevel@tonic-gate /*
3127c478bd9Sstevel@tonic-gate * Clear the alarm, then schedule an EV_ALARM. This will clear
3137c478bd9Sstevel@tonic-gate * all events that had been scheduled for later without waiting
3147c478bd9Sstevel@tonic-gate * for the next tick.
3157c478bd9Sstevel@tonic-gate */
3167c478bd9Sstevel@tonic-gate alarm (0);
3177c478bd9Sstevel@tonic-gate schedule (EV_ALARM);
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate /*
3207c478bd9Sstevel@tonic-gate * Start the ball rolling.
3217c478bd9Sstevel@tonic-gate */
3227c478bd9Sstevel@tonic-gate schedule (EV_INTERF, (PSTATUS *)0);
3237c478bd9Sstevel@tonic-gate schedule (EV_NOTIFY, (RSTATUS *)0);
3247c478bd9Sstevel@tonic-gate schedule (EV_SLOWF, (RSTATUS *)0);
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate for (EVER) {
3277c478bd9Sstevel@tonic-gate take_message ();
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate if (Sig_Alrm)
3307c478bd9Sstevel@tonic-gate schedule (EV_ALARM);
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate if (DoneChildren)
3337c478bd9Sstevel@tonic-gate dowait ();
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate if (Shutdown)
3367c478bd9Sstevel@tonic-gate check_children();
3377c478bd9Sstevel@tonic-gate if (Shutdown == 2)
3387c478bd9Sstevel@tonic-gate break;
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3437c478bd9Sstevel@tonic-gate static void
ticktock(int sig)3447c478bd9Sstevel@tonic-gate ticktock(int sig)
3457c478bd9Sstevel@tonic-gate {
3467c478bd9Sstevel@tonic-gate Sig_Alrm = 1;
3477c478bd9Sstevel@tonic-gate (void)signal (SIGALRM, ticktock);
3487c478bd9Sstevel@tonic-gate return;
3497c478bd9Sstevel@tonic-gate }
350*2a8bcb4eSToomas Soome
3517c478bd9Sstevel@tonic-gate static void
background()3527c478bd9Sstevel@tonic-gate background()
3537c478bd9Sstevel@tonic-gate {
3547c478bd9Sstevel@tonic-gate #if defined(DEBUG)
3557c478bd9Sstevel@tonic-gate if (debug & DB_SDB)
3567c478bd9Sstevel@tonic-gate return;
3577c478bd9Sstevel@tonic-gate #endif
358*2a8bcb4eSToomas Soome
3597c478bd9Sstevel@tonic-gate switch(fork())
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate case -1:
3627c478bd9Sstevel@tonic-gate fail ("Failed to fork child process (%s).\n", PERROR);
3637c478bd9Sstevel@tonic-gate /*NOTREACHED*/
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate case 0:
3667c478bd9Sstevel@tonic-gate (void) setpgrp();
3677c478bd9Sstevel@tonic-gate am_in_background = 1;
3687c478bd9Sstevel@tonic-gate return;
369*2a8bcb4eSToomas Soome
3707c478bd9Sstevel@tonic-gate default:
3717c478bd9Sstevel@tonic-gate note ("Print services started.\n");
3727c478bd9Sstevel@tonic-gate exit(0);
3737c478bd9Sstevel@tonic-gate /* NOTREACHED */
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate static void
usage()3787c478bd9Sstevel@tonic-gate usage()
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate note ("\
3817c478bd9Sstevel@tonic-gate usage: lpsched [ options ]\n\
3827c478bd9Sstevel@tonic-gate [ -f #filter-slots ] (increase no. concurrent slow filters)\n\
3837c478bd9Sstevel@tonic-gate [ -n #notify-slots ] (increase no. concurrent notifications)\n\
3847c478bd9Sstevel@tonic-gate [ -r #reserved-fds ] (increase margin of file descriptors)\n"
3857c478bd9Sstevel@tonic-gate );
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate #if defined(DEBUG)
3887c478bd9Sstevel@tonic-gate note ("\
3897c478bd9Sstevel@tonic-gate [ -d ] (same as -D ALL)\n\
3907c478bd9Sstevel@tonic-gate [ -s ] (don't trap most signals)\n"
3917c478bd9Sstevel@tonic-gate );
3927c478bd9Sstevel@tonic-gate #endif
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate note ("\
3957c478bd9Sstevel@tonic-gate WARNING: all these options are currently unsupported\n"
3967c478bd9Sstevel@tonic-gate );
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate return;
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate static void
Exit(n)4027c478bd9Sstevel@tonic-gate Exit(n)
4037c478bd9Sstevel@tonic-gate int n;
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate fail ("Received unexpected signal %d; terminating.\n", n);
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate static void
disable_signals()4097c478bd9Sstevel@tonic-gate disable_signals()
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate int i;
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate # if defined(DEBUG)
4147c478bd9Sstevel@tonic-gate if (!signals)
4157c478bd9Sstevel@tonic-gate # endif
4167c478bd9Sstevel@tonic-gate for (i = 0; i < NSIG; i++)
4177c478bd9Sstevel@tonic-gate if (signal(i, SIG_IGN) != SIG_IGN)
4187c478bd9Sstevel@tonic-gate signal (i, Exit);
419*2a8bcb4eSToomas Soome
4207c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN);
4217c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN);
4227c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_IGN);
4237c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, ticktock);
4247c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, lpshut); /* needs arg, but sig# OK */
4257c478bd9Sstevel@tonic-gate (void) signal(SIGCLD, SIG_IGN);
4267c478bd9Sstevel@tonic-gate (void) signal(SIGTSTP, SIG_IGN);
4277c478bd9Sstevel@tonic-gate (void) signal(SIGCONT, SIG_DFL);
4287c478bd9Sstevel@tonic-gate (void) signal(SIGTTIN, SIG_IGN);
4297c478bd9Sstevel@tonic-gate (void) signal(SIGTTOU, SIG_IGN);
4307c478bd9Sstevel@tonic-gate (void) signal(SIGXFSZ, SIG_IGN); /* could be a problem */
4317c478bd9Sstevel@tonic-gate (void) signal(SIGWINCH, SIG_IGN); /* if started in a window */
4327c478bd9Sstevel@tonic-gate (void) signal(SIGTHAW, SIG_IGN); /* used by CPR - energystar */
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate #if defined(DEBUG)
4357c478bd9Sstevel@tonic-gate if (debug & DB_ABORT)
4367c478bd9Sstevel@tonic-gate (void) signal(SIGABRT, SIG_DFL);
4377c478bd9Sstevel@tonic-gate #endif
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate }
440