/* * Read in from stdin and run MD5 on the input */ static void read_file(const char *filename) { unsigned char sig[MD5_SIZE]; char buffer[4096]; md5_t md5; int ret; FILE *stream; if (strcmp(filename, "-") == 0) { stream = stdin; } else { stream = fopen(filename, "r"); if (stream == NULL) { perror(filename); exit(1); } } md5_init(&md5); /* iterate over file */ while (1) { /* read in from our file */ ret = fread(buffer, sizeof(char), sizeof(buffer), stream); if (ret <= 0) break; /* process our buffer buffer */ md5_process(&md5, buffer, ret); } md5_finish(&md5, sig); if (stream != stdin) { (void)fclose(stream); } (void)printf("%25s '", "Resulting signature:"); print_sig(sig); (void)printf("'\n"); /* convert to string to print */ md5_sig_to_string(sig, buffer, sizeof(buffer)); (void)printf("%25s '%s'\n", "Results of md5_to_string:", buffer); /* now we convert it from string back into the sig */ md5_sig_from_string(sig, buffer); (void)printf("%25s '", "After md5_from_string:"); print_sig(sig); (void)printf("'\n"); }
void sighandler(int sig){ message_t msgsnd, msgrcv; printf("\ncompute get signal "); print_sig(sig); msgsnd.type= CEND; msgsnd.id= getpid(); msgsnd.data= (finished= TRUE? n: n-1); if(my_send(fds, &msgsnd, sizeof(message_t), 0)== -1){ fprintf(stderr, "my_send\n"); close(fds); exit(EXIT_FAILURE); } if(my_recv(fds, &msgrcv, sizeof(message_t), 0)== -1){ fprintf(stderr, "my_recv\n"); close(fds); exit(EXIT_FAILURE); } if(msgrcv.type!= CEND){ fprintf(stderr, "unexpected type\n"); close(fds); exit(EXIT_FAILURE); } close(fds); exit(EXIT_SUCCESS); }
int main() { signal(2, handler); sigset_t s, p, o; sigemptyset(&s); sigemptyset(&o); sigaddset(&s, SIGINT); sigprocmask(SIG_SETMASK, &s, &o); int count = 0; while(1) { sigemptyset(&p); sigpending(&p); print_sig(&p); sleep(1); if(count++ == 10) { sigprocmask(SIG_SETMASK, &o, NULL); printf("recover block\n"); sleep(3); } } return 0; }
void handler(int signo){ int i; printf("\nenter manage handler\n"); print_sig(signo); // loop and find active compute processes, no need a queue to keep track for(i=0; i< NUM_PROC; i++){ if(seg->proc[i].pid !=(pid_t)0){ kill(seg->proc[i].pid, SIGINT); printf("\n send signal to compute process: %d\n", seg->proc[i].pid); } } sleep(5); shmdt((void*)seg); struct shmid_ds ds; shmctl(shmid, IPC_STAT, &ds); printf("nattch before calling rm: %ld\n", ds.shm_nattch); if(shmctl(shmid, IPC_RMID, NULL)== -1){ perror("shmctl rm"); exit(EXIT_FAILURE); } if(msgctl(msqid, IPC_RMID, NULL)== -1){ perror("msgctl rm"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
void jl_type_infer(jl_lambda_info_t *li, jl_tuple_t *argtypes, jl_lambda_info_t *def) { int last_ii = jl_in_inference; jl_in_inference = 1; if (jl_typeinf_func != NULL) { // TODO: this should be done right before code gen, so if it is // interrupted we can try again the next time the function is // called assert(li->inInference == 0); li->inInference = 1; jl_value_t *fargs[4]; fargs[0] = (jl_value_t*)li; fargs[1] = (jl_value_t*)argtypes; fargs[2] = (jl_value_t*)jl_null; fargs[3] = (jl_value_t*)def; #ifdef TRACE_INFERENCE ios_printf(ios_stderr,"inference on %s(", li->name->name); print_sig(argtypes); ios_printf(ios_stderr, ")\n"); #endif #ifdef ENABLE_INFERENCE jl_value_t *newast = jl_apply(jl_typeinf_func, fargs, 4); li->ast = jl_tupleref(newast, 0); li->inferred = jl_true; #endif li->inInference = 0; } jl_in_inference = last_ii; }
// if signal comes before report send out request, shall report send terminate msg? void handler(int sig){ printf("\nenter report handler\n"); print_sig(sig); message_t msgsnd; msgsnd.id= getpid(); msgsnd.type= (flag==TRUE? RKILL: REPORT); if(my_send(fds, &msgsnd, sizeof(message_t), 0)!= sizeof(message_t)){ exit(EXIT_FAILURE); } close(fds); exit(EXIT_SUCCESS); }
static void print_sig(jl_tuple_t *type) { size_t i; for(i=0; i < type->length; i++) { if (i > 0) ios_printf(ios_stderr, ", "); jl_value_t *v = jl_tupleref(type,i); if (jl_is_tuple(v)) { ios_putc('(', ios_stderr); print_sig((jl_tuple_t*)v); ios_putc(')', ios_stderr); } else { ios_printf(ios_stderr, "%s", type_summary(v)); } } }