+/*
+ * get_cmdline_by_pid
+ *
+ * Get command line from /proc for a specific pid.
+ *
+ * On success, return an allocated string pointer pointing to
+ * the proc cmdline.
+ * On error, return NULL.
+ */
+static char *get_cmdline_by_pid(pid_t pid)
+{
+ int ret;
+ FILE *fp;
+ char *cmdline = NULL;
+ char path[24]; /* Can't go bigger than /proc/65535/cmdline */
+
+ snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ goto end;
+ }
+
+ /* Caller must free() *cmdline */
+ cmdline = malloc(PATH_MAX);
+ ret = fread(cmdline, 1, PATH_MAX, fp);
+ fclose(fp);
+
+end:
+ return cmdline;
+}
+
+/*
+ * validate_options
+ *
+ * Make sure that all options passed to the command line
+ * are compatible with each others.
+ *
+ * On error, return -1
+ * On success, return 0
+ */
+static int validate_options(void)
+{
+ /* Conflicting command */
+ if (opt_start_trace && opt_stop_trace) {
+ ERR("Can't use --start and --stop together.");
+ goto error;
+ /* Must have a session UUID for trace action. */
+ } else if ((opt_session_uuid == NULL) &&
+ (opt_create_trace || opt_start_trace || opt_stop_trace || opt_list_traces)) {
+ ERR("You need to specify a session UUID.\nPlease use --session UUID to do so.");
+ goto error;
+ /* If no PID specified and trace_kernel is off */
+ } else if ((opt_trace_pid == 0 && opt_trace_kernel == 0) &&
+ (opt_create_trace || opt_start_trace || opt_stop_trace)) {
+ ERR("Please specify a PID using -p, --pid PID.");
+ goto error;
+ }
+
+ return 0;
+
+error:
+ return -1;
+}
+