Example #1
0
File: util.c Project: demo4sc/patch
void import_kernel_cmdline(int in_qemu,
                           void (*import_kernel_nv)(char *name, int in_qemu))
{
    char cmdline[1024];
    char *ptr;
    int fd;

    fd = open("/proc/cmdline", O_RDONLY);
    if (fd >= 0) {
        int n = read(fd, cmdline, 1023);
        if (n < 0) n = 0;

        /* get rid of trailing newline, it happens */
        if (n > 0 && cmdline[n-1] == '\n') n--;

        cmdline[n] = 0;
        close(fd);
    } else {
        cmdline[0] = 0;
    }

    ptr = cmdline;
    while (ptr && *ptr) {
        char *x = strchr(ptr, ' ');
        if (x != 0) *x++ = 0;
        import_kernel_nv(ptr, in_qemu);
        ptr = x;
    }
}
Example #2
0
static void import_kernel_cmdline(int in_qemu)
{
    char cmdline[1024];
    char *ptr;
    int fd;

    fd = open("/proc/cmdline", O_RDONLY);
    if (fd >= 0) {
        int n = read(fd, cmdline, 1023);
        if (n < 0) n = 0;

        /* get rid of trailing newline, it happens */
        if (n > 0 && cmdline[n-1] == '\n') n--;

        cmdline[n] = 0;
        close(fd);
    } else {
        cmdline[0] = 0;
    }

    ptr = cmdline;
    while (ptr && *ptr) {
        char *x = strchr(ptr, ' ');
        if (x != 0) *x++ = 0;
        import_kernel_nv(ptr, in_qemu);
        ptr = x;
    }

        /* don't expose the raw commandline to nonpriv processes */
    chmod("/proc/cmdline", 0440);
}
/*
 * import_kernel_cmdline: get parameters from cmdline and initialize
 * corresponding loble variables. 
 * If you want use parameters in cmdline, you needn't change this funiton,
 * you should check wether import_kernel_nv() has parsed the parameter, if not,
 * add the parsing in import_kernel_nv(). 
 * Return value: void
 * Side effect : none
 */
void import_kernel_cmdline(void)
{
    char cmdline[512];
    char *ptr;
    
	printk(KERN_INFO "%s\n", __func__);

    memcpy(cmdline, saved_command_line, strlen(saved_command_line));

    ptr = cmdline;
    while (ptr && *ptr) {
        char *x = strchr(ptr, ' ');
        if (x != 0) *x++ = 0;
        import_kernel_nv(ptr);
        ptr = x;
    }
        
    printk(KERN_INFO "cmdline sb_serial=%s,usb_pid_index=%d\n", usb_para_data.usb_para.usb_serial,
            usb_para_data.usb_para.usb_pid_index);
    
    printk(KERN_INFO "cmdline vendor=%s,country=%s\n", usb_para_data.vender_para.vender_name,
            usb_para_data.vender_para.country_name);
}