|
|
1.1 root 1: #include "defs"
2: #include <signal.h>
3:
4: dosys(comstring,nohalt)
5: register char *comstring;
6: int nohalt;
7: {
8: register int status;
9:
10: if(metas(comstring))
11: status = doshell(comstring,nohalt);
12: else status = doexec(comstring);
13:
14: return(status);
15: }
16:
17:
18:
19: metas(s) /* Are there are any Shell meta-characters? */
20: register char *s;
21: {
22: register char c;
23:
24: while( (funny[c = *s++] & META) == 0 )
25: ;
26: return( c );
27: }
28:
29: doshell(comstring,nohalt)
30: char *comstring;
31: int nohalt;
32: {
33: if((waitpid = vfork()) == 0)
34: {
35: enbint(SIG_DFL);
36: doclose();
37:
38: execl(SHELLCOM, "sh", (nohalt ? "-c" : "-ce"), comstring, 0);
39: fatal("Couldn't load Shell");
40: }
41:
42: return( await() );
43: }
44:
45:
46:
47:
48: await()
49: {
50: int intrupt();
51: int status;
52: register int pid;
53:
54: enbint(intrupt);
55: while( (pid = wait(&status)) != waitpid)
56: if(pid == -1)
57: fatal("bad wait code");
58: waitpid = 0;
59: return(status);
60: }
61:
62:
63:
64:
65:
66:
67: doclose() /* Close open directory files before exec'ing */
68: {
69: register struct opendir *od;
70: for (od = firstod; od; od = od->nxtopendir)
71: if (od->dirfc != NULL)
72: /* fclose(od->dirfc); */
73: close(od->dirfc->_file);
74: }
75:
76:
77:
78:
79:
80: doexec(str)
81: register char *str;
82: {
83: register char *t;
84: char *argv[200];
85: register char **p;
86:
87: while( *str==' ' || *str=='\t' )
88: ++str;
89: if( *str == '\0' )
90: return(-1); /* no command */
91:
92: p = argv;
93: for(t = str ; *t ; )
94: {
95: *p++ = t;
96: while(*t!=' ' && *t!='\t' && *t!='\0')
97: ++t;
98: if(*t)
99: for( *t++ = '\0' ; *t==' ' || *t=='\t' ; ++t)
100: ;
101: }
102:
103: *p = NULL;
104:
105: if((waitpid = vfork()) == 0)
106: {
107: enbint(SIG_DFL);
108: doclose();
109: execvp(str, argv);
110: fatal1("Cannot load %s",str);
111: }
112:
113: return( await() );
114: }
115:
116: #include <errno.h>
117:
118: #include <sys/types.h>
119: #include <sys/stat.h>
120:
121:
122:
123:
124: touch(force, name)
125: int force;
126: char *name;
127: {
128: struct stat stbuff;
129: char junk[1];
130: int fd;
131:
132: if( stat(name,&stbuff) < 0)
133: if(force)
134: goto create;
135: else
136: {
137: fprintf(stderr, "touch: file %s does not exist.\n", name);
138: return;
139: }
140:
141: if(stbuff.st_size == 0)
142: goto create;
143:
144: if( (fd = open(name, 2)) < 0)
145: goto bad;
146:
147: if( read(fd, junk, 1) < 1)
148: {
149: close(fd);
150: goto bad;
151: }
152: lseek(fd, 0L, 0);
153: if( write(fd, junk, 1) < 1 )
154: {
155: close(fd);
156: goto bad;
157: }
158: close(fd);
159: return;
160:
161: bad:
162: fprintf(stderr, "Cannot touch %s\n", name);
163: return;
164:
165: create:
166: if( (fd = creat(name, 0666)) < 0)
167: goto bad;
168: close(fd);
169: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.