version 1.18, 2002/12/09 08:15:29 |
version 1.19, 2003/03/13 15:47:12 |
|
|
void done(int sig); |
void done(int sig); |
void do_write(char *, char *, uid_t); |
void do_write(char *, char *, uid_t); |
void wr_fputs(char *); |
void wr_fputs(char *); |
void search_utmp(char *, char *, char *, uid_t); |
void search_utmp(char *, char *, int, char *, uid_t); |
int term_chk(char *, int *, time_t *, int); |
int term_chk(char *, int *, time_t *, int); |
int utmp_chk(char *, char *); |
int utmp_chk(char *, char *); |
|
|
|
|
/* check args */ |
/* check args */ |
switch (argc) { |
switch (argc) { |
case 2: |
case 2: |
search_utmp(argv[1], tty, mytty, myuid); |
search_utmp(argv[1], tty, sizeof tty, mytty, myuid); |
do_write(tty, mytty, myuid); |
do_write(tty, mytty, myuid); |
break; |
break; |
case 3: |
case 3: |
|
|
* writing from, unless that's the only terminal with messages enabled. |
* writing from, unless that's the only terminal with messages enabled. |
*/ |
*/ |
void |
void |
search_utmp(char *user, char *tty, char *mytty, uid_t myuid) |
search_utmp(char *user, char *tty, int ttyl, char *mytty, uid_t myuid) |
{ |
{ |
struct utmp u; |
struct utmp u; |
time_t bestatime, atime; |
time_t bestatime, atime; |
|
|
++nttys; |
++nttys; |
if (atime > bestatime) { |
if (atime > bestatime) { |
bestatime = atime; |
bestatime = atime; |
(void)strcpy(tty, atty); |
(void)strlcpy(tty, atty, ttyl); |
} |
} |
} |
} |
|
|
|
|
errx(1, "%s is not logged in", user); |
errx(1, "%s is not logged in", user); |
if (nttys == 0) { |
if (nttys == 0) { |
if (user_is_me) { /* ok, so write to yourself! */ |
if (user_is_me) { /* ok, so write to yourself! */ |
(void)strcpy(tty, mytty); |
(void)strlcpy(tty, mytty, ttyl); |
return; |
return; |
} |
} |
errx(1, "%s has messages disabled", user); |
errx(1, "%s has messages disabled", user); |
|
|
|
|
/* print greeting */ |
/* print greeting */ |
if (gethostname(host, sizeof(host)) < 0) |
if (gethostname(host, sizeof(host)) < 0) |
(void)strcpy(host, "???"); |
(void)strlcpy(host, "???", sizeof host); |
now = time((time_t *)NULL); |
now = time((time_t *)NULL); |
nows = ctime(&now); |
nows = ctime(&now); |
nows[16] = '\0'; |
nows[16] = '\0'; |