11 Rune samname[] = { '~', '~', 's', 'a', 'm', '~', '~', 0 };
13 static Rune l1[] = { '{', '[', '(', '<', 0253, 0};
14 static Rune l2[] = { '\n', 0};
15 static Rune l3[] = { '\'', '"', '`', 0};
16 Rune *left[]= { l1, l2, l3, 0};
18 static Rune r1[] = {'}', ']', ')', '>', 0273, 0};
19 static Rune r2[] = {'\n', 0};
20 static Rune r3[] = {'\'', '"', '`', 0};
21 Rune *right[]= { r1, r2, r3, 0};
24 #define SAMTERMNAME "/usr/local/bin/samterm"
27 #define TMPDIRNAME "/tmp"
33 #define SHPATHNAME "/bin/rc"
39 #define RXPATHNAME "/usr/local/bin/ssh"
41 #ifndef SAMSAVECMDNAME
42 #define SAMSAVECMDNAME "/bin/rc\n/usr/local/bin/samsave"
46 char SAMTERM[] = SAMTERMNAME;
48 char TMPDIR[] = TMPDIRNAME;
50 char SHPATH[] = SHPATHNAME;
52 char RXPATH[] = RXPATHNAME;
53 char SAMSAVECMD[] = SAMSAVECMDNAME;
63 vseprint(buf, &buf[BLOCKSIZE], z, arg);
69 print_ss(char *s, String *a, String *b)
71 dprint("?warning: %s: `%.*S' and `%.*S'\n", s, a->n, a->s, b->n, b->s);
75 print_s(char *s, String *a)
77 dprint("?warning: %s `%.*S'\n", s, a->n, a->s);
85 struct passwd *pw = getpwuid(getuid());
86 strcpy(user, pw ? pw->pw_name : "nobody");
92 statfile(char *name, ulong *dev, uvlong *id, long *time, long *length, long *appendonly)
96 if (stat(name, &dirb) == -1)
103 *time = dirb.st_mtime;
105 *length = dirb.st_size;
112 statfd(int fd, ulong *dev, uvlong *id, long *time, long *length, long *appendonly)
116 if (fstat(fd, &dirb) == -1)
123 *time = dirb.st_mtime;
125 *length = dirb.st_size;
134 panicking = 1; // ???
140 notify (void(*f)(void *, char *))
142 signal(SIGINT, SIG_IGN);
143 signal(SIGPIPE, SIG_IGN); // XXX - bpipeok?
149 notifyf(void *a, char *b) /* never called; hup is instead */
154 temp_file(char *buf, int bufsize)
159 tmp = getenv("TMPDIR");
163 n = snprint(buf, bufsize, "%s/sam.%d.XXXXXXX", tmp, getuid());
166 if ((fd = mkstemp(buf)) < 0) /* SES - linux sometimes uses mode 0666 */
168 if (fcntl(fd, F_SETFD, fcntl(fd,F_GETFD,0) | FD_CLOEXEC) < 0)
177 int fd = temp_file(buf, sizeof buf);
190 do; while((rpid = wait(&wm)) != pid && rpid != -1);
191 return (WEXITSTATUS(wm));
197 sprint(buf, "%s/sam.%s.err", TMPDIR, getuser());
207 panic("malloc fails");
213 erealloc(void *p, ulong n)
217 panic("realloc fails");
223 strdup(const char *s)
225 return strcpy(emalloc(strlen(s)), s);
230 void exits(const char *s)
232 if (s) fprint(2, "exit: %s\n", s);
237 _exits(const char *s)
239 if (s) fprint(2, "exit: %s\n", s);
243 int errstr(char *buf, int size)
247 snprint(buf, size, "%s", strerror(errno));
252 int create(char *name, int omode, int perm)
257 if (omode & OWRITE) mode = O_WRONLY;
258 else if (omode & OREAD) mode = O_RDONLY;
261 if ((fd = open(name, mode|O_CREAT|O_TRUNC, perm)) < 0)
265 fcntl(fd, F_SETFD, fcntl(fd,F_GETFD,0) | FD_CLOEXEC);
267 /* SES - not exactly right, but hopefully good enough. */