示例#1
0
void clientLscsConnectionsOpen(void)
{
        int fd; 
        enter_suid();
        struct sockaddr_un addr_UNIX;
        addr_UNIX.sun_family = AF_LOCAL;
        char path[4096];
        snprintf(path, 4096, "/tmp/xiaosi%d", opt_squid_id);
        strcpy(addr_UNIX.sun_path,path);
        unlink(path);
        fd = comm_open_un(SOCK_STREAM,
                        PF_LOCAL,
                        path,   
                        COMM_NONBLOCKING,
                        "LSCS Socket");
        leave_suid();
        comm_listen(fd);
        commSetSelect(fd, COMM_SELECT_READ, lscsAccept, NULL, 0);
        /*      
         * We need to set a defer handler here so that we don't
         * peg the CPU with select() when we hit the FD limit.
         */
        commSetDefer(fd, httpAcceptDefer, NULL);
        debug(191, 1) ("Accepting LSCS connections at %s, FD %d.\n",
                        path,   
                        fd);    
}
示例#2
0
文件: log.c 项目: AlexeyDemidov/fidod
static void vmessage(int loglevel, const char *format, va_list ap)
{

    /* FIXME: try to log messages of any size */
#define BUFSIZE 256

    char buf[BUFSIZE];

    /* FIXME: logging to console if errors and logfile still not initilized */
    if (syslog_init)
	vsyslog(loglevel, format, ap);

    if (logfile || !daemon_mode) {
	/* FIXME: %m format */
	char str[BUFSIZE];
	char timestamp[BUFSIZE];

	time_t t = time(NULL);
	struct tm *ptm = localtime(&t);

	int saved_errno = errno;
	char *errstr = strerror(saved_errno);

	char *p;

	vsnprintf(str, BUFSIZE, format, ap);
	strftime(timestamp, BUFSIZE, "%b %d %H:%M:%S", ptm);
	snprintf(buf, BUFSIZE, "%s %s[%d]: %s\n",
		 timestamp, program, (int) getpid(), str);

	if (p = strstr(buf, "%m")) {
	    char newbuf[BUFSIZE];

	    strncpy(newbuf, buf, p - buf);
	    strcpy(newbuf, errstr);
	    strcpy(newbuf, p + 2);
	}
    }

    if (logfile) {
	FILE *log;

	enter_suid();
	log = fopen(logfile, "a");
	leave_suid();

	if (!log) {
	    /* FIXME: don't try write to file */
	    /* error("can't open logfile %s:%m", logfile); */
	}
	else {
	    fprintf(log, buf);
	    fclose(log);
	}
    }

    if (!daemon_mode) {
	fprintf(stderr, buf);
    }
}
示例#3
0
int main (int argc, char **argv) { 

    leave_suid();
    
    if ( (program = strrchr(argv[0], '/')) == 0 ) 
        program = argv[0]; 
    else 
        program ++;
    
    parse_args(argc, argv);

    debug("start up");

    initlog(program, facility, logfile);

    debug("init log"); 
    
#ifndef NO_FORK
    
    if (daemon_mode) { 
        if (daemon(0, 0)) 
            av_shutdown(1); 
    } 
#endif

    set_signals(); 
    signal(SIGPIPE, SIG_IGN);
    
    if (create_pid_file())          /* bug - don't call shutdown - it removes pidfile */ 
        av_shutdown(1);

    notice("started");

    if ( !no_check && (drweb_ver = dw_getversion()) != -1 ) {
        notice("drwebd %d.%d found", drweb_ver/100, drweb_ver % 100);
    }
    else {
        no_check = 1;
    }

    if ( !no_check && (drweb_id = dw_getid()) != NULL ) {
        notice("drwebd id = <%s>", drweb_id );
    }

    if ( !no_check ) {
        dw_getbaseinfo();
    }

    main_loop();

    av_shutdown(0);
    

    return 0;
}
示例#4
0
static void m3u8Event(void *args)
{
    if(!is_m3u8_prefetch_alive()){
        debug(207,3)("m3u8_prefetch dont run,now starting it!\n");
        enter_suid();

        int cid = fork();
        if (cid == 0) {
            int ret = execl("/usr/local/squid/bin/m3u8_prefetch", "m3u8_prefetch","15101",(char *)0);
            if (ret < 0) {
                debug(207,3)("(m3u8) --> execl error : %s\n",xstrerror());
            }
            exit(-1);
        }
        leave_suid();
    }

    eventAdd("m3u8Event", m3u8Event, NULL, 30, 0);	
}
示例#5
0
void
icpConnectionsOpen(void)
{
    u_short port;
    struct in_addr addr;
    struct sockaddr_in xaddr;
    int x;
    socklen_t len;
    wordlist *s;
    if (Config2.Accel.on && !Config.onoff.accel_with_proxy)
	return;
    if ((port = Config.Port.icp) <= 0)
	return;
    enter_suid();
    theInIcpConnection = comm_open(SOCK_DGRAM,
	0,
	Config.Addrs.udp_incoming,
	port,
	COMM_NONBLOCKING,
	"ICP Socket");
    leave_suid();
    if (theInIcpConnection < 0)
	fatal("Cannot open ICP Port");
    commSetSelect(theInIcpConnection,
	COMM_SELECT_READ,
	icpHandleUdp,
	NULL,
	0);
    for (s = Config.mcast_group_list; s; s = s->next)
	ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
    debug(12, 1) ("Accepting ICP messages at %s, port %d, FD %d.\n",
	inet_ntoa(Config.Addrs.udp_incoming),
	(int) port, theInIcpConnection);
    if ((addr = Config.Addrs.udp_outgoing).s_addr != no_addr.s_addr) {
	enter_suid();
	theOutIcpConnection = comm_open(SOCK_DGRAM,
	    0,
	    addr,
	    port,
	    COMM_NONBLOCKING,
	    "ICP Port");
	leave_suid();
	if (theOutIcpConnection < 0)
	    fatal("Cannot open Outgoing ICP Port");
	commSetSelect(theOutIcpConnection,
	    COMM_SELECT_READ,
	    icpHandleUdp,
	    NULL,
	    0);
	debug(12, 1) ("Outgoing ICP messages on port %d, FD %d.\n",
	    (int) port, theOutIcpConnection);
	fd_note(theOutIcpConnection, "Outgoing ICP socket");
	fd_note(theInIcpConnection, "Incoming ICP socket");
    } else {
	theOutIcpConnection = theInIcpConnection;
    }
    memset(&theOutICPAddr, '\0', sizeof(struct in_addr));
    len = sizeof(struct sockaddr_in);
    memset(&xaddr, '\0', len);
    x = getsockname(theOutIcpConnection,
	(struct sockaddr *) &xaddr, &len);
    if (x < 0)
	debug(50, 1) ("theOutIcpConnection FD %d: getsockname: %s\n",
	    theOutIcpConnection, xstrerror());
    else
	theOutICPAddr = xaddr.sin_addr;
}