Example #1
0
static Line*
consume(Line *ptr, int *eaten)
{
    Line *next;
    int blanks=0;

    for (; ptr && blankline(ptr); ptr = next, blanks++ ) {
	next = ptr->next;
	___mkd_freeLine(ptr);
    }
    if ( ptr ) *eaten = blanks;
    return ptr;
}
Example #2
0
/*
 * Send mail to a bunch of user names.  The interface is through
 * the mail routine below.
 * save a copy of the letter
 */
static int 
Sendmail(char *str)
{
	struct header head;

	if (blankline(str))
		head.h_to = NOSTR;
	else
		head.h_to = addto(NOSTR, str);
	head.h_subject = head.h_cc = head.h_bcc = head.h_defopt = NOSTR;
	head.h_others = NOSTRPTR;
	head.h_seq = 0;
	mail1(&head, 1, NOSTR);
	return(0);
}
Example #3
0
void writebreak()
{
    int q;
    if (assylen) writeline(0, 1);
    q = TXTLEN;
    if (o_sp) {
        if (o_sp + line_no > q)
            newpage();
        else if (line_no)
            while (o_sp) {
                blankline();
                o_sp--;
            }
    }
}
Example #4
0
/*
 * Print the top so many lines of each desired message.
 * The number of lines is taken from the variable "toplines"
 * and defaults to 5.
 */
int 
top(void *v)
{
	int *msgvec = v;
	int *ip;
	struct message *mp;
	int c, topl, lines, lineb;
	char *valtop, *linebuf = NULL;
	size_t linesize;
	FILE *ibuf;

	topl = 5;
	valtop = value("toplines");
	if (valtop != NULL) {
		topl = atoi(valtop);
		if (topl < 0 || topl > 10000)
			topl = 5;
	}
	lineb = 1;
	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
		mp = &message[*ip - 1];
		touch(mp);
		setdot(mp);
		did_print_dot = 1;
		if (value("quiet") == NULL)
			printf(catgets(catd, CATSET, 19,
					"Message %2d:\n"), *ip);
		if (mp->m_flag & MNOFROM)
			printf("From %s %s\n", fakefrom(mp),
					fakedate(mp->m_time));
		if ((ibuf = setinput(&mb, mp, NEED_BODY)) == NULL)	/* XXX could use TOP */
			return 1;
		c = mp->m_lines;
		if (!lineb)
			printf("\n");
		for (lines = 0; lines < c && lines <= topl; lines++) {
			if (readline(ibuf, &linebuf, &linesize) < 0)
				break;
			puts(linebuf);
			lineb = blankline(linebuf);
		}
	}
	if (linebuf)
		free(linebuf);
	return(0);
}
Example #5
0
LogSetAttribute::LogSetAttribute(const char *k, const char *n, const char *val, bool dirty)
{
	op_type = CondorLogOp_SetAttribute;
	key = strdup(k);
	name = strdup(n);
	value_expr = NULL;
	if (val && strlen(val) && !blankline(val) &&
		!ParseClassAdRvalExpr(val, value_expr))
	{
		value = strdup(val);
	} else {
		if (value_expr) delete value_expr;
		value_expr = NULL;
		value = strdup("UNDEFINED");
	}
	is_dirty = dirty;
}
Example #6
0
static int
endoftextblock(Line *t, int toplevelblock, DWORD flags)
{
    int z;

    if ( blankline(t)||isquote(t)||ishdr(t,&z)||ishr(t) )
	return 1;

    /* HORRIBLE STANDARDS KLUDGE: non-toplevel paragraphs absorb adjacent
     * code blocks
     */
    if ( toplevelblock && iscode(t) )
	return 1;

    /* HORRIBLE STANDARDS KLUDGE: Toplevel paragraphs eat absorb adjacent
     * list items, but sublevel blocks behave properly.
     */
    return toplevelblock ? 0 : islist(t,&z,flags, &z);
}
Example #7
0
static int
islist(Line *t, int *clip, DWORD flags, int *list_type)
{
    int i, j;
    char *q;
    
    if ( /*iscode(t) ||*/ blankline(t) || ishdr(t,&i) || ishr(t) )
	return 0;

    if ( !(flags & (MKD_NODLIST|MKD_STRICT)) && isdefinition(t,clip,list_type) )
	return DL;

    if ( strchr("*-+", T(t->text)[t->dle]) && isspace(T(t->text)[t->dle+1]) ) {
	i = nextnonblank(t, t->dle+1);
	*clip = (i > 4) ? 4 : i;
	*list_type = UL;
	return AL;
    }

    if ( (j = nextblank(t,t->dle)) > t->dle ) {
	if ( T(t->text)[j-1] == '.' ) {

	    if ( !(flags & (MKD_NOALPHALIST|MKD_STRICT))
				    && (j == t->dle + 2)
			  && isalpha(T(t->text)[t->dle]) ) {
		j = nextnonblank(t,j);
		*clip = (j > 4) ? 4 : j;
		*list_type = AL;
		return AL;
	    }

	    strtoul(T(t->text)+t->dle, &q, 10);
	    if ( (q > T(t->text)+t->dle) && (q == T(t->text) + (j-1)) ) {
		j = nextnonblank(t,j);
		*clip = (j > 4) ? 4 : j;
		*list_type = OL;
		return AL;
	    }
	}
    }
    return 0;
}
Example #8
0
static Line*
is_extra_dt(Line *t, int *clip)
{
#if USE_EXTRA_DL
    int i;
    
    if ( t && t->next && T(t->text)[0] != '='
		      && T(t->text)[S(t->text)-1] != '=') {
	Line *x;
    
	if ( iscode(t) || blankline(t) || ishdr(t,&i) || ishr(t) )
	    return 0;

	if ( (x = skipempty(t->next)) && is_extra_dd(x) ) {
	    *clip = x->dle+2;
	    return t;
	}
	
	if ( x=is_extra_dt(t->next, clip) )
	    return x;
    }
#endif
    return 0;
}
Example #9
0
static void
decomment_sh(const char *fname, FILE *in)
{
    register int c, c1;
    char outbuf[4 * 1024];
    char *op = outbuf;

    enum
    {
	NORMAL,
	SH_COMMENT,
	DOUBLEQUOTESTRING,
	SINGLEQUOTESTRING
    } state = NORMAL;

    while ((c = getc(in)) != EOF)
    {
	switch (state)
	{
	case NORMAL:
	    switch (c)
	    {
	    case '\'':
		state = SINGLEQUOTESTRING;
		*op++ = c;
		break;
	    case '"':
		state = DOUBLEQUOTESTRING;
		*op++ = c;
		break;
	    case '#':
		state = SH_COMMENT;
		break;
	    case '\\':
		*op++ = c;
		c1 = getc(in);
		*op++ = c1;
		break;
	    default:
		*op++ = c;
		break;
	    }
	    break;

	case SH_COMMENT:	/* C++ comment */
	    if (c == '\n')
	    {
		state = NORMAL;
	    }
	    break;

	case DOUBLEQUOTESTRING:
	    *op++ = c;
	    switch (c)
	    {
	    case '"':
		state = NORMAL;
		break;
	    case '\\':		/* handle quoted quotes */
		c1 = getc(in);
		*op++ = c1;
		break;
	    }
	    break;

	case SINGLEQUOTESTRING:
	    *op++ = c;
	    switch (c)
	    {
	    case '\'':
		state = NORMAL;
		break;
	    case '\\':
		getc(in);
		break;
	    }
	    break;
	}

	/* If we just stuffed a \n into the output buffer... */
	if (op > outbuf && op[-1] == '\n')
	{
	    blankline(outbuf, &op);
	}
    }
}
Example #10
0
static
void
decomment_c(const char *fname, FILE *in)
{
    register int c, c1;
    char outbuf[4 * 1024];
    char *op = outbuf;

    enum
    {
	NORMAL,
	    C_COMMENT,
	    CC_COMMENT,
	    STRINGLITERAL,
	    CHARLITERAL
    } state = NORMAL;

    while ((c = getc(in)) != EOF)
    {
	switch (state)
	{
	case NORMAL:
	    switch (c)
	    {
	    case '\'':
		state = CHARLITERAL;
		*op++ = c;
		break;
	    case '"':
		state = STRINGLITERAL;
		*op++ = c;
		break;
	    case '/':
		c1 = getc(in);
		switch (c1)
		{
		case '/':
		    state = CC_COMMENT;
		    break;
		case '*':
		    state = C_COMMENT;
		    break;
		case EOF:
		    break;
		default:
		    *op++ = c;
		    ungetc(c1, in);
		    break;
		}
		break;
	    default:
		*op++ = c;
		break;
	    }
	    break;

	case C_COMMENT:		/* K&R C comment */
	    if (c == '*')
	    {
		c1 = getc(in);
		if (c1 == '/')
		{
		    state = NORMAL;
		}
		else
		{
		    ungetc(c1, in);
		}
	    }
	    break;

	case CC_COMMENT:	/* C++ comment */
	    if (c == '\n')
	    {
		state = NORMAL;
	    }
	    break;

	case STRINGLITERAL:
	    *op++ = c;
	    switch (c)
	    {
	    case '"':
		state = NORMAL;
		break;
	    case '\\':		/* handle quoted quotes */
		c1 = getc(in);
		*op++ = c1;
		break;
	    }
	    break;

	case CHARLITERAL:
	    *op++ = c;
	    switch (c)
	    {
	    case '\'':
		state = NORMAL;
		break;
	    case '\\':
		getc(in);
		break;
	    }
	    break;
	}

	/* If we just stuffed a \n into the output buffer... */
	if (op > outbuf && op[-1] == '\n')
	{
	    blankline(outbuf, &op);
	}
    };
}
Example #11
0
int
main(int argc, char *argv[])
{

	has_proc = false;

	MyString constraint;
	Qmgr_connection *q;
	int nextarg = 1, cluster=0, proc=0;
	bool UseConstraint = false;
	MyString schedd_name;
	MyString pool_name;
	ExprTree* value_expr;

	myDistro->Init( argc, argv );
	config();

#if !defined(WIN32)
	install_sig_handler(SIGPIPE, SIG_IGN );
#endif

	if (argc < 2) {
		usage(argv[0]);
	}

	// if -debug is present, it must be first. sigh.
	if (argv[nextarg][0] == '-' && argv[nextarg][1] == 'd') {
		// output dprintf messages to stderror at TOOL_DEBUG level
		dprintf_set_tool_debug("TOOL", 0);
		nextarg++;
	}

	// if it is present, it must be first after debug.
	if (argv[nextarg][0] == '-' && argv[nextarg][1] == 'n') {
		nextarg++;
		// use the given name as the schedd name to connect to
		if (argc <= nextarg) {
			fprintf(stderr, "%s: -n requires another argument\n", 
					argv[0]);
			exit(1);
		}				
		schedd_name = argv[nextarg];
		nextarg++;
	}

	if (argc <= nextarg) {
		usage(argv[0]);
	}

	// if it is present, it must be just after -n flag
	if (argv[nextarg][0] == '-' && argv[nextarg][1] == 'p') {
		nextarg++;
		if (argc <= nextarg) {
			fprintf(stderr, "%s: -pool requires another argument\n", 
					argv[0]);
			exit(1);
		}
		pool_name = argv[nextarg];
		nextarg++;
	}

	DCSchedd schedd((schedd_name.Length() == 0) ? NULL : schedd_name.Value(),
					(pool_name.Length() == 0) ? NULL   : pool_name.Value());
	if ( schedd.locate() == false ) {
		if (schedd_name == "") {
			fprintf( stderr, "%s: ERROR: Can't find address of local schedd\n",
				argv[0] );
			exit(1);
		}

		if (pool_name == "") {
			fprintf( stderr, "%s: No such schedd named %s in local pool\n",
				argv[0], schedd_name.Value() );
		} else {
			fprintf( stderr, "%s: No such schedd named %s in "
				"pool %s\n",
				argv[0], schedd_name.Value(), pool_name.Value() );
		}
		exit(1);
	}

	// Open job queue 
	q = ConnectQ( schedd.addr(), 0, false, NULL, NULL, schedd.version() );
	if( !q ) {
		fprintf( stderr, "Failed to connect to queue manager %s\n", 
				 schedd.addr() );
		exit(1);
	}

	if (argc <= nextarg) {
		usage(argv[0]);
	}

	if (isdigit(argv[nextarg][0])) {
		char *tmp;
		cluster = strtol(argv[nextarg], &tmp, 10);
		if (cluster <= 0) {
			fprintf( stderr, "Invalid cluster # from %s.\n", argv[nextarg]);
			exit(1);
		}
		if (*tmp == '.') {
			proc = strtol(tmp + 1, &tmp, 10);
			if (cluster <= 0) {
				fprintf( stderr, "Invalid proc # from %s.\n", argv[nextarg]);
				exit(1);
			}
			UseConstraint = false;
			has_proc = true;
		} else {
			constraint.formatstr("(%s == %d)", ATTR_CLUSTER_ID, cluster);
			UseConstraint = true;
		}
		nextarg++;
	} else if (!match_prefix(argv[nextarg], "-constraint")) {
		constraint.formatstr("(%s == \"%s\")", ATTR_OWNER, argv[nextarg]);
		nextarg++;
		UseConstraint = true;
	}

	if (argc <= nextarg) {
		usage(argv[0]);
	}

	while (match_prefix(argv[nextarg], "-constraint")) {

		if ( has_proc ){
			fprintf(stderr, "condor_qedit: proc_id specified. Ignoring constraint option\n");
			nextarg+=2;
			continue;
		}

		nextarg++;
		
		if (argc <= nextarg) {
			usage(argv[0]);
		}

		if ( !UseConstraint ){
			constraint = argv[nextarg];
		}
		else{
			constraint = "( " + constraint + " ) && " + argv[nextarg];
		}

		nextarg++;
		UseConstraint = true;
	}

	if (argc <= nextarg) {
		usage(argv[0]);
	}

	for (; nextarg < argc; nextarg += 2) {
		if (argc <= nextarg+1) {
			usage(argv[0]);
		}
		if (ProtectedAttribute(argv[nextarg])) {
			fprintf(stderr, "Update of attribute \"%s\" is not allowed.\n",
					argv[nextarg]);
			fprintf(stderr,
				"Transaction failed.  No attributes were set.\n");
			exit(1);
		}

		// Check validity of attribute-name
		if ( blankline(argv[nextarg]) ||
			 !IsValidAttrName(argv[nextarg]) )
		{
			fprintf(stderr,
				"Update aborted, illegal attribute-name specified for attribute \"%s\".\n",
				argv[nextarg]);
			fprintf(stderr,
				"Transaction failed.  No attributes were set.\n");
			exit(1);
		}

		// Check validity of attribute-value
		value_expr = NULL;
		if ( blankline(argv[nextarg+1]) ||
			 !IsValidAttrValue(argv[nextarg+1]) ||
			 ParseClassAdRvalExpr(argv[nextarg+1], value_expr) )
		{
			fprintf(stderr,
				"Update aborted, illegal attribute-value specified for attribute \"%s\".\n",
				argv[nextarg]);
			fprintf(stderr,
				"Transaction failed.  No attributes were set.\n");
			exit(1);
		}
		if (value_expr) delete value_expr;

		if (UseConstraint) {
			// Try to communicate with the newer protocol first
			if (SetAttributeByConstraint(constraint.Value(),
							argv[nextarg],
							argv[nextarg+1],
							SETDIRTY) < 0) {
				if (SetAttributeByConstraint(constraint.Value(),
							argv[nextarg],
							argv[nextarg+1]) < 0) {

					fprintf(stderr,
						"Failed to set attribute \"%s\" by constraint: %s\n",
						argv[nextarg], constraint.Value());
					fprintf(stderr,
						"Transaction failed.  No attributes were set.\n");
					exit(1);
				}
			}
		} else {
			if (SetAttribute(cluster, proc, argv[nextarg],
							 argv[nextarg+1], SETDIRTY) < 0) {
				fprintf(stderr,
						"Failed to set attribute \"%s\" for job %d.%d.\n",
						argv[nextarg], cluster, proc);
				fprintf(stderr,
						"Transaction failed.  No attributes were set.\n");
				exit(1);
			}
		}
		printf("Set attribute \"%s\".\n", argv[nextarg]);
	}

	if (!DisconnectQ(q)) {
		fprintf(stderr,
				"Queue transaction failed.  No attributes were set.\n");
		exit(1);
	}

	return 0;
}
Example #12
0
/* Main routine */
int main(int argc, char **argv) 
{
    char *shellargv[MAXARGS];
    int child_pid;
    char c;
    char *bufp;
    FILE *tracefp;
    int n=0;
    struct stat statbuf;
    
    /* Install the signal handler */
    signal(SIGALRM, sigalrm_handler);
printf("%d\n",n);
    /* Parse the command line */
    while ((c = getopt(argc, argv, "hVxs:f:")) != EOF) {
        switch (c) {
        case 'h':             /* Print help message */
            usage("");
	    break;
        case 'V':             /* Be more verbose */
            verbose++;
	    break;
	case 's':             /* The shell program name (default ./tsh) */
	    shellprog = strdup(optarg);
	    break;
	case 'f':             /* Trace file name */
	    tracefile = strdup(optarg);
	    break;
	case 'x':             /* Enable sandboxing */
	    sandboxing = 1;   /* Hidden argument */
	    break;
	default:
            usage("Unrecognized argument");
	}
    }

    if (!tracefile)
	  usage("Missing required argument (-f)");
    
    /* Make sure the requested shell is executable */
    if (stat(shellprog, &statbuf) < 0) {
	fprintf(stderr, "%s: File not found\n", shellprog);
	exit(1);
    }
    if (!(statbuf.st_mode & S_IXUSR)) {
	fprintf(stderr, "%s: File is not executable\n", shellprog);
	exit(1);
    } 

    /* Open the trace file for reading */
    if ((tracefp = fopen(tracefile, "r")) == NULL) {
	fprintf(stderr, "Unable to open trace file %s\n", tracefile);
	exit(1);
    }

    /* Socket pair for data transfers between runtrace and shell */
    if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, datafd) < 0) {
	perror("socketpair datafd");
	exit(1);
    }

    /* Socket pair for synchronization between runtrace and shell jobs */
    if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, syncfd) < 0) {
	perror("socketpair syncfd");
	exit(1);
    }

    /*
     * Create an environment variable that tells shell jobs
     * such as myspin which descriptor to synchronize on.
     */
    sprintf(buf, "SYNCFD=%d", syncfd[1]);
    if (putenv(buf) < 0) {
	perror("putenv");
	exit(1);
    }

    if (verbose) {
	printf("Created environment variable %s\n", buf);
    }


    /************************* 
     * Child code runs a shell
     *************************/ 
    if ((child_pid  = fork()) == 0) {  

	/* Close the descriptor the child is not using */
	close(datafd[0]);

	/* Redirect stdin and stdout to the domain socket */
	dup2(datafd[1], 0);
	dup2(datafd[1], 1);
	
	/* Create the shell command line arguments */
	shellargv[0] = shellprog;
	if (verbose) {
	    shellargv[1] = "-v";
	    shellargv[2] = '\0';
	}
	else {
	    shellargv[1] = '\0';
	}

	/* Modify the environment if sandboxing is enabled */
	if (sandboxing) {
	    strcpy(line, "LD_PRELOAD=/usr/lib/libdl.so ./sandbox.so");
	    putenv(line);
	}

	/* Now go ahead and run the shell */
	if (execve(shellprog, shellargv, environ) < 0) {
	    perror("execve");
	    exit(1);
	}
    }

    /******************************************************** 
     * Parent code sends trace-driven commands to child shell
     *******************************************************/

    /* Close the descriptor the parent is not using */
    close(datafd[1]); 

    /* Read the initial prompt from the shell */
    if (readable(datafd[0], DRIVER_TIMEOUT) == 0) {
	fprintf(stderr, "%s: Runtrace timed out waiting for initial shell prompt\n", tracefile);
    }     
    else {
	bzero(buf, MAXBUF);
	n = recv(datafd[0], buf, MAXBUF, 0);
	if (strcmp(buf, PROMPT)) {
	    fprintf(stderr, "%s: Runtrace expected initial shell prompt but got '%s' instead.\n", tracefile, buf);
	    exit(1);
	}
    }

    /* 
     * Parent reads trace file and sends commands to the shell 
     */
    while (fgets(line, MAXBUF, tracefp)) {

	/* Delete newline character */
	line[strlen(line)-1] = '\0';

	/* Ignore blank lines */
	if (blankline(line)) { 
	    if (verbose) 
		printf("runtrace: Ignoring blank line\n");
	    continue;
	}

	/* Echo comment lines */ 
	if (line[0] == '#') {
	    printf("%s\n", line);
	    continue;
	}

	/* Parse the command line */
	sscanf(line, "%s", command);
	if (verbose)
	    printf("runtrace: command=%s line=%s\n", command, line);
	
	/* WAIT command */
	if (!strcmp(command, "WAIT")) {
	    if (readable(syncfd[0], DRIVER_TIMEOUT) == 0) {
		printf("%s: Runtrace timed out waiting for sync from job\n", 
		       tracefile);
		exit(1);
	    }
	    else {
		bzero(buf, MAXBUF);
		if ((recv(syncfd[0], buf, MAXBUF, 0)) < 0) {
		    perror("recv syncfd");
		    exit(1);
		}
		if (verbose)
		    printf("runtrace: received sync from job\n");
		continue;
	    }
	}


	/* NEXT command */
	else if (!strcmp(command, "NEXT")) {
	    if (next_prompt() == 0) 
		exit(0);
	    continue;
	}

	/* SIGNAL command */
	else if (!strcmp(command, "SIGNAL")) {
	    bufp = "signal";
	    if ((send(syncfd[0], bufp, strlen(bufp), 0)) < 0) {
		perror("send syncfd");
		exit(1);
	    }
	    if (verbose)
		printf("runtrace: sent sync to shell job\n");
	    continue;
	}

	/* SIGINT command */
	else if (!strcmp(command, "SIGINT")) {
	    if (kill(child_pid, SIGINT) < 0) {
		perror("kill SIGINT");
		exit(1);
	    }
	    if (verbose)
		printf("Runtrace sent SIGINT to process %d\n", child_pid);
	    continue;
	}

	/* SIGTSTP command */
	else if (!strcmp(command, "SIGTSTP")) {
	    if (kill(child_pid, SIGTSTP) < 0) {
		perror("kill SIGTSTP");
		exit(1);
	    }
	    if (verbose)
		printf("Runtrace sent SIGTSTP to process %d\n", child_pid);
	    continue;
	}

	/* Pass the command line on to the shell */
	else {
	    if (verbose) {
		printf("runtrace: Sending '%s' to shell\n", line);
	    }
	    strcat(line, "\n");
	    if ((send(datafd[0], line, strlen(line), 0)) < 0) {
		perror("send datafd[0]");
		exit(1);
	    }
	}

    } /* while loop */

    /* Signal EOF to the shell */
    bufp = "";
    send(datafd[0], bufp, 0, 0);

    /* Wait for the shell to terminate */
    alarm(DRIVER_TIMEOUT);
    state = "waiting for shell to terminate";
    waitpid(child_pid, NULL, 0);

    /* Kill any of our stray shells and jobs */
    clean();
    exit(0);
}