|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T d
Length: 11122 (0x2b72)
Types: TextFile
Names: »dish.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
└─⟦eba4602b1⟧ »./isode-5.0.tar.Z«
└─⟦d3ac74d73⟧
└─⟦this⟧ »isode-5.0/quipu/dish/dish.c«
/* dish.c - */
#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/dish.c,v 6.1 89/03/23 22:27:49 mrose Exp $";
#endif
/*
* $Header: /f/osi/quipu/dish/RCS/dish.c,v 6.1 89/03/23 22:27:49 mrose Exp $
*
*
* $Log: dish.c,v $
* Revision 6.1 89/03/23 22:27:49 mrose
* out-the-door
*
* Revision 6.0 89/03/18 23:40:41 mrose
* Release 5.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "quipu/util.h"
#include "quipu/name.h"
#include "errno.h"
#include <varargs.h>
#ifdef lint
#define ETCDIR "/etc"
#endif
extern LLog *log_dua;
DN dn = NULLDN; /* This actually stores the current position. */
extern PS opt; /* This is the pstream for errors. */
PS rps; /* Pstream for results */
extern char doneget;
DN savename;
SFD dish_quit ();
unsigned cache_time = 3600; /* time to keep process alive */
unsigned connect_time = 120; /* time to keep connection open */
#define BIGBUF 100000
#define MAXARGS 50
char retpipe[LINESIZE];
char frompipe = FALSE;
char resbuf[BIGBUF];
char inbuf[LINESIZE];
char bound = FALSE;
int fd, wfd;
char remote_prob;
char *TidyString();
extern int call_read (), call_list (), call_compare (), call_search (),
call_add (), call_delete (), call_showentry (), call_showname (),
call_showattribute (), call_unbind (), call_help (), call_ds (),
unknown_cmd (), dsa_control (), call_modify (), call_modifyrdn (),
call_quit (), call_bind (), call_moveto ();
static struct {
char *command;
int (*handler) ();
int unique;
char defaults [LINESIZE];
} Commands[] = {
{"list", call_list, 1,0},
{"compare", call_compare, 1,0},
{"search", call_search, 2,0},
{"add", call_add, 1,0},
{"delete", call_delete, 2,0},
{"modify", call_modify, 3,0},
{"modifyrdn", call_modifyrdn, 7,0},
{"showentry", call_showentry, 2,0},
{"showname", call_showname, 5,0},
{"bind", call_bind, 1,0},
{"unbind", call_unbind, 1,0},
{"moveto", call_moveto, 3,0},
{"dsacontrol", dsa_control, 2,0},
{"quit", call_quit, 1,0}, /* quick way out for interactive program */
{"squid", call_ds, 2,0},
{"?", call_help, 1,0},
{"help", call_help, 1,0},
{0, unknown_cmd, 0,0}
};
#ifndef NO_STATS
static LLog lstat_log =
{
"dish.log",
NULLCP,
NULLCP,
LLOG_NOTICE,
LLOG_NONE,
50,
LLOGCLS | LLOGCRT | LLOGZER,
NOTOK,
};
LLog *log_stat = &lstat_log;
#endif
main (argc, argv)
int argc;
char **argv;
{
extern char *isodepath;
int i;
char *ttyname (), *getenv();
char *vec [1];
char **vecptr;
isodepath = ETCDIR;
for (i = 1; i <= 15; i++)
(void) signal (i, dish_quit);
if ( (argc >1) && (test_arg (argv[1], "-pipe",3))) {
(void) sprintf (retpipe, "/tmp/dish-%s-%d",rindex (ttyname (0), '/') + 1, getuid());
(void) umask (0);
if ((fd = open (retpipe, O_RDONLY)) < 0) {
(void) mknod (retpipe, S_IFIFO | 0600, 0);
if ((fd = open (retpipe, O_RDONLY)) < 0) {
(void) fprintf (stderr, "ropen failed\n");
(void) unlink (retpipe);
exit (-60);
}
}
frompipe = TRUE;
if ((wfd = open (retpipe, O_WRONLY)) < 0) {
(void) fprintf (stderr, "wr open failed\n");
(void) unlink (retpipe);
(void) close (fd);
exit (-61);
}
} else {
if ((opt = ps_alloc (std_open)) == NULLPS)
fatal (-62, "ps_alloc failed");
if (std_setup (opt, stderr) == NOTOK)
fatal (-63, "std_setup failed");
if ((rps = ps_alloc (std_open)) == NULLPS)
fatal (-64, "ps_alloc 2 failed");
if (std_setup (rps, stdout) == NOTOK)
fatal (-65, "std_setup 2 failed");
(void) printf ("Welcome to Dish (DIrectory SHell)\n");
(void) fflush (stdout);
}
i = 1;
vec[0] = argv[0];
vecptr = vec;
dsap_init (&i, &vecptr);
for (i = 1; i <= 15; i++)
(void) signal (i, dish_quit);
#ifndef NO_STATS
ll_hdinit (log_stat,vec[0]);
#endif
check_known_oids();
if (user_tailor () != OK) {
char * command;
int file;
(void) fprintf (stderr, "Tailoring failed\n");
if (frompipe) {
if (read (fd, inbuf, LINESIZE) <= 0) {
(void) fprintf (stderr,"I'm in a mess - exiting\n");
exit (-75);
}
(void) close (fd);
(void) close (wfd);
command = index (inbuf, ':');
*command = 0;
if ((file = open (inbuf, O_WRONLY)) == -1) {
exit (-76);
} else {
*resbuf = '2';
(void) write (file, resbuf, 1);
(void) close (file);
}
(void) unlink (retpipe);
}
exit (-66);
}
if (! frompipe) {
#ifndef NO_STATS
char buf [LINESIZE];
for (i=0; i<argc; i++) {
(void) strcat (buf,argv[i]);
(void) strcat (buf," ");
}
LLOG (log_stat,LLOG_NOTICE,(buf));
#endif
for (i=1; i<argc; i++) {
if (test_arg (argv[i],"-help",1)) {
help_arg ("dish");
exit (0);
}
}
if (call_bind (argc,argv) != OK)
exit (-67);
}
main_loop ();
}
unknown_cmd ()
{
if (frompipe)
ps_print (opt,"Serious dish error");
else {
if (print_arg_error (opt) != OK)
ps_print (opt,"Unknown command --- type '?' for help\n");
}
}
main_loop ()
{
char *command;
char cmd_buf [LINESIZE];
char *ptr;
char *vector[MAXARGS];
int no_of_args;
int x,
file;
int res;
char noarg;
extern int parse_line;
extern int dsa_dead;
extern int errno;
SFD unbind_sig();
while (1) {
if (dsa_dead)
(void) unbind_sig();
doneget = FALSE; /* extern to manage showing */
parse_line = 0;
reset_arg ();
set_current_pos();
remote_prob = FALSE;
if (frompipe) {
if ((res = read (fd, inbuf, LINESIZE)) <= 0) {
perror ("read error");
reopen_ret ();
continue;
}
*(inbuf + res) = 0;
(void) signal (SIGALRM, SIG_IGN);
/* don't want a timeout during a long operation */
command = index (inbuf, ':');
*command++ = 0;
if ((opt = ps_alloc (str_open)) == NULLPS) {
(void) close (fd);
(void) unlink (retpipe);
fatal (-68, "ps_alloc failed");
}
if (str_setup (opt, &resbuf[1], BIGBUF - 1, 1) == NOTOK) {
(void) close (fd);
(void) close (wfd);
(void) unlink (retpipe);
fatal (-69, "str_setup failed");
}
/* second stream at same inbuf - only 1 is used !!! */
if ((rps = ps_alloc (str_open)) == NULLPS) {
(void) close (fd);
(void) close (wfd);
(void) unlink (retpipe);
fatal (-70, "ps_alloc 2 failed");
}
if (str_setup (rps, &resbuf[1], BIGBUF - 1, 1) == NOTOK) {
(void) close (wfd);
(void) close (fd);
(void) unlink (retpipe);
fatal (-71, "str_setup 2 failed");
}
} else {
(void) printf ("Dish -> ");
if (gets (inbuf) == 0)
call_quit();
while (*inbuf == 0) {
(void) printf ("Dish -> ");
if (gets (inbuf) == 0)
call_quit();
}
command = TidyString(inbuf);
}
savename = dn_cpy (dn);
hide_picture();
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,(command));
#endif
ptr = command;
while (*ptr)
if (isspace (*ptr))
break;
else
ptr++;
if (*ptr == 0) {
noarg = TRUE;
} else {
*ptr = 0;
noarg = FALSE;
}
for (x = 0; Commands[x].command != 0; x++)
if (test_arg (command, Commands[x].command, Commands[x].unique))
break;
if (! noarg)
*ptr++ = ' ';
if (* Commands[x].defaults != 0) {
if (noarg) {
(void) sprintf (cmd_buf,"%s %s",Commands[x].command,Commands[x].defaults);
} else {
(void) sprintf (cmd_buf,"%s %s %s",Commands[x].command,Commands[x].defaults,ptr);
}
command = cmd_buf;
}
if ((no_of_args = sstr2arg (command, MAXARGS, vector, " \t")) == NOTOK)
ps_printf (opt, "Too many arguments... Can't cope.\n");
else {
char help_flag = FALSE;
int y;
vector[0] = Commands[x].command;
for (y=1; y<no_of_args; y++) {
if (test_arg (vector[y],"-help",1)) {
help_arg (vector[0]);
help_flag = TRUE;
break;
}
}
if ( ! help_flag)
(*Commands[x].handler) (no_of_args, vector);
}
/* if from pipe, return results */
if (frompipe && !remote_prob) {
if ((file = open (inbuf, O_WRONLY)) <= 0) {
(void) fprintf (stderr,"result write error\n");
reopen_ret ();
continue;
}
if (rps->ps_byteno == 0) {
*opt->ps_ptr = 0;
*resbuf = '2';
} else {
*resbuf = '1';
*rps->ps_ptr = 0;
}
(void) write (file, resbuf, strlen (resbuf));
(void) close (file);
ps_free (opt);
ps_free (rps);
if (! bound) {
(void) signal (SIGALRM, dish_quit);
(void) alarm (cache_time);
} else {
(void) signal (SIGALRM,unbind_sig);
(void) alarm (connect_time);
}
reopen_ret ();
} else {
(void) ps_flush (opt);
(void) ps_flush (rps);
(void) fflush (stdout);
}
}
}
reopen_ret ()
{
(void) close (fd);
(void) close (wfd);
if ((fd = open (retpipe, O_RDONLY)) < 0) {
if ( errno == EINTR ) {
reopen_ret ();
return;
}
(void) fprintf (stderr, "re-ropen failed\n");
(void) unlink (retpipe);
exit (-72);
}
if ((wfd = open (retpipe, O_WRONLY)) < 0) {
(void) fprintf (stderr, "re-wr open failed\n");
(void) unlink (retpipe);
(void) close (fd);
exit (-73);
}
}
SFD dish_quit (sig)
int sig;
{
(void) ds_unbind ();
bound = FALSE;
if (frompipe) {
(void) close (wfd);
(void) close (fd);
(void) unlink (retpipe);
} else {
ps_free (opt);
ps_free (rps);
}
hide_picture();
switch (sig) {
case SIGALRM:
LLOG (log_dua, LLOG_EXCEPTIONS, ("Timer expierd :- Dish quitting"));
exit (0);
case SIGHUP:
case SIGINT:
case SIGTERM:
LLOG (log_dua, LLOG_EXCEPTIONS, ("Dish quitting on signal"));
exit (0);
default:
LLOG (log_dua, LLOG_FATAL, ("Dish quitting on signal"));
(void) signal (sig, SIG_DFL); /* to stop recursion */
(void) signal (SIGILL, SIG_DFL); /* for vax abort */
(void) signal (SIGIOT, SIG_DFL); /* for most others aborts */
abort ();
}
}
call_quit ()
{
/* can only get called if run interactively - dont worry about pipe */
LLOG (log_dua, LLOG_DEBUG, ("Dish:- Exiting Dish successfully..."));
if (bound)
(void) ds_unbind ();
bound = FALSE;
ps_free (opt);
ps_free (rps);
hide_picture();
exit (0);
}
set_cmd_default (cmd, dflt)
char * cmd;
char * dflt;
{
int x;
for (x = 0; Commands[x].command != 0; x++)
if (strcmp (cmd, Commands[x].command) == 0) {
if (* Commands[x].defaults != 0)
(void) strcat (Commands[x].defaults, " ");
(void) strcat (Commands[x].defaults, dflt);
return (OK);
}
return (NOTOK);
}
void advise (va_alist)
va_dcl
{
int code;
va_list ap;
extern LLog *log_dsap;
va_start (ap);
code = va_arg (ap, int);
(void) _ll_log (log_dsap, code, ap);
va_end (ap);
}