Пример #1
0
// Process console messages sent by the system
static BOOL WINAPI console_control_handler( DWORD dwCtrlType ){
    BOOL bReturnStatus = FALSE;
    BOINCTRACE("***** Console Event Detected *****\n");
    switch( dwCtrlType ){
    case CTRL_LOGOFF_EVENT:
        BOINCTRACE("Event: CTRL-LOGOFF Event\n");
        if (!gstate.executing_as_daemon) {
           quit_client();
        }
        bReturnStatus =  TRUE;
        break;
    case CTRL_C_EVENT:
    case CTRL_BREAK_EVENT:
        BOINCTRACE("Event: CTRL-C or CTRL-BREAK Event\n");
        quit_client();
        bReturnStatus =  TRUE;
        break;
    case CTRL_CLOSE_EVENT:
    case CTRL_SHUTDOWN_EVENT:
        BOINCTRACE("Event: CTRL-CLOSE or CTRL-SHUTDOWN Event\n");
        quit_client();
        break;
    }
    return bReturnStatus;
}
Пример #2
0
//
//  FUNCTION: BOINCServiceCtrl
//
//  PURPOSE: This function is called by the SCM whenever
//           ControlService() is called on this service.
//
//  PARAMETERS:
//    dwCtrlCode - type of control requested
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
VOID WINAPI BOINCServiceCtrl(DWORD dwCtrlCode) {
    // Handle the requested control code.
    //
    switch(dwCtrlCode) {
        // Stop the service.
        //
        // SERVICE_STOP_PENDING should be reported before
        // setting the Stop Event - hServerStopEvent - in
        // ServiceStop().  This avoids a race condition
        // which may result in a 1053 - The Service did not respond...
        // error.
        case SERVICE_CONTROL_STOP:
        case SERVICE_CONTROL_SHUTDOWN:
            ReportStatus(SERVICE_STOP_PENDING, ERROR_SUCCESS, 30000);
            quit_client();
            return;

        // Pause the service.
        //
        case SERVICE_CONTROL_PAUSE:
            ReportStatus(SERVICE_PAUSE_PENDING, ERROR_SUCCESS, 10000);
            suspend_client();
            ReportStatus(SERVICE_PAUSED, ERROR_SUCCESS, 10000);
            return;

        // Continue the service.
        //
        case SERVICE_CONTROL_CONTINUE:
            ReportStatus(SERVICE_CONTINUE_PENDING, ERROR_SUCCESS, 10000);
            resume_client();
            ReportStatus(SERVICE_RUNNING, ERROR_SUCCESS, 10000);
            return;

        // Update the service status.
        //
        case SERVICE_CONTROL_INTERROGATE:
            break;

        // invalid control code
        //
        default:
            break;

    }

    ReportStatus(ssStatus.dwCurrentState, ERROR_SUCCESS, 1000);
}
Пример #3
0
/*main function*/
int main(int argc, char **argv)
{
    int opt;
    enum OPER_TYPE type;
    char path[FILE_NAME_LEN] = {0};
	char output_path[FILE_NAME_LEN] = {0};
    int delete_job;
    Client *c= NULL;
	
    if(argc<2)
  	    return -1;
	struct option long_options[] = {
		{"Simulate", 1, NULL, 'S'},
    	{"quit", 0, NULL, 'q'},
    	{"backup", 1, NULL, 'b'},
    	{"delete", 1, NULL, 'd'},
    	{"restore", 1, NULL, 'r'},
    	{"list", 0, NULL, 'l'},
    	{"pipeline", 0, NULL, 'p'},
    	{"output", 1, NULL, 'o'},
    	{"cloud", 0, NULL, 'c'},
    	
    	{"rewrite", 1, NULL, 'R'},
    	/*CFL*/
    	{"CFL", 1, NULL, 'C'},
    	{"seg_reuse", 1, NULL, 's'},
    	/*capping*/
    	{"cap_size", 1, NULL, 'a'},
    	{"cap_count", 1, NULL, 'e'},
    	/*perferect rewrite*/
    	{"ref_threshold", 1, NULL, 'u'},
    	
		{"overhead", 1, NULL, 'O'},
    	{"test", 1, NULL, 't'},
    	{"server", 1, NULL, 'H'},
    	{"help", 0, NULL, 'h'},
    	{NULL, 0, NULL, 0}
	};
	
    while((opt=getopt_long(argc, argv, "S:qb:d:r:lpo:cR:C:s:a:e:u:O:t:H:h", long_options, NULL))!=-1){
        switch(opt){
			case 'S':
				type=type_simulate;
				SIMULATE = true;
				strncpy(path, optarg, strlen(optarg));
				break;
            case 'q':
		        type=type_quit;
		        break;
            case 'b':
	  	        type=type_backup;
		        strncpy(path,optarg,strlen(optarg));
		        break;
            case 'd':
               	type=type_delete;
		        sscanf(optarg, "%d", &delete_job); 
		        break;
            case 'r':
              	type=type_restore;
		        strncpy(path,optarg,strlen(optarg));
		        break;
			case 'R':
				if (strcmp(optarg, "CFL") == 0)
					REWRITE = CFL_REWRITE;
				else if (strcmp(optarg, "CAP") == 0)
					REWRITE = CAPPING_REWRITE;
				else if (strcmp(optarg, "PER") == 0)
					REWRITE = PERFECT_REWRITE;
				break;
				
			case 'C':
				sscanf(optarg, "%f", &LWM);
				break;
			case 's':
				sscanf(optarg, "%f", &default_container_reuse);
				break;
			case 'a':
				sscanf(optarg, "%lld", &buffer_capacity);
				break;
			case 'e':
				sscanf(optarg, "%d", &max_refer_count);
				break;
			case 'u':
				sscanf(optarg, "%f", &segment_usage_threshold);
				break;
			case 'O':
				OVERHEAD = true;
				sscanf(optarg, "%f", &bandwidth);
				break;
	        case 't':
	  	        type=type_test;
		        strncpy(path,optarg,strlen(optarg));
		        break;
	        case 'h':
	   	        type=type_help;
		        break;
	            break;
            case 'H':
	  	        memset(SERVER_IP,0,30);
	  	        strncpy(SERVER_IP,optarg,strlen(optarg));
	  	        break;
			case 'l':
				type=type_list;
				break;
			case 'p':
				G_PIPELINE = true;
				break;
			case 'o':
				OUTPUT_RESULT = true;
				strncpy(output_path, optarg, strlen(optarg));
				break;
			case 'c':
				CLOUD = true;
				break;
	        default:
	   	        printf("Your command is wrong \n");
		        type=type_help;
		        break;
        }
    }

    if(type==type_help){
   	    usage(argv[0]);
	    return 0;
    }
    c = create_client();
	
	if (type == type_simulate) {
		simulata_backup(c, path, output_path);
		free(c);
		return 0;
	}else if(OVERHEAD == true) {
		backup_overhead(c, path, output_path);
		free(c);
		return 0;
	}
	
	
    if ((c->fd = bnet_connect(SERVER_IP, SERVER_PORT)) == -1){
	    err_msg1("Connection rejected!");
	    return 0;
    }

	if (G_PIPELINE) {
		c->recipe_fd = bnet_connect(SERVER_IP, SERVER_OTH_PORT);
		if (c->recipe_fd == -1) {
			err_msg1("Connection rejected!");
			return 0;
		}
	}
    
    if(type==type_test){
  	    test_data(c->fd, path);
	    return 0;
    }
    switch(type){
	    case type_login:
	        login(c);
	        break;
	    case type_logout:
	        logout(c);
	        break;
	    case type_quit:
            quit_client(c);
            break;
        case type_backup:
			if (G_PIPELINE)
				pipeline_backup(c, path, output_path);
			else
            	backup_client(c, path, output_path);
            break;
        case type_restore:
            restore_client(c, path, output_path);
            break;
        case type_delete:
            delete_client(c, delete_job);
            break;	
		case type_list:
			list_client(c);
			break;
	   default:
	   	    printf("Your command is wrong \n");
		    break;
    }
    free_client(c);
    return 0;
}
Пример #4
0
// Trap events on Windows so we can clean ourselves up.
// NOTE: this runs in a separate thread.
// Be careful accessing global data structures.
//
static LRESULT CALLBACK WindowsMonitorSystemPowerWndProc(
    HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
) {
    switch(uMsg) {
        // If we are not installed as a service, begin the task shutdown process
        // when we are notified that the system is going down. If we are installed
        // as a service, wait until the service control manager tells us to shutdown.
        //
        // The console handler happens a little to late in the cycle and leads
        // to BOINC attempting to start new tasks, which fail, when the OS has
        // shutdown some of the ones that were executing.
        //
        case WM_QUERYENDSESSION:
            if (!gstate.executing_as_daemon) {
                quit_client();
            }
            return TRUE;
            break;

        // On Windows power events are broadcast via the WM_POWERBROADCAST
        //   window message.  It has the following parameters:
        //     PBT_APMQUERYSUSPEND
        //     PBT_APMQUERYSUSPENDFAILED
        //     PBT_APMSUSPEND
        //     PBT_APMRESUMECRITICAL
        //     PBT_APMRESUMESUSPEND
        //     PBT_APMBATTERYLOW
        //     PBT_APMPOWERSTATUSCHANGE
        //     PBT_APMOEMEVENT
        //     PBT_APMRESUMEAUTOMATIC 
        case WM_POWERBROADCAST:
            switch(wParam) {
                // System is preparing to suspend.  This is valid on
                //   Windows versions older than Vista
                case PBT_APMQUERYSUSPEND:
                    return TRUE;
                    break;

                // System is resuming from a failed request to suspend
                //   activity.  This is only valid on Windows versions
                //   older than Vista
                case PBT_APMQUERYSUSPENDFAILED:
                    resume_client();
                    break;

                // System is critically low on battery power.  This is
                //   only valid on Windows versions older than Vista
                case PBT_APMBATTERYLOW:
                    post_sysmon_msg("Critical battery alarm, Windows is suspending operations");
                    suspend_client();
                    break;

                // System is suspending
                case PBT_APMSUSPEND:
                    post_sysmon_msg("Windows is suspending operations");
                    suspend_client();
                    break;

                // System is resuming from a normal power event
                case PBT_APMRESUMESUSPEND:
                    gstate.set_now();
                    post_sysmon_msg("Windows is resuming operations");

                    // Check for a proxy
                    working_proxy_info.need_autodetect_proxy_settings = true;

                    resume_client();
                    break;
            }
            break;
        default:
            break;
    }
    return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}