int main(int argc, char ** argv) { struct swift_context *c = NULL; struct client_options opts; swift_error e; if (!read_options(&opts, argc, argv)) { exit(EXIT_FAILURE); } if (!validate_options(&opts)) { exit(EXIT_FAILURE); } if (opts.filename) { opts.datahandle = setupio(&opts); } else { if (opts.action == ACTION_OBJ_WRITE) { opts.datahandle = stdin; } else { opts.datahandle = stdout; } } if (!opts.datahandle) { exit(EXIT_FAILURE); } swift_init(); e = swift_context_create(&c, opts.url, opts.username, opts.password); if (e) { fprintf(stderr, "Error: %s, line %d\n", swift_errormsg(e), __LINE__); exit(EXIT_FAILURE); } e = execute_action(&opts, c); if (e) { fprintf(stderr, "Error: %s, line %d\n", swift_errormsg(e), __LINE__); exit(EXIT_FAILURE); } swift_context_delete(&c); fclose(opts.datahandle); return 0; }
main(int argc, char **argv) { pthread_attr_t sched_attr; int maxprio, minprio; int go = 1; struct sched_param fifo_param; struct sigaction ignoreChildDeath = {NULL, 0, (SA_NOCLDSTOP | SA_RESTART), NULL}; struct sigaction hupAction = {hupcatch, 0, SA_RESTART, NULL}; struct sigaction termAction = {termcatch, 0, SA_RESTART, NULL}; myName=argv[0]; ch_flag = 0; terminate = 0; fprintf(stderr,"%s daemon start.\n", myName); pthread_attr_init(&sched_attr); pthread_attr_setinheritsched(&sched_attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&sched_attr, /*SCHED_RR */ SCHED_FIFO); maxprio = sched_get_priority_max(SCHED_FIFO); minprio = sched_get_priority_min(SCHED_FIFO); sigaction(SIGCHLD, &ignoreChildDeath, NULL); /*zombie protection */ sigaction(SIGHUP, &hupAction, NULL); sigaction(SIGTERM, &termAction, NULL); if (terminate == TERM_TERM) { go = 0; } else { go = 1; } while (go) { /*The main restart loop */ terminate = 0; /*read config file here */ cfg_read(CONFIG_FILE, "", ""); /* do command line option processing, they override config file opts */ do_opts(argc, argv); if (!foreground) { daemon(); } wxin = serial_open(opts.ttydev); last_write_time = time(NULL); if (wxin > 0) { sane_defaults(); init_db(); if (setupio(wxin) < 0) { errlog(9, "setupio bailed."); } iobuf = make_cbuf(BSIZE); pthread_mutex_init(¤t_obs_lock, pthread_mutexattr_default); pthread_mutex_init(¤t_cal_lock, pthread_mutexattr_default); pthread_mutex_init(&terminate_lock, pthread_mutexattr_default); pthread_mutex_init(&cond_update_lock, pthread_mutexattr_default); pthread_cond_init(&cond_update, pthread_condattr_default); #if USE_CBUF /* fifo_param.sched_priority = (minprio + maxprio) / 2; pthread_attr_setschedparam(&sched_attr, &fifo_param);*/ pthread_create(&reader, /*pthread_attr_default */ NULL, (pthread_startroutine_t) serial_reader, (pthread_addr_t) iobuf); pthread_create(&parser, NULL /*&sched_attr*/, (pthread_startroutine_t) parse_input, (pthread_addr_t) iobuf); #if SCREENOUT pthread_create(&writer, NULL /*&sched_attr*/, (pthread_startroutine_t) screen_writer, (pthread_addr_t) NULL); #else /* Make a db writer thread */ pthread_create(&writer, NULL /*&sched_attr*/, (pthread_startroutine_t) db_writer, (pthread_addr_t) NULL); #endif pthread_join(reader, NULL); pthread_join(parser, NULL); pthread_join(writer, NULL); #else parse_input(iobuf); #endif release_cbuf(iobuf); serial_close(opts.ttydev); if (terminate == TERM_TERM) { errlog1(1, "%s: TERMINATE.", argv[0]); go = 0; } if (terminate == TERM_RESTART) { errlog1(1, "%s: RESTART.", argv[0]); go = 1; } #if SCREENOUT #else db_getout(dbconn); #endif } else { go = 0; errlog2(1, "%s: cannot open serial port: %s", argv[0], opts.ttydev); } } errlog1(1,"%s daemon shutdown.", myName); exit(0); }