static void handle_client (struct arglist *globals) { struct arglist *prefs = arg_get_value (globals, "preferences"); /* Become process group leader and the like ... */ start_daemon_mode (); wait: comm_wait_order (globals); preferences_reset_cache (); ntp_timestamp_scan_starts (globals); attack_network (globals); ntp_timestamp_scan_ends (globals); comm_terminate (globals); if (arg_get_value (prefs, "ntp_keep_communication_alive")) { log_write ("Kept alive connection"); goto wait; } }
int main(int argc, char **argv) { int err = 0; int id2 = 0, c; double yk = 0.0; /* controller output */ int target_tz_index; if (geteuid() != 0) { printf("TMON needs to be run as root\n"); exit(EXIT_FAILURE); } while ((c = getopt_long(argc, argv, "c:dlht:vgz:", opts, &id2)) != -1) { switch (c) { case 'c': no_control = 0; strncpy(ctrl_cdev, optarg, CDEV_NAME_SIZE); break; case 'd': start_daemon_mode(); printf("Run TMON in daemon mode\n"); break; case 't': ticktime = strtod(optarg, NULL); if (ticktime < 1) ticktime = 1; break; case 'l': printf("Logging data to /var/tmp/tmon.log\n"); logging = 1; break; case 'h': usage(); break; case 'v': version(); break; case 'g': debug_on = 1; break; case 'z': target_thermal_zone = strtod(optarg, NULL); break; default: break; } } if (pthread_mutex_init(&input_lock, NULL) != 0) { fprintf(stderr, "\n mutex init failed, exit\n"); return 1; } start_syslog(); if (signal(SIGINT, tmon_sig_handler) == SIG_ERR) syslog(LOG_DEBUG, "Cannot handle SIGINT\n"); if (signal(SIGTERM, tmon_sig_handler) == SIG_ERR) syslog(LOG_DEBUG, "Cannot handle SIGINT\n"); if (probe_thermal_sysfs()) { pthread_mutex_destroy(&input_lock); closelog(); return -1; } initialize_curses(); setup_windows(); signal(SIGWINCH, resize_handler); show_title_bar(); show_sensors_w(); show_cooling_device(); update_thermal_data(); show_data_w(); prepare_logging(); init_thermal_controller(); nodelay(stdscr, TRUE); err = pthread_create(&event_tid, NULL, &handle_tui_events, NULL); if (err != 0) { printf("\ncan't create thread :[%s]", strerror(err)); tmon_cleanup(); exit(EXIT_FAILURE); } /* validate range of user selected target zone, default to the first * instance if out of range */ target_tz_index = zone_instance_to_index(target_thermal_zone); if (target_tz_index < 0) { target_thermal_zone = ptdata.tzi[0].instance; syslog(LOG_ERR, "target zone is not found, default to %d\n", target_thermal_zone); } while (1) { sleep(ticktime); show_title_bar(); show_sensors_w(); update_thermal_data(); if (!dialogue_on) { show_data_w(); show_cooling_device(); } cur_thermal_record++; time_elapsed += ticktime; controller_handler(trec[0].temp[target_tz_index] / 1000, &yk); trec[0].pid_out_pct = yk; if (!dialogue_on) show_control_w(); if (tmon_exit) break; } tmon_cleanup(); return 0; }