int main(const int argc, char * const * argv) { parse_arguments(argc, argv); if (is_server) { run_as_server(); } if (is_client) { run_as_client(); } if (stdin_file_descriptor) fclose(stdin_file_descriptor); if (stdout_file_descriptor) fclose(stdout_file_descriptor); if (stderr_file_descriptor) fclose(stderr_file_descriptor); if (server_hostname) { free (server_hostname); } if (connection_type) { free (connection_type); } return 0; }
int main (int argc, char **argv) { int c = 0; FILE *fp = stdin; char command[MAX_LINE + 1] = {0}; int quit_after_command = ESIF_FALSE; #if defined(ESIF_ATTR_DAEMON) int start_as_server = ESIF_FALSE; int start_with_pipe = ESIF_FALSE; int start_with_log = ESIF_FALSE; #else int start_as_server = ESIF_TRUE; #endif // Init ESIF int rc = chdir(".."); optind = 1; // Rest To 1 Restart Vector Scan while ((c = getopt(argc, argv, "d:f:c:b:nxhq?spl")) != -1) { switch (c) { case 'd': g_dst = (u8)esif_atoi(optarg); break; case 'n': g_autocpc = ESIF_FALSE; break; case 'x': g_format = FORMAT_XML; break; case 'b': g_binary_buf_size = (int)esif_atoi(optarg); break; case 'f': fp = fopen(optarg, "r"); break; case 'c': sprintf(command, "%s", optarg); break; case 'q': quit_after_command = ESIF_TRUE; break; #if defined (ESIF_ATTR_DAEMON) case 's': start_as_server = ESIF_TRUE; break; case 'p': start_with_pipe = ESIF_TRUE; break; case 'l': start_with_log = ESIF_TRUE; break; #endif case 'h': case '?': printf( "EsiF Eco-System Independent Framework Shell\n" "(c) 2013 Intel Corp\n\n" "-d [*id] Set Destination\n" "-f [*filename] Load Filename\n" "-n No Auto CPC Assignment\n" "-x XML Output Data Format\n" "-c [*command] Issue Shell Command\n" "-q Quit After Command\n" "-b [*size] Set Binary Buffer Size\n" #if defined (ESIF_ATTR_DAEMON) "-s Run As Server\n" "-p Use Pipe For Input\n" "-l Use Log For Output\n" #endif "-h or -? This Help\n\n"); exit(0); break; default: break; } } #if defined (ESIF_ATTR_DAEMON) if (start_as_server) { run_as_server(fp, command, quit_after_command); } else { run_as_daemon(start_with_pipe, start_with_log); } #else run_as_server(fp, command, quit_after_command); #endif if (fp && fp != stdin) { fclose(fp); } /* NICE Wait For Worker Thread To Exit */ printf("Waiting For EVENT Thread To Exit...\n"); while (!g_quit2) { esif_ccb_sleep(1); } printf("Errorlevel Returned: %d\n", g_errorlevel); /* Exit ESIF */ esif_uf_exit(); exit(g_errorlevel); }