Пример #1
0
/* main function */
	int 
main(int argc, char ** argv){
		
	if(argc == 2)
		config_file[0] = argv[1];
	else
		config_file[0] = "opencp.conf";
		
	if(!udp_init_socket())
		exit(0);
	signal(SIGHUP, reconfigure);
	reconfigure(SIGHUP);
	
	list_db(ms_db->lisp_db4);
	list_db(ms_db->lisp_db6);
	list_site(site_db);
	plumb(); 
	exit(EXIT_SUCCESS);
}
Пример #2
0
	int 
main(int argc, char ** argv){
	if(argc !=2){
		fprintf(stderr, "usage: %s <config_file>\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	
	config_file[0] = argv[1];
	
	signal(SIGHUP, reconfigure);
	reconfigure(SIGHUP);
	
	list_db(ms_db->lisp_db4);
	list_db(ms_db->lisp_db6);
	list_site(site_db);
	
	plumb();

	exit(EXIT_SUCCESS);
}
Пример #3
0
int
mesgopen(Message *mbox, char *dir, char *s, Message *mesg, int plumbed, char *digest)
{
	char *t, *u, *v;
	Message *m;
	char *direlem[10];
	int i, ndirelem, reuse;

	/* find white-space-delimited first word */
	for(t=s; *t!='\0' && !isspace(*t); t++)
		;
	u = emalloc(t-s+1);
	memmove(u, s, t-s);
	/* separate it on slashes */
	ndirelem = tokenizec(u, direlem, nelem(direlem), "/");
	if(ndirelem <= 0){
    Error:
		free(u);
		return 0;
	}
	if(plumbed){
		write(wctlfd, "top", 3);
		write(wctlfd, "current", 7);
	}
	/* open window for message */
	m = mesglookup(mbox, direlem[0], digest);
	if(m == nil)
		goto Error;
	if(mesg!=nil && m!=mesg)	/* string looked like subpart but isn't part of this message */
		goto Error;
	if(m->opened == 0){
		if(m->w == nil){
			reuse = 0;
			m->w = newwindow();
		}else{
			reuse = 1;
			/* re-use existing window */
			if(winsetaddr(m->w, "0,$", 1)){
				if(m->w->data < 0)
					m->w->data = winopenfile(m->w, "data");
				write(m->w->data, "", 0);
			}
		}
		v = estrstrdup(mbox->name, m->name);
		winname(m->w, v);
		free(v);
		if(!reuse){
			if(m->deleted)
				wintagwrite(m->w, "Q Reply all UnDelmesg Save ", 2+6+4+10+5);
			else
				wintagwrite(m->w, "Q Reply all Delmesg Save ", 2+6+4+8+5);
		}
		threadcreate(mesgctl, m, STACK);
		winopenbody(m->w, OWRITE);
		mesgload(m, dir, m->name, m->w);
		winclosebody(m->w);
		winclean(m->w);
		m->opened = 1;
		if(ndirelem == 1){
			free(u);
			return 1;
		}
	}
	if(ndirelem == 1 && plumbport(m->type, m->filename) <= 0){
		/* make sure dot is visible */
		ctlprint(m->w->ctl, "show\n");
		return 0;
	}
	/* walk to subpart */
	dir = estrstrdup(dir, m->name);
	for(i=1; i<ndirelem; i++){
		m = mesglookup(m, direlem[i], digest);
		if(m == nil)
			break;
		dir = egrow(dir, m->name, nil);
	}
	if(m != nil && plumbport(m->type, m->filename) > 0)
		plumb(m, dir);
	free(dir);
	free(u);
	return 1;
}
Пример #4
0
	int 
main(int argc, char ** argv){
		
	config_file[0] = "opencp.conf";
	int c;
	opterr = 0;
	_daemon = 0;
	while ((c = getopt (argc, argv, "df:")) != -1){
		switch (c){
		case 'd':
			_daemon = 1;
			break;
		case 'f':
			config_file[0] = optarg;
			break;
		case '?':
			if (optopt == 'f')
				fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (isprint (optopt))
				fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
				fprintf (stderr,
                        "Unknown option character `\\x%x'.\n",
                        optopt);
            return 1;
        default:
            abort ();
        }
	}
	
	if(_daemon){
		pid_t pid;
 
		/* Clone child from ourselves */  
		pid = fork(); 
		
		if (pid < 0) {
			exit(EXIT_FAILURE);
		}
		
		/* pid > 0, we are the parent, exit */
		if (pid > 0) {
			exit(EXIT_SUCCESS);
		}
 		/* now I'm child */
		FILE *fpid;
		pid = getpid();
		printf("my pid is %d\n",pid);
		fpid = fopen("/var/run/opencp.pid", "w");
		
		fprintf(fpid,"%d",pid);
		fclose(fpid);
	}
	
	if(_daemon){
		flog = fopen("/var/log/opencp.log","a");
		signal(SIGUSR1, reopenlog);
	}else{
		flog = NULL;
	}
	
	//signal(SIGHUP, reconfigure);
	reconfigure(SIGHUP);
	if(!udp_init_socket())
		exit(0);
	if(_daemon){
		fflush(stdout);
		//close(STDOUT_FILENO);
		//close(STDIN_FILENO);
		//close(STDERR_FILENO);
	}
	
	list_db(ms_db->lisp_db4);
	list_db(ms_db->lisp_db6);
	list_site(site_db);
	plumb(); 
	fclose(flog);
	exit(EXIT_SUCCESS);
}