25 #include <sys/types.h> 28 #include <sys/socket.h> 29 #include <netinet/in.h> 34 #include <sys/resource.h> 42 #include <sys/ioctl.h> 54 typedef RETSIGTYPE (*
SigType)();
70 int maxjobs = MAXJOBS;
73 extern char **environ;
83 struct sockaddr_in from,
sin;
84 int g, i, len =
sizeof (
struct sockaddr_in);
98 if (!strcmp(*av,
"-i"))
101 maxjobs = atoi(av[1]);
107 sp = getservbyname(
"spice",
"tcp");
109 fprintf(stderr,
"Error: spice/tcp: unknown service\n");
112 pp = getprotobyname(
"tcp");
114 fprintf(stderr,
"Error: tcp: unknown protocol\n");
119 s = socket(AF_INET, SOCK_STREAM, pp->p_proto);
124 sin.sin_port = sp->s_port;
125 if (bind(s, (
struct sockaddr *) &
sin,
sizeof 126 (
struct sockaddr_in)) < 0) {
135 for (i = 0; i < 10; i++)
138 (void) open(
"/", O_RDONLY);
154 (void) signal(SIGCHLD, (
SigType)sigchild);
157 (void) signal(SIGCLD, (
SigType)sigchild);
161 fprintf(fp,
"\n-- new daemon, pid = %d, date = %s\n\n",
168 g = accept(s, (
struct sockaddr *) &from, &len);
170 if (errno != EINTR) {
172 fprintf(fp,
"\n>>> accept: %s\n\n", strerror(errno));
180 (void) signal(SIGCHLD, (
SigType)SIG_IGN);
183 (void) signal(SIGCLD, (
SigType)SIG_IGN);
204 char buf[BUFSIZ], user[16], host[32], program[128];
208 #ifdef HAVE_GETRUSAGE 213 i = read(s, buf, BUFSIZ);
218 i = sscanf(buf,
"%s %s %s", user, host, program);
220 fprintf(stderr,
"Error: bad init line: %s\n", buf);
226 if (nrunning > maxjobs - 1) {
228 (void) write(s,
"toomany", 8);
230 fprintf(fp,
"%s: %s@%s: turned down - %d jobs now\n",
235 (void) write(s,
"ok", 3);
237 if ((i = fork()) == 0) {
244 (void) execve(program, argv, environ);
248 #ifdef HAVE_GETRUSAGE 250 if (wait3(&stats, 0, &ru) != i) {
255 #ifdef HAVE_SYS_WAIT_H 258 rc = WEXITSTATUS(stats);
263 #ifdef HAVE_GETRUSAGE 264 (void) sprintf(buf,
"%d:%d.%6d", ru.ru_utime.tv_sec / 60,
265 ru.ru_utime.tv_sec % 60, ru.ru_utime.tv_usec);
266 for (t = buf; *t; t++)
268 for (t--; *t ==
'0'; *t-- =
'\0')
271 (void)
strcpy(buf,
"unknown");
274 fprintf(fp,
"%s: %s@%s: %s - \n\texit %d, time %s\n",
292 fprintf(fp,
"\n>>>spiced: wait: %s\n\n", strerror(errno));
303 "The program \"spiced\" is not available on this system.\n");
323 while (*
string && isspace(*
string))
331 if (!*
string || *
string ==
'/') {
332 pw = getpwuid(getuid());
337 while ((c = *
string) && c !=
'/')
354 return (
copy(
string));
static char buf[MAXPROMPT]
char * tilde_expand(char *string)