Example #1
0
int main(int argc, char *argv[])
{
	static const char optstr[] = "D:M:";
	int c, args, ret = 0;
	char *device = NULL;
	char *module = NULL;

	while ((c = getopt(argc, argv, optstr)) != -1) {
		switch (c) {
		case 'D':
			device = optarg;
			break;

		case 'M':
			module = optarg;
			break;

		default:
			usage(argv[0]);
			break;
		}
	}

	args = argc - optind;

	fd = util_open(device, module);
	if (fd < 0)
		return 1;

	res = drmModeGetResources(fd);
	if (!res) {
		fprintf(stderr, "Failed to get resources: %s\n",
			strerror(errno));
		ret = 1;
		goto done;
	}

	if (args < 1) {
		listAllProperties();
	} else if (args == 4) {
		ret = setProperty(&argv[optind]);
	} else {
		usage(argv[0]);
		ret = 1;
	}

	drmModeFreeResources(res);
done:
	drmClose(fd);
	return ret;
}
Example #2
0
/**
 * returns record in name file that matches the name id.
 * This has format 
 * id tab name 
 * eg
 * 1\tJohn Doe
 */
char *dbnames_fetch_static(char *key,char *file)
{
    char *result = NULL;
    struct STAT64 st;

    if (util_stat(file,&st) == 0) {
        FILE *f = util_open(file,"rba");
        if (f) {
            result = dbnames_fetch_chop_static(key,f,0,st.st_size);

            chomp(result);

            fclose(f);
        }
    }
    HTML_LOG(1,"dbnames_fetch_chop_static[%s]=[%s]",key,result);

    return result;
}
Example #3
0
static int read_checkfile (
	const char *fname,		// File to read and validate
	UMSDOS_REGISTER &reg,
	int blocksize,
	int length,
	int line_length)
{
	int ret = -1;
	int fd = util_open (fname,O_RDONLY,reg,0);
	if (fd != -1){
		char *buf = (char*)malloc(blocksize);
		if (buf == NULL){
			reg.prterr ("Can't allocate %d bytes\n",blocksize);
		}else{
			ret = 0;
			while (reg.getnberr()==0){
				int readlen = read (fd,buf,blocksize);
				if (readlen <= 0) break;
				for (int j=0; j<readlen; j++,ret++){
					char expected = read_getvalue(ret,line_length);
					if (buf[j] != expected){
						reg.prterr ("Read mismatch"
							" [%d] %d != %d\n"
							,ret,buf[j],expected);
						ret = -1;
						break;
					}
				}
			}
			if (reg.getnberr()==0 && ret != length){
				reg.prterr ("Size mismatch"
					"expected %d, got %d\n"
					,length,ret);
				ret = -1;
			}
			free (buf);
		}
		close (fd);
	}
	return ret;
}
Example #4
0
// Only look at the standard NMT NETWORK media mount points.
void get_mount_points() {
    if (mount_points == NULL) {

        HTML_LOG(0,"getting mount points...");
        mount_points = string_string_hashtable("mount points",16); //let the OS clean this up at the end

        FILE *fp = util_open("/etc/mtab","r");
        if (fp) {
#define BUFSIZE 999
            char buf[BUFSIZE];

            PRE_CHECK_FGETS(buf,BUFSIZE);

            while(fgets(buf,BUFSIZE,fp) != NULL) {

                HTML_LOG(1,"mount[%s]",buf);

                CHECK_FGETS(buf,BUFSIZE);


                char *p = strstr(buf,NETWORK_SHARE);
                if (p) {

#define MAX_SHARE_NAME_LEN 100
                    char share_name[MAX_SHARE_NAME_LEN];
                    char *s = share_name;

                    char *q = p+strlen(NETWORK_SHARE);

                    //seek to end of path skipping escapes.
                    while(*q) {
                       if (*q == '\\' ) {
                          if (isdigit((unsigned char)q[1]) && isdigit((unsigned char)q[2]) && isdigit((unsigned char)q[3])) {
                              // octal
                              int c;
                              q++;
                              if (sscanf(q,"%03o",&c) ) {
                                  q += 3;
                                  *s++ = c;
                              } else {
                                  HTML_LOG(0,"Error parsing octal [%s]",q);
                              }
                          } else if (q[1] == 'x') {
                              // hex
                              int c;
                              q+=2;
                              if (sscanf(q,"%2x",&c) ) {
                                  q += 2;
                                  *s++ = c;
                              } else {
                                  HTML_LOG(0,"Error parsing hex [%s]",q);
                              }

                          } else {
                              // normal escape
                              q++;
                              *s++ = *q++;
                          }
                       } else if (*q == ' ') {
                           break;
                       } else {
                           *s++ = *q++;
                       }
                    }
                    assert(s < share_name + MAX_SHARE_NAME_LEN);
                    *s = '\0';


                    HTML_LOG(0,"mtab share name = [%s]",share_name);

                    set_mount_status(share_name,MOUNT_STATUS_IN_MTAB);
                }

            }
            fclose(fp);
        }
        html_hashtable_dump(0,"mount points",mount_points);
        HTML_LOG(0,"got mount points");
    }
}
Example #5
0
// input host based link
// output ip based link
char *wins_resolve(char *link) {
    char *iplink = NULL;
    static char *nbtscan_outfile = NULL;
    static char *workgroup = NULL;
    static int updated_wins_file=0;

    HTML_LOG(0,"wins_resolve[%s]",link);
    if (workgroup == NULL ) {
       workgroup = setting_val("workgroup");
    }
    HTML_LOG(0,"wins_resolve workgroup[%s]",workgroup);

    if (nbtscan_outfile  == NULL ) {
        ovs_asprintf(&nbtscan_outfile,"%s/conf/wins.txt",appDir());
    }
    HTML_LOG(0,"wins_resolve nbtscan_outfile[%s]",nbtscan_outfile);

    if (!updated_wins_file && ( !exists(nbtscan_outfile) || file_age(nbtscan_outfile) > 60*60*24 ) ) {
        char *cmd;
        int c = cidr(setting_val("eth_netmask"));
        // Avoid scanning too many ips 
        // we can just scan a /21 subnet in about 25 secs.
        if (c < 21 ) c = 21; 
        ovs_asprintf(&cmd,"nbtscan -T 1 %s/%d > '%s/conf/wins.txt' && chown nmt:nmt '%s/conf/wins.txt'",
                setting_val("eth_gateway"),
                c,
                appDir(),appDir());
        if (system(cmd) == 0) {
            updated_wins_file=1;
        } else {
            HTML_LOG(0,"ERROR wins_resolve running [%s]",cmd);
        }
    }

    char *host = link + 6;
    char *hostend = strchr(host,'/');
    *hostend = '\0';


    FILE *fp = util_open(nbtscan_outfile,"r");
    if (fp) {
#define WINS_BUFSIZE 200
        char buf[WINS_BUFSIZE];

        PRE_CHECK_FGETS(buf,WINS_BUFSIZE);

        while(fgets(buf,WINS_BUFSIZE,fp)) {

            CHECK_FGETS(buf,WINS_BUFSIZE);

            HTML_LOG(0,"Check wins %s",buf);
            char *p=NULL;

#define IGNORE_WORKGROUP 1
#ifdef IGNORE_WORKGROUP
            // Ignore the workgroup
            p = strchr(buf,'\\');
            if (p != NULL) {
                p++;
            }
#else
            // Look for host in output of nbtscan (which is run by the catalog process)
            // 1.1.1.1<space>WORKGROUP\host<space>
            if ((p=delimited_substring(buf," ",workgroup,"\\",0,0)) != NULL) {
                p += 1+strlen(workgroup);
            }
#endif
            if (p) {
                if (util_starts_with_ignore_case(p,host) && p[strlen(host)] == ' ' ) {
                    // found it - get ip address from the start.
                    char *sp = strchr(buf,' ');
                    if (sp) {
                        ovs_asprintf(&iplink,"smb://%.*s/%s",sp-buf,buf,hostend+1);
                        break;
                    }
                }
            }
        }
        fclose(fp);
    }

    *hostend = '/';
    HTML_LOG(0,"New ip based link = [%s]",iplink);
    return iplink;
}
Example #6
0
int main(int argc, char **argv)
{
	const char *device = NULL, *module = NULL;
	int c, fd, ret;
	drmVBlank vbl;
	drmEventContext evctx;
	struct vbl_info handler_info;

	opterr = 0;
	while ((c = getopt(argc, argv, optstr)) != -1) {
		switch (c) {
		case 'D':
			device = optarg;
			break;
		case 'M':
			module = optarg;
			break;
		case 's':
			secondary = 1;
			break;
		default:
			usage(argv[0]);
			break;
		}
	}

	fd = util_open(module, device);
	if (fd < 0)
		return 1;

	/* Get current count first */
	vbl.request.type = DRM_VBLANK_RELATIVE;
	if (secondary)
		vbl.request.type |= DRM_VBLANK_SECONDARY;
	vbl.request.sequence = 0;
	ret = drmWaitVBlank(fd, &vbl);
	if (ret != 0) {
		printf("drmWaitVBlank (relative) failed ret: %i\n", ret);
		return -1;
	}

	printf("starting count: %d\n", vbl.request.sequence);

	handler_info.vbl_count = 0;
	gettimeofday(&handler_info.start, NULL);

	/* Queue an event for frame + 1 */
	vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT;
	if (secondary)
		vbl.request.type |= DRM_VBLANK_SECONDARY;
	vbl.request.sequence = 1;
	vbl.request.signal = (unsigned long)&handler_info;
	ret = drmWaitVBlank(fd, &vbl);
	if (ret != 0) {
		printf("drmWaitVBlank (relative, event) failed ret: %i\n", ret);
		return -1;
	}

	/* Set up our event handler */
	memset(&evctx, 0, sizeof evctx);
	evctx.version = DRM_EVENT_CONTEXT_VERSION;
	evctx.vblank_handler = vblank_handler;
	evctx.page_flip_handler = NULL;

	/* Poll for events */
	while (1) {
		struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
		fd_set fds;

		FD_ZERO(&fds);
		FD_SET(0, &fds);
		FD_SET(fd, &fds);
		ret = select(fd + 1, &fds, NULL, NULL, &timeout);

		if (ret <= 0) {
			fprintf(stderr, "select timed out or error (ret %d)\n",
				ret);
			continue;
		} else if (FD_ISSET(0, &fds)) {
			break;
		}

		ret = drmHandleEvent(fd, &evctx);
		if (ret != 0) {
			printf("drmHandleEvent failed: %i\n", ret);
			return -1;
		}
	}

	return 0;
}