static int proxy_traffic() { #define _DIE(label, msg, ...) do { \ fprintf(stderr, msg, ##__VA_ARGS__); \ rval = EXIT_FAILURE; \ goto label; \ } while (0) int rval = EXIT_SUCCESS; if (get_socket() < 0) _DIE(exit, "Socket initialization failure!\n"); if (!(pkt_queue = minq_new(pkt_slot_cmp))) _DIE(sfd, "Cannot create priority queue!\n"); /* Process incoming traffic until error (or forever) */ if ((rval = proxy_loop())) _DIE(queue, "The proxy loop crashed, " "had %zu element(s) left in pkt_queue\n", minq_size(pkt_queue)); queue: minq_del(pkt_queue); sfd: close(sfd); exit: return rval; #undef _DIE }
int main(int argc, char* argv[]) { int rc; /* drop privileges */ if (drop_privs() < 0) return EXIT_FAILURE; /* parse arguments */ parse_args(argc, argv); /* initialize secure storage directory */ rc = storage_init(ss_data_root); if (rc < 0) return EXIT_FAILURE; /* open rpmb device */ rc = rpmb_open(rpmb_devname, dev_type); if (rc < 0) return EXIT_FAILURE; /* connect to Trusty secure storage server */ rc = ipc_connect(trusty_devname, ss_srv_name); if (rc < 0) return EXIT_FAILURE; /* enter main loop */ rc = proxy_loop(); ALOGE("exiting proxy loop with status (%d)\n", rc); ipc_disconnect(); rpmb_close(); return (rc < 0) ? EXIT_FAILURE : EXIT_SUCCESS; }