Example #1
0
// It will return NULL if fault
// The returned string should be freed when no longer needed.
gchar *get_tab_name_with_cmdline(struct Page *page_data)
{
#ifdef DETAIL
	if (page_data)
		g_debug("! Launch get_tab_name_with_cmdline() for tpgid %d", page_data->current_tpgid);
#endif
#ifdef DEFENSIVE
	if (page_data==NULL) return NULL;
#endif
	// if cmdline always be "", don't call get_cmdline(). It always get "".
	if (! vte_fork_cmdline_returned_empty)
	{
		if (page_data->pid_cmdline == NULL) page_data->pid_cmdline = get_cmdline(page_data->pid);
		if (page_data->pid_cmdline == NULL) vte_fork_cmdline_returned_empty = TRUE;
	}

#ifdef OUT_OF_MEMORY
	return NULL;
#endif
	if (page_data->current_tpgid>0)
	{
		gchar *tpgid_cmdline = get_cmdline(page_data->current_tpgid);
		//if ((page_data->pid == page_data->current_tpgid) ||
		//    (compare_strings(page_data->pid_cmdline, tpgid_cmdline, TRUE)))
		if ((page_data->pid == page_data->current_tpgid) ||
		    (tpgid_cmdline && page_data->pid_cmdline &&
		     (! g_str_has_suffix(tpgid_cmdline, page_data->pid_cmdline))))
			return tpgid_cmdline;
		else
		{
			// g_debug("pid = %d, tpgid = %d, pid_cmdline = %s", pid, tpgid, pid_cmdline);
#ifdef DEBUG
			g_message("Got (%s), Trying to reread the /proc/%d/cmdline...",
				  tpgid_cmdline, (gint)page_data->current_tpgid);
#endif
			g_free(tpgid_cmdline);
			// Magic number: we wait for 0.15 sec then reread cmdline again.
			usleep(150000);
			tpgid_cmdline = get_cmdline(page_data->current_tpgid);
#ifdef DEBUG
			g_message("Got (%s) after reread the /proc/%d/cmdline.",
				tpgid_cmdline, (gint)page_data->current_tpgid);
#endif
			return tpgid_cmdline;
		}
	}
	else
		return NULL;
}
Example #2
0
char *get_cmdline_prop(char *prop) {
   static char ret[PROP_SIZE];
   char *retptr = ret;
   char *cmdline = get_cmdline();
   char *cmdptr = cmdline;
   int proplen = strlen(prop);

   // continue until the end terminator
   while (cmdptr && *cmdptr) {      
      // compare the property name
      if (strncasecmp(cmdptr, prop, proplen) == 0) {
         // check for an equals in the expected place
         if (*(cmdptr + proplen) == '=') {
            // skip the equals
            cmdptr += proplen + 1;
            // copy the property value to the return buffer
            while (*cmdptr != ' ' && *cmdptr != '\0') {
               *retptr++ = *cmdptr++;
            }
            *retptr = '\0';
            return ret;
         }
      }
      // Skip to the next property
      cmdptr = index(cmdptr, ' ');
      while (cmdptr && *cmdptr == ' ') {
         cmdptr++;
      }
   }
   return NULL;
}
Example #3
0
static int	check_procname(FILE *f_cmd, FILE *f_stat, const char *procname)
{
	char	*tmp = NULL, *p;
	size_t	l;
	int	ret = SUCCEED;

	if ('\0' == *procname)
		return SUCCEED;

	if (SUCCEED == get_procname(f_stat, &tmp))
	{
		if (0 == strcmp(tmp, procname))
			goto clean;
	}
	else if (SUCCEED == get_cmdline(f_cmd, &tmp, &l))
	{
		if (NULL == (p = strrchr(tmp, '/')))
			p = tmp;
		else
			p++;

		if (0 == strcmp(p, procname))
			goto clean;
	}

	ret = FAIL;
clean:
	zbx_free(tmp);

	return ret;
}
Example #4
0
static int	check_procname(FILE *f_cmd, FILE *f_stat, const char *procname)
{
	char	*tmp = NULL, *p;
	size_t	l;
	int	ret = SUCCEED;

	if ('\0' == *procname)
		return SUCCEED;

	/* process name in /proc/[pid]/status contains limited number of characters */
	if (SUCCEED == cmp_status(f_stat, procname))
		return SUCCEED;

	if (SUCCEED == get_cmdline(f_cmd, &tmp, &l))
	{
		if (NULL == (p = strrchr(tmp, '/')))
			p = tmp;
		else
			p++;

		if (0 == strcmp(p, procname))
			goto clean;
	}

	ret = FAIL;
clean:
	zbx_free(tmp);

	return ret;
}
Example #5
0
static int	check_proccomm(FILE *f_cmd, const char *proccomm)
{
	char	*tmp = NULL;
	size_t	i, l;
	int	ret = SUCCEED;

	if ('\0' == *proccomm)
		return SUCCEED;

	if (SUCCEED == get_cmdline(f_cmd, &tmp, &l))
	{
		for (i = 0, l -= 2; i < l; i++)
			if ('\0' == tmp[i])
				tmp[i] = ' ';

		if (NULL != zbx_regexp_match(tmp, proccomm, NULL))
			goto clean;
	}

	ret = FAIL;
clean:
	zbx_free(tmp);

	return ret;
}
Example #6
0
/* Enter the command-line interface. HEAP is used for the command-line
   buffer. Return only if FOREVER is nonzero and get_cmdline returns
   nonzero (ESC is pushed).  */
void
enter_cmdline (char *heap, int forever)
{
  /* Initialize the data and print a message.  */
  init_cmdline ();
  grub_setjmp (restart_cmdline_env);
  init_page ();
#ifdef SUPPORT_DISKLESS
  print_network_configuration ();
  grub_putchar ('\n');
#endif
  print_cmdline_message (forever);

  while (1)
    {
      struct builtin *builtin;
      char *arg;

      *heap = 0;
      print_error ();
      errnum = ERR_NONE;

      /* Get the command-line with the minimal BASH-like interface.  */
      if (get_cmdline (PACKAGE "> ", heap, 2048, 0, 1))
	return;

      /* If there was no command, grab a new one. */
      if (! heap[0])
	continue;

      /* Find a builtin.  */
      builtin = find_command (heap);
      if (! builtin)
	continue;

      /* If BUILTIN cannot be run in the command-line, skip it.  */
      if (! (builtin->flags & BUILTIN_CMDLINE))
	{
	  errnum = ERR_UNRECOGNIZED;
	  continue;
	}

      /* Invalidate the cache, because the user may exchange removable
	 disks.  */
      buf_drive = -1;

      /* Start to count lines, only if the internal pager is in use.  */
      if (use_pager)
	count_lines = 0;
      
      /* Run BUILTIN->FUNC.  */
      arg = skip_to (1, heap);
      (builtin->func) (arg, BUILTIN_CMDLINE);

      /* Finish the line count.  */
      count_lines = -1;
    }
}
/* Add command line to a process */
int addCommandLine(ProvObjectPtr p_prov, ProcessPtr p_proc, int argc, char** argv)
{
    RecordPtr p_record = ((ProvPtr)p_prov)->p_record;
    IDREF id = (IDREF)p_proc;
    char *cmdline = get_cmdline(argc, argv);
    addAttribute(p_record, id, "ni", NULL, "cmdline", cmdline);
    free(cmdline);
    return(0);
}
Example #8
0
void start(unsigned long a1, unsigned long a2, void *promptr, void *sp)
{
	kernel_entry_t kentry;
	char cmdline[COMMAND_LINE_SIZE];
	unsigned long ft_addr = 0;

	memset(__bss_start, 0, _end - __bss_start);
	memset(&platform_ops, 0, sizeof(platform_ops));
	memset(&dt_ops, 0, sizeof(dt_ops));
	memset(&console_ops, 0, sizeof(console_ops));

	if (platform_init(promptr, _dtb_start, _dtb_end))
		exit();
	if (console_ops.open && (console_ops.open() < 0))
		exit();
	if (platform_ops.fixups)
		platform_ops.fixups();

	printf("\n\rzImage starting: loaded at 0x%p (sp: 0x%p)\n\r",
	       _start, sp);

	prep_kernel(a1, a2);

	/* If cmdline came from zimage wrapper or if we can edit the one
	 * in the dt, print it out and edit it, if possible.
	 */
	if ((strlen(builtin_cmdline) > 0) || console_ops.edit_cmdline) {
		get_cmdline(cmdline, COMMAND_LINE_SIZE);
		printf("\n\rLinux/PowerPC load: %s", cmdline);
		if (console_ops.edit_cmdline)
			console_ops.edit_cmdline(cmdline, COMMAND_LINE_SIZE);
		printf("\n\r");
		set_cmdline(cmdline);
	}

	printf("Finalizing device tree...");
	if (dt_ops.finalize)
		ft_addr = dt_ops.finalize();
	if (ft_addr)
		printf(" flat tree at 0x%lx\n\r", ft_addr);
	else
		printf(" using OF tree (promptr=%p)\n\r", promptr);

	if (console_ops.close)
		console_ops.close();

	kentry = (kernel_entry_t) vmlinux.addr;
	if (ft_addr)
		kentry(ft_addr, 0, NULL);
	else
		/* XXX initrd addr/size should be passed in properties */
		kentry(initrd.addr, initrd.size, promptr);

	/* console closed so printf below may not work */
	printf("Error: Linux kernel returned to zImage boot wrapper!\n\r");
	exit();
}
Example #9
0
/* Given a single connection message, evaluate and process
 * the enclosed proc message.
 */
void dispatch_nl_cn(struct cn_msg *hdr) {
	if (hdr->id.idx != CN_IDX_PROC || hdr->id.val != CN_VAL_PROC)
		return;
	struct proc_event *pe = (struct proc_event *)hdr->data;
	switch (pe->what) {
		case PROC_EVENT_FORK:
			if (!forkflag)
				break;
			if (pe->event_data.fork.child_pid == pe->event_data.fork.child_tgid) {
				/* Regular fork, parent process is the originator */
				printf("Fork %d %d %s\n",
					pe->event_data.fork.parent_pid,
					pe->event_data.fork.child_pid,
					get_cmdline(pe->event_data.fork.child_tgid));
			} else {
				/* Thread fork, thread group leader is the originator */
				if (threadflag)
					printf("Thread %d %d %s\n",
						pe->event_data.fork.child_tgid,
						pe->event_data.fork.child_pid,
						get_cmdline(pe->event_data.fork.child_tgid));
			}
			break;
		case PROC_EVENT_EXEC:
			if (!execflag)
				break;
			if (pe->event_data.exec.process_pid == pe->event_data.exec.process_tgid) {
				/* Thread group leader did an exec */
				printf("Exec - %d %s\n",
					pe->event_data.exec.process_pid,
					get_cmdline(pe->event_data.exec.process_tgid));
			} else {
				/* Subordinate thread did an exec */
				if (threadflag)
					printf("Exec %d %d %s\n",
						pe->event_data.exec.process_tgid,
						pe->event_data.exec.process_pid,
						get_cmdline(pe->event_data.exec.process_tgid));
			}
			break;
	}
}
Example #10
0
static char *prepare_line(struct wdgt *w, struct process *p)
{
	char *tree, state = p->proc->state;
	int offset = 0;
	if (!p) return 0;
	tree = tree_string(tree_root, p->proc);
	if(state == 'S') state = ' ';
	if (show_linenr) 
		offset = snprintf(w->mwin->gbuf, w->mwin->gbsize, "\x6%4d ", p->line + 1);
	if (offset < 0) return "";
	if(show_owner) 
		snprintf(w->mwin->gbuf+offset, w->mwin->gbsize-offset ,"\x3%5d %c%c \x3%-8s \x2%s \x3%s", 
			p->proc->pid, get_state_color(state), 
			state, get_owner_name(proc_pid_uid(p->proc->pid)), tree, 
			get_cmdline(p->proc->pid));
	 else 
		snprintf(w->mwin->gbuf+offset, w->mwin->gbsize-offset,"\x3%5d %c%c \x2%s \x3%s",
			p->proc->pid, get_state_color(state), 
			state, tree, get_cmdline(p->proc->pid));
		
	return w->mwin->gbuf;
}
Example #11
0
static int create_pidfile(void)
{
    /* Note:
     * No O_EXCL: we would happily overwrite stale pidfile from previous boot.
     * No O_TRUNC: we must first try to lock the file, and if lock fails,
     * there is another live abrtd. O_TRUNCing the file in this case
     * would be wrong - it'll erase the pid to empty string!
     */
    int fd = open(VAR_RUN_PIDFILE, O_RDWR|O_CREAT, 0644);
    if (fd >= 0)
    {
        if (lockf(fd, F_TLOCK, 0) < 0)
        {
            perror_msg("Can't lock file '%s'", VAR_RUN_PIDFILE);
            /* should help with problems like rhbz#859724 */
            char pid_str[sizeof(long)*3 + 4];
            int r = full_read(fd, pid_str, sizeof(pid_str));
            close(fd);

            /* File can contain garbage. Be careful interpreting it as PID */
            if (r > 0)
            {
                pid_str[r] = '\0';
                errno = 0;
                long locking_pid = strtol(pid_str, NULL, 10);
                if (!errno && locking_pid > 0 && locking_pid <= INT_MAX)
                {
                    char *cmdline = get_cmdline(locking_pid);
                    if (cmdline)
                    {
                        error_msg("Process %lu '%s' is holding the lock", locking_pid, cmdline);
                        free(cmdline);
                    }
                }
            }

            return -1;
        }
        close_on_exec_on(fd);
        /* write our pid to it */
        char buf[sizeof(long)*3 + 2];
        int len = sprintf(buf, "%lu\n", (long)getpid());
        IGNORE_RESULT(write(fd, buf, len));
        IGNORE_RESULT(ftruncate(fd, len));
        /* we leak opened+locked fd intentionally */
        return 0;
    }

    perror_msg("Can't open '%s'", VAR_RUN_PIDFILE);
    return -1;
}
Example #12
0
File: main.c Project: seazson/zbase
int main(int argc, char * argv[])
{
	int len;
	int list;
	char *p=" ";
	struct ztools_t *cmdtp;
	
	show_menu();
	while(1)	
	{
		printf("============================================\n");
		printf("Enter your cmd : ");	
		len = get_cmdline(console_buffer);
		if(len==-1)
			return 0;
		else if(len==0)
			continue;
		
		printf("You enter %d words : %s\n",len, console_buffer);
		printf("----------------------------------------->>>\n");
		cmd_argv[0] = strtok(console_buffer,p);
		cmd_argc=0;
		while(cmd_argv[(cmd_argc++)+1]=strtok(NULL," "));
		
		if(strcmp(cmd_argv[0],"quit") == 0)
		{
			return 0;
		}
		
	    for (cmdtp = &__ztools_cmd_start; cmdtp != &__ztools_cmd_end; cmdtp++) 
		{
			if(strcmp(cmd_argv[0], cmdtp->name) == 0)
			{
				cmdtp->cmd_func(cmd_argc,cmd_argv);
			}	
		}
	}
	return 0;
}
Example #13
0
Process *get_process(pid_t pid) {
  /* TODO: Add test for invalid pid. Right now, we get a lot of errors and some
   * structure.*/
  Process *retval = (Process *)calloc(1, sizeof(Process));
  unsigned int *uids = NULL;
  unsigned int *gids = NULL;
  retval->pid = pid;
  retval->ppid = get_ppid(pid);
  retval->name = get_procname(pid);
  retval->exe = get_exe(pid);
  retval->cmdline = get_cmdline(pid);
  retval->create_time = get_create_time(pid);
  uids = get_ids(pid, "Uid:");
  if (uids) {
    retval->uid = uids[0];
    retval->euid = uids[1];
    retval->suid = uids[2];
    retval->username =
        get_username(retval->uid); /* Uses real uid and not euid */
  } else {
    retval->uid = retval->euid = retval->suid = 0;
    retval->username = NULL;
  }

  gids = get_ids(pid, "Gid:");
  if (uids) {
    retval->gid = gids[0];
    retval->egid = gids[1];
    retval->sgid = gids[2];
  } else {
    retval->uid = retval->euid = retval->suid = 0;
  }

  retval->terminal = get_terminal(pid);
  free(uids);
  free(gids);
  return retval;
}
Example #14
0
/*
 * Find process by its command line. 
 * 't' is type of operation:
 *  0 - search below cursor only
 *  1 - below but including cursor line
 *  2 - from the beginning
 */
static int  getprocbyname(struct wdgt *w, int t)
{
	struct process *p;
	char *tmp, buf[8];
	int l = w->crsr;
	for(p = begin; p ; p = p->next){
		if(!p->proc) continue;
		if(!t && p->line <= l) continue;
		if(t == 1 && p->line < l) continue;
		/* try the pid first */
		snprintf(buf, sizeof buf, "%d", p->proc->pid);
		if(reg_match(buf)) goto found; //return p->line;
		/* next process owner */
		if(show_owner && reg_match(get_owner_name(p->uid))) 
			goto found; //return p->line;
		tmp = get_cmdline(p->proc->pid);
		if(reg_match(tmp)) goto found; // return p->line;
	}
	return 2;
found:
	scr_crsr_jmp(w, p->line);
	return 1;
}
Example #15
0
Process *
get_process(unsigned pid)
{
  Process *retval = calloc(1, sizeof(Process));
  unsigned int *uids = NULL;
  unsigned int *gids = NULL;
  retval->pid = pid;
  retval->ppid = get_ppid(pid);
  retval->name = get_procname(pid);
  retval->exe = get_exe(pid);
  retval->cmdline = get_cmdline(pid);
  retval->create_time = get_create_time(pid);
  uids = get_ids(pid, "Uid:");
  if (uids) {
    retval->uid = uids[0];
    retval->euid = uids[1];
    retval->suid = uids[2];
    retval->username = get_username(retval->uid); /* Uses real uid and not euid */
  } else {
    retval->uid = retval->euid = retval->suid = 0;
    retval->username = NULL;
  }

  gids = get_ids(pid, "Gid:");
  if (uids) {
    retval->gid = gids[0];
    retval->egid = gids[1];
    retval->sgid = gids[2];
  } else {
    retval->uid = retval->euid = retval->suid = 0;
  }

  retval->terminal = get_terminal(pid);
  if (uids) free(uids);
  if (gids) free(gids);
  return retval;
}
Example #16
0
/* Enter the command-line interface. HEAP is used for the command-line
   buffer. Return only if FOREVER is nonzero and get_cmdline returns
   nonzero (ESC is pushed).  */
void
enter_cmdline (char *heap, int forever)
{
  if (! debug)
      debug++;

  //grub_setjmp (restart_cmdline_env);

  /* Initialize the data and print a message.  */
  current_drive = GRUB_INVALID_DRIVE;
  count_lines = -1;
  kernel_type = KERNEL_TYPE_NONE;
  errnum = 0;
  errorcheck = 1;	/* errorcheck on */
  init_page ();
  grub_putchar ('\n');
#ifdef SUPPORT_DISKLESS
  print_network_configuration ();
  grub_putchar ('\n');
#endif
  print_cmdline_message (forever);
  
  while (1)
    {
      struct builtin *builtin;
      char *arg;
      grub_error_t errnum_old;

      errnum_old = errnum;
      *heap = 0;
      if (errnum && errorcheck)
	print_error ();
      errnum = ERR_NONE;

      /* Get the command-line with the minimal BASH-like interface.  */
      prompt = PACKAGE "> ";
      maxlen = 2048;
      echo_char = 0;
      readline = 1;
      if (get_cmdline (heap))
	{
	  kernel_type = KERNEL_TYPE_NONE;
	  return;
	}

      /* If there was no command, grab a new one. */
      if (! heap[0])
	continue;

      /* Find a builtin.  */
      builtin = find_command (heap);
      if (! builtin)
	continue;

      /* If BUILTIN cannot be run in the command-line, skip it.  */
      if (! (builtin->flags & BUILTIN_CMDLINE))
	{
	  errnum = ERR_UNRECOGNIZED;
	  continue;
	}

      /* Invalidate the cache, because the user may exchange removable
	 disks.  */
      buf_drive = -1;

      /* Start to count lines, only if the internal pager is in use.  */
      if (use_pager)
	count_lines = 0;
      
      if ((builtin->func) == errnum_func || (builtin->func) == checkrange_func)
	errnum = errnum_old;

      /* find && and || */

      for (arg = skip_to (0, heap); *arg != 0; arg = skip_to (0, arg))
      {
	struct builtin *builtin1;
	int ret;
	char *arg1;
	arg1 = arg;
        if (*arg == '&' && arg[1] == '&' && (arg[2] == ' ' || arg[2] == '\t'))
        {
		/* handle the AND operator */
		arg = skip_to (0, arg);
		builtin1 = find_command (arg);
		if (! builtin1 || ! (builtin1->flags & BUILTIN_CMDLINE))
		{
			errnum = ERR_UNRECOGNIZED;
			goto next;
		}

		*arg1 = 0;
		ret = (builtin->func) (skip_to (1, heap), BUILTIN_CMDLINE);
		*arg1 = '&';
		if (ret)
		{
			arg = skip_to (1, arg);
			if ((builtin1->func) != errnum_func && (builtin1->func) != checkrange_func)
				errnum = 0;
			(builtin1->func) (arg, BUILTIN_CMDLINE);
		} else
			errnum = 0;
		goto next;
	} else if (*arg == '|' && arg[1] == '|' && (arg[2] == ' ' || arg[2] == '\t'))
	{
		/* handle the OR operator */
		arg = skip_to (0, arg);
		builtin1 = find_command (arg);
		if (! builtin1 || ! (builtin1->flags & BUILTIN_CMDLINE))
		{
			errnum = ERR_UNRECOGNIZED;
			goto next;
		}

		*arg1 = 0;
		ret = (builtin->func) (skip_to (1, heap), BUILTIN_CMDLINE);
		*arg1 = '|';
		if (! ret)
		{
			arg = skip_to (1, arg);
			if ((builtin1->func) != errnum_func && (builtin1->func) != checkrange_func)
				errnum = 0;
			(builtin1->func) (arg, BUILTIN_CMDLINE);
		} else
			errnum = 0;
		goto next;
	}
      }

	/* Run BUILTIN->FUNC.  */
	arg = (builtin->func) == commandline_func ? heap : skip_to (1, heap);
	(builtin->func) (arg, BUILTIN_CMDLINE);
next:
      /* Finish the line count.  */
      count_lines = -1;
    }
}
Example #17
0
static int pfs_readdir(const char *path,
                       void *buf,
                       fuse_fill_dir_t filler,
                       off_t offset,
                       struct fuse_file_info *fi) {
    (void) offset;
    (void) fi;

    filler(buf, ".", NULL, 0);
    filler(buf, "..", NULL, 0);

    if (strcmp(path, "/") == 0) {
        DIR *dp = opendir ("/proc");
        if (dp != NULL) {
            while (1) {
                struct dirent *dir = readdir (dp);
                if (!dir) {
                    break;
                }

                char proc_path[1024] = { 0, };
                sprintf(proc_path, "/proc/%s", dir->d_name);

                int pid = atoi(dir->d_name);

                struct stat file_stat;
                lstat(proc_path, &file_stat);

                // fill only directories(processes)
                // if result of atoi function is 0, that is invalid file
                if (S_ISDIR(file_stat.st_mode) && pid != 0) {
                    char cmdline[1024] = { 0, };
                    get_cmdline(pid, cmdline);

                    if (strlen(cmdline) == 0) {
                        continue;
                    }

                    int i;
                    for (i = 0; i < strlen(cmdline); i ++) {
                        if (cmdline[i] == '/') {
                            cmdline[i] = '-';
                        }
                    }

                    int offset = 0;
                    if (cmdline[0] == '-') {
                        offset = 1;
                    }

                    // make formatted file name
                    char result[1024] = { 0, };
                    sprintf(result, "%d-%s", pid, cmdline + offset);

                    filler(buf, result, NULL, 0);
                }
            }
            closedir (dp);
        } else {
            return -ENOENT;
        }
    } else {
        return -ENOENT;
    }

    return 0;
}
Example #18
0
/* 
 * Get process group ID of the process which currently owns the tty
 * that the process is connected to and return its command line.
 */
char *get_w(int pid)
{
	struct procinfo p;
	get_info(pid, &p);
        return get_cmdline(p.tpgid);
}
Example #19
0
int main( void )
{
   unsigned char *pCmdline;
   STARTDATA  sd;               /* structure defined in bsedos.h */
   STATUSDATA statusData;
   char      *buffer;
   char      *p1, *p2;
   char      *doscl2;
   ULONG      action;
   BOOL       Done, Done2=FALSE;


  /* Set exception handler for CTRL-C and CTRL-BREAK.                        */
  if ( SIG_ERR==signal(SIGILL, handler )  ||
       SIG_ERR==signal(SIGTERM, handler )  ||
       SIG_ERR==signal(SIGBREAK, handler )  )
     exit(2);

   /* Get a pointer to the command line.                                      */
   pCmdline = get_cmdline( );

   /* Get the executable directory, use it for doscl2.exe */
   p1 = pCmdline + strlen( pCmdline );
   p2 = p1 + 1;
   while ( p1 != pCmdline && *(p1-1) != '\\' && *(p1-1) != '/' ) --p1;

   *p1 = '\0';

   /* Fully qualify doscl2.exe */
   doscl2 = malloc( strlen(pCmdline) + strlen("doscl2.exe") + 1 );
   strcpy( doscl2, pCmdline );
   strcat( doscl2, "doscl2.exe" );

   /* Open a tempfile for doscl2.exe to write and doscl1.exe to read */
   tempfile = tmpnam( NULL );
   if ( (rc=DosOpen( tempfile,
                              &handle,
                              &action,
                              0,
                              FILE_NORMAL,
                              OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
                              OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
                              0 )) != 0 )
     {
     return rc;
     }

   /* Construct the input parameter string to doscl2.exe */
   buffer = malloc( strlen(tempfile) + strlen(p2) + 2 );
   strcpy( buffer, tempfile );
   strcat( buffer, " " );
   strcat( buffer, p2 );

   sd.Length      = 32;
   sd.Related     = SSF_RELATED_CHILD;
   sd.FgBg        = SSF_FGBG_BACK;
   sd.TraceOpt    = SSF_TRACEOPT_NONE;
   sd.PgmTitle    = "WF/2 DOS Client";
   sd.PgmName     = doscl2;
   sd.PgmInputs   = buffer;
   sd.TermQ       = NULL;
   sd.Environment = NULL;
   sd.InheritOpt  = SSF_INHERTOPT_PARENT;
   sd.SessionType = SSF_TYPE_WINDOWEDVDM;

   statusData.Length = 6;
   statusData.SelectInd = 0;
   statusData.SelectInd = 0;

   if (!DosStartSession( &sd, &sess_id, &pid ))
      Done      = FALSE;

   /* Wait for doscl2.exe to finish, keep reading tempfile at the same time */
   while( !Done )
      {
      if ( DosSetSession( sess_id, &statusData ) )
         Done = TRUE;

      DosSleep(5000);

      Done2 = ReadData( handle );
      }

   while ( !Done2 )
      {
      Done2 = ReadData( handle );
      } /* endwhile */

   DosClose( handle );
   DosDelete( tempfile );
   free( doscl2 );
   free( buffer );

   return(rc);
}
Example #20
0
void
get_stats()
{
    DIR *dir = opendir(PROC);
    struct dirent *ent;
    char filename[BUFFERLEN + 1];
    char buffer[BUFFERLEN + 1];

    char value[BUFFERLEN + 1];

    /* Display column headers. */
    if (hr_flag == 1)
        printf("%5s %5s %5s %8s %8s %5s %6s %7s %s\n", "pid", "rchar", "wchar",
               "syscr", "syscw", "reads", "writes", "cwrites", "command");
    else if (kb_flag == 1)
        printf("%5s %8s %8s %8s %8s %8s %8s %8s %s\n", "pid", "rchar", "wchar",
               "syscr", "syscw", "rkb", "wkb", "cwkb", "command");
    else if (mb_flag == 1)
        printf("%5s %8s %8s %8s %8s %8s %8s %8s %s\n", "pid", "rchar", "wchar",
               "syscr", "syscw", "rmb", "wmb", "cwmb", "command");
    else
        printf("%5s %8s %8s %8s %8s %8s %8s %8s %s\n", "pid", "rchar", "wchar",
               "syscr", "syscw", "rbytes", "wbytes", "cwbytes", "command");

    /* Loop through the process table and display a line per pid. */
    while ((ent = readdir(dir)) != NULL)
    {
        int rc;
        int fd;
        int length;

        char *p;
        char *q;

        struct io_node *ion;
        struct io_node *old_ion;

        long long rchar;
        long long wchar;
        long long syscr;
        long long syscw;
        long long read_bytes;
        long long write_bytes;
        long long cancelled_write_bytes;

        if (!isdigit(ent->d_name[0]))
            continue;

        ion = new_ion(ent->d_name);

        if (command_flag == 1)
            rc = get_cmdline(ion);
        if (command_flag == 0 || rc != 0)
            /* If the full command line is not asked for or is empty... */
            rc = get_tcomm(ion);

        if (rc != 0)
        {
            free(ion);
            continue;
        }

        /* Read 'io' file. */
        length = snprintf(filename, BUFFERLEN, "%s/%s/io", PROC, ent->d_name);
        if (length == BUFFERLEN)
            printf("WARNING - filename length may be too big for buffer: %d\n",
                   __LINE__);
        fd = open(filename, O_RDONLY);
        if (fd == -1)
        {
            free(ion);
            continue;
        }
        length = read(fd, buffer, sizeof(buffer) - 1);
        close(fd);
        buffer[length] = '\0';

        /* Parsing the io file data. */
        p = buffer;
        GET_VALUE(ion->rchar);
        GET_VALUE(ion->wchar);
        GET_VALUE(ion->syscr);
        GET_VALUE(ion->syscw);
        GET_VALUE(ion->read_bytes);
        GET_VALUE(ion->write_bytes);
        GET_VALUE(ion->cancelled_write_bytes);

        old_ion = get_ion(ion->pid);

        /* Display the pid's io data. */
        if (old_ion != NULL)
        {
            rchar = ion->rchar - old_ion->rchar;
            wchar = ion->wchar - old_ion->wchar;
            syscr = ion->syscr - old_ion->syscr;
            syscw = ion->syscw - old_ion->syscw;
            read_bytes = ion->read_bytes - old_ion->read_bytes;
            write_bytes = ion->write_bytes - old_ion->write_bytes;
            cancelled_write_bytes = ion->cancelled_write_bytes -
                                    old_ion->cancelled_write_bytes;

            if (kb_flag == 1 && hr_flag == 0)
            {
                rchar = BTOKB(rchar);
                wchar = BTOKB(wchar);
                syscr = BTOKB(syscr);
                syscw = BTOKB(syscw);
                read_bytes = BTOKB(read_bytes);
                write_bytes = BTOKB(write_bytes);
                cancelled_write_bytes = BTOKB(cancelled_write_bytes);
            }
            else if (mb_flag == 1 && hr_flag == 0)
            {
                rchar = BTOMB(rchar);
                wchar = BTOMB(wchar);
                syscr = BTOMB(syscr);
                syscw = BTOMB(syscw);
                read_bytes = BTOMB(read_bytes);
                write_bytes = BTOMB(write_bytes);
                cancelled_write_bytes = BTOMB(cancelled_write_bytes);
            }

            if (!(idle_flag == 1 && rchar == 0 && wchar == 0 && syscr == 0 &&
                    syscw == 0 && read_bytes == 0 && write_bytes == 0 &&
                    cancelled_write_bytes == 0)) {
                if (hr_flag == 0)
                    printf("%5d %8lld %8lld %8lld %8lld %8lld %8lld %8lld %s\n",
                           ion->pid,
                           rchar,
                           wchar,
                           syscr,
                           syscw,
                           read_bytes,
                           write_bytes,
                           cancelled_write_bytes,
                           ion->command);
                else
                    printf("%5d %5s %5s %8lld %8lld %5s %6s %7s %s\n",
                           ion->pid,
                           format_b(rchar),
                           format_b(wchar),
                           syscr,
                           syscw,
                           format_b(read_bytes),
                           format_b(write_bytes),
                           format_b(cancelled_write_bytes),
                           ion->command);
            }
        }
        else if (idle_flag != 1)
            /*
             * No previous data, show 0's instead of calculating negatives
             * only if we are shoring idle processes.
             */
            printf("%5d %8d %8d %8d %8d %8d %8d %8d %s\n",
                   ion->pid, 0, 0, 0, 0, 0, 0, 0, ion->command);

        upsert_data(ion);
    }
    closedir(dir);
    return;
}
Example #21
0
static int get_root_array(char * page, int type, char **start, off_t offset, int length)
{
    switch (type) {
    case PROC_LOADAVG:
        return get_loadavg(page);

    case PROC_UPTIME:
        return get_uptime(page);

    case PROC_MEMINFO:
        return get_meminfo(page);

#ifdef CONFIG_PCI
    case PROC_PCI:
        return get_pci_list(page);
#endif

    case PROC_CPUINFO:
        return get_cpuinfo(page);

    case PROC_VERSION:
        return get_version(page);

#ifdef CONFIG_DEBUG_MALLOC
    case PROC_MALLOC:
        return get_malloc(page);
#endif

#ifdef CONFIG_MODULES
    case PROC_MODULES:
        return get_module_list(page);

    case PROC_KSYMS:
        return get_ksyms_list(page, start, offset, length);
#endif

    case PROC_STAT:
        return get_kstat(page);

    case PROC_DEVICES:
        return get_device_list(page);

    case PROC_INTERRUPTS:
        return get_irq_list(page);

    case PROC_FILESYSTEMS:
        return get_filesystem_list(page);

    case PROC_DMA:
        return get_dma_list(page);

    case PROC_IOPORTS:
        return get_ioport_list(page);
#ifdef CONFIG_BLK_DEV_MD
    case PROC_MD:
        return get_md_status(page);
#endif
#ifdef __SMP_PROF__
    case PROC_SMP_PROF:
        return get_smp_prof_list(page);
#endif
    case PROC_CMDLINE:
        return get_cmdline(page);

    case PROC_MTAB:
        return get_filesystem_info( page );
#ifdef CONFIG_RTC
    case PROC_RTC:
        return get_rtc_status(page);
#endif
    case PROC_LOCKS:
        return get_locks_status(page);
    }
    return -EBADF;
}
Example #22
0
/* A simple example on using the provenance library
*/
int
main(int argc, char **argv, char** envp)
{
    ProvPtr p_prov = newProvenanceFactory("1");
    RecordPtr p_record = p_prov->p_record;
    IDREF id, act_id, used_id, genby_id;
    char arg[50];
    int i;

    addNamespace(p_prov, "https://github.com/INCF/ProvenanceLibrary/wiki/terms", "ni");

    // Add program information
    act_id = newActivity(p_record, NULL, "11/30/11 00:13:20.650432 EST", "11/30/11 00:13:20.650550 EST");
    addAttribute(p_record, act_id, "prov", "xsd:string", "type", "program");
    addAttribute(p_record, act_id, "ni", NULL, "name", argv[0]);
    addAttribute(p_record, act_id, "ni", NULL, "version", version);
    char * cmdline = get_cmdline(argc, argv);
    addAttribute(p_record, act_id, "ni", NULL, "cmdline", cmdline);
    free(cmdline);

    //Add all input parameters. if you use getopt this can be refined further
    for(i=1;i<argc; i++){
        id = newEntity(p_record);
	addAttribute(p_record, id, "prov", "xsd:string", "type", "input");
        sprintf(arg, "arg%d", i);
	addAttribute(p_record, id, NULL, NULL, arg, argv[i]);
	used_id = newUsedRecord(p_record, act_id, id, NULL);
	freeID(used_id);
	freeID(id);
    }

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "environment");
    // add all environment variables
    char** env;
    for (env = envp; *env != 0; env++)
    {
       char* thisEnv = *env;
       char *name;
       char* p_index = thisEnv;
       int pos = 0;
       while (thisEnv[pos++] != '=');
       name = strndup(thisEnv, pos-1);
       if (name[0] != '_')
	   addAttribute(p_record, id, "ni", "xsd:string", name, &thisEnv[pos]);
       free(name);
    }
    freeID(id);

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "runtime");
    // add runtime info such as walltime, cputime, host,
    freeID(id);

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "output:file");
    addAttribute(p_record, id, "ni", NULL, "warped_file", "/full/path/to/file");
    genby_id = newGeneratedByRecord(p_record, id, act_id, NULL);
    freeID(id);
    freeID(genby_id);

    id = newEntity(p_record);
    addAttribute(p_record, id, "prov", "xsd:string", "type", "output:stat");
    addAttribute(p_record, id, "ni", NULL, "pearson_correlation_coefficient", ".234");
    genby_id = newGeneratedByRecord(p_record, id, act_id, NULL);
    freeID(id);
    freeID(genby_id);
    freeID(act_id);

    /* Test i/o manipulations */
    char *buffer;
    int bufsize;
    //print_provenance(p_prov, NULL);
    //fprintf(stdout, "==============\n");
    print_provenance(p_prov, "testprov.xml");
    dumpToMemoryBuffer(p_prov, &buffer, &bufsize);
    delProvenanceFactory(p_prov);
    p_prov = newProvenanceFactoryFromMemoryBuffer(buffer, bufsize);
    freeMemoryBuffer(buffer);
    delProvenanceFactory(p_prov);
    p_prov = newProvenanceFactoryFromFile("testprov.xml");
    ProvPtr p_prov2 = newProvenanceFactory("1");
    addProvAsAccount(p_prov2->p_record, p_prov, NULL);
    print_provenance(p_prov2, NULL);
    print_provenance(p_prov2, "testprov2.xml");
    delProvenanceFactory(p_prov);
    delProvenanceFactory(p_prov2);
    return(0);
}
Example #23
0
/* Create a new problem directory from client session.
 * Caller must ensure that all fields in struct client
 * are properly filled.
 */
static int create_problem_dir(GHashTable *problem_info, unsigned pid)
{
    /* Exit if free space is less than 1/4 of MaxCrashReportsSize */
    if (g_settings_nMaxCrashReportsSize > 0)
    {
        if (low_free_space(g_settings_nMaxCrashReportsSize, g_settings_dump_location))
            exit(1);
    }

    /* Create temp directory with the problem data.
     * This directory is renamed to final directory name after
     * all files have been stored into it.
     */

    gchar *dir_basename = g_hash_table_lookup(problem_info, "basename");
    if (!dir_basename)
        dir_basename = g_hash_table_lookup(problem_info, FILENAME_TYPE);

    char *path = xasprintf("%s/%s-%s-%u.new",
                           g_settings_dump_location,
                           dir_basename,
                           iso_date_string(NULL),
                           pid);

    /* This item is useless, don't save it */
    g_hash_table_remove(problem_info, "basename");

    /* No need to check the path length, as all variables used are limited,
     * and dd_create() fails if the path is too long.
     */
    struct dump_dir *dd = dd_create(path, /*fs owner*/0, DEFAULT_DUMP_DIR_MODE);
    if (!dd)
    {
        error_msg_and_die("Error creating problem directory '%s'", path);
    }

    dd_create_basic_files(dd, client_uid, NULL);
    dd_save_text(dd, FILENAME_ABRT_VERSION, VERSION);

    gpointer gpkey = g_hash_table_lookup(problem_info, FILENAME_CMDLINE);
    if (!gpkey)
    {
        /* Obtain and save the command line. */
        char *cmdline = get_cmdline(pid);
        if (cmdline)
        {
            dd_save_text(dd, FILENAME_CMDLINE, cmdline);
            free(cmdline);
        }
    }

    /* Store id of the user whose application crashed. */
    char uid_str[sizeof(long) * 3 + 2];
    sprintf(uid_str, "%lu", (long)client_uid);
    dd_save_text(dd, FILENAME_UID, uid_str);

    GHashTableIter iter;
    gpointer gpvalue;
    g_hash_table_iter_init(&iter, problem_info);
    while (g_hash_table_iter_next(&iter, &gpkey, &gpvalue))
    {
        dd_save_text(dd, (gchar *) gpkey, (gchar *) gpvalue);
    }

    dd_close(dd);

    /* Not needing it anymore */
    g_hash_table_destroy(problem_info);

    /* Move the completely created problem directory
     * to final directory.
     */
    char *newpath = xstrndup(path, strlen(path) - strlen(".new"));
    if (rename(path, newpath) == 0)
        strcpy(path, newpath);
    free(newpath);

    log_notice("Saved problem directory of pid %u to '%s'", pid, path);

    /* We let the peer know that problem dir was created successfully
     * _before_ we run potentially long-running post-create.
     */
    printf("HTTP/1.1 201 Created\r\n\r\n");
    fflush(NULL);
    close(STDOUT_FILENO);
    xdup2(STDERR_FILENO, STDOUT_FILENO); /* paranoia: don't leave stdout fd closed */

    /* Trim old problem directories if necessary */
    if (g_settings_nMaxCrashReportsSize > 0)
    {
        trim_problem_dirs(g_settings_dump_location, g_settings_nMaxCrashReportsSize * (double)(1024*1024), path);
    }

    run_post_create(path);

    /* free(path); */
    exit(0);
}
Example #24
0
void hd_scan_serial(hd_data_t *hd_data)
{
  hd_t *hd, *hd2;
  serial_t *ser, *next;
  hd_res_t *res, *res2;
  int i;
  char buf[4], *skip_dev[16];
  str_list_t *sl, *cmd;
  unsigned skip_devs = 0;

  if(!hd_probe_feature(hd_data, pr_serial)) return;

  hd_data->module = mod_serial;

  /* some clean-up */
  remove_hd_entries(hd_data);
  hd_data->serial = NULL;

  PROGRESS(1, 0, "read info");

  get_serial_info(hd_data);
  if((hd_data->debug & HD_DEB_SERIAL)) dump_serial_data(hd_data);

  for(i = 0; i < 2; i++) {
    cmd = get_cmdline(hd_data, i == 0 ? "yast2ser" : "console");
    for(sl = cmd; sl; sl = sl->next) {
      if(sscanf(sl->str, "tty%3[^,]", buf) == 1) {
        if(buf[1] == 0) {
          switch(*buf) {
            case 'a': strcpy(buf, "S0"); break;
            case 'b': strcpy(buf, "S1"); break;
          }
        }
        if(skip_devs < sizeof skip_dev / sizeof *skip_dev) {
          skip_dev[skip_devs] = NULL;
          str_printf(&skip_dev[skip_devs++], 0, "/dev/tty%s", buf);
        }
      }
    }
    free_str_list(cmd);
  }

  PROGRESS(2, 0, "build list");

  for(ser = hd_data->serial; ser; ser = ser->next) {
    hd = add_hd_entry(hd_data, __LINE__, 0);
    hd->base_class.id = bc_comm;
    hd->sub_class.id = sc_com_ser;
    hd->prog_if.id = 0x80;
    for(i = 0; (unsigned) i < sizeof ser_names / sizeof *ser_names; i++) {
      if(strstr(ser->name, ser_names[i])) hd->prog_if.id = i;
    }
    hd->device.name = new_str(ser->name);
    hd->func = ser->line;
    if(ser->name && !strcmp(ser->name, "AgereModem")) {
      str_printf(&hd->unix_dev_name, 0, "/dev/ttyAGS%u", ser->line);
    }
    else {
      str_printf(&hd->unix_dev_name, 0, "/dev/ttyS%u", ser->line);
    }
    for(i = 0; i < (int) skip_devs; i++) {
      if(!strcmp(skip_dev[i], hd->unix_dev_name)) {
        hd->tag.skip_mouse = hd->tag.skip_modem = hd->tag.skip_braille = 1;
        break;
      }
    }
    if(ser->device) {
      if(strstr(ser->device, "modem-printer")) {
        hd->tag.ser_device = 1;
      }
      else if(strstr(ser->device, "infrared")) {
         hd->tag.ser_device = 2;
      }
      else if(strstr(ser->device, "modem")) {
         hd->tag.ser_device = 3;
      }
    }
    if(ser->baud) {
      res = add_res_entry(&hd->res, new_mem(sizeof *res));
      res->baud.type = res_baud;
      res->baud.speed = ser->baud;
    }
    res = add_res_entry(&hd->res, new_mem(sizeof *res));
    res->io.type = res_io;
    res->io.enabled = 1;
    res->io.base = ser->port;
    res->io.access = acc_rw;

    res = add_res_entry(&hd->res, new_mem(sizeof *res));
    res->irq.type = res_irq;
    res->irq.enabled = 1;
    res->irq.base = ser->irq;

    /* skip Dell Remote Access Cards - bug #145051 */
    for(hd2 = hd_data->hd; hd2; hd2 = hd2->next) {
      if(
        hd2->vendor.id == MAKE_ID(TAG_PCI, 0x1028) && /* Dell */
        hd2->device.id >= MAKE_ID(TAG_PCI, 0x07) &&
        hd2->device.id <= MAKE_ID(TAG_PCI, 0x12) /* range that covers DRACs */
      ) {
        for(res2 = hd2->res; res2; res2 = res2->next) {
          if(
            res2->any.type == res_io &&
            ser->port >= res2->io.base &&
            ser->port < res2->io.base + res2->io.range
          ) {
            hd->tag.skip_mouse = hd->tag.skip_modem = hd->tag.skip_braille = 1;
          }
        }
      }
    }
  }

  for(ser = hd_data->serial; ser; ser = next) {
    next = ser->next;

    free_mem(ser->name);
    free_mem(ser->device);
    free_mem(ser);
  }
  hd_data->serial = NULL;

#if 0
  if(hd_module_is_active(hd_data, "irda")) {
    hd = add_hd_entry(hd_data, __LINE__, 0); 
    hd->base_class.id = bc_comm;
    hd->sub_class.id = sc_com_ser;
    hd->prog_if.id = 0x80;
    hd->device.name = new_str("IrDA Serial");
    hd->unix_dev_name = new_str("/dev/ircomm0");
  }
#endif
}
Example #25
0
File: main.c Project: texane/aspect
int main(int ac, char** av)
{
  pcm_desc_t desc;
  pcm_handle_t ipcm;
  pcm_handle_t opcm;
  mod_handle_t mod;
  int err;
  cmdline_t cmd;
  size_t i;

  err = -1;

  if (get_cmdline(&cmd, ac - 1, av + 1)) goto on_error_0;

  pcm_init_desc(&desc);
  desc.flags |= PCM_FLAG_IN;
  if (cmd.flags & CMDLINE_FLAG(IPCM)) desc.name = cmd.ipcm;
  if (pcm_open(&ipcm, &desc)) goto on_error_0;

  pcm_init_desc(&desc);
  desc.flags |= PCM_FLAG_OUT;
  if (cmd.flags & CMDLINE_FLAG(OPCM)) desc.name = cmd.opcm;
  if (pcm_open(&opcm, &desc)) goto on_error_1;

  if (mod_open(&mod, 512)) goto on_error_2;

  if (pcm_start(&ipcm)) goto on_error_3;
  if (pcm_start(&opcm)) goto on_error_3;

  signal(SIGINT, on_sigint);

  for (i = 0; is_sigint == 0; i += 1)
  {
    size_t nsampl;
    size_t navail;
    size_t off;

    /* read ipcm */

    err = snd_pcm_wait(ipcm.pcm, -1);
    if (is_sigint) break ;
    if (err < 0) goto on_ipcm_xrun;

    navail = (size_t)snd_pcm_avail_update(ipcm.pcm);

    if (ipcm.wpos >= ipcm.rpos) nsampl = ipcm.nsampl - ipcm.wpos;
    else nsampl = ipcm.rpos - ipcm.wpos;
    if (nsampl > navail) nsampl = navail;

    off = ipcm.wpos * ipcm.scale;
    err = snd_pcm_readi(ipcm.pcm, ipcm.buf + off, nsampl);
    if (err < 0) goto on_ipcm_xrun;

    ipcm.wpos += (size_t)err;
    if (ipcm.wpos == ipcm.nsampl) ipcm.wpos = 0;

    /* apply modifier */

  redo_mod:
    if (ipcm.wpos >= ipcm.rpos) nsampl = ipcm.wpos - ipcm.rpos;
    else nsampl = ipcm.nsampl - ipcm.rpos + ipcm.wpos;

    if (cmd.flags & CMDLINE_FLAG(FILT))
    {
      const size_t n = mod_apply
	(&mod, ipcm.buf, ipcm.nsampl, ipcm.rpos, nsampl);
      nsampl = n;
    }

    if (nsampl == 0) continue ;

    if ((ipcm.rpos + nsampl) > ipcm.nsampl)
    {
      const size_t n = ipcm.nsampl - ipcm.rpos;
      off = ipcm.rpos * ipcm.scale;
      err = snd_pcm_writei(opcm.pcm, ipcm.buf + off, n);
      if (err < 0) goto on_opcm_xrun;
      nsampl -= n;
      ipcm.rpos = 0;
    }

    off = ipcm.rpos * ipcm.scale;
    err = snd_pcm_writei(opcm.pcm, ipcm.buf + off, nsampl);
    if (err < 0) goto on_opcm_xrun;
    ipcm.rpos += nsampl;
    if (ipcm.rpos == ipcm.nsampl) ipcm.rpos = 0;

    goto redo_mod;

    continue ;

  on_ipcm_xrun:
    if (pcm_recover_xrun(&ipcm, err)) PERROR_GOTO("", on_error_2);
    continue ;

  on_opcm_xrun:
    if (pcm_recover_xrun(&opcm, err)) PERROR_GOTO("", on_error_2);
    continue ;
  }

  err = 0;

 on_error_3:
  mod_close(&mod);
 on_error_2:
  pcm_close(&opcm);
 on_error_1:
  pcm_close(&ipcm);
 on_error_0:
  return err;
}
Example #26
0
void dump_useful_info() {
   int i;
   rpi_mailbox_property_t *buf;
   clock_info_t *clk_info;

   rpi_mailbox_tag_t tags[] = {
        TAG_GET_FIRMWARE_VERSION
      , TAG_GET_BOARD_MODEL
      , TAG_GET_BOARD_REVISION
      , TAG_GET_BOARD_MAC_ADDRESS
      , TAG_GET_BOARD_SERIAL
      //, TAG_GET_ARM_MEMORY
      //, TAG_GET_VC_MEMORY
      //, TAG_GET_DMA_CHANNELS
      //, TAG_GET_CLOCKS
      //, TAG_GET_COMMAND_LINE
   };

   char *tagnames[] = {
      "FIRMWARE_VERSION"
      , "BOARD_MODEL"
      , "BOARD_REVISION"
      , "BOARD_MAC_ADDRESS"
      , "BOARD_SERIAL"
      //, "ARM_MEMORY"
      //, "VC_MEMORY"
      //, "DMA_CHANNEL"
      //, "CLOCKS"
      //, "COMMAND_LINE"
   };

   char *clock_names[] = {
      "RESERVED",
      "EMMC",
      "UART",
      "ARM",
      "CORE",
      "V3D",
      "H264",
      "ISP",
      "SDRAM",
      "PIXEL",
      "PWM"
   };

   int n = sizeof(tags) / sizeof(rpi_mailbox_tag_t);

   RPI_PropertyInit();
   for (i = 0; i < n ; i++) {
      RPI_PropertyAddTag(tags[i]);
   }

   RPI_PropertyProcess();
   
   for (i = 0; i < n; i++) {
      buf = RPI_PropertyGet(tags[i]);
      print_tag_value(tagnames[i], buf, 1);
   }

   for (i = MIN_CLK_ID; i <= MAX_CLK_ID; i++) {
      clk_info = get_clock_rates(i);
      printf("%15s_FREQ : %10.3f MHz %10.3f MHz %10.3f MHz\r\n",
             clock_names[i],
             (double) (clk_info->rate)  / 1.0e6,
             (double) (clk_info->min_rate)  / 1.0e6,
             (double) (clk_info->max_rate)  / 1.0e6
         );
   }

   printf("           CORE TEMP : %6.2f °C\r\n", get_temp());
   printf("        CORE VOLTAGE : %6.2f V\r\n", get_voltage(COMPONENT_CORE));
   printf("     SDRAM_C VOLTAGE : %6.2f V\r\n", get_voltage(COMPONENT_SDRAM_C));
   printf("     SDRAM_P VOLTAGE : %6.2f V\r\n", get_voltage(COMPONENT_SDRAM_P));
   printf("     SDRAM_I VOLTAGE : %6.2f V\r\n", get_voltage(COMPONENT_SDRAM_I));

   printf("            CMD_LINE : %s\r\n", get_cmdline());

   printf("               COPRO : %s\r\n", get_cmdline_prop("copro"));

}
Example #27
0
////
// main
//
//   The main function to the shell program.
//
int main (int argc, char **argv) {
   (void) argc;
   
   // variables
   set_execname (argv[0]);
   
   // loop until user exits
   while (TRUE) {   // repeat until user exits the shell
      char cmdline[1025]; // will only accept 1024
      bzero (cmdline, 1025);
      char parsebuffer[2024];
      bzero (parsebuffer, 2024);
      char *tokens[512];
      int toknum = 0;
//      bool pipein = FALSE;
//      bool pipeout = FALSE;
      
      print_prompt();    // print the prompt
      // get up to 1024 chars from the user
      if (get_cmdline (cmdline) == FALSE) continue;
      // break the line into tokens
      if (parseline (cmdline, parsebuffer, tokens, &toknum)) {
         // parseline returned an error
         eprintf ("%s: %s\n", "Error",
                  "parsing error caused by incorrect usage");
         continue;
      }

      // Check if the user wishes to exit the shell
      if (check_exit (tokens, toknum)) exit (get_exitstatus());
      

      // set the number of commands to be executed
      int numcmds = set_numofcmds (tokens, toknum);
      // the number of commands should not exceed 20
      if (numcmds > 20) {
         eprintf ("%s: %s\n", "ERROR", "cannot handle more than 20 commands");
         continue;
      }

      // initialize the current start index of the tokens
      int curstart;
      int nextstart = 0;
      
      int fd[2];
//      int fdin[2];
//      int fdout[2];
      // loop fork-exec for each command
      int i;
      for (i = 0; i < numcmds && nextstart < toknum; ++i) {
         // setup current command, update current start, and determine pipe
         curstart = nextstart;
         char *command = set_command (tokens, toknum, &nextstart);
         // a null command will cause an error
         if (command == NULL || command[0] == '\0') {
            eprintf ("%s: %s\n", "FATAL ERROR", "encountered a null command");
            break;
         }
         // make a new argv
         int newargc = get_newargc (tokens, curstart, nextstart);
         char *newargv[newargc + 1];
         newargv[0] = command;
         newargv[newargc] = NULL;
         int j = 1;
         int k;
         for (k = curstart; k < nextstart && j < newargc; ++k) {
            if (tokens[k][0] == '1') {
               newargv[j] = &tokens[k][1];
               ++j;
            }
         }

/*         // set pipe
         pipeout = checktopipe (tokens, curstart, nextstart);
         if (pipein) {
            fdin[0] = fdout[0];
            fdin[1] = fdout[1];
         }
         if (pipeout) {
            pipe (fdout);
         }
*/       
         // set redirection
         char *input_redirect = get_redirectarg (tokens, curstart, nextstart, '<');
         char *output_redirect = get_redirectarg (tokens, curstart, nextstart, '>');
         if (input_redirect != NULL) {
            // open file and set file descriptor
            fd[0] = open (input_redirect, O_RDONLY, 0755);
         }
         if (output_redirect != NULL) {
            // open file and set file descriptor
            fd[1] = open (output_redirect, O_CREAT | O_WRONLY | O_TRUNC, 0644);
         }


         // fork child process
         int status = 0;
         int pid = fork();
         if (pid != 0) {
            /* this is the PARENT PROCESS */
/*            // write to pipe from parent to child
            if (pipein) {
               close (fdin[0]);
               if (dup2 (fdin[1], STDOUT_FILENO) == -1)
                  eprintf ("%s: %s\n", "ERROR",
                           "could not open and write to pipe from parent to child");
               close (fdin[1]);
               pipein = FALSE;
               
            }
*/
            // wait for any child process to finish
            int waitstatus = waitpid (-1, &status, 0);

/*            // read pipe from child to parent
            if (pipeout) {
               close (fdout[1]);
               if (dup2 (fdout[0], STDIN_FILENO) == -1)
                  eprintf ("%s: %s\n", "ERROR",
                           "could not open and read pipe from child to parent");
               pipein = TRUE;
            }
*/          // close the file descriptors caused by redirection
            // close stdin
            if (input_redirect != NULL) close (fd[0]);
            // close stdout
            if (output_redirect != NULL) close (fd[1]);
            // determine errors
            if (waitstatus == 0) {
               eprintf ("%s: %s\n", "ERROR", "error waiting on child process");
               break;
            }else if (waitstatus == -1) {
               eprintf ("%s: %s\n", "ERROR", "error executing child process");
               break;
            }
            if (status != 0) {
               eprintf ("%s: %s: %s %d\n", "ERROR", command, "exit status of", status);
               break;
            }
         }else {
            /* this is the CHILD PROCESS */
            // set up pipe in from a previous command
/*            if (pipein) {
               close (fdin[1]);
               if (dup2 (fdin[0], STDIN_FILENO) == -1)
                  eprintf ("%s: %s\n", "ERROR",
                           "could not open and write to pipe from child to parent");
               close (fdin[0]);
            }
            // set up pipe out to the next command
            if (pipeout) {
               close (fdout[0]);
               if (dup2 (fdout[1], STDOUT_FILENO) == -1)
                  eprintf ("%s: %s\n", "ERROR",
                           "could not open and write to pipe from child to parent");
            }
*/            
            // set up redirection
            if (input_redirect != NULL) {
               // open file and set file descriptor
               // set file to stdin
               if (dup2 (fd[0], STDIN_FILENO) == -1)
                  eprintf ("%s: %s \"%s\" %s\n", "ERROR", "could not open",
                           input_redirect, "for input redirection");
            }
            if (output_redirect != NULL) {
               // open file and set file descriptor
               // set stdout to file
               if (dup2 (fd[1], STDOUT_FILENO) == -1)
                  eprintf ("%s: %s \"%s\" %s\n", "ERROR", "could not open",
                           output_redirect, "for output redirection");
            }

            // execute the command
            set_exitstatus (execvp (command, newargv));
            // if there was an error executing the command
            eprintf ("%s: %s: %s\n", "ERROR", command, "could not execute");
            return (get_exitstatus());
         }
         
      }

   }
   return get_exitstatus();
}