static void check_discharging( fwts_framework *fw, const uint32_t index, const char *name) { uint32_t i; /* when we get here we KNOW the state is "discharging" */ uint32_t initial_value; fwts_printf(fw, "==== Waiting to see if battery '%s' discharges ====\n", name); fwts_cpu_consume_start(); initial_value = get_full(fw, index); for (i = 0; i <= 120; i++) { uint32_t new_value = get_full(fw, index); if (new_value<initial_value) { fwts_passed(fw, "Battery %s charge is decrementing as expected.", name); fwts_cpu_consume_complete(); return; } fwts_printf(fw, "Waiting %3.3d/120\r", 120-i); sleep(1); } fwts_cpu_consume_complete(); fwts_failed(fw, LOG_LEVEL_MEDIUM, "BatteryNotDischarging", "Battery %s claims it is discharging but no charge is used.", name); }
static void check_battery_trip_point( fwts_framework *fw, const uint32_t index, const char *name) { uint32_t trip_point; uint32_t trip_point_org; fwts_printf(fw, "==== Checking trip point of battery '%s' ====\n", name); if (!fwts_battery_check_trip_point_support(fw, index)) { fwts_printf(fw, "==== Not supported - skip test ====\n"); return; } if (fwts_battery_get_trip_point(fw, index, &trip_point) == FWTS_OK) trip_point_org = trip_point; else trip_point_org = 0; fwts_log_info(fw, "Test battery '%s' downward trip point.", name); fwts_printf(fw, "==== Please now UNPLUG the AC power of the machine ====\n"); fwts_press_enter(fw); sleep(1); trip_point = get_full(fw, index) - 5; fwts_battery_set_trip_point(fw, index, trip_point); fwts_cpu_consume_start(); wait_for_acpi_event(fw, name); fwts_cpu_consume_complete(); fwts_log_info(fw, "Test battery '%s' upwards trip point.", name); fwts_printf(fw, "==== Please PLUG IN the AC power of the machine ====\n"); fwts_press_enter(fw); sleep(1); trip_point = get_full(fw, index) + 3; fwts_battery_set_trip_point(fw, index, trip_point); wait_for_acpi_event(fw, name); if (trip_point_org != 0) fwts_battery_set_trip_point(fw, index, trip_point_org); }
static void *worker(void *data) { queue_t *q = data; piece_t *p; SHA_CTX c; while ((p = get_full(q))) { SHA1_Init(&c); SHA1_Update(&c, p->data, p->len); SHA1_Final(p->dest, &c); put_free(q, p, 1); } return NULL; }
int main( int argc, char * argv[]) { struct sockaddr_in server; int port; int dtch=1; int one=1,i; struct rlimit l; int needed=0; char * as_user=USER; struct sigaction act,oact; in_addr_t bound = INADDR_ANY; const char * erm; errorout = stderr; port = PORT; for( i=1; i<argc; i++) { if ((!strcmp(argv[i],"-p")) && (i+1<argc)) { port=atoi(argv[++i]); if (port<=1) { fprintf(stderr,"Aborted: You really want a port number >1.\n"); exit(1); }; } else if ((!strcmp(argv[i],"-b")) && (i+1<argc)) { char * iface = argv[++i]; bound = inet_addr(iface); /* First treat it as an UP address */ if (bound == INADDR_NONE) { /* Not a valid IP address - try to look it up */ struct hostent * hp; if((hp = gethostbyname(iface))==NULL) { perror("Address to listen on not found"); exit(1); }; bound = *(u_long *) hp->h_addr; } } else if ((!strcmp(argv[i],"-d")) && (i+1<argc)) { my_dir = argv[++i]; } else if ((!strcmp(argv[i],"-u")) && (i+1<argc)) { as_user= argv[++i]; } else if (!strcmp(argv[i],"-U")) { as_user= NULL; } else if ((!strcmp(argv[i],"-C")) && (i+1<argc)) { conf_file = argv[++i]; if ((erm=parse_config(conf_file))) { fprintf(stderr,"Aborted: %s\n",erm); exit(1); }; printf("Config file parsed OK\n"); exit(0); } else if ((!strcmp(argv[i],"-c")) && (i+1<argc)) { conf_file = argv[++i]; } else if ((!strcmp(argv[i],"-P")) && (i+1<argc)) { pid_file= argv[++i]; } else if ((!strcmp(argv[i],"-n")) && (i+1<argc)) { max_processes = atoi( argv[ ++i ] ); if ((max_processes < 1) || (max_processes > MAX_CHILD)) { fprintf(stderr,"Aborted: Max Number of child processes must be between 1 and %d\n",MAX_CHILD); exit(1); }; } else if ((!strcmp(argv[i],"-m")) && (i+1<argc)) { max_dbms = atoi( argv[ ++i ] ); if ((max_dbms < 1) || (max_dbms > MAX_DBMS)) { fprintf(stderr,"Aborted: Max Number of DB's must be between 1 and %d\n",MAX_DBMS); exit(1); }; } else if ((!strcmp(argv[i],"-C")) && (i+1<argc)) { max_clients = atoi( argv[ ++i ] ); if ((max_clients < 1) || (max_clients> MAX_CLIENT)) { fprintf(stderr,"Aborted: Max Number of children must be between 1 and %d\n",MAX_CLIENT); exit(1); }; } else if (!strcmp(argv[i],"-x")) { verbose++; debug++; if (debug>2) dtch = 0; } else if (!strcmp(argv[i],"-D")) { dtch = 0; } else if (!strcmp(argv[i],"-t")) { trace_on= 1; } else if (!strcmp(argv[i],"-v")) { printf("%s\n",get_full()); printf("Max clients: %d\n",MAX_CLIENT); printf("Max DBs: %d\n",MAX_DBMS); printf("Max Children: %d\n",MAX_CHILD); printf("Max Payload: %d bytes\n",MAX_PAYLOAD); printf("Default dir: %s\n",DIR_PREFIX); printf("Default config: %s\n",CONF_FILE); exit(0); } else if (!strcmp(argv[i],"-X")) { verbose=debug=100; dtch = 0; sysloglog = 0; stderrlog = 1; } else if ((!strcmp(argv[i],"-e")) && (i+1<argc)) { stderrlog = 1; if ((errorout = fopen(argv[++i],"a")) == NULL) { fprintf(stderr,"Aborted. Cannot open logfile %s for writing: %s\n", argv[i],strerror(errno)); exit(1); }; } else if (!strcmp(argv[i],"-E")) { stderrlog = 1; } else { fprintf(stderr,"Syntax: %s [-U | -u <userid>] [-E] [-P <pid-file>] [-d <directory_prefix>] [-b <ip to bind to>] [-p <port>] [-x] [-n <max children>] [-m <max databases>] [-C <max clients>] <-c conffile>\n",argv[0]); exit(1); }; }; if ((erm=parse_config(conf_file))) { fprintf(stderr,"Aborted: %s\n",erm); exit(1); } if (HARD_MAX_CLIENTS < max_clients +3) { fprintf(stderr,"Aborted: Max number of clients larger than compiled hard max(%d)\n",HARD_MAX_CLIENTS); exit(1); }; needed=MAX(max_processes, max_clients/max_processes+max_dbms/max_processes) + 5; if (FD_SETSIZE < needed ) { fprintf(stderr,"Aborted: Number of select()-able file descriptors too low (FD_SETSIZE)\n"); exit(1); }; if (getrlimit(RLIMIT_NOFILE,&l)==-1) barf("Could not obtain limit of files open\n"); if (l.rlim_cur < needed ) { fprintf(stderr,"Aborted: Resource limit imposes on number of open files too limiting\n"); exit(1); }; #ifndef RDFSTORE_PLATFORM_SOLARIS if (getrlimit(RLIMIT_NPROC,&l)==-1) barf("Could not obtain limit on children\n"); if (l.rlim_cur < 2+max_processes) { fprintf(stderr,"Aborted: Resource limit imposes on number of children too limiting\n"); exit(1); }; #endif if (sysloglog) openlog("dbms",LOG_LOCAL4, LOG_PID | LOG_CONS); if ( (sockfd = socket( AF_INET, SOCK_STREAM, 0))<0 ) barf("Cannot open socket"); if( (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,(const char *)&one,sizeof(one))) <0) barf("Could not set REUSEADDR option"); if( (setsockopt(sockfd,IPPROTO_TCP,TCP_NODELAY,(const void *)&one,sizeof(one))) <0) barf("Could not distable Nagle algoritm"); { int sendbuf = 32 * 1024; int recvbuf = 32 * 1024; if( (setsockopt(sockfd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf))) <0) barf("Could not set sendbuffer size"); if( (setsockopt(sockfd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf))) <0) barf("Could not set sendbuffer size"); } if ( (i=fcntl(sockfd, F_GETFL, 0)<0) || (fcntl(sockfd, F_SETFL,i | O_NONBLOCK)<0) ) barf("Could not make socket non blocking"); bzero( (char *) &server,sizeof(server) ); server.sin_family = AF_INET; server.sin_addr.s_addr = bound; /* Already in network order. */ server.sin_port = htons( port ); if ( (bind( sockfd, ( struct sockaddr *) &server, sizeof (server)))<0 ) barf("Cannot bind server to (lcoal) address."); /* Allow for a que.. */ if ( listen(sockfd,MAX_QUEUE)<0 ) barf("Could not start to listen to my port"); /* fork and detach if ness. */ if (dtch) { #ifdef FORKING pid_t pid; /* fclose(stdin); if (!trace_on) fclose(stdout); */ if ( (pid = fork()) < 0) { perror("Could not fork"); exit(1); } else if (pid != 0) { FILE * fd; if (!(fd=fopen(pid_file,"w"))) { fprintf(stderr,"Warning: Could not write pid file %s:%s",pid_file,strerror(errno)); exit(1); }; fprintf(fd,"%d\n", (int)pid); fclose(fd); exit(0); }; #else fprintf(stderr,"No forking compiled in, no detach\n"); #endif /* become session leader */ if ((mum_pgid = setsid())<0) barf("Could not become session leader"); }; /* XXX security hole.. yes I know... */ if (as_user != NULL) { struct passwd * p = getpwnam( as_user ); uid_t uid; uid = (p == NULL) ? atoi( as_user ) : p->pw_uid; if ( !uid || setuid(uid) ) { perror("Cannot setuid"); exit(0); }; }; #if 0 chdir(my_dir); /* change working directory */ // chroot(my_dir); /* for sanities sake */ umask(0); /* clear our file mode creation mask */ #endif mum_pid = 0; FD_ZERO(&allrset); FD_ZERO(&allwset); FD_ZERO(&alleset); FD_SET(sockfd,&allrset); FD_SET(sockfd,&alleset); maxfd=sockfd; client_list=NULL; dbms_log(L_INFORM,"Waiting for connections"); signal(SIGHUP,dumpie); signal(SIGUSR1,loglevel); signal(SIGUSR2,loglevel); signal(SIGINT,cleandown); signal(SIGQUIT,cleandown); signal(SIGKILL,cleandown); signal(SIGTERM,cleandown); #ifdef FORKING signal(SIGCHLD,childied); #endif mum = NULL; trace("Tracing started\n"); /* for now, SA_RESTART any interupted PIPE calls */ act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); act.sa_flags = SA_RESTART; sigaction(SIGPIPE,&act,&oact); init_cmd_table(); select_loop(); /* get down to handling.. (as the mother) */ return 0; /* keep the compiler happy.. */ }