@@ -94,32 +94,32 @@ static inline void strv_cleanup(char ***strv)
9494#define CMD_SIZE 1024
9595#define MAX_EVENTS 10
9696
97- static bool terminal = false;
97+ static bool opt_terminal = false;
9898static bool opt_stdin = false;
99- static char * cid = NULL ;
100- static char * cuuid = NULL ;
101- static char * runtime_path = NULL ;
102- static char * bundle_path = NULL ;
103- static char * pid_file = NULL ;
104- static bool systemd_cgroup = false;
105- static char * exec_process_spec = NULL ;
106- static bool exec = false;
107- static char * log_path = NULL ;
108- static int timeout = 0 ;
109- static GOptionEntry entries [] =
99+ static char * opt_cid = NULL ;
100+ static char * opt_cuuid = NULL ;
101+ static char * opt_runtime_path = NULL ;
102+ static char * opt_bundle_path = NULL ;
103+ static char * opt_pid_file = NULL ;
104+ static bool opt_systemd_cgroup = false;
105+ static char * opt_exec_process_spec = NULL ;
106+ static bool opt_exec = false;
107+ static char * opt_log_path = NULL ;
108+ static int opt_timeout = 0 ;
109+ static GOptionEntry opt_entries [] =
110110{
111- { "terminal" , 't' , 0 , G_OPTION_ARG_NONE , & terminal , "Terminal" , NULL },
111+ { "terminal" , 't' , 0 , G_OPTION_ARG_NONE , & opt_terminal , "Terminal" , NULL },
112112 { "stdin" , 'i' , 0 , G_OPTION_ARG_NONE , & opt_stdin , "Stdin" , NULL },
113- { "cid" , 'c' , 0 , G_OPTION_ARG_STRING , & cid , "Container ID" , NULL },
114- { "cuuid" , 'u' , 0 , G_OPTION_ARG_STRING , & cuuid , "Container UUID" , NULL },
115- { "runtime" , 'r' , 0 , G_OPTION_ARG_STRING , & runtime_path , "Runtime path" , NULL },
116- { "bundle" , 'b' , 0 , G_OPTION_ARG_STRING , & bundle_path , "Bundle path" , NULL },
117- { "pidfile" , 'p' , 0 , G_OPTION_ARG_STRING , & pid_file , "PID file" , NULL },
118- { "systemd-cgroup" , 's' , 0 , G_OPTION_ARG_NONE , & systemd_cgroup , "Enable systemd cgroup manager" , NULL },
119- { "exec" , 'e' , 0 , G_OPTION_ARG_NONE , & exec , "Exec a command in a running container" , NULL },
120- { "exec-process-spec" , 0 , 0 , G_OPTION_ARG_STRING , & exec_process_spec , "Path to the process spec for exec" , NULL },
121- { "log-path" , 'l' , 0 , G_OPTION_ARG_STRING , & log_path , "Log file path" , NULL },
122- { "timeout" , 'T' , 0 , G_OPTION_ARG_INT , & timeout , "Timeout in seconds" , NULL },
113+ { "cid" , 'c' , 0 , G_OPTION_ARG_STRING , & opt_cid , "Container ID" , NULL },
114+ { "cuuid" , 'u' , 0 , G_OPTION_ARG_STRING , & opt_cuuid , "Container UUID" , NULL },
115+ { "runtime" , 'r' , 0 , G_OPTION_ARG_STRING , & opt_runtime_path , "Runtime path" , NULL },
116+ { "bundle" , 'b' , 0 , G_OPTION_ARG_STRING , & opt_bundle_path , "Bundle path" , NULL },
117+ { "pidfile" , 'p' , 0 , G_OPTION_ARG_STRING , & opt_pid_file , "PID file" , NULL },
118+ { "systemd-cgroup" , 's' , 0 , G_OPTION_ARG_NONE , & opt_systemd_cgroup , "Enable systemd cgroup manager" , NULL },
119+ { "exec" , 'e' , 0 , G_OPTION_ARG_NONE , & opt_exec , "Exec a command in a running container" , NULL },
120+ { "exec-process-spec" , 0 , 0 , G_OPTION_ARG_STRING , & opt_exec_process_spec , "Path to the process spec for exec" , NULL },
121+ { "log-path" , 'l' , 0 , G_OPTION_ARG_STRING , & opt_log_path , "Log file path" , NULL },
122+ { "timeout" , 'T' , 0 , G_OPTION_ARG_INT , & opt_timeout , "Timeout in seconds" , NULL },
123123 { NULL }
124124};
125125
@@ -742,7 +742,7 @@ static void write_sync_fd(int sync_pipe_fd, int res, const char *message)
742742 if (sync_pipe_fd == -1 )
743743 return ;
744744
745- if (exec )
745+ if (opt_exec )
746746 res_key = "exit_code" ;
747747 else
748748 res_key = "pid" ;
@@ -799,26 +799,26 @@ int main(int argc, char *argv[])
799799
800800 /* Command line parameters */
801801 context = g_option_context_new ("- conmon utility" );
802- g_option_context_add_main_entries (context , entries , "conmon" );
802+ g_option_context_add_main_entries (context , opt_entries , "conmon" );
803803 if (!g_option_context_parse (context , & argc , & argv , & error )) {
804804 g_print ("option parsing failed: %s\n" , error -> message );
805805 exit (1 );
806806 }
807807
808- if (cid == NULL )
808+ if (opt_cid == NULL )
809809 nexit ("Container ID not provided. Use --cid" );
810810
811- if (!exec && cuuid == NULL )
811+ if (!opt_exec && opt_cuuid == NULL )
812812 nexit ("Container UUID not provided. Use --cuuid" );
813813
814- if (runtime_path == NULL )
814+ if (opt_runtime_path == NULL )
815815 nexit ("Runtime path not provided. Use --runtime" );
816816
817- if (bundle_path == NULL && !exec ) {
817+ if (opt_bundle_path == NULL && !opt_exec ) {
818818 if (getcwd (cwd , sizeof (cwd )) == NULL ) {
819819 nexit ("Failed to get working directory" );
820820 }
821- bundle_path = cwd ;
821+ opt_bundle_path = cwd ;
822822 }
823823
824824 dev_null_r = open ("/dev/null" , O_RDONLY | O_CLOEXEC );
@@ -829,19 +829,19 @@ int main(int argc, char *argv[])
829829 if (dev_null_w < 0 )
830830 pexit ("Failed to open /dev/null" );
831831
832- if (exec && exec_process_spec == NULL ) {
832+ if (opt_exec && opt_exec_process_spec == NULL ) {
833833 nexit ("Exec process spec path not provided. Use --exec-process-spec" );
834834 }
835835
836- if (pid_file == NULL ) {
836+ if (opt_pid_file == NULL ) {
837837 if (snprintf (default_pid_file , sizeof (default_pid_file ),
838- "%s/pidfile-%s" , cwd , cid ) < 0 ) {
838+ "%s/pidfile-%s" , cwd , opt_cid ) < 0 ) {
839839 nexit ("Failed to generate the pidfile path" );
840840 }
841- pid_file = default_pid_file ;
841+ opt_pid_file = default_pid_file ;
842842 }
843843
844- if (log_path == NULL )
844+ if (opt_log_path == NULL )
845845 nexit ("Log file path not provided. Use --log-path" );
846846
847847 start_pipe = getenv ("_OCI_STARTPIPE" );
@@ -892,7 +892,7 @@ int main(int argc, char *argv[])
892892 }
893893
894894 /* Open the log path file. */
895- logfd = open (log_path , O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC , 0600 );
895+ logfd = open (opt_log_path , O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC , 0600 );
896896 if (logfd < 0 )
897897 pexit ("Failed to open log file" );
898898
@@ -905,7 +905,7 @@ int main(int argc, char *argv[])
905905 pexit ("Failed to set as subreaper" );
906906 }
907907
908- if (terminal ) {
908+ if (opt_terminal ) {
909909 struct sockaddr_un addr = {0 };
910910
911911 /*
@@ -972,38 +972,38 @@ int main(int argc, char *argv[])
972972 slavefd_stderr = fds [1 ];
973973
974974 runtime_argv = g_ptr_array_new ();
975- g_ptr_array_add (runtime_argv , runtime_path );
975+ g_ptr_array_add (runtime_argv , opt_runtime_path );
976976
977977 /* Generate the cmdline. */
978- if (!exec && systemd_cgroup )
978+ if (!opt_exec && opt_systemd_cgroup )
979979 g_ptr_array_add (runtime_argv , "--systemd-cgroup" );
980980
981- if (exec ) {
981+ if (opt_exec ) {
982982 g_ptr_array_add (runtime_argv , "exec" );
983983 g_ptr_array_add (runtime_argv , "-d" );
984984 g_ptr_array_add (runtime_argv , "--pid-file" );
985- g_ptr_array_add (runtime_argv , pid_file );
985+ g_ptr_array_add (runtime_argv , opt_pid_file );
986986 } else {
987987 g_ptr_array_add (runtime_argv , "create" );
988988 g_ptr_array_add (runtime_argv , "--bundle" );
989- g_ptr_array_add (runtime_argv , bundle_path );
989+ g_ptr_array_add (runtime_argv , opt_bundle_path );
990990 g_ptr_array_add (runtime_argv , "--pid-file" );
991- g_ptr_array_add (runtime_argv , pid_file );
991+ g_ptr_array_add (runtime_argv , opt_pid_file );
992992 }
993993
994- if (terminal ) {
994+ if (opt_terminal ) {
995995 g_ptr_array_add (runtime_argv , "--console-socket" );
996996 g_ptr_array_add (runtime_argv , csname );
997997 }
998998
999999 /* Set the exec arguments. */
1000- if (exec ) {
1000+ if (opt_exec ) {
10011001 g_ptr_array_add (runtime_argv , "--process" );
1002- g_ptr_array_add (runtime_argv , exec_process_spec );
1002+ g_ptr_array_add (runtime_argv , opt_exec_process_spec );
10031003 }
10041004
10051005 /* Container name comes last. */
1006- g_ptr_array_add (runtime_argv , cid );
1006+ g_ptr_array_add (runtime_argv , opt_cid );
10071007 g_ptr_array_add (runtime_argv , NULL );
10081008
10091009 /*
@@ -1047,7 +1047,7 @@ int main(int argc, char *argv[])
10471047 close (slavefd_stderr );
10481048
10491049 ninfo ("about to waitpid: %d" , create_pid );
1050- if (terminal ) {
1050+ if (opt_terminal ) {
10511051 guint terminal_watch = g_unix_fd_add (csfd , G_IO_IN , terminal_accept_cb , csname );
10521052 g_child_watch_add (create_pid , runtime_exit_cb , NULL );
10531053 g_main_loop_run (main_loop );
@@ -1058,7 +1058,7 @@ int main(int argc, char *argv[])
10581058 int old_errno = errno ;
10591059 kill (create_pid , SIGKILL );
10601060 errno = old_errno ;
1061- pexit ("Failed to wait for `runtime %s`" , exec ? "exec" : "create" );
1061+ pexit ("Failed to wait for `runtime %s`" , opt_exec ? "exec" : "create" );
10621062 }
10631063 }
10641064
@@ -1077,11 +1077,11 @@ int main(int argc, char *argv[])
10771077 nexit ("Failed to create container: exit status %d" , WEXITSTATUS (runtime_status ));
10781078 }
10791079
1080- if (terminal && masterfd_stdout == -1 )
1080+ if (opt_terminal && masterfd_stdout == -1 )
10811081 nexit ("Runtime did not set up terminal" );
10821082
10831083 /* Read the pid so we can wait for the process to exit */
1084- g_file_get_contents (pid_file , & contents , NULL , & err );
1084+ g_file_get_contents (opt_pid_file , & contents , NULL , & err );
10851085 if (err ) {
10861086 nwarn ("Failed to read pidfile: %s" , err -> message );
10871087 g_error_free (err );
@@ -1095,21 +1095,21 @@ int main(int argc, char *argv[])
10951095 char attach_symlink_dir_path [PATH_MAX ] = { 0 };
10961096 struct sockaddr_un attach_addr = {0 };
10971097
1098- if (!exec ) {
1098+ if (!opt_exec ) {
10991099 attach_addr .sun_family = AF_UNIX ;
11001100
11011101 /*
11021102 * Create a symlink so we don't exceed unix domain socket
11031103 * path length limit.
11041104 */
1105- snprintf (attach_symlink_dir_path , PATH_MAX , "/var/run/crio/%s" , cuuid );
1105+ snprintf (attach_symlink_dir_path , PATH_MAX , "/var/run/crio/%s" , opt_cuuid );
11061106 if (unlink (attach_symlink_dir_path ) == -1 && errno != ENOENT ) {
11071107 pexit ("Failed to remove existing symlink for attach socket directory" );
11081108 }
1109- if (symlink (bundle_path , attach_symlink_dir_path ) == -1 )
1109+ if (symlink (opt_bundle_path , attach_symlink_dir_path ) == -1 )
11101110 pexit ("Failed to create symlink for attach socket" );
11111111
1112- snprintf (attach_sock_path , PATH_MAX , "/var/run/crio/%s/attach" , cuuid );
1112+ snprintf (attach_sock_path , PATH_MAX , "/var/run/crio/%s/attach" , opt_cuuid );
11131113 ninfo ("attach sock path: %s" , attach_sock_path );
11141114
11151115 strncpy (attach_addr .sun_path , attach_sock_path , sizeof (attach_addr .sun_path ) - 1 );
@@ -1137,8 +1137,8 @@ int main(int argc, char *argv[])
11371137 /* Setup fifo for reading in terminal resize and other stdio control messages */
11381138 _cleanup_close_ int ctlfd = -1 ;
11391139 _cleanup_close_ int dummyfd = -1 ;
1140- if (!exec ) {
1141- snprintf (ctl_fifo_path , PATH_MAX , "%s/ctl" , bundle_path );
1140+ if (!opt_exec ) {
1141+ snprintf (ctl_fifo_path , PATH_MAX , "%s/ctl" , opt_bundle_path );
11421142 ninfo ("ctl fifo path: %s" , ctl_fifo_path );
11431143
11441144 if (mkfifo (ctl_fifo_path , 0666 ) == -1 )
@@ -1160,7 +1160,7 @@ int main(int argc, char *argv[])
11601160 }
11611161
11621162 /* Send the container pid back to parent */
1163- if (!exec ) {
1163+ if (!opt_exec ) {
11641164 write_sync_fd (sync_pipe_fd , cpid , NULL );
11651165 }
11661166
@@ -1215,8 +1215,8 @@ int main(int argc, char *argv[])
12151215 g_unix_fd_add (ctlfd , G_IO_IN , ctrl_cb , NULL );
12161216 }
12171217
1218- if (timeout > 0 ) {
1219- g_timeout_add_seconds (timeout , timeout_cb , NULL );
1218+ if (opt_timeout > 0 ) {
1219+ g_timeout_add_seconds (opt_timeout , timeout_cb , NULL );
12201220 }
12211221 g_main_loop_run (main_loop );
12221222
@@ -1242,7 +1242,7 @@ int main(int argc, char *argv[])
12421242 }
12431243 }
12441244
1245- if (!exec ) {
1245+ if (!opt_exec ) {
12461246 _cleanup_free_ char * status_str = NULL ;
12471247 ret = asprintf (& status_str , "%d" , exit_status );
12481248 if (ret < 0 ) {
0 commit comments