Пример #1
0
CThreadPool::CThreadPool(int nServiceType)
{
	m_nThreadSum				= 250;
	m_nThreadRunCount		= 0;

	m_ServiceType				= DogService4;
	m_bInit						= FALSE;
	m_bDebug					= FALSE;
	m_bLogger					= FALSE;
	m_bThreadPoolRun		= FALSE;
	m_bAddTaskRun			= FALSE;
	m_bEndPrint				= FALSE;
	m_bReadCfg				= FALSE;
	m_ServiceType				= nServiceType;
	m_strIniPath				= L"";
	m_strLogPath				= L"";	

	get_cfg_path();
	read_cfg();	
	get_log_path();

	m_hWaitingWork		= CreateEvent(NULL, false, false, NULL);
	m_hGotgWork			= CreateEvent(NULL, false, false, NULL);
	m_hAddTask			= CreateEvent(NULL, false, false, NULL);

	HANDLE hAddTask = (HANDLE)_beginthreadex(NULL, 0, _thr_add_task, this, 0, NULL);
	CloseHandle(hAddTask);
	HANDLE hReadCfg = (HANDLE)_beginthreadex(NULL, 0, _thr_read_config, this, 0, NULL);
	CloseHandle(hReadCfg);
	HANDLE hPrintState = (HANDLE)_beginthreadex(NULL, 0, _thr_print_state, this, 0, NULL);
	CloseHandle(hPrintState);
	
	init_thread_pool(m_nThreadSum);
}
Пример #2
0
/* Dumps crawler nodes list to log file. */
static int crawler_dump_log(Crawler *cwl)
{
    char log_path[PATH_MAX];
    if (get_log_path(log_path, sizeof(log_path)) == -1) {
        return -1;
    }

    char log_path_temp[strlen(log_path) + strlen(TEMP_FILE_EXT) + 1];
    snprintf(log_path_temp, sizeof(log_path_temp), "%s%s", log_path, TEMP_FILE_EXT);

    FILE *fp = fopen(log_path_temp, "w");

    if (fp == NULL) {
        return -2;
    }

    LOCK;   // ip_ntoa() isn't thread safe
    for (uint32_t i = 0; i < cwl->num_nodes; ++i) {
        fprintf(fp, "%s ", ip_ntoa(&cwl->nodes_list[i].ip_port.ip));
    }
    UNLOCK;

    fclose(fp);

    if (rename(log_path_temp, log_path) != 0) {
        return -3;
    }

    return 0;
}
Пример #3
0
void logn(char *filename, char *str)
{
	char	buffer[4196];
	char    path[256];
    int     fd;

	ASSERTLOG( filename );
	ASSERTLOG( str );

    sprintf(path, "%s/%s", get_log_path(), filename);
    fd = open(path, O_RDWR | O_APPEND | O_BINARY );
    if(fd < 0) 
	{
        fd = open(path, O_RDWR | O_CREAT | O_BINARY, ACC);
        if(fd < 0) 
			return;
    }
    lseek(fd, 0L, 2);

	/* put a time stamp on everything */
	sprintf(buffer, "%s: %s\n", get_time_str(), str );
    write(fd, buffer, strlen(buffer));

    close(fd);

	return;
}
Пример #4
0
/* renames chatlog file replacing src with dest.
   Returns 0 on success or if no log exists, -1 on failure. */
int rename_logfile(char *src, char *dest, const char *selfkey, const char *otherkey, int winnum)
{
    ToxWindow *toxwin = get_window_ptr(winnum);
    struct chatlog *log = NULL;
    bool log_on = false;

    /* disable log if necessary and save its state */
    if (toxwin != NULL) {
        log = toxwin->chatwin->log;
        log_on = log->log_on;
    }

    if (log_on)
        log_disable(log);

    char newpath[MAX_STR_SIZE];
    char oldpath[MAX_STR_SIZE];

    if (get_log_path(oldpath, sizeof(oldpath), src, selfkey, otherkey, LOG_CHAT) == -1)
        goto on_error;

    if (!file_exists(oldpath))
        return 0;

    if (get_log_path(newpath, sizeof(newpath), dest, selfkey, otherkey, LOG_CHAT) == -1)
        goto on_error;

    if (rename(oldpath, newpath) != 0)
        goto on_error;

    if (log_on)
        log_enable(dest, selfkey, otherkey, log, LOG_CHAT);

    return 0;

on_error:
    if (log_on)
        log_enable(src, selfkey, otherkey, log, LOG_CHAT);

    return -1;
}
Пример #5
0
/*================================================================*/
void mvc_log(){
/*  This function renames the list of all command file to include  *
 *  the date.  This is done to preserve the list commands that     *
 *  occured before a crash. */

	char *date, mfile[128], rfile[128];
	time_t i,t;

	t = time(0);
	date = ctime(&t);

	for(i=0;i<24;i++)
		if(date[i] == ' ')
			date[i] = '_';
	date[24] = 0;
	sprintf(rfile,"%s/%s", get_log_path(), "all_cmd");
	sprintf(mfile,"%s/%s_%s", get_log_path(), "all_cmd",date);

	rename( rfile, mfile);

	return;
}
Пример #6
0
void LogParser::get_lines(int nl, stack<string>* sl) {
	ifstream fi;
	fi.open(get_log_path().c_str(), ios::ate);
	int end_log=fi.tellg();

	while(nl>0) {
		int pos=find_back(&fi, end_log, 0, '\n');
		string line=get_single_line(&fi, pos, end_log);
		sl->push(line);
		end_log=pos;
		--nl;
	}
	fi.close();
}
Пример #7
0
/* Opens log file or creates a new one */
static int init_logging_session(char *name, const char *selfkey, const char *otherkey, struct chatlog *log, int logtype)
{
    if (selfkey == NULL || (logtype == LOG_CHAT && otherkey == NULL))
        return -1;

    char log_path[MAX_STR_SIZE];

    if (get_log_path(log_path, sizeof(log_path), name, selfkey, otherkey, logtype) == -1)
        return -1;

    log->file = fopen(log_path, "a+");
    snprintf(log->path, sizeof(log->path), "%s", log_path);

    if (log->file == NULL)
        return -1;

    return 0;
}
Пример #8
0
int main(int argc, char *argv[]) {
    int retval;
    R_RSA_PUBLIC_KEY key;
    char log_path[MAXPATHLEN];
#ifdef _USING_FCGI_
    unsigned int counter=0;
#endif

    for(int c = 1; c < argc; c++) {
        std::string option(argv[c]);
        if(option == "-v" || option == "--version") {
            printf("%s\n", SVN_VERSION);
            exit(0);
        } else if(option == "-h" || option == "--help") {
            usage(argv[0]);
            exit(0);
        } else if (option.length()){
            fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]);
            usage(argv[0]);
            exit(1);
        }
    }

    installer();

    get_log_path(log_path, "file_upload_handler.log");
#ifndef _USING_FCGI_
    if (!freopen(log_path, "a", stderr)) {
        fprintf(stderr, "Can't open log file '%s' (errno: %d)\n",
            log_path, errno
        );
        return_error(ERR_TRANSIENT, "can't open log file '%s' (errno: %d)",
            log_path, errno
        );
        exit(1);
    }
#else
    FCGI_FILE *f = FCGI::fopen(log_path, "a");
    if (f) {
       log_messages.redirect(f);
    } else {
        fprintf(stderr, "Can't redirect FCGI log messages\n");
        return_error(ERR_TRANSIENT, "can't open log file (FCGI)");
        exit(1);
    }
#endif

    retval = config.parse_file();
    if (retval) {
        fprintf(stderr, "Can't parse config.xml: %s\n", boincerror(retval));
        return_error(ERR_TRANSIENT,
            "can't parse config file", log_path, errno
        );
        exit(1);
    }

    log_messages.pid = getpid();
    log_messages.set_debug_level(config.fuh_debug_level);

    if (boinc_file_exists(config.project_path("stop_upload"))) {
        return_error(ERR_TRANSIENT, "Maintenance underway: file uploads are temporarily disabled.");
        exit(1);
    }

    if (!config.ignore_upload_certificates) {
        retval = get_key(key);
        if (retval) {
            return_error(ERR_TRANSIENT, "can't read key file");
            exit(1);
        }
    }

#ifdef _USING_FCGI_
    while(FCGI_Accept() >= 0) {
        counter++;
        //fprintf(stderr, "file_upload_handler (FCGI): counter: %d\n", counter);
        log_messages.set_indent_level(0);
#endif
        handle_request(stdin, key);
#ifdef _USING_FCGI_
        // flush log for FCGI, otherwise it just buffers a lot
        log_messages.flush();
    }
    // when exiting, write headers back to apache so it won't complain
    // about "incomplete headers"
    fprintf(stdout,"Content-type: text/plain\n\n");
#endif
    return 0;
}
Пример #9
0
void LogParser::set_num_lines() {
	ifstream fi;
	fi.open(get_log_path().c_str());
	log_lines = (int) count(istreambuf_iterator<char>(fi), istreambuf_iterator<char>(), '\n');
	fi.close();
}
Пример #10
0
int main(int argc, char** argv) {
#ifndef _USING_FCGI_
    FILE* fin, *fout;
#else
    FCGI_FILE *fin, *fout;
#endif
    int i, retval;
    char req_path[MAXPATHLEN], reply_path[MAXPATHLEN];
    char log_path[MAXPATHLEN], path[MAXPATHLEN];
    unsigned int counter=0;
    char* code_sign_key;
    int length = -1;
    log_messages.pid = getpid();
    bool debug_log = false;

    for (i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--batch")) {
            batch = true;
            continue;
        } else if (!strcmp(argv[i], "--mark_jobs_done")) {
            mark_jobs_done = true;
        } else if (!strcmp(argv[i], "--debug_log")) {
            debug_log = true;
#ifdef GCL_SIMULATOR
        } else if (!strcmp(argv[i], "--simulator")) {
            if(!argv[++i]) {
                log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
                usage(argv[0]);
                exit(1);
            }
            simtime = atof(argv[i]);
#endif 
        } else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            usage(argv[0]);
            exit(0);
        } else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
            printf("%s\n", SVN_VERSION);
            exit(0);
        } else if (strlen(argv[i])){
            log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]);
            usage(argv[0]);
            exit(1);
        }
    }

    // install a signal handler that catches SIGTERMS sent by Apache if the CGI
    // times out.
    //
    signal(SIGTERM, sigterm_handler);

    if (debug_log) {
        if (!freopen("debug_log", "w", stderr)) {
            fprintf(stderr, "Can't redirect stderr\n");
            exit(1);
        }
    } else {
        char *stderr_buffer;
        get_log_path(path, "scheduler.log");
#ifndef _USING_FCGI_
        char buf[256];
        if (!freopen(path, "a", stderr)) {
            fprintf(stderr, "Can't redirect stderr\n");
            sprintf(buf, "Server can't open log file (%s)", path);
            send_message(buf, 3600);
            exit(1);
        }
#else
        FCGI_FILE* f = FCGI::fopen(path, "a");
        if (f) {
            log_messages.redirect(f);
        } else {
            char buf[256];
            fprintf(stderr, "Can't redirect FCGI log messages\n");
            sprintf(buf, "Server can't open log file for FCGI (%s)", path);
            send_message(buf, 3600);
            exit(1);
        }
#endif
        // install a larger buffer for stderr.  This ensures that
        // log information from different scheduler requests running
        // in parallel aren't intermingled in the log file.
        //
        if (config.scheduler_log_buffer) {
            stderr_buffer = (char*)malloc(config.scheduler_log_buffer);
            if (!stderr_buffer) {
                log_messages.printf(MSG_CRITICAL,
                    "Unable to allocate stderr buffer\n"
                );
            } else {
#ifdef _USING_FCGI_
                retval = setvbuf(
                    f->stdio_stream, stderr_buffer, _IOFBF,
                    config.scheduler_log_buffer
                );
#else
                retval = setvbuf(
                    stderr, stderr_buffer, _IOFBF, config.scheduler_log_buffer
                );
#endif
                if (retval) {
                    log_messages.printf(MSG_CRITICAL,
                        "Unable to change stderr buffering\n"
                    );
                }
            }
        }
    }

    srand(time(0)+getpid());
    log_messages.set_debug_level(DEBUG_LEVEL);

#if DUMP_CORE_ON_SEGV
    set_core_dump_size_limit();
#endif

    retval = config.parse_file();
    if (retval) {
        log_messages.printf(MSG_CRITICAL,
            "Can't parse config.xml: %s\n", boincerror(retval)
        );
        send_message("Server can't parse configuration file", 3600);
        exit(0);
    }

    log_messages.set_debug_level(config.sched_debug_level);
    if (config.sched_debug_level == 4) g_print_queries = true;

    gui_urls.init();
    project_files.init();
    init_file_delete_regex();

    sprintf(path, "%s/code_sign_public", config.key_dir);
    retval = read_file_malloc(path, code_sign_key);
    if (retval) {
        log_messages.printf(MSG_CRITICAL,
            "Can't read code sign key file (%s)\n", path
        );
        send_message("Server can't find key file", 3600);
        exit(0);
    }
    strip_whitespace(code_sign_key);


    g_pid = getpid();
#ifdef _USING_FCGI_
    //while(FCGI_Accept() >= 0 && counter < MAX_FCGI_COUNT) {
    while(FCGI_Accept() >= 0) {
        counter++;
        log_messages.set_indent_level(0);
#endif
    if (config.debug_request_headers) {
        log_request_headers(length);
    }

    if (!debug_log && check_stop_sched()) {
        send_message("Project is temporarily shut down for maintenance", 3600);
        goto done;
    }

    if (!ssp) {
        attach_to_feeder_shmem();
    }
    if (!ssp) {
        send_message("Server error: can't attach shared memory", 3600);
        goto done;
    }

    if (strlen(config.debug_req_reply_dir)) {
        struct stat statbuf;
        // the code below is convoluted because,
        // instead of going from stdin to stdout directly,
        // we go via a pair of disk files
        // (this makes it easy to save the input,
        // and to know the length of the output).
        // NOTE: to use this, you must create group-writeable dirs
        // boinc_req and boinc_reply in the project dir
        //
        sprintf(req_path, "%s/%d_%u_sched_request.xml", config.debug_req_reply_dir, g_pid, counter);
        sprintf(reply_path, "%s/%d_%u_sched_reply.xml", config.debug_req_reply_dir, g_pid, counter);

        // keep an own 'log' per PID in case general logging fails
        // this allows to associate at leas the scheduler request with the client
        // IP address (as shown in httpd error log) in case of a crash
        sprintf(log_path, "%s/%d_%u_sched.log", config.debug_req_reply_dir, g_pid, counter);
#ifndef _USING_FCGI_
        fout = fopen(log_path, "a");
#else
        fout = FCGI::fopen(log_path,"a");
#endif
        fprintf(fout, "PID: %d Client IP: %s\n", g_pid, get_remote_addr());
        fclose(fout);

        log_messages.printf(MSG_DEBUG,
            "keeping sched_request in %s, sched_reply in %s, custom log in %s\n",
            req_path, reply_path, log_path
        );
#ifndef _USING_FCGI_
        fout = fopen(req_path, "w");
#else
        fout = FCGI::fopen(req_path,"w");
#endif
        if (!fout) {
            log_messages.printf(MSG_CRITICAL,
                "can't write request file\n"
            );
            exit(1);
        }
        copy_stream(stdin, fout);
        fclose(fout);
        stat(req_path, &statbuf);
        if (length>=0 && (statbuf.st_size != length)) {
            log_messages.printf(MSG_CRITICAL,
                "Request length %d != CONTENT_LENGTH %d\n",
                (int)statbuf.st_size, length
            );
        }

#ifndef _USING_FCGI_
        fin = fopen(req_path, "r");
#else
        fin = FCGI::fopen(req_path,"r");
#endif
        if (!fin) {
            log_messages.printf(MSG_CRITICAL,
                "can't read request file\n"
            );
            exit(1);
        }
#ifndef _USING_FCGI_
        fout = fopen(reply_path, "w");
#else
        fout = FCGI::fopen(reply_path, "w");
#endif
        if (!fout) {
            log_messages.printf(MSG_CRITICAL,
                "can't write reply file\n"
            );
            exit(1);
        }

        handle_request(fin, fout, code_sign_key);
        fclose(fin);
        fclose(fout);
#ifndef _USING_FCGI_
        fin = fopen(reply_path, "r");
#else
        fin = FCGI::fopen(reply_path, "r");
#endif
        if (!fin) {
            log_messages.printf(MSG_CRITICAL,
                "can't read reply file\n"
            );
            exit(1);
        }
        copy_stream(fin, stdout);
        fclose(fin);

        // if not contacted from a client, don't keep the log files
        /* not sure what lead to the assumption of a client setting
           CONTENT_LENGTH, but it's wrong at least on our current
           project / Apache / Client configuration. Commented out.
        if (getenv("CONTENT_LENGTH")) {
          unlink(req_path);
          unlink(reply_path);
        }
        */

#ifndef _USING_FCGI_
    } else if (batch) {
        while (!feof(stdin)) {
            handle_request(stdin, stdout, code_sign_key);
            fflush(stdout);
        }
#endif
    } else {
        handle_request(stdin, stdout, code_sign_key);
        fflush(stderr);
    }
done:
#ifdef _USING_FCGI_
        if (config.debug_fcgi) {
            log_messages.printf(MSG_NORMAL,
                "FCGI: counter: %d\n", counter
            );
            log_messages.flush();
        }
    }   // do()
    if (counter == MAX_FCGI_COUNT) {
        fprintf(stderr, "FCGI: counter passed MAX_FCGI_COUNT - exiting..\n");
    } else {
        fprintf(stderr, "FCGI: FCGI_Accept failed - exiting..\n");
    }
    // when exiting, write headers back to apache so it won't complain
    // about "incomplete headers"
    fprintf(stdout,"Content-type: text/plain\n\n");
#endif
    if (db_opened) {
        boinc_db.close();
    }
}
Пример #11
0
main(int argc, char *argv[])
{
    char ipaddr[80], filename[127];
    int oport, iport;
    int	return_code = 0;
    char buf[80];
    struct hostent *h;
    struct in_addr in;


    /* initialize these now in case the 20 second timer runs out */
    strcpy(Output[0], "no_port");
    strcpy(Output[1], "UNKNOWN");

    if(argc != 4) {
        fprintf(stderr, "auth v6.2\n");
        fprintf(stderr, "Syntax: %s ip_address oport iport\n", argv[0]);
        exit(0);
    }

    init_sockets();

    set_abort_timer(20);

    sprintf(filename, "%s/auth/lookup.%d", get_log_path(), getpid());
    fp = fopen(filename, "w");

    strcpy(ipaddr, argv[1]);
    oport = atoi(argv[2]);
    iport = atoi(argv[3]);
    in.s_addr = inet_addr(ipaddr);

    /* Perform the host name lookup on the IP address*/
    h = gethostbyaddr((char *)&in, sizeof(in), AF_INET);
    if(!h)
        strcpy(Output[1], "UNKNOWN");
    else
        strcpy(Output[1], h->h_name);


    if( strncmp(ipaddr, "127.0", 5)) {
        if(check_proxies(ipaddr, 1080)) {
            proxies = 1;
        }
        else if(check_proxies(ipaddr, 8088)) {
            proxies = 1;
        }
        else if(check_proxies(ipaddr, 23))  {
            proxies = 1;
        }
    }

    /* Begin the user id lookup */
    if(proxies != 1) {
        if(start_auth(&in, oport, iport, buf))
            strcpy(Output[0], buf);
        else
            strcpy(Output[0], "no_port");
    }

    /* Save the results to a file so frp can look them up */
    if(fp)
    {
        fprintf(fp, "%s\n%s\n%d\n", Output[0], Output[1], proxies);
        fclose(fp);
    }
    else
    {
        return_code = -1;
    }

#ifdef WIN32
    timeKillEvent(mmID);
#endif

    cleanup_sockets();

    return(return_code);
}
//------------------------------------------------------------
int log_cuda_result(RESULT& result, double& granted_credit) {
//------------------------------------------------------------

    const char * cuda_str = "SETI@home using CUDA accelerated device ";
    time_t log_time;
    int i, retval;
    char stderr_txt[1024];
    char log_path[256];
    char device_str[256];
    char * p;
    static FILE * log_fp=NULL;

    device_str[0] = '\0';

    get_log_path(log_path, "cuda_result_log");
    if (!log_fp) {
        log_fp = fopen(log_path, "a");
        if (!log_fp) {
            log_messages.printf(
                SCHED_MSG_LOG::MSG_CRITICAL,
                "[RESULT#%d] cannot open cuda_result_log\n",
                result.id
            );
            exit(1);
        } else {
            setbuf(log_fp, NULL);
        }
    }

    //get stderr_txt and determine cuda status
    p = strstr(result.stderr_out, cuda_str);
    if (p == NULL) {
        log_messages.printf(
            SCHED_MSG_LOG::MSG_DEBUG,
            "[RESULT#%d] is not a cuda result\n",
            result.id
        );
        return(0);         // not a cuda result - nothing more to do
    } else {
        log_messages.printf(
            SCHED_MSG_LOG::MSG_DEBUG,
            "[RESULT#%d] is a cuda result\n",
            result.id
        );
        return(1);         // is a cuda result - hack - we will remove this entire routine later
    }
    // pull out device string and replace spaces with underscores
    p += strlen(cuda_str);
    for (i=0; p[i] != '\n' && p[i] != '\0'; i++) {
        device_str[i] = p[i];
    }
    device_str[i] = '\0';
    for (i=0; device_str[i] != '\0'; i++) {
        if (device_str[i] == ' ') {
            device_str[i] = '_';
        }
    }

    log_time = time(NULL);

    retval = fprintf(log_fp, "%d %d %d %d %d %d %lf %lf %s\n",
                     log_time, result.received_time, result.id,
                     result.hostid, result.userid,
                     result.teamid, result.claimed_credit,
                     granted_credit, device_str);
    if (retval < 0) {
        log_messages.printf(
            SCHED_MSG_LOG::MSG_CRITICAL,
            "[RESULT#%d] cannot write to cuda_result_log : %s\n",
            strerror(errno)
        );
    }

    return(1);           // this was a cuda result
}
Пример #13
0
/* Initialization routine
Resume all the saved settings (if configured to do so), and setup the
timer so we know how often to save state. */
int init()
{
	int loc_in_playlist = 0;
	int loc_in_song = 0;
	int ii = 0;
    int result = 0;
	char eq_string[EQSIZE];
	int ini_song_name_length = 0;
	char *song_filename = NULL;
	char *song_title = NULL;
	int song_name_len = 0;
	char *str_to_check = NULL;
	char song_name[SONG_NAME_BUF];

	/* Initialize our global ini_path and log_path*/
	get_winamp_ini_path(ini_path, INI_BUFSIZE);
    get_log_path(log_path, LOG_BUFSIZE );

	/* If we're supposed to, resume playing with saved settings. */

	if (GetPrivateProfileInt(INI_SECTNAME, KEY_RESUME, 0, ini_path)) {
		/* Resume requested */

		/* Get the following information from the last saved state:
		location in playlist, time in song, EQ settings */
		
		/* Get location in playlist */
		loc_in_playlist = GetPrivateProfileInt(INI_SECTNAME, KEY_PLAYLISTLOC, 0, ini_path);

		/* Get location in song */
		loc_in_song = GetPrivateProfileInt(INI_SECTNAME, KEY_SONGLOC, 0, ini_path);

		/* Get EQ settings from INI and set them up in WinAmp */

		GetPrivateProfileString(INI_SECTNAME, KEY_EQ, "0,0,0,0,0,0,0,0,0,0", eq_string, EQSIZE, ini_path);

		for ( ii = 0 ; ii < NUM_EQS ; ii++ ) {
			/* First request info so WinAmp knows what to modify */
			SendMessage(module.hwndParent, WM_WA_IPC, ii, IPC_GETEQDATA);
			/* Now assign the new data */
			SendMessage(module.hwndParent, WM_WA_IPC, get_num(eq_string, ii+1, ','), IPC_SETEQDATA);
		}

		/* Set the Preamp */
		SendMessage(module.hwndParent, WM_WA_IPC, PREAMP, IPC_GETEQDATA);
		SendMessage(module.hwndParent, WM_WA_IPC, GetPrivateProfileInt(INI_SECTNAME, KEY_EQPREAMP, 0, ini_path), IPC_SETEQDATA);
		
		/* Set the enabled status of the EQ */
		SendMessage(module.hwndParent, WM_WA_IPC, EQENABLED, IPC_GETEQDATA);
		SendMessage(module.hwndParent, WM_WA_IPC, GetPrivateProfileInt(INI_SECTNAME, KEY_EQENABLED, 0, ini_path), IPC_SETEQDATA);

		/* Attempt to determine if we're playing the same song as we were when we exited */
		/* i.e., the user didn't exit WinAmp in the middle of a song, and then load a new song by double-clicking it or */
		/* something.  That would cause the plug-in to resume that song in the same position as the first one left */
		/* off. */
		/* This addition recommended by a few of my friends, and Dave Glaeser. */


		ini_song_name_length = GetPrivateProfileString(INI_SECTNAME, KEY_SONG_NAME, "", song_name, SONG_NAME_BUF, ini_path);

		song_filename = strdup((char*)SendMessage(module.hwndParent, WM_WA_IPC, loc_in_playlist, IPC_GETPLAYLISTFILE));
		song_title = strdup((char*)SendMessage(module.hwndParent, WM_WA_IPC, loc_in_playlist, IPC_GETPLAYLISTTITLE));

		if ( (song_filename != NULL) && (song_title != NULL) ) {
			song_name_len = strlen(song_title) + strlen(song_filename) + 1;
			str_to_check = (char*)malloc(sizeof(char)*(song_name_len+1));
			_snprintf(str_to_check, SONG_NAME_BUF, "%s-%s", song_filename, song_title);
		}
		else
			str_to_check = NULL;
		
        if ( (ini_song_name_length == 0) || /* Nothing returned, the user didn't have this feature before. */
            ((str_to_check != NULL) &&
            (strcmp(str_to_check, song_name) == 0)) ) /* They match */
        {
            /* Jump to loc_in_playlist */
            result = SendMessage(module.hwndParent, WM_WA_IPC, loc_in_playlist, IPC_SETPLAYLISTPOS);
            mylog( "SetPLaylistPos=%d, res=%d", loc_in_playlist, result );

            /* Start playing selected track */
            
            //result = SendMessage(module.hwndParent, WM_WA_IPC, 0, IPC_STARTPLAY);
            result = SendMessage(module.hwndParent,WM_COMMAND,MAKEWPARAM(WM_BUTTON_PLAY,0),0);
            mylog( "StartPlay, res=%u ", result);

            /* Jump to saved location within track */
            result = SendMessage(module.hwndParent, WM_WA_IPC, loc_in_song, IPC_JUMPTOTIME);
            mylog( "JumpToTime=%dms, res=%u ",  loc_in_song, result);


        }

		if (song_filename != NULL) 
			free(song_filename);
		if (song_title != NULL) 
			free(song_title);
		if (str_to_check != NULL) 
			free(str_to_check);
	}

	/* Fire off an alarm clock to let us know when we need to write out the state of WinAmp */
	
	/* Setup the timer */
	do_timer();

	return 0;
}
Пример #14
0
int DEFAULT_CC
main(int argc, char **argv)
{
    tbus waiters[4];
    int pid = 0;
    char text[256];
    char* log_path;
    char *display_text;
    char log_file[256];
    enum logReturns error;
    struct log_config logconfig;
    unsigned int log_level;

    g_init("xrdp-chansrv"); /* os_calls */

    log_path = get_log_path();
    if (log_path == 0)
    {
        g_writeln("error reading CHANSRV_LOG_PATH and HOME environment variable");
        g_deinit();
        return 1;
    }

    read_ini();
    pid = g_getpid();

    log_level = get_log_level(g_getenv("CHANSRV_LOG_LEVEL"), LOG_LEVEL_ERROR);

    /* starting logging subsystem */
    g_memset(&logconfig, 0, sizeof(struct log_config));
    logconfig.program_name = "XRDP-Chansrv";
    g_snprintf(log_file, 255, "%s/xrdp-chansrv.log", log_path);
    g_writeln("chansrv::main: using log file [%s]", log_file);

    if (g_file_exist(log_file))
    {
        g_file_delete(log_file);
    }

    logconfig.log_file = log_file;
    logconfig.fd = -1;
    logconfig.log_level = log_level;
    logconfig.enable_syslog = 0;
    logconfig.syslog_level = 0;
    error = log_start_from_param(&logconfig);

    if (error != LOG_STARTUP_OK)
    {
        switch (error)
        {
            case LOG_ERROR_MALLOC:
                g_writeln("error on malloc. cannot start logging. quitting.");
                break;
            case LOG_ERROR_FILE_OPEN:
                g_writeln("error opening log file [%s]. quitting.",
                          getLogFile(text, 255));
                break;
            default:
                g_writeln("log_start error");
                break;
        }

        g_deinit();
        return 1;
    }

    LOGM((LOG_LEVEL_ALWAYS, "main: app started pid %d(0x%8.8x)", pid, pid));
    /*  set up signal handler  */
    g_signal_kill(term_signal_handler); /* SIGKILL */
    g_signal_terminate(term_signal_handler); /* SIGTERM */
    g_signal_user_interrupt(term_signal_handler); /* SIGINT */
    g_signal_pipe(nil_signal_handler); /* SIGPIPE */
    g_signal_child_stop(child_signal_handler); /* SIGCHLD */
    g_signal_segfault(segfault_signal_handler);

    display_text = g_getenv("DISPLAY");
    LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text));
    get_display_num_from_display(display_text);

    if (g_display_num == 0)
    {
        LOGM((LOG_LEVEL_ERROR, "main: error, display is zero"));
        g_deinit();
        return 1;
    }

    LOGM((LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num));
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
    g_term_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
    g_thread_done_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_exec", pid);
    g_exec_event = g_create_wait_obj(text);
    g_exec_mutex = tc_mutex_create();
    g_exec_sem = tc_sem_create(0);
    tc_thread_create(channel_thread_loop, 0);

    while (g_term_event > 0 && !g_is_wait_obj_set(g_term_event))
    {
        waiters[0] = g_term_event;
        waiters[1] = g_exec_event;

        if (g_obj_wait(waiters, 2, 0, 0, 0) != 0)
        {
            LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
            break;
        }

        if (g_is_wait_obj_set(g_term_event))
        {
            break;
        }

        if (g_is_wait_obj_set(g_exec_event))
        {
            g_reset_wait_obj(g_exec_event);
            run_exec();
        }
    }

    while (g_thread_done_event > 0 && !g_is_wait_obj_set(g_thread_done_event))
    {
        /* wait for thread to exit */
        if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
        {
            LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
            break;
        }
    }

    /* cleanup */
    main_cleanup();
    LOGM((LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid));
    g_deinit();
    return 0;
}
Пример #15
0
int main(int argc, char** argv) {
#ifndef _USING_FCGI_
    FILE* fin, *fout;
#else
    FCGI_FILE *fin, *fout;
#endif
    int i, retval;
    char req_path[256], reply_path[256], path[256];
    unsigned int counter=0;
    char* code_sign_key;
    int length=-1;
    log_messages.pid = getpid();
    bool debug_log = false;

    for (i=1; i<argc; i++) {
        if (!strcmp(argv[i], "--batch")) {
            batch = true;
            continue;
        } else if (!strcmp(argv[i], "--mark_jobs_done")) {
            mark_jobs_done = true;
        } else if (!strcmp(argv[i], "--debug_log")) {
            debug_log = true;
#ifdef GCL_SIMULATOR
        } else if (!strcmp(argv[i], "--simulator")) {
            simtime = atof(argv[++i]);
#endif 
        } else {
            usage(argv[0]);
        }
    }

    // install a signal handler that catches SIGTERMS sent by Apache if the cgi
    // times out.
    //
    signal(SIGTERM, sigterm_handler);

    if (debug_log) {
        freopen("debug_log", "w", stderr);
    } else {
        char *stderr_buffer, buf[256];
        get_log_path(path, "scheduler.log");
#ifndef _USING_FCGI_
        if (!freopen(path, "a", stderr)) {
            fprintf(stderr, "Can't redirect stderr\n");
            sprintf(buf, "Server can't open log file (%s)", path);
            send_message(buf, 3600);
            exit(1);
        }
        // install a larger buffer for stderr.  This ensures that
        // log information from different scheduler requests running
        // in parallel don't collide in the log file and appear intermingled.
        //
        if (!(stderr_buffer=(char *)malloc(32768)) || setvbuf(stderr, stderr_buffer, _IOFBF, 32768)) {
            log_messages.printf(MSG_CRITICAL,
                "Unable to change stderr buffering preferences\n"
            );
        }
#else
        FCGI_FILE* f = FCGI::fopen(path, "a");
        if (f) {
           log_messages.redirect(f);
        } else {
            char buf[256];
            fprintf(stderr, "Can't redirect FCGI log messages\n");
            sprintf(buf, "Server can't open log file for FCGI (%s)", path);
            send_message(buf, 3600);
            exit(1);
        }
        // set buffer as above, note that f is really a struct from fcgi_stdio.h
        if (!(stderr_buffer=(char *)malloc(32768)) || setvbuf(f->stdio_stream, stderr_buffer, _IOFBF, 32768)) {
            log_messages.printf(MSG_CRITICAL,
                "Unable to change stderr FCGI buffering preferences\n"
            );
        }
#endif
    }

    srand(time(0)+getpid());
    log_messages.set_debug_level(DEBUG_LEVEL);

#if DUMP_CORE_ON_SEGV
    set_core_dump_size_limit();
#endif

    retval = config.parse_file();
    if (retval) {
        log_messages.printf(MSG_CRITICAL,
            "Can't parse config.xml: %s\n", boincerror(retval)
        );
        send_message("Server can't parse configuration file", 3600);
        exit(0);
    }

    log_messages.set_debug_level(config.sched_debug_level);

    gui_urls.init();
    project_files.init();

    sprintf(path, "%s/code_sign_public", config.key_dir);
    retval = read_file_malloc(path, code_sign_key);
    if (retval) {
        log_messages.printf(MSG_CRITICAL,
            "Can't read code sign key file (%s)\n", path
        );
        send_message("Server can't find key file", 3600);
        exit(0);
    }


    g_pid = getpid();
#ifdef _USING_FCGI_
    //while(FCGI_Accept() >= 0 && counter < MAX_FCGI_COUNT) {
    while(FCGI_Accept() >= 0) {
        counter++;
        log_messages.set_indent_level(0);
#endif
    if (config.debug_request_headers) {
        log_request_headers(length);
    }

    if (check_stop_sched()) {
        send_message("Project is temporarily shut down for maintenance", 3600);
        goto done;
    }

    if (!ssp) {
        attach_to_feeder_shmem();
    }
    if (!ssp) {
        send_message("Server error: can't attach shared memory", 3600);
        goto done;
    }

    if (use_files) {
        struct stat statbuf;
        // the code below is convoluted because,
        // instead of going from stdin to stdout directly,
        // we go via a pair of disk files
        // (this makes it easy to save the input,
        // and to know the length of the output).
        // NOTE: to use this, you must create group-writeable dirs
        // boinc_req and boinc_reply in the project dir
        //
        sprintf(req_path, "%s%d_%u", config.project_path(REQ_FILE_PREFIX), g_pid, counter);
        sprintf(reply_path, "%s%d_%u", config.project_path(REPLY_FILE_PREFIX), g_pid, counter);
#ifndef _USING_FCGI_
        fout = fopen(req_path, "w");
#else
        fout = FCGI::fopen(req_path,"w");
#endif
        if (!fout) {
            log_messages.printf(MSG_CRITICAL,
                "can't write request file\n"
            );
            exit(1);
        }
        copy_stream(stdin, fout);
        fclose(fout);
        stat(req_path, &statbuf);
        if (length>=0 && (statbuf.st_size != length)) {
            log_messages.printf(MSG_CRITICAL,
                "Request length %d != CONTENT_LENGTH %d\n",
                (int)statbuf.st_size, length
            );
        }

#ifndef _USING_FCGI_
        fin = fopen(req_path, "r");
#else
        fin = FCGI::fopen(req_path,"r");
#endif
        if (!fin) {
            log_messages.printf(MSG_CRITICAL,
                "can't read request file\n"
            );
            exit(1);
        }
#ifndef _USING_FCGI_
        fout = fopen(reply_path, "w");
#else
        fout = FCGI::fopen(reply_path, "w");
#endif
        if (!fout) {
            log_messages.printf(MSG_CRITICAL,
                "can't write reply file\n"
            );
            exit(1);
        }

        handle_request(fin, fout, code_sign_key);
        fclose(fin);
        fclose(fout);
#ifndef _USING_FCGI_
        fin = fopen(reply_path, "r");
#else
        fin = FCGI::fopen(reply_path, "r");
#endif
        if (!fin) {
            log_messages.printf(MSG_CRITICAL,
                "can't read reply file\n"
            );
            exit(1);
        }
        copy_stream(fin, stdout);
        fclose(fin);
#ifdef EINSTEIN_AT_HOME
        if (getenv("CONTENT_LENGTH")) unlink(req_path);
        if (getenv("CONTENT_LENGTH")) unlink(reply_path);
#else
        // unlink(req_path);
        // unlink(reply_path);
#endif
#ifndef _USING_FCGI_
    } else if (batch) {
        while (!feof(stdin)) {
            handle_request(stdin, stdout, code_sign_key);
            fflush(stdout);
        }
#endif
    } else {
        handle_request(stdin, stdout, code_sign_key);
    }
done:
#ifdef _USING_FCGI_
        log_messages.printf(MSG_DEBUG,
            "FCGI: counter: %d\n", counter
        );
        log_messages.flush();
    }   // do()
    if (counter == MAX_FCGI_COUNT) {
        fprintf(stderr, "FCGI: counter passed MAX_FCGI_COUNT - exiting..\n");
    } else {
        fprintf(stderr, "FCGI: FCGI_Accept failed - exiting..\n");
    }
    // when exiting, write headers back to apache so it won't complain
    // about "incomplete headers"
    fprintf(stdout,"Content-type: text/plain\n\n");
#endif
    if (db_opened) {
        boinc_db.close();
    }
}